Using PCFFont

To install PCFFont, unzip into a directory "pcffont". Next, create a directory "pcf" and copy the appropriate fonts into the directory. Finally, write your program that uses the pcffont library, and put it in the directory that contains pcffont and pcf.

To use the font class, you create a PCFFont object by passing it the stream of a font file. Then you can use drawString or stringImage to display a string. Functions such as stringWidth and getHeight can be used to determine the size of characters or text. The foreground and background colors can be set with setFgColor and setBgColor; null indicates transparency.

An example:

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 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 CompletionCallback; this 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

Back to the PCFFont pages.

Ken Shirriff:
This page:
Copyright 1998 Ken Shirriff. Java and other Java-based names are trademarks of Sun Microsystems, Inc. and refer to Sun's family of Java-branded technologies. Use of this software is subject to the terms of the license agreement.