diff --git a/core/src/processing/core/PGraphics.java b/core/src/processing/core/PGraphics.java index cbb8f8290..2f20b5a3d 100644 --- a/core/src/processing/core/PGraphics.java +++ b/core/src/processing/core/PGraphics.java @@ -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); diff --git a/core/todo.txt b/core/todo.txt index 8e4bfa98b..44e765ebf 100644 --- a/core/todo.txt +++ b/core/todo.txt @@ -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?