EVALUATION
we can do something like this in SwingUtilities2.clipString:
--
availTextWidth -= SwingUtilities2.stringWidth(c, fm, clipString);
+ if (availTextWidth <= 0) {
+ //can not fit any characters
+ return clipString;
+ }
+
--
This is how non i18n case works anyways.
|
EVALUATION
What is happening in LineBreakMeasurer.nextOffset can be demonstrated more simply :
import java.awt.font.*;
import java.text.*;
public class Test {
public static void main(String[] args) {
FontRenderContext frc = new FontRenderContext(null,false,false);
AttributedString aString = new AttributedString("\u0634");
LineBreakMeasurer measurer =
new LineBreakMeasurer(aString.getIterator(), frc);
System.out.println("nchars="+measurer.nextOffset(-6));
}
}
% java Test
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: -1
at java.awt.font.LineBreakMeasurer.nextOffset(LineBreakMeasurer.java:346)
at java.awt.font.LineBreakMeasurer.nextOffset(LineBreakMeasurer.java:310)
at Test.main(Test.java:11)
This is not new in JDK 1.6. Passing in a negative offset is clearly incorrect.
What is new is the code in SwingUtilities2 that passes in this value.
It was introduced in the fix for 4374406, which resolved that Swing did
not use TextLayout in some cases it should. This example is when Swing
displays '...' to terminate a string that cannot fit in the space provided.
The calculation presumes that the space provided is at least sufficient to
fit '...' and so subtracts the width of '...' from the available width
to determine the with available to pass to LineBreakMeasurer.nextOffset().
When this ends up negative, the exception occurs.
Swing probably should simply treat a negative value as being zero.
|