< prev index next >

src/java.desktop/share/classes/java/awt/font/LineBreakMeasurer.java

Print this page

        

*** 113,142 **** * Rendering a paragraph in a component * <blockquote> * <pre>{@code * public void paint(Graphics graphics) { * ! * Point2D pen = new Point2D(10, 20); * Graphics2D g2d = (Graphics2D)graphics; * FontRenderContext frc = g2d.getFontRenderContext(); * ! * // let styledText be an AttributedCharacterIterator containing at least ! * // one character * ! * LineBreakMeasurer measurer = new LineBreakMeasurer(styledText, frc); ! * float wrappingWidth = getSize().width - 15; * ! * while (measurer.getPosition() < fStyledText.length()) { * * TextLayout layout = measurer.nextLayout(wrappingWidth); * ! * pen.y += (layout.getAscent()); * float dx = layout.isLeftToRight() ? * 0 : (wrappingWidth - layout.getAdvance()); * ! * layout.draw(graphics, pen.x + dx, pen.y); ! * pen.y += layout.getDescent() + layout.getLeading(); * } * } * }</pre> * </blockquote> * <p> --- 113,143 ---- * Rendering a paragraph in a component * <blockquote> * <pre>{@code * public void paint(Graphics graphics) { * ! * float dx = 0f, dy = 5f; * Graphics2D g2d = (Graphics2D)graphics; * FontRenderContext frc = g2d.getFontRenderContext(); * ! * AttributedString text = new AttributedString("....."); ! * AttributedCharacterIterator paragraph = text.getIterator(); * ! * LineBreakMeasurer measurer = new LineBreakMeasurer(paragraph, frc); ! * measurer.setPosition(paragraph.getBeginIndex()); ! * float wrappingWidth = (float)getSize().width; * ! * while (measurer.getPosition() < paragraph.getEndIndex()) { * * TextLayout layout = measurer.nextLayout(wrappingWidth); * ! * dy += (layout.getAscent()); * float dx = layout.isLeftToRight() ? * 0 : (wrappingWidth - layout.getAdvance()); * ! * layout.draw(graphics, dx, dy); ! * dy += layout.getDescent() + layout.getLeading(); * } * } * }</pre> * </blockquote> * <p>
< prev index next >