|Ken Shirriff -> Java -> Fonts -> Using PCFFont|
To use the font class, you create a PCFFont object by passing it the
stream of a font file. Then you can use
stringImage to display a string. Functions such as
getHeight can be used to determine
the size of characters or text. The foreground and background colors
can be set with
null indicates transparency.
URL url = new URL(getDocumentBase(), "pcf/roughage40.pcf"); PCFFont font = new PCFFont(url.openStream()); font.drawString(g, "Hello world", 0, 20);
For antialiasing of a font, use the PCFFontAA.java class. This class antialiases the font by rendering groups of four pixels as one shaded pixel (which also cuts the font size in half). Antialiasing works with colored backgrounds, but will look terrible with a transparent (i.e. null) background.
The constructor can also be passed a
will be called periodically as the font is loaded, which allows the application
to provide feedback as the font is loaded.
The Fontlist class is a helper class to manage a list of fonts and allow selection of a font from the list. You can download Fontlist.java
Back to the PCFFont pages.