6.3. Fonts
Fonts, represented by instances of java.awt.Font, are a cornerstone of the 2D API's text rendering system. The Font class has existed since JDK 1.0, but it has evolved considerably since then. Fonts have three different names, like characters in a Dostoyevsky novel, and there are several paths you can follow to obtain a font.
6.3.1. Names
Fonts are identified by names. Fonts in the 2D API have three distinct names:
family name
Several fonts may belong to the same family. For example, the bold and italic versions of a font have the same family name. You can find out a Font's family using the getFamily() method.
face name or font name
This name uniquely identifies a font. For example, "Garamond Italic" is a font face name for a font whose family is "Garamond." The face name is also called the font name. This name is returned from Font's getFontName() method.
logical name
Logical names were used before the 2D API to uniquely identify fonts. Toolkit's getFontList() method returns a list of logical font names. Logical font names are mapped to an actual font on a particular machine. "Serif," for example, is a logical font name that corresponds to "Times New Roman" on my Windows NT machine. A font's logical name is retrieved using the getName() method. Don't get tripped up by the method names: getFontName() returns the font name, while getName() returns the logical name.
You can create a font from a name, a style, and a size:
public Font(String name, int style, int size) ...
Get Java 2D Graphics now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.