views:

19

answers:

1

Hi

I've figured out how to get the shape of a text string before drawing it on this screen in Java, for example by using the TextLayout class [1]. However I could only find a way to get the Shape of the whole text. I need a Shape for each character in the text. Does anybody know an elegant way of how to obtain the Shape per character?

[1] http://download.oracle.com/javase/tutorial/2d/advanced/transforming.html

+2  A: 

Get a GlyphVector object from your Font. The returned GlyphVector will contain the sequence of glyphs that are used to represent the specified text.

Once you have a GlyphVector, you can obtain detailed metrics or a bounding shape for each individual glyph through the getGlyphMetrics() and getGlyphOutline() methods, respectively.

(Note: The getGlyphCharIndex() method can be used to discover the glyph to character mapping.)

Grodriguez
Yes but it gives me all the glyhps of which the characters consist at once, w/o telling me which glyph belongs to which character.. or did I miss something?
Nils
You can use the `getGlyphCharIndex()` method to find out the glyph to character mapping.
Grodriguez
Thank you, I missed this!
Nils
You're welcome. I have updated the answer to include this information.
Grodriguez