mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-01-09 17:38:00 +00:00
Support Unicode flag glyphs in terminal.c (works in GTK).
This is the only one of the newly added cases in test/utf8.txt which I can (try to) fix unilaterally just by changing PuTTY's display code, because it doesn't change the number of character cells occupied by the text, only the appearance of those cells. In this commit I make the necessary changes in terminal.c, which makes flags start working in GTK PuTTY and pterm, but not on Windows. The system of encoding flags in Unicode is that there's a space of 26 regional-indicator letter code points (U+1F1E6 to U+1F1FF inclusive) corresponding to the unaccented Latin alphabet, and an adjacent pair of those letters represents the flag associated with that two-letter code (usually a nation, although at least one non-nation pair exists, namely EU). There are two plausible ways we could handle this in terminal.c: (a) leave the regional indicators as they are in the internal data model, so that each RI letter occupies its own character cell, and at display time have do_paint() spot adjacent pairs of them and send each pair to the frontend as a combined glyph. (b) combine the pairs _in_ the internal data model, by special-casing them in term_display_graphic_char(). This choice makes a semantic difference. What if a flag is displayed in the terminal and something overprints one of its two character cells? With option (a), overprinting one cell of an RI pair with a different RI letter would change it into a different flag; with option (b), flags behave like any other wide character, in that overprinting one of the two cells blanks the other as a side effect. I think we need (a), because not all terminal redraw systems (curses-style libraries) will understand the Unicode flag glyph system at all. So if a full-screen application genuinely wants to do a screen redraw in which a flag changes to a different flag while keeping one of its constituent letters the same (say, swapping between BA and CA, or between AC and AD), then the redraw library might very well implement that screen update by redrawing only the changed letter, and we need not to corrupt the flag. All of this is now implemented in terminal.c. The effect is that pairs of RI characters are passed to the TermWin draw_text() method as if they were a wide character with a combining mark: that is, you get a two-character (or four-surrogate) string, with TATTR_COMBINING indicating that it represents a single glyph, and ATTR_WIDE indicating that that glyph occupies two character cells rather than one. In GTK, that's enough to make flag display Just Work. But on Windows (at least the Win10 machine I have to test on), that doesn't make flags start working all by itself. But then, the rest of the new emoji tests also look a bit confused on Windows too. Help would be welcome from someone who knows how Windows emoji display is supposed to work!
This commit is contained in:
parent
640c7028f8
commit
b6ef4f18d5
3
putty.h
3
putty.h
@ -2701,6 +2701,9 @@ Socket *platform_start_subprocess(const char *cmd, Plug *plug,
|
||||
#define LOW_SURROGATE_END 0xdfff
|
||||
#endif
|
||||
|
||||
/* REGIONAL INDICATOR SYMBOL LETTER A-Z */
|
||||
#define IS_REGIONAL_INDICATOR_LETTER(wc) ((unsigned)(wc) - 0x1F1E6U < 26)
|
||||
|
||||
/* These macros exist in the Windows API, so the environment may
|
||||
* provide them. If not, define them in terms of the above. */
|
||||
#ifndef IS_HIGH_SURROGATE
|
||||
|
@ -5998,6 +5998,10 @@ static void do_paint_draw(Terminal *term, termline *ldata, int x, int y,
|
||||
ldata->lattr, term->basic_erase_char.truecolour);
|
||||
win_draw_trust_sigil(term->win, x, y);
|
||||
} else {
|
||||
if (ccount == 2 &&
|
||||
IS_REGIONAL_INDICATOR_LETTER(ch[0]) &&
|
||||
IS_REGIONAL_INDICATOR_LETTER(ch[1]))
|
||||
attr |= ATTR_WIDE | TATTR_COMBINING;
|
||||
win_draw_text(term->win, x, y, ch, ccount, attr, ldata->lattr, tc);
|
||||
if (attr & (TATTR_ACTCURS | TATTR_PASCURS))
|
||||
win_draw_cursor(term->win, x, y, ch, ccount,
|
||||
@ -6264,7 +6268,7 @@ static void do_paint(Terminal *term)
|
||||
tc = term->erase_char.truecolour;
|
||||
for (j = 0; j < term->cols; j++) {
|
||||
unsigned long tattr, tchar;
|
||||
bool break_run, do_copy;
|
||||
bool break_run, do_copy, next_run_dirty = false;
|
||||
termchar *d = lchars + j;
|
||||
|
||||
tattr = newline[j].attr;
|
||||
@ -6300,6 +6304,29 @@ static void do_paint(Terminal *term)
|
||||
(j > 0 && d[-1].cc_next != 0))
|
||||
break_run = true;
|
||||
|
||||
/*
|
||||
* Break on both sides of a regional indicator letter.
|
||||
*/
|
||||
if (IS_REGIONAL_INDICATOR_LETTER(tchar)) {
|
||||
break_run = true;
|
||||
if (j+1 < term->cols) {
|
||||
/* Also, check if there are any changes to whether or
|
||||
* not we're drawing this and the next character as a
|
||||
* single flag glyph. */
|
||||
bool flag_now = IS_REGIONAL_INDICATOR_LETTER(d[1].chr);
|
||||
bool flag_before = (
|
||||
IS_REGIONAL_INDICATOR_LETTER(
|
||||
term->disptext[i]->chars[j].chr) &&
|
||||
IS_REGIONAL_INDICATOR_LETTER(
|
||||
term->disptext[i]->chars[j+1].chr) &&
|
||||
(term->disptext[i]->chars[j].attr & DATTR_STARTRUN));
|
||||
if (flag_now != flag_before)
|
||||
next_run_dirty = true; /* must redraw this flag */
|
||||
}
|
||||
} else if (j>0 && IS_REGIONAL_INDICATOR_LETTER(d[-1].chr)) {
|
||||
break_run = true;
|
||||
}
|
||||
|
||||
/*
|
||||
* Break on both sides of a trust sigil.
|
||||
*/
|
||||
@ -6328,7 +6355,7 @@ static void do_paint(Terminal *term)
|
||||
cset = CSET_OF(tchar);
|
||||
if (term->ucsdata->dbcs_screenfont)
|
||||
last_run_dirty = dirty_run;
|
||||
dirty_run = dirty_line;
|
||||
dirty_run = dirty_line || next_run_dirty;
|
||||
}
|
||||
|
||||
do_copy = false;
|
||||
@ -6407,6 +6434,44 @@ static void do_paint(Terminal *term)
|
||||
copy_termchar(term->disptext[i], j, d);
|
||||
}
|
||||
}
|
||||
|
||||
/* If it's a regional indicator letter, and so is the next
|
||||
* one, then also step to the next one, keeping the flag
|
||||
* sequence together. */
|
||||
if (IS_REGIONAL_INDICATOR_LETTER(d->chr) &&
|
||||
(j+1 < term->cols && IS_REGIONAL_INDICATOR_LETTER(d[1].chr))) {
|
||||
j++;
|
||||
d++;
|
||||
|
||||
/* Set ATTR_WIDE, so that the pair is displayed as one */
|
||||
attr |= ATTR_WIDE;
|
||||
|
||||
/* Include the second letter in the text buffer */
|
||||
unsigned long rchar = d->chr;
|
||||
#ifdef PLATFORM_IS_UTF16
|
||||
sgrowarrayn(ch, chlen, ccount, 2);
|
||||
ch[ccount++] = (wchar_t)HIGH_SURROGATE_OF(rchar);
|
||||
ch[ccount++] = (wchar_t)LOW_SURROGATE_OF(rchar);
|
||||
#else
|
||||
sgrowarrayn(ch, chlen, ccount, 1);
|
||||
ch[ccount++] = (wchar_t)rchar;
|
||||
#endif
|
||||
|
||||
/* Display the cursor, if it's on the right half */
|
||||
if (i == our_curs_y && j == our_curs_x) {
|
||||
attr |= cursor;
|
||||
term->disptext[i]->chars[j-1].attr |= cursor;
|
||||
}
|
||||
|
||||
if (!termchars_equal_override(
|
||||
&term->disptext[i]->chars[j],
|
||||
d, rchar, term->disptext[i]->chars[j-1].attr))
|
||||
dirty_run = true;
|
||||
|
||||
copy_termchar(term->disptext[i], j, d);
|
||||
term->disptext[i]->chars[j].attr =
|
||||
term->disptext[i]->chars[j-1].attr & ~DATTR_STARTRUN;
|
||||
}
|
||||
}
|
||||
if (dirty_run && ccount > 0)
|
||||
do_paint_draw(term, ldata, start, i, ch, ccount, attr, tc);
|
||||
|
@ -26,5 +26,5 @@ Emoji via U+FE0F: ❤️ ☺️ ☹️ (narrow, because wcwidth mishandl
|
||||
Dedicated emoji: 💜 🙂 🙁 (wide and should look correct)
|
||||
Combined via ZWJ: 👩💻 (PuTTY doesn't understand ZWJ)
|
||||
Skin tone mod: 👩🏻 👩🏿 (wcwidth doesn't know those are modifiers)
|
||||
Flags: 🇬🇧 🇺🇦 🇪🇺 (also too complicated)
|
||||
Flags: 🇬🇧 🇺🇦 🇪🇺 (should work in GTK 2 or better)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user