fonts – Manipulate the shape of each character in a string using Java graphics – Education Career Blog

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

,

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.)

Leave a Comment