Skip to content

Commit

Permalink
failed attempt to output multiple non-BMP characters in one chunk
Browse files Browse the repository at this point in the history
  • Loading branch information
mintty committed Jan 5, 2018
1 parent 75b0c10 commit 7da9b45
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 6 deletions.
39 changes: 35 additions & 4 deletions src/term.c
Original file line number Diff line number Diff line change
Expand Up @@ -1456,6 +1456,14 @@ term_paint(void)
}
#endif

#define dont_debug_run

#define dont_debug_out_text

#ifdef debug_run
# define debug_out_text
#endif

void out_text(int x, int y, wchar *text, int len, cattr attr, cattr *textattr, ushort lattr, bool has_rtl)
{
#ifdef debug_out_text
Expand Down Expand Up @@ -1494,10 +1502,9 @@ term_paint(void)
if ((dispchars[j].attr.attr ^ tattr.attr) & ATTR_WIDE)
dirty_line = true;

#define dont_debug_run

#ifdef debug_run
#define trace_run(tag) ({/*if (tchar & 0xFF00)*/ if (tchar != ' ') printf("break (%s) %04X\n", tag, tchar);})
#define trace_run(tag) ({/*if (tchar & 0xFF00)*/ if (tchar != ' ') printf("break (%s) (%04X)%04X\n", tag, j > 0 ? newchars[j - 1].chr : 0, tchar);})

#else
#define trace_run(tag) (void)0
#endif
Expand All @@ -1506,12 +1513,36 @@ term_paint(void)
|| (tattr.truefg != attr.truefg)
|| (tattr.truebg != attr.truebg);

inline bool has_comb(termchar * tc)
{
if (!tc->cc_next)
return false;
if (!is_high_surrogate(tc->chr))
return true;
tc += tc->cc_next;
return tc->cc_next;
}

/*
* Break on both sides of any combined-character cell.
*/
if (d->cc_next || (j > 0 && d[-1].cc_next))
if (has_comb(d) || (j > 0 && has_comb(&d[-1])))
trace_run("cc"), break_run = true;

#ifdef keep_non_BMP_characters_together_in_one_chunk
/*
* Break when switching BMP/non-BMP.
*/
if (j > 0 && is_high_surrogate(d->chr) ^ is_high_surrogate(d[-1].chr))
trace_run("bmp"), break_run = true;
#else
/*
* Break on both sides of non-BMP character.
*/
if (j > 0 && (is_high_surrogate(d->chr) || is_high_surrogate(d[-1].chr)))
trace_run("bmp"), break_run = true;
#endif

if (!dirty_line) {
if (dispchars[j].chr == tchar &&
(dispchars[j].attr.attr & ~DATTR_STARTRUN) == tattr.attr)
Expand Down
13 changes: 11 additions & 2 deletions src/wintext.c
Original file line number Diff line number Diff line change
Expand Up @@ -1886,15 +1886,24 @@ win_text(int x, int y, wchar *text, int len, cattr attr, cattr *textattr, ushort
/* Array with offsets between neighbouring characters */
int dxs[len];
int dx = combining ? 0 : char_width;
for (int i = 0; i < len; i++)
dxs[i] = dx;
for (int i = 0; i < len; i++) {
if (is_low_surrogate(text[i]))
// This does not have the expected effect so we keep splitting up
// non-BMP characters into single character chunks for now (term.c)
dxs[i] = 0;
else
dxs[i] = dx;
}

/* Character cells length */
int ulen = 0;
for (int i = 0; i < len; i++) {
ulen++;
if (char1ulen(&text[i]) == 2)
i++; // skip low surrogate;
}

/* Painting box */
int width = char_width * (combining ? 1 : ulen);
RECT box = {
.top = y, .bottom = y + cell_height,
Expand Down

0 comments on commit 7da9b45

Please sign in to comment.