Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove CHAR_INFO munging for raster fonts #17681

Merged
merged 2 commits into from
Aug 13, 2024
Merged

Conversation

lhecker
Copy link
Member

@lhecker lhecker commented Aug 7, 2024

RealUnicodeToFalseUnicode was described as:

This routine converts a unicode string into the correct characters
for an OEM (cp 437) font. This code is needed because the gdi glyph
mapper converts unicode to ansi using codepage 1252 to index font.
This is how the data is stored internally.

In other words, it takes a UCS2 string, translates it to the current
codepage and translates it back to UCS2 in the US version of Windows.
In the "eastern" DBCS version it "reinterprets" the DBCS string as
CP_USA (a particularly weird quirk).

The original implementation used to do this translation at every
opportunity where text went into or out of conhost.
The translation was weird, but it was consistent.
In Windows 10 RS1 conhost got a new UCS2-aware text buffer and
this translation was removed from most places, as the text buffer
was converted to store proper UCS2. This broke the entire concept
of the translation though. Whatever data you previously wrote with
something like WriteConsoleOutputCharacter now came back with
something entirely else via ReadConsoleOutput.

In other words, I believe past RS1 there was technically never any
point in "munging" CHAR_INFOs, as this only covered 2 API functions.

Still, this does mean that this PR represents an API breaking change.
It's a minor one though, because it only affects 2 API functions.
And more importantly, it's a necessary breaking change as we move
further and further away from correlating codepoint and column counts.

Validation Steps Performed

  • Remaining tests pass ✅

@lhecker lhecker added Product-Conhost For issues in the Console codebase Area-Output Related to output processing (inserting text into buffer, retrieving buffer text, etc.) labels Aug 7, 2024
Copy link
Member

@DHowett DHowett left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sure you note it in https://github.com/microsoft/terminal/wiki/Console:-Potential-Breaking-Changes

Love this cleanup work. Thanks!

{
// When written with WriteConsoleOutputW and read back with ReadConsoleOutputW when the font is Raster,
// we will get a deduplicated set of Unicode characters with no lead/trailing markings and space padded at the end...
// ... except something weird happens with truncation (TODO figure out what)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yikes

@lhecker
Copy link
Member Author

lhecker commented Aug 8, 2024

Given that I was wrong in my initial PR description, I've done some more & better due diligence:

image

This essentially uses WriteConsole as a test. The test string is:

*カキクケコ*ガギグゲゴ*サシスセソ*ザジズゼゾ*タチツテト*ダヂヅデド*ハヒフヘホ*バビブベボ*パピプペポ*
{カキクケコ}
(カキクケコ)
[カキクケコ]
【カキクケコ】
「カキクケコ」
『カキクケコ』
〝カキクケコ〟
 ⟨カキクケコ⟩

This basically shows what I meant with that "munging" was removed from anything but these two CHAR_INFO APIs. I believe this means we've already done a significant breaking change in the past and I think it's fine to break the remaining 10% as well. This does run the risk of breaking an old application, but it at least means that the behavior is consistent and predictable across all APIs.

I'm considering writing some additional tests to run on each version, but merely looking at the code I know that any version past the first one lacks support for the Unicode "falsification" and it's certainly not in our main branch right now either.

Copy link
Member

@carlos-zamora carlos-zamora left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work!

@DHowett DHowett merged commit 0fd8dc5 into main Aug 13, 2024
20 checks passed
@DHowett DHowett deleted the dev/lhecker/igfw-munging branch August 13, 2024 23:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Output Related to output processing (inserting text into buffer, retrieving buffer text, etc.) Product-Conhost For issues in the Console codebase this-will-be-a-breaking-change
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants