Anothe TextUtilities issue

A discussion forum for the JCommon class library.
Locked
alex20140116
Posts: 4
Joined: Wed Feb 12, 2014 12:16 pm
antibot: No, of course not.

Anothe TextUtilities issue

Post by alex20140116 » Wed Feb 12, 2014 12:20 pm

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;
    }

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Re: Anothe TextUtilities issue

Post by david.gilbert » Thu Feb 13, 2014 9:33 am

Do you have a test case that triggers this bug? I'm not able to reproduce it yet.
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

alex20140116
Posts: 4
Joined: Wed Feb 12, 2014 12:16 pm
antibot: No, of course not.

Re: Anothe TextUtilities issue

Post by alex20140116 » Thu Feb 13, 2014 9:44 am

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

alex20140116
Posts: 4
Joined: Wed Feb 12, 2014 12:16 pm
antibot: No, of course not.

Re: Anothe TextUtilities issue

Post by alex20140116 » Thu Feb 13, 2014 9:56 am

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

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Re: Anothe TextUtilities issue

Post by david.gilbert » Thu Feb 13, 2014 11:13 am

OK, I'll try this. Are you running on Windows or some other platform?

alex20140116
Posts: 4
Joined: Wed Feb 12, 2014 12:16 pm
antibot: No, of course not.

Re: Anothe TextUtilities issue

Post by alex20140116 » Thu Feb 13, 2014 3:25 pm

It seems to me there is no difference Win Or Linux there. I used Windows 7, Java 7, but our production platform uses Solaris.

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Re: Anothe TextUtilities issue

Post by david.gilbert » Tue Feb 25, 2014 6:03 pm

Yes, I was just wondering if it was some issue with the line separator characters but in any case I have reproduced this locally.

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Re: Anothe TextUtilities issue

Post by david.gilbert » Fri Feb 28, 2014 3:07 pm

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/
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

Locked