mirror of
https://github.com/processing/processing4.git
synced 2026-06-16 04:26:26 +02:00
improve string breaking performance with edge case (fixes #211)
This commit is contained in:
@@ -4716,15 +4716,34 @@ public class PGraphics extends PImage implements PConstants {
|
||||
// If this is the first word on the line, and its width is greater
|
||||
// than the width of the text box, then break the word where at the
|
||||
// max width, and send the rest of the word to the next line.
|
||||
do {
|
||||
if (index - wordStart < 25) {
|
||||
do {
|
||||
index--;
|
||||
if (index == wordStart) {
|
||||
// Not a single char will fit on this line. screw 'em.
|
||||
return false;
|
||||
}
|
||||
wordWidth = textWidthImpl(buffer, wordStart, index);
|
||||
} while (wordWidth > boxWidth);
|
||||
} else {
|
||||
// This word is more than 25 characters long, might be faster to
|
||||
// start from the beginning of the text rather than shaving from
|
||||
// the end of it, which is super slow if it's 1000s of letters.
|
||||
// https://github.com/processing/processing/issues/211
|
||||
int lastIndex = index;
|
||||
index = wordStart + 1;
|
||||
// walk to the right while things fit
|
||||
while ((wordWidth = textWidthImpl(buffer, wordStart, index)) < boxWidth) {
|
||||
index++;
|
||||
if (index > lastIndex) { // Unreachable?
|
||||
break;
|
||||
}
|
||||
}
|
||||
index--;
|
||||
if (index == wordStart) {
|
||||
// Not a single char will fit on this line. screw 'em.
|
||||
//System.out.println("screw you");
|
||||
return false; //Float.NaN;
|
||||
return false; // nothing fits
|
||||
}
|
||||
wordWidth = textWidthImpl(buffer, wordStart, index);
|
||||
} while (wordWidth > boxWidth);
|
||||
}
|
||||
|
||||
//textLineImpl(buffer, lineStart, index, x, y);
|
||||
textSentenceBreak(lineStart, index);
|
||||
|
||||
+4
-1
@@ -1,7 +1,10 @@
|
||||
0242 core (3.0b4)
|
||||
X dataPath() not working when app is not run from app dir on Linux
|
||||
X https://github.com/processing/processing/issues/2195
|
||||
|
||||
X Zero length string passed to TextLayout constructor
|
||||
X https://github.com/processing/processing/issues/3487
|
||||
X improve speed of text(x, y, w, h) when using large strings with no spaces
|
||||
X https://github.com/processing/processing/issues/211
|
||||
|
||||
earlier
|
||||
X are we clear on sketchPath() for OS X?
|
||||
|
||||
Reference in New Issue
Block a user