Best Font Forward
By Al Williams
Java has never been famous for its flexibility with fonts. In all fairness, decreased font versatility may be a necessary sacrifice for the myriad platforms that Java supports. Still, the documentation for java.awt.Font says that you can depend only on Serif, SansSerif, Monospaced, Dialog, DialogInput, and Symbol fontsnot much of a choice. You can always use system-specific fonts, but by doing so you lose portability.
The Java 2 Platform (JDK 1.2) improves the situation measurably by extending the Font class; however, doing anything uncommon still requires quite a bit of work. Besides, not all browsers support the latest version of Java, so all of your extra effort might only prohibit some users from using your applet.
With Java 2 you can construct a Font object using one of the predefined names, or you can use the name of a native font. You can also pass a Map-derived object (like a Hashtable) that contains attributes, defined by the TextAttribute class, to describe the font. You can even retrieve an array of all the fonts on a system using GraphicsEnvironment.GetAllFonts. Armed with this list, you can make new fonts using deriveFont.
What if you just want simple font effects that are compatible with any platform, even with older browsers? The answer is to create your own special effects using simple, widely available functions. Using text to do your drawing, this can be quite simple and effective.
In this month's column, I'll show you how to create some simple text effects like those in