Skip to content

Commit

Permalink
Provides full unicode output for wincon
Browse files Browse the repository at this point in the history
Windows API requires a sequence of UTF-16 encoded wchars. This commit identifies whether a Unicode codepoint is above 0xFFFF and, in that case, encodes them into UTF-16 before passing it to windows API.
  • Loading branch information
okibcn authored and Bill-Gray committed May 9, 2023
1 parent 07ecb7b commit 3ec63c9
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions wincon/pdcdisp.c
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,14 @@ static void _show_run_of_ansi_characters( const attr_t attr,
ch = ' ';

#ifdef PDC_WIDE
if( (ch & A_CHARTEXT) != DUMMY_CHAR_NEXT_TO_FULLWIDTH)
buffer[n_out++] = (WCHAR)( ch & A_CHARTEXT);
chtype uc = ch & A_CHARTEXT; //o//
if( uc != DUMMY_CHAR_NEXT_TO_FULLWIDTH){
if (uc & 0xFF0000){
buffer[n_out++] = (WCHAR)((uc - 0x10000) >> 10 | 0xD800); /* first UTF-16 unit */
buffer[n_out++] = (WCHAR)(uc & 0x3FF) | 0xDC00; /* second UTF-16 unit */
}else
buffer[n_out++] = (WCHAR)( ch & A_CHARTEXT);
}
#else
buffer[n_out++] = (char)( ch & A_CHARTEXT);
#endif
Expand Down

0 comments on commit 3ec63c9

Please sign in to comment.