layout = layout.getJustifiedLayout((float)wrappingWidth);
public TextLayout next() { if (first) { first = false; } else { y += ascent * lineHeight; } double layoutWidth = width == 0 ? Float.MAX_VALUE : width; TextLayout layout = currentMeasurer.nextLayout((float) layoutWidth); if (width == 0) { layoutWidth = layout.getAdvance(); if (align == Align.RIGHT) { x = -layoutWidth; } else if (align == Align.CENTER) { x = -layoutWidth / 2.0; } } else if (align == Align.RIGHT) { x = width - layout.getAdvance(); } else if (align == Align.CENTER) { x = (width - layout.getAdvance()) / 2.0; } else if (align == Align.JUSTIFY) { // Don't justify the last line. if (currentMeasurer.getPosition() < currentText.length()) { layout = layout.getJustifiedLayout((float) width); } } ascent = layout.getAscent(); // y += layout.getDescent() + layout.getLeading() + layout.getAscent(); return layout; }
protected TextLayout postProcess( final int start, final TextLayout textLayout, final LineBreakMeasurer lineBreakMeasurer ) { if ( justifiedLayout ) { return textLayout.getJustifiedLayout( wrappingWidth ); } else { return textLayout; } }
/** * * @param tree * @param labels * @param g * @return */ public double getMaxLabelHeight(BoundsTree tree, Map<String, String> labels, Graphics2D g) { double maxHeight = 0; Font font = new Font(params.labelPanelFont, PLAIN, params.labelPanelFontSize); FontRenderContext frc = g.getFontRenderContext(); for (String boundsLabel : labels.keySet()) { String label = labels.get(boundsLabel); Rectangle2D bounds = tree.get(boundsLabel); float boundsWidth = (float) bounds.getWidth(); TextLayout textLayout = new TextLayout(label, font, frc); if (boundsWidth <= 0) { continue; // XXX } TextLayout justifiedLayout = textLayout.getJustifiedLayout(boundsWidth); double height = justifiedLayout.getBounds().getHeight(); if (height > maxHeight) { maxHeight = height; } } return maxHeight; }
layout = layout.getJustifiedLayout((float)wrappingWidth);
private Dimension paintOrGetSize(Graphics2D g, int width) { Insets insets = getInsets(); width -= insets.left + insets.right + margin.left + margin.right; float w = insets.left + insets.right + margin.left + margin.right; float x = insets.left + margin.left, y = insets.top + margin.top; if (width > 0 && text != null && text.length() > 0) { AttributedString as = new AttributedString(getText()); as.addAttribute(TextAttribute.FONT, getFont()); AttributedCharacterIterator aci = as.getIterator(); LineBreakMeasurer lbm = new LineBreakMeasurer(aci, frc); float max = 0; while (lbm.getPosition() < aci.getEndIndex()) { TextLayout textLayout = lbm.nextLayout(width); if (g != null && isJustified() && textLayout.getVisibleAdvance() > 0.80 * width) textLayout = textLayout.getJustifiedLayout(width); if (g != null) textLayout.draw(g, x, y + textLayout.getAscent()); y += textLayout.getDescent() + textLayout.getLeading() + textLayout.getAscent(); max = Math.max(max, textLayout.getVisibleAdvance()); } w += max; } return new Dimension((int)Math.ceil(w), (int)Math.ceil(y) + insets.bottom + margin.bottom); } }
private Dimension paintOrGetSize(Graphics2D g, int width) { Insets insets = getInsets(); width -= insets.left + insets.right + margin.left + margin.right; float w = insets.left + insets.right + margin.left + margin.right; float x = insets.left + margin.left, y=insets.top + margin.top; if (width > 0 && text != null && text.length() > 0) { AttributedString as = new AttributedString(getText()); as.addAttribute(TextAttribute.FONT, getFont()); AttributedCharacterIterator aci = as.getIterator(); LineBreakMeasurer lbm = new LineBreakMeasurer(aci, frc); float max = 0; while (lbm.getPosition() < aci.getEndIndex()) { TextLayout textLayout = lbm.nextLayout(width); if (g != null && isJustified() && textLayout.getVisibleAdvance() > 0.80 * width) textLayout = textLayout.getJustifiedLayout(width); if (g != null) textLayout.draw(g, x, y + textLayout.getAscent()); y += textLayout.getDescent() + textLayout.getLeading() + textLayout.getAscent(); max = Math.max(max, textLayout.getVisibleAdvance()); } w += max; } return new Dimension((int)Math.ceil(w), (int)Math.ceil(y) + insets.bottom + margin.bottom); } }
layout = layout.getJustifiedLayout((float)wrappingWidth);
while (layoutSuivant != null) { layoutEnCours = layoutEnCours.getJustifiedLayout(w);
TextLayout layout = lineMeasurer.nextLayout(breakWidth); TextLayout justifiedLayout = layout.getJustifiedLayout(breakWidth);
layout = layout.getJustifiedLayout(formatWidth);