Enumerating Fonts

In some instances, an application must be able to enumerate and retrieve detailed information about the available fonts, and to select the font most appropriate for a particular operation.

The WFC FontDescriptor object describes a font, including the font's name, height, orientation, and so forth. For a detailed description of all the fonts available on your system, use the Graphics object's getFontDescriptors method. This method returns an array of FontDescriptor objects, in which each element in the array describes a font.

The following example illustrates how to use the getFontDescriptors method. This example retrieves an array of available fonts and then inserts a unique list of the font names into a list box:

Graphics g = this.createGraphics();

// Create the array.
FontDescriptor rgFonts[] = g.getFontDescriptors();

for(int i = 0; i < rgFonts.length; i++){

    if(listBox1.findString(rgFonts[i].fullName == -1){

        listBox1.addItem(rgFonts[i].fullName);
    }
}