changeset 17035:eb4e9fb470a7

6479801: java.awt.font.LineBreakMeasurer code incorrect Reviewed-by: serb
author prr
date Mon, 17 Apr 2017 08:52:59 -0700
parents a1a3ef8fd66f
children 8320693956ea
files src/java.desktop/share/classes/java/awt/font/LineBreakMeasurer.java
diffstat 1 files changed, 10 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/src/java.desktop/share/classes/java/awt/font/LineBreakMeasurer.java	Mon Apr 17 18:44:53 2017 +0300
+++ b/src/java.desktop/share/classes/java/awt/font/LineBreakMeasurer.java	Mon Apr 17 08:52:59 2017 -0700
@@ -115,26 +115,27 @@
  * <pre>{@code
  * public void paint(Graphics graphics) {
  *
- *     Point2D pen = new Point2D(10, 20);
+ *     float dx = 0f, dy = 5f;
  *     Graphics2D g2d = (Graphics2D)graphics;
  *     FontRenderContext frc = g2d.getFontRenderContext();
  *
- *     // let styledText be an AttributedCharacterIterator containing at least
- *     // one character
+ *     AttributedString text = new AttributedString(".....");
+ *     AttributedCharacterIterator paragraph = text.getIterator();
  *
- *     LineBreakMeasurer measurer = new LineBreakMeasurer(styledText, frc);
- *     float wrappingWidth = getSize().width - 15;
+ *     LineBreakMeasurer measurer = new LineBreakMeasurer(paragraph, frc);
+ *     measurer.setPosition(paragraph.getBeginIndex());
+ *     float wrappingWidth = (float)getSize().width;
  *
- *     while (measurer.getPosition() < fStyledText.length()) {
+ *     while (measurer.getPosition() < paragraph.getEndIndex()) {
  *
  *         TextLayout layout = measurer.nextLayout(wrappingWidth);
  *
- *         pen.y += (layout.getAscent());
+ *         dy += (layout.getAscent());
  *         float dx = layout.isLeftToRight() ?
  *             0 : (wrappingWidth - layout.getAdvance());
  *
- *         layout.draw(graphics, pen.x + dx, pen.y);
- *         pen.y += layout.getDescent() + layout.getLeading();
+ *         layout.draw(graphics, dx, dy);
+ *         dy += layout.getDescent() + layout.getLeading();
  *     }
  * }
  * }</pre>