--- java/awt/font/TextLayout.java 17 Feb 2003 08:05:50 -0000 1.1 +++ java/awt/font/TextLayout.java 18 Nov 2003 21:27:04 -0000 @@ -43,8 +43,12 @@ import java.awt.Shape; import java.awt.geom.AffineTransform; import java.awt.geom.Rectangle2D; +import java.text.CharacterIterator; import java.text.AttributedCharacterIterator; +import java.text.AttributedString; import java.util.Map; +import java.awt.font.TextAttribute; + /** * @author Michael Koch @@ -67,24 +71,26 @@ } } + private AttributedString attributedString; private FontRenderContext fontRenderContext; public TextLayout (AttributedCharacterIterator text, FontRenderContext frc) { - // FIXME - this.fontRenderContext = frc; + attributedString = new AttributedString (text); + fontRenderContext = frc; } public TextLayout (String string, Font font, FontRenderContext frc) { - // FIXME - this.fontRenderContext = frc; + attributedString = new AttributedString (string); + attributedString.addAttribute (TextAttribute.FONT, font); + fontRenderContext = frc; } public TextLayout (String string, Map attributes, FontRenderContext frc) { - // FIXME - this.fontRenderContext = frc; + attributedString = new AttributedString (string, attributes); + fontRenderContext = frc; } protected Object clone () @@ -102,7 +108,42 @@ public void draw (Graphics2D g2, float x, float y) { - throw new Error ("not implemented"); + AttributedCharacterIterator ci = attributedString.getIterator (); + Font defFont = g2.getFont (); + + for (char c = ci.first (); + c != CharacterIterator.DONE; + c = ci.next ()) + { + Object fnt = ci.getAttribute(TextAttribute.FONT); + + int limit = ci.getRunLimit(TextAttribute.FONT); + String run = new String(); + while (ci.current () != CharacterIterator.DONE && + ci.getIndex() < limit) + { + run += ci.current (); + ci.next (); + } + + GlyphVector gv; + if (fnt != null && fnt instanceof Font) + gv = ((Font)fnt).createGlyphVector (fontRenderContext, run); + else + gv = defFont.createGlyphVector (fontRenderContext, run); + + g2.drawGlyphVector (gv, x, y); + + int n = gv.getNumGlyphs (); + for (int i = 0; i < n; ++i) + { + GlyphMetrics gm = gv.getGlyphMetrics (i); + if (gm.getAdvanceX() == gm.getAdvance ()) + x += gm.getAdvanceX (); + else + y += gm.getAdvanceY (); + } + } } public boolean equals (Object obj)