Ignore:
Timestamp:
12/12/13 17:15:00 (11 years ago)
Author:
jts21
Message:

Text wrapping now only wraps around whitespace/special characters, when there isn't enough space to display a word it just drops down to the next line

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/expeditee/items/Text.java

    r613 r615  
    135135        private List<Integer> _lineOffsets = new LinkedList<Integer>();
    136136
     137        private FontRenderContext frc = null;
    137138        private LineBreakMeasurer _lineBreaker = null;
    138139
     
    14091410                                        .toString());
    14101411                        paragraphText.addAttribute(TextAttribute.FONT, getPaintFont());
    1411                         _lineBreaker = new LineBreakMeasurer(paragraphText.getIterator(),
    1412                                         new FontRenderContext(null, true, true));
     1412                        frc = new FontRenderContext(null, true, true);
     1413                        _lineBreaker = new LineBreakMeasurer(paragraphText.getIterator(), frc);
    14131414                }
    14141415
     
    14551456                }
    14561457                width = getLineWidth(getX(), getY(), lines);
    1457                
    1458                 if(width < 100) {
    1459                         width = 100;
    1460                 }
    14611458                } else {
    14621459                        width = Float.MAX_VALUE;
     
    14721469
    14731470                // --- Get the output of the LineBreakMeasurer and store it in a
    1474                 while ((layout = _lineBreaker.nextLayout(width)) != null) {
     1471                while (_lineBreaker.getPosition() < _text.length()) {
     1472                       
     1473                        layout = _lineBreaker.nextLayout(width, _text.length(), true);
    14751474                       
    14761475                        // lineBreaker does not break on newline
     
    14841483                                if (_text.charAt(i) == '\n') {// || c == '\t'){
    14851484                                        _lineBreaker.setPosition(start);
    1486                                         layout = _lineBreaker.nextLayout(width, i, false);
     1485                                        layout = _lineBreaker.nextLayout(width, i, true);
    14871486                                        break;
    14881487                                }
     
    14901489
    14911490                        _lineOffsets.add(_lineBreaker.getPosition());
     1491                       
     1492                        if(layout == null) {
     1493                                layout = new TextLayout(" ", getPaintFont(), frc);
     1494                        }
    14921495
    14931496                        if (/* hasWidth() && */getJustification() == Justification.full
    14941497                                        && _lineBreaker.getPosition() < _text.length())
    14951498                                layout = layout.getJustifiedLayout(width);
    1496 
     1499                       
    14971500                        _textLayouts.add(layout);
    1498                        
     1501                                               
    14991502                        if(_autoWrap || UserSettings.AutoWrap) {
     1503                               
    15001504                        if(lineHeight != Float.NaN) {
    15011505                                lineHeight = getLineDrop(layout);
    15021506                        }
    1503                         width = getLineWidth(getX(), getY() + (lineHeight * (_lineOffsets.size() - 1)), lines);
    1504                         if(width < 100) {
    1505                                 width = 100;
    1506                         }
     1507                        width = getLineWidth(getX(), getY() + (lineHeight * (_textLayouts.size() - 1)), lines);
    15071508                        }
    15081509                }
Note: See TracChangeset for help on using the changeset viewer.