Ticket #1977: MakeMultiLineLabelSupportNewLines.patch

File MakeMultiLineLabelSupportNewLines.patch, 2.6 KB (added by xeen, 15 years ago)
  • src/org/openstreetmap/josm/gui/JMultilineLabel.java

     
    9292        width -= insets.left + insets.right;
    9393        float w = insets.left + insets.right;
    9494        float x = insets.left, y=insets.top;
     95             
     96       
    9597        if (width > 0 && text != null && text.length() > 0) {
    96             AttributedString as = new AttributedString(getText());
    97             as.addAttribute(TextAttribute.FONT, getFont());
    98             AttributedCharacterIterator aci = as.getIterator();
    99             LineBreakMeasurer lbm = new LineBreakMeasurer(aci, frc);
    100             float max = 0;
    101             while (lbm.getPosition() < aci.getEndIndex()) {
    102                 TextLayout textLayout = lbm.nextLayout(width);
    103                 if (g != null && isJustified() && textLayout.getVisibleAdvance() > 0.80 * width)
    104                     textLayout = textLayout.getJustifiedLayout(width);
    105                 if (g != null)
    106                     textLayout.draw(g, x, y + textLayout.getAscent());
    107                 y += textLayout.getDescent() + textLayout.getLeading() + textLayout.getAscent();
    108                 max = Math.max(max, textLayout.getVisibleAdvance());
     98            String[] lines = getText().split("\n");             
     99            for(String line : lines) {
     100                // Insert a space so new lines get rendered
     101                if(line.length() == 0) line = " ";
     102                AttributedString as = new AttributedString(line);
     103                as.addAttribute(TextAttribute.FONT, getFont());
     104                AttributedCharacterIterator aci = as.getIterator();
     105                LineBreakMeasurer lbm = new LineBreakMeasurer(aci, frc);
     106                float max = 0;
     107                while (lbm.getPosition() < aci.getEndIndex()) {
     108                    TextLayout textLayout = lbm.nextLayout(width);
     109                    if (g != null && isJustified() && textLayout.getVisibleAdvance() > 0.80 * width)
     110                        textLayout = textLayout.getJustifiedLayout(width);
     111                    if (g != null)
     112                        textLayout.draw(g, x, y + textLayout.getAscent());
     113                    y += textLayout.getDescent() + textLayout.getLeading() + textLayout.getAscent();
     114                    max = Math.max(max, textLayout.getVisibleAdvance());
     115                }
     116                w += max;
    109117            }
    110             w += max;
    111118        }
    112119        return new Dimension((int)Math.ceil(w), (int)Math.ceil(y) + insets.bottom);
    113120    }