Status: Accepted
Owner: atdixon

New issue 192 by atdixon: PStyledText breaks when using Insets and unconstrained width
http://code.google.com/p/piccolo2d/issues/detail?id=192

PStyledText throws exception when using insets with unconstrained width:

public void testInsetsWithUnconstrainedWidth() {
    PStyledText text = new PStyledText();
    text.setInsets(new Insets(10, 10, 10, 10));
    text.setConstrainWidthToTextWidth(false);
    text.setDocument(new DefaultStyledDocument());
}

Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: -1
        at 
java.awt.font.LineBreakMeasurer.nextOffset(LineBreakMeasurer.java:346)
        at 
java.awt.font.LineBreakMeasurer.nextLayout(LineBreakMeasurer.java:422)
        at 
java.awt.font.LineBreakMeasurer.nextLayout(LineBreakMeasurer.java:395)
        at
PStyledText.extractLineBreaks(_PStyledText.java:)


When determining line breaks with LineBreakMeasurer, we can call when the PStyledText's node answers a value < insets/margins for getWidth(). An update to PStyledText like the following fixes the issue:

551 | measurer.nextLayout((float) Math.max(0, Math.ceil(getWidth() - insets.left - insets.right)));

Going to think on the fix/await comments.

--
Piccolo2D Developers Group: http://groups.google.com/group/piccolo2d-dev?hl=en

Reply via email to