Skip to content

Commit

Permalink
eclipse-platform#414: slow StyledTextRenderer for unicode and unprint…
Browse files Browse the repository at this point in the history
…able control characters

This test replaces the characters 0x00-0x1F with some alternative
character (by default '?') for rendering. This improves the performance
significantly.
  • Loading branch information
Thomas Singer committed Sep 3, 2024
1 parent 243f2c5 commit c37643d
Showing 1 changed file with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2854,6 +2854,14 @@ public boolean isDisposed () {
return device == null;
}

private static char replaceBelowSpaceCharacters(char chr) {
if (chr >= 0x20 || chr == '\t' || chr == '\r' || chr == '\n') {
return chr;
}

return '?'; // (char)(0x2400 + chr);
}

/*
* Itemize the receiver text
*/
Expand Down Expand Up @@ -2881,6 +2889,9 @@ StyleItem[] itemize () {
int[] pcItems = new int[1];
char[] chars = new char[length];
segmentsText.getChars(0, length, chars, 0);
for (int i = 0; i < length; i++) {
chars[i] = replaceBelowSpaceCharacters(chars[i]);
}
// enable font ligatures
scriptControl.fMergeNeutralItems = true;
/*
Expand Down Expand Up @@ -3740,6 +3751,9 @@ void shape (GC gc, final long hdc, final StyleItem run) {
final int[] buffer = new int[1];
final char[] chars = new char[run.length];
segmentsText.getChars(run.start, run.start + run.length, chars, 0);
for (int i = 0; i < chars.length; i++) {
chars[i] = replaceBelowSpaceCharacters(chars[i]);
}

final int maxGlyphs = (chars.length * 3 / 2) + 16;
long hHeap = OS.GetProcessHeap();
Expand Down

0 comments on commit c37643d

Please sign in to comment.