Text Effects in Java
Friday, July 29, 2005
I haven’t seen many examples of using GlyphVector in Java2D to do text effects, like gradient fills or create outlines of text. So I tried.

WebStart demo
Source code
Updated to fix issue with gradients.
There are a few odd things about GlyphVector. It contains methods to transform each glyph (a glyph could be character, part of a character, or multiple characters), but it seems that is incomplete. To transform each glyph, you’ll need to create a GeneralPath, obtain each glyph from the GlyphVector, transform it, and append it to the GeneralPath.
The gradient fills, beveling, and drop shadows could have been faked by using AlphaComposite and rendering multiple times, but the jiggle (Each character rotated slightly) and fatten needed the vector shapes instead of bitmap fakery.
The “fatten” is like Photoshop’s expand (or grow) selection. Expanding the section can help create a lot of effects and generally make text look better (most fonts are too thin for good looking titles). There does not seem to be an good way to approximate this in Java2D. The method implemented here is to use a Stroke to create an outline of the text and use Area to merge the text and it’s outline together. That is very slow. I’ve had a few other ideas for doing this, but I haven’t had time to try them.
I created this a few months ago and never posted. -I’m not sure the webstart demo and the source code still match.- This was a test-bed I created to try some effects that I later used in other places. I know the UI is not good, I needed something quick and usable. The are many other (better) uses for transforming glyphs like custom spacing between letters and creating type on a curve.
