Skip to content

Commit

Permalink
WinCon display : if we hit a 'dummy next to fullwidth' character, we …
Browse files Browse the repository at this point in the history
…skip it and end the packet, restarting at the next character location. This ensures that the column will advance correctly, both in Win10 and Win11 (where a fullwidth character advances by two columns by default) or in older forks of Windows (where all characters advance by one column, no matter what).
  • Loading branch information
Bill-Gray committed Jun 2, 2023
1 parent 1a8ace4 commit fac87bd
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions wincon/pdcdisp.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ static void _set_ansi_color(short f, short b, attr_t attr)
const chtype MAX_UNICODE = 0x10ffff;
const chtype DUMMY_CHAR_NEXT_TO_FULLWIDTH = 0x110000;

#define IS_SUPPLEMENTAL_MULTILINGUAL_PLANE( c) ((c) & 0x1f0000)
#endif

static void _show_run_of_ansi_characters( const attr_t attr,
Expand Down Expand Up @@ -181,7 +182,7 @@ static void _show_run_of_ansi_characters( const attr_t attr,
ch &= A_CHARTEXT;
if( ch <= MAX_UNICODE)
{
if (ch & 0x1F0000)
if( IS_SUPPLEMENTAL_MULTILINGUAL_PLANE( ch))
{
buffer[n_out++] = (WCHAR)((ch - 0x10000) >> 10 | 0xD800); /* first UTF-16 unit */
buffer[n_out++] = (WCHAR)(ch & 0x3FF) | 0xDC00; /* second UTF-16 unit */
Expand Down Expand Up @@ -243,7 +244,7 @@ static void _show_run_of_nonansi_characters( attr_t attr,
ch &= A_CHARTEXT;
if( ch <= MAX_UNICODE)
{
if (ch & 0x1F0000)
if( IS_SUPPLEMENTAL_MULTILINGUAL_PLANE( ch))
{
buffer[n_out++].Char.UnicodeChar = (WCHAR)((ch - 0x10000) >> 10 | 0xD800); /* first UTF-16 unit */
buffer[n_out].Attributes = mapped_attr;
Expand Down Expand Up @@ -274,8 +275,23 @@ static void _new_packet( attr_t attr, const int lineno,
{
int fore, back;
bool blink, ansi;
#ifdef PDC_WIDE
int i = 0;
#endif

assert( len >= 0);
#ifdef PDC_WIDE
while( i < len && MAX_UNICODE >= (srcp[i] & A_CHARTEXT))
i++;
if( i < len)
{
_new_packet( attr, lineno, x, i, srcp);
i++; /* skip the 'dummy' character */
srcp += i;
x += i;
len -= i;
}
#endif
while( len > MAX_PACKET_SIZE)
{
_new_packet( attr, lineno, x, MAX_PACKET_SIZE, srcp);
Expand Down

3 comments on commit fac87bd

@GitMensch
Copy link
Collaborator

Choose a reason for hiding this comment

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

That seems relevant for HISTORY.md, no?

@Bill-Gray
Copy link
Owner Author

Choose a reason for hiding this comment

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

I felt that it fell in the general category of 'WinCon: supports full Unicode output including SMP", and listed this commit under that bullet point in HISTORY.md. If I confirm that the combining character fix also works, I'll commit it and change that line to say "WinCon: supports full Unicode output including SMP, fullwidth characters, and combining characters".

But I don't expect to say anything in HISTORY.md about the details of how we got those things to work. Generally speaking, comments on implementation details have gone into the commit messages (as here), or as comments within the code.

@GitMensch
Copy link
Collaborator

@GitMensch GitMensch commented on fac87bd Jun 3, 2023 via email

Choose a reason for hiding this comment

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

Please sign in to comment.