Skip to content
This repository was archived by the owner on Jan 14, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,11 @@ public void drawTextRun(Canvas canvas, float x, float y, int lineOffset,
left + runWidth * mCharWidth, y,
mTextPaint);

boolean cursorVisible = index <= cursorOffset && cursorOffset < (index + count);
boolean cursorVisible = lineOffset <= cursorOffset && cursorOffset < (lineOffset + runWidth);
float cursorX = 0;
if (cursorVisible) {
int cursorX = (int) (x + cursorOffset * mCharWidth);
drawCursorImp(canvas, cursorX, y, cursorWidth * mCharWidth, mCharHeight, cursorMode);
cursorX = x + cursorOffset * mCharWidth;
drawCursorImp(canvas, (int) cursorX, y, cursorWidth * mCharWidth, mCharHeight, cursorMode);
}

boolean invisible = (effect & TextStyle.fxInvisible) != 0;
Expand All @@ -97,19 +98,19 @@ public void drawTextRun(Canvas canvas, float x, float y, int lineOffset,
if (cursorVisible) {
// Text before cursor
int countBeforeCursor = cursorIndex - index;
int countAfterCursor = count - (countBeforeCursor + 1);
int countAfterCursor = count - (countBeforeCursor + cursorIncr);
if (countBeforeCursor > 0){
canvas.drawText(text, index, countBeforeCursor, left, textOriginY, mTextPaint);
}
// Text at cursor
mTextPaint.setColor(mPalette[TextStyle.ciCursorForeground]);
canvas.drawText(text, cursorIndex, cursorIncr, x + cursorOffset * mCharWidth,
canvas.drawText(text, cursorIndex, cursorIncr, cursorX,
textOriginY, mTextPaint);
// Text after cursor
if (countAfterCursor > 0) {
mTextPaint.setColor(textPaintColor);
canvas.drawText(text, cursorIndex + cursorIncr, countAfterCursor,
x + (cursorOffset + cursorWidth) * mCharWidth,
cursorX + cursorWidth * mCharWidth,
textOriginY, mTextPaint);
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,8 +290,16 @@ public void write(String data) {
* @param codePoint The Unicode code point to write to the terminal.
*/
public void write(int codePoint) {
CharBuffer charBuf = mWriteCharBuffer;
ByteBuffer byteBuf = mWriteByteBuffer;
if (codePoint < 128) {
// Fast path for ASCII characters
byte[] buf = byteBuf.array();
buf[0] = (byte) codePoint;
write(buf, 0, 1);
return;
}

CharBuffer charBuf = mWriteCharBuffer;
CharsetEncoder encoder = mUTF8Encoder;

charBuf.clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -823,7 +823,11 @@ private boolean handleUTF8Sequence(byte b) {
mUTF8ToFollow = 0;
mUTF8ByteBuffer.clear();
emit(UNICODE_REPLACEMENT_CHAR);
return true;

/* The Unicode standard (section 3.9, definition D93) requires
* that we now attempt to process this byte as though it were
* the beginning of another possibly-valid sequence */
return handleUTF8Sequence(b);
}

mUTF8ByteBuffer.put(b);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,19 +204,20 @@ public final void drawText(int row, Canvas canvas, float x, float y,
}

int columns = mColumns;
int lineLen = line.length;
int lastStyle = 0;
boolean lastSelectionStyle = false;
int runWidth = 0;
int lastRunStart = -1;
int lastRunStartIndex = -1;
boolean forceFlushRun = false;
int column = 0;
int nextColumn = 0;
int displayCharWidth = 0;
int index = 0;
int cursorIndex = 0;
int cursorIncr = 0;
while (column < columns) {
int style = color.get(column);
boolean selectionStyle = false;
while (column < columns && index < lineLen && line[index] != '\0') {
int incr = 1;
int width;
if (Character.isHighSurrogate(line[index])) {
Expand All @@ -225,7 +226,15 @@ public final void drawText(int row, Canvas canvas, float x, float y,
} else {
width = UnicodeTranscript.charWidth(line[index]);
}
if (column >= selx1 && column <= selx2) {
if (width > 0) {
// We've moved on to the next column
column = nextColumn;
displayCharWidth = width;
}
int style = color.get(column);
boolean selectionStyle = false;
if ((column >= selx1 || (displayCharWidth == 2 && column == selx1 - 1)) &&
column <= selx2) {
// Draw selection:
selectionStyle = true;
}
Expand All @@ -247,12 +256,17 @@ public final void drawText(int row, Canvas canvas, float x, float y,
forceFlushRun = false;
}
if (cx == column) {
cursorIndex = index;
cursorIncr = incr;
cursorWidth = width;
if (width > 0) {
cursorIndex = index;
cursorIncr = incr;
cursorWidth = width;
} else {
// Combining char attaching to the char under the cursor
cursorIncr += incr;
}
}
runWidth += width;
column += width;
nextColumn += width;
index += incr;
if (width > 1) {
/* We cannot draw two or more East Asian wide characters in the
Expand Down Expand Up @@ -357,13 +371,24 @@ private String internalGetTranscriptText(GrowableIntArray colors, int selX1, int
int lastPrintingChar = -1;
int lineLen = line.length;
int i;
int width = x2 - x1;
int column = 0;
for (i = 0; i < lineLen && column < width; ++i) {
for (i = 0; i < lineLen; ++i) {
char c = line[i];
if (c == 0) {
break;
} else if (c != ' ' || ((rowColorBuffer != null) && (rowColorBuffer.get(column) != defaultColor))) {
}

int style = defaultColor;
try {
if (rowColorBuffer != null) {
style = rowColorBuffer.get(column);
}
} catch (ArrayIndexOutOfBoundsException e) {
// XXX This probably shouldn't happen ...
style = defaultColor;
}

if (c != ' ' || style != defaultColor) {
lastPrintingChar = i;
}
if (!Character.isLowSurrogate(c)) {
Expand Down
Loading