Skip to content

Commit 3c62815

Browse files
committed
Fix rendering of non-BMP characters at start or end of text run
We currently discover a non-BMP character at the start or end of a text run only after we process both halves of the surrogate pair representing the character individually, resulting in off-by-one errors in calculating the portion of the char array containing the run to be drawn (we erroneously omit any high surrogate at the start of a run, and erroneously include any high surrogate immediately following the end of a run). Fix this by processing both halves of the surrogate pair immediately when we see the high surrogate.
1 parent fe682ae commit 3c62815

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

libraries/emulatorview/src/jackpal/androidterm/emulatorview/TranscriptScreen.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -204,19 +204,16 @@ public final void drawText(int row, Canvas canvas, float x, float y,
204204
int lastRunStart = -1;
205205
int lastRunStartIndex = -1;
206206
boolean forceFlushRun = false;
207-
char cHigh = 0;
208207
int column = 0;
209208
int index = 0;
210209
while (column < columns) {
211-
int style;
210+
int style = color.get(column);
212211
boolean cursorStyle = false;
213-
style = color.get(column);
212+
int incr = 1;
214213
int width;
215214
if (Character.isHighSurrogate(line[index])) {
216-
cHigh = line[index++];
217-
continue;
218-
} else if (Character.isLowSurrogate(line[index])) {
219-
width = UnicodeTranscript.charWidth(cHigh, line[index]);
215+
width = UnicodeTranscript.charWidth(line, index);
216+
incr++;
220217
} else {
221218
width = UnicodeTranscript.charWidth(line[index]);
222219
}
@@ -242,7 +239,7 @@ public final void drawText(int row, Canvas canvas, float x, float y,
242239
}
243240
runWidth += width;
244241
column += width;
245-
index++;
242+
index += incr;
246243
if (width > 1) {
247244
/* We cannot draw two or more East Asian wide characters in the
248245
same run, because we need to make each wide character take

0 commit comments

Comments
 (0)