Page 1 of 1

Anothe TextUtilities issue

Posted: Wed Feb 12, 2014 12:20 pm
by alex20140116
When nextLineBreak() method renurns 0, the programm will infinite loop. To resolve this we need to modify

Code: Select all

public static TextBlock createTextBlock(final String text, final Font font,
            final Paint paint, final float maxWidth, final int maxLines,
            final TextMeasurer measurer) {

        final TextBlock result = new TextBlock();
        final BreakIterator iterator = BreakIterator.getLineInstance();
        iterator.setText(text);
        int current = 0;
        int lines = 0;
        final int length = text.length();
        while (current < length && lines < maxLines) {
            final int next = nextLineBreak(text, current, maxWidth, iterator, measurer);
            if (next == BreakIterator.DONE) {
                result.addLine(text.substring(current), font, paint);
                return result;
            }
//MODIFIED CODE BEGIN
            if (next==0) {
              //fix for OOME when width of text is less, that real place for text
              result.addLine("", font, paint);
              break;
            }
//MODIFIED CODE END
            result.addLine(text.substring(current, next), font, paint);
            lines++;
            current = next;
            while (current < text.length()&& text.charAt(current) == '\n') {
                current++;
            }
        }
        if (current < length) {
            final TextLine lastLine = result.getLastLine();
            final TextFragment lastFragment = lastLine.getLastTextFragment();
            final String oldStr = lastFragment.getText();
            String newStr = "...";
            if (oldStr.length() > 3) {
                newStr = oldStr.substring(0, oldStr.length() - 3) + "...";
            }

            lastLine.removeFragment(lastFragment);
            final TextFragment newFragment = new TextFragment(newStr,
                    lastFragment.getFont(), lastFragment.getPaint());
            lastLine.addFragment(newFragment);
        }
        return result;
    }

Re: Anothe TextUtilities issue

Posted: Thu Feb 13, 2014 9:33 am
by david.gilbert
Do you have a test case that triggers this bug? I'm not able to reproduce it yet.

Re: Anothe TextUtilities issue

Posted: Thu Feb 13, 2014 9:44 am
by alex20140116
I's quite difficult, but we've reproduced it many times:
- create 3d pie chart diagram with 2 options (50% and 50%) with width 250 and height 250 pixels
- create labels for options with big texts (for instance 'Yes Yes Yes Yes Yes Yes' and 'No No No No No No No')
- Image looks good
- reduce width for chart to 100 pixels or less
- charts is not being processed, OutOfMemoryError

Re: Anothe TextUtilities issue

Posted: Thu Feb 13, 2014 9:56 am
by alex20140116
I have not managed to attach images, so I uploaded then into 3-party server
http://ksbeta.pr1.ssstest.com/User/60/6 ... /49800.png - It's normal picture, while you reduce width
http://ksbeta.pr1.ssstest.com/User/60/6 ... /49801.png - It's fixed library picture, not fixed could not generate it with OOME

Re: Anothe TextUtilities issue

Posted: Thu Feb 13, 2014 11:13 am
by david.gilbert
OK, I'll try this. Are you running on Windows or some other platform?

Re: Anothe TextUtilities issue

Posted: Thu Feb 13, 2014 3:25 pm
by alex20140116
It seems to me there is no difference Win Or Linux there. I used Windows 7, Java 7, but our production platform uses Solaris.

Re: Anothe TextUtilities issue

Posted: Tue Feb 25, 2014 6:03 pm
by david.gilbert
Yes, I was just wondering if it was some issue with the line separator characters but in any case I have reproduced this locally.

Re: Anothe TextUtilities issue

Posted: Fri Feb 28, 2014 3:07 pm
by david.gilbert
I've included a fix in JCommon 1.0.22 which has been uploaded to SourceForge:

https://sourceforge.net/projects/jfreec ... on/1.0.22/