Drawing Multiple Lines of Text
by, 03-07-2012 at 04:56 PM (1013 Views)
LineBreakMeasurer shall be used in case you want your styled text paragraph to get fit in a specific width. Styled text is broken down into lines by this class so that to make them fit in a visual advance. As a TextLayout object every line is returned, that presents the styled and unchangeable character data. This class accesses the layout information.
The getDescent and getAscent methods of Textlayout make the information to be returned regarding font which positions the component lines.As AttributedCharacterIterator object, text is stored. It makes the point size and fonts to be stored with text.
These applet positions styled text paragraph in a component, by using TextLayout, LineBreakMeasurer, and AttributedCharacterIterator.
This code makes an iterator along with a string vanGogh. The start as well as end of the iterator gets retrieved. A new LineBreakMeasurer is made from the iterator.
Java Code:AttributedCharacterIterator paragraph = vanGogh.getIterator(); paragraphStart = paragraph.getBeginIndex(); paragraphEnd = paragraph.getEndIndex(); FontRenderContext frc = g2d.getFontRenderContext(); lineMeasurer = new LineBreakMeasurer(paragraph, frc);