Font : Java Glossary

go to home page F words local find full screen, hide local find menu Google search web for more information on this topic jump to foot of page translate this page with Babelfish 2008-02-24 by Roedy Green ©1996-2008 Canadian Mind Products
index page for letter ⇒ punctuation 0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z (all)
CurrCon neededThe CurrCon Java Applet displays prices on this web page converted with today’s exchange rates into your local international currency, e.g. Euros, US dollars, Canadian dollars, British Pounds, Indian Rupees… CurrCon requires Java 1.1 or later, preferably 1.6.0_10. If you can’t see the prices, or if you just want to learn more about CurrCon, click here for help.
JDisplay neededThe JDisplay Java Applet displays the large program listings on this web page. JDisplay requires Java version 1.5 or later, preferably 1.6.0_10 . If you can’t see the listings, of you if just want to learn more about JDisplay, click here for help.
fonts Font
A font is a triple e.g. SansSerif / Bold Italic / 11 point — the combination of type Family, style and size encapsulated into a Font object. See the file font.properties. Inside it are the definitions that map the virtual Java Unicode fonts onto the 8-bit native fonts. Sun may have had to stitch together several 8-bit fonts to cover different regions of the Unicode character set in a Java virtual font. This allows the magic ability to simulate 16-bit Unicode fonts that can display more than 256 different characters when you only have 8-bit native fonts available. In JDK 1.1 you can’t use a native font in Java unless it has entries in the font.properties file to hook it up to some Java virtual font name. In subsequent JDK versions, you can also use any native font installed on the target system. Fontlab Composer is a tool for stitching fonts together.
Acquiring Fonts Displayable? Naming Fonts
Adding Fonts in JDK 1.2 Free Fonts Personal Picks
Adding Fonts in JDK 1.3+ Font Class PostScript Fonts
Anti-aliasing FontShower Amanuensis Proportional Fonts
Art Gotchas Readability
Available Java Fonts Hinting Rendering
Available Windows Fonts Installing a Font In Windows Sans Serif Fonts
Browser Fonts Java Font Support Title Fonts
Bundling Licensing TrueType Fonts
Changing The Default Fonts Java Logical Fonts Units of Measure
ClearType Logical Fonts in CSS Vista Fonts
Commonly Installed Fonts Logical Fonts in Java Windows XP Fonts
Conserving Fonts Macintosh OS X Fonts Books
Corruption Monospaced Fonts Learning More
CSS Logical Fonts Monospaced Programmer Fonts Links
Default CSS Fonts MS Office and Publisher Fonts

Java Font Support

Font Support Under Java
Font Type Extension Java 1.6 Windows Java 1.6 Linux Java 1.6 Fedora Old Java Windows Notes
OpenType
(TrueType internally)
otf High-end fonts for Windows.
OpenType
(PostScript Adobe CCF internally)
otf High end PostScript fonts. You can detect these by the file signature { 0x4F, 0x54, 0x54, 0x4F } — the string "OTTO", at the head of the file.
TrueType ttf Most common font for Windows.
PostScript pfm/pfb Older style PS fonts. Supported by PostScript printer hardware. Windows itself supports PS fonts, at least with Adobe Type Manager, but Java ignores them.
Bitmap fon Used primarily for small font sizes. Come only a small set of point sizes.
Vector outline fon These are obsolete. Used by Windows without Java.
8-bit fonts any Java needs 16-bit fonts. It won’t use 8-bit fonts directly. Old or specialty 8-bit fonts can be used by stitching them together with a Unicode mapping, a daunting task.
AWT will only support the five basic logical fonts, unless you paint on a Canvas, however oddly under Fedora and AWT you can use up to 82 of your installed fonts. If you try to use more, you get an ArrayIndexOutOfBoundsException. The above information may be incorrect or may become incorrect at any time. Feel free to try any fonts with Java on any platform. The worst that could happen is they won’t work.

Java’s Font Class

Sun’s Javadoc on the Font class : available:
// To create a font, you specify:
// 1. The font family name
// 2. The style (combining attribute bits Font.PLAIN, Font.BOLD and Font.Italic)
// 3. The font size in points.
Font font = new Font( "Tiresias PCFont Z", Font.BOLD+Font.Italic, 15 );
A Font does not have a colour attribute. It is always painted in the current foreground colour.

If you accidentally reverse the second and third constructor parameters, your code will compile, but the font display will be microscopic or invisible.

Font Design Is An Art

Circa 1980, I decided to add the French accented letters we use in Canada to the programmable font of an Okidata dot matrix printer. In isolation, my accented letters looked beautiful, but when melded into the rest of the alphabet they looked like a ransom note. I have great respect for the artists who design the world’s classic fonts. Each shape has to have an artistic consistency that says it belongs with the others. At the same time the glyphs must be easily distinguishable from each other. The design has to look good even when rendered crudely on a CRT in small font sizes. Some people like to look at Flemish paintings. I love to look at beautiful fonts. When you understand how much work goes into creating a great one, you would be less likely to pirate it. Peruse the “art gallery” at Adobe or BitStream MyFonts.

What Fonts Are Available Windows

To see what fonts are available to Windows, click Start ⇒ Control Panel ⇒ Appearance and Personalization ⇒ Fonts . These fonts will work in Windows word processors and many Windows programs including browsers. Not all of the fonts will work in Java, or Java Applets however. To find out the name of the corresponding file in C:\Windows, right click Properties.

Installing a Font In Windows

To install a font in Windows Vista, usually TTF or OpenType-TTF:
  1. Click Start
  2. Control Panel
  3. Appearance and Personalisation
  4. Install or Remove a Font
  5. Click File. If you don’t see File, click Alt.
  6. Install New Font
  7. In the Add Fonts dialog box, under Drives, click the drive where the font that you want to install is located
  8. Under Folders, double-click the folder containing the fonts that you want to add
  9. Under List of fonts, click the font that you want to add
  10. click Install

What Fonts Are Available On My Machine under Java?

Adding Fonts to JDK 1.3+

Font f = Font.createFont( Font.TRUETYPE_FONT, inputStream );
let’s you dynamically create a 1-point plain font from a TrueType font file. It does not have to be installed in the OS. You can then deriveFont to create the fonts in the required sizes and styles. These fonts don’t work well at small point sizes because they don’t implement hinting. You could then fish fonts from the net, from the local hard disk or from the jar, much the way you can fetch images.

This does not permanently install the font. There is no platform-independent way to do that. In Windows 2000, you can copy the TrueType font to C:\WINNT\FONTS.

You would have to read your font licence agreement carefully to see if it permits you to use the font in this way.

If you wish to use PostScript Type 1 multiple master fonts with W2K/XP/W2K3/Vista, you need to install Adobe Type Manager 4.1 or later. Do not install ATM 4.0 or earlier on W2K/XP/W2K3/Vista. W2K/XP/W2K3/Vista have built-in support for ordinary PostScript Type 1 fonts, and OpenType, though Java ignores the PostScript fonts.

Adding Fonts to JDK 1.2 (obsolete)

In JDK 1.2+ you can access fonts either by Java logical or native-physical name. To make a new font accessible to JDK 1.2 you have three choices:
  1. Install the font on your host by following the host’s directions for installing fonts. On Windows, for example, you do this via control panel ⇒ Fonts. The font will be available both to your native Windows apps and your Java apps. Most TrueType fonts have a Unicode cmap index. You’ll notice that only a few do not. For example, if you look in your font.properties files, only Wingdings and Symbol fonts have the NEED_CONVERTED tag on them, which indicates that they require a conversion from a Unicode codepoint to a different indexing scheme within the font. If they have a native cmap index, Java is able to use them without special entries in the font.properties file.
  2. Copy the font into your jre/lib/fonts subdirectory. The font will be available only to Java. Notice that there are a set of Lucida fonts in there already: Lucida Bright, Lucida Sans and Lucida Sans Typewriter.
  3. Install the font using the font.properties file as you would in JDK 1.1. You would need to use this technique if you needed to stitch several 8-bit fonts together to form one big Java logical Unicode font.

Units of Measure, Points and Pixels

Fonts are nominally measured in points, 1/72 of an inch tall. If Java truly did this, the number of pixels tall a given font was would depend both on the screen resolution and the size of the user’s monitor. Fonts would grow and shrink all out of proportion to the surrounding graphical elements based on pixels. To get around this problem, Java declares that one point equals one pixel. If you ask for a 10 point font, you are actually getting one nominally 10 pixels high. There will still be some characters taller and some shorter than 10 pixels.

But the real problem is historical. Two fonts families, both 12 points can be drastically different sizes. The size includes a variable about of vertical white space the designer thinks looks good with his font. You can see this effect clearly when you examine fonts with FontShower. Different fonts all rendered at the same point size are drastically different in size. This creates a WORA nightmare for Java programmers. If a font used to design an application is not not available on the client’s computer, or if the font has the same name, but a different provider, the text may be way too big or too small to fit in the space allotted. You run into this problem even with the Sun standard logical default fonts like Dialog. Phhht! To deal with this, I resorted to the ugly kludge of making my Applets 12% bigger than optimal on my Vista machine to give them some slop to run with larger versions of the 16 point Dialog font on other platforms. Of course, this makes the Applets look silly on Vista machines.

Font Naming

Fonts have three names:
  1. The retail name used to sell the font, e.g. Century Schoolbook.
  2. The family name, usually abbreviated, e.g. CentSchbook BT. This is typically what you use in Java or in your CSS style sheet. You must get the spelling exactly right including spaces.
  3. The precise font name, including adoments (suffixes to describe weight, style, stretch etc.), e.g. CentSchbook BT Roman, CentSchbook BT Italic, CentSchbook BT Bold, CentSchbook BT Bold Italic, CentSchbook BdCn BT Bold (bold condensed) or CentSchbook Mono BT (monospaced).

Acquiring Fonts

When buying fonts be aware that usually you buy the bold, italic, light, condensed etc. versions separately. They behave more or less as one font once you install them. Sometimes you pay extra for the full character set. Check to see if your font has upper and lower case, accented letters, the €, ligatures, ornaments, small caps… Check carefully exactly what is included in the bundle you buy.

Unfortunately, when you buy a font that usually gives you the right to use it on only your computer, but not to let people download it to view your webpages, or to include it in your programs. Usually you would not even be permitted to include them in PDF documents. BitStream discontinued its scheme of downloadable fonts called webfonts that let you include the font in your web pages. CSS provides a scheme to include your fonts in your web pages, but they have to be free fonts or fonts you have licenced to distribute.

Personal Picks

Here are some of my favourite fonts. If you don’t have the font installed you will see something only vaguely similar:
Tiresias PCFont Z The letters are unusually distinctive so there is no confusing them. It is very clean simple proportional font. It was designed for people with poor eyesight so gives particularly smooth reading for people with normal eyesight. Most fonts are poorly designed so it is hard to tell the characters iI!|l o0O8¤[]() qg Ww `'‘’“” ()[]{} ;,. apart. Tiresias is a special font family designed so that even the visually impaired can distinguish them. It looks like this:

TiresiasScreenFont and Tiresias PCFont Z font samples

If you already have it installed, all the type in this sentence will look similar. It is the default font for my website for non-Windows platforms. I asked the designers to create a monospace variant but they declined.

Calibri Comes bundled with Vista. Renders very sharply. Very spare, like something an engineer might use on drawings. Lighter than Arial.
Consolas Comes bundled with Vista. Renders very sharply. Monospaced. Perhaps the best looking monospaced font. Has a sort of Euro spare look.
Constantia Comes bundled with Vista. Renders very sharply. Somewhat old-fashioned looking with pronounced serifs. Used old-style figures. 0123456789 will be different sizes and alignments if you have it installed.
Segoe UI Comes bundled with Vista. Renders very sharply. Delicate, clean, works well in small sizes for labelling things.
DPCustomMono2 A monospaced font designed expressly for proofreading. It makes it easy to tell comma/period and colon/semicolon apart. You need anti-aliasing turned on for it to look half-way decent.
Bookman Old Style This has an old-fashioned, relaxed, hot-oatmeal for breakfast look.
Palatino This an elegant font, something like the font equivalent of Paul Revere silver designs emphasising utility and simplicity.
Warnock Pro Opticals These are the Porsches of fonts. I doubt I will ever own them since they are so expensive.
Frutiger Microsoft ripped this elegant design off by changing it slightly and calling it Segoe and reserving it as their corporate font.
OCR-B A monospaced font designed originally for optical character recognition. In making the characters distinct enough for computers, they also made them distinct for rapid human reading. There are no decent free ones around.
Keystrokes Keycaps to let you explain the keystrokes you need to get do something on your PC. The problem is you are not allowed to use the font on your website, which defeats the purpose of it.
Aquila Regular Just a touch of eccentricity to make it interesting.
Cash EF This a modern-looking monospace font. Further, even in the tiniest font sizes it is eminently readable. It’s big problem is the zero and capital O are identical making this font useless for programmers. I have written the Eslner+Flake type foundry who created it asking them to create a variant suitable for programmers. They ignored me.
Base Nine and Twelve This font is particularly good at small point sizes. It is an open design so the loops don’t clog. It offers small caps. It is somewhat heavy looking.
Segoe Print looks like hand printing. Comes bundled with Vista.

Font Licensing

I have been trying to make sense of the legalese on the font sites and talking with company representatives. I think the basic idea is, you can allow an many people as you please to view your document using the font, but you can’t allow more than 1 to 20 people, depending on the agreement for the particular font, at your site to compose new messages or documents using the font.

As I understand it, you typically can do the following things without needing an extra multi-user licence above and beyond buying the font:

As I understand it, you need an extra multi-user license to do the following things:

Readable Fonts

In Windows, you can increase or decrease the size of fonts universally for all applications, dialog boxes, menus, icon titles etc. click Start ⇒ Settings ⇒ Control Panel ⇒ Display ⇒ Settings ⇒ Advanced ⇒ General ⇒ Font Size. The catch is, if you increase fonts to 120% bigger, some program such as ASO and PadCreator will garble their layouts. You can of course lower the screen resolution to get bigger fonts, but that impairs your ability to look at images.

To control the font and size of any individual item such as tooltip, click Start ⇒ Settings ⇒ Control Panel ⇒ Display ⇒ Appearance ⇒ Item . You can then select Active Title Bar, Inactive Title Bar, Palette Title, Message Box, Menu, Selected Item or Icon and set the font and size.

Neither of these techniques will change the font sizes used by applications. For that you need to look to custom ways in each application to customise the fonts and sizes.

Java fonts look terrible because by default they do no antialiasing and ignore the hints. You can improve them with anti-aliasing.

Most fonts don’t support many of the national currency symbols. Tahoma is better than most.

Rendering

There are three ways to render fonts in Java.
  1. AWT: limited to the 5 Java logical fonts. Anti-aliasing is controlled by the OS. Easy to program. Rendering is handled by the OS which renders the heavyweight peers associated with each Component. For an example of such rendering see FontShowerAWT.
  2. AWT Canvas: can use all the OS fonts. Can choose programmatically whether you want Anti-aliasing. This is difficult to program since you do all your rendering at the low-level drawString level. For an example of such rendering see com.mindprod.fontshowerawt. AntiAliastedFontedTextArea or FontedTextArea.
  3. Swing: can use all the OS fonts. Easy to program. Rendering the fonts is managed by the Swing runtime on lightweight JComponents. Anti-aliasing is controlled by the OS. For an example of such rendering see FontShower for Swing.

On my Vista machine, configured in the Control Panel to use ClearType anti-aliasing to smooth font edges, under both AWT and Swing I see fonts fully anti-aliased. The only time I see degraded fonts are when I view fonts rendered on an AWT Canvas without anti-alias. Ditto for XP. With an LCD monitor, you want ClearType subpixel anti-aliasing. To turn it on click Start ⇒ Control Panel ⇒ Appearance and Personalization ⇒ Personalization ⇒ Windows color and appearance ⇒ Open classic colour and appearance ⇒ Effects ⇒ ClearType.

Hinting

A separate matter from anti-aliasing is hinting. PostScript and OpenType fonts include hints on how to render small font sizes. You could think of it in principle as raster versions of the fonts for tiny font sizes. In AWT, the OS renders the fonts using its native facilities for taking hints. In Swing, Java renders the fonts, for all practical purposes ignoring the hints. The result is Swing fonts can look ratty at small point sizes, but quite decent at larger ones.

ClearType

Antialiasing creates the illusion of crisp smooth edges on rendered type ironically, by fuzzy the edge, by filling in a jaggy pixel with a colour intermediate between the colours on either side of the boundary. This anti-aliasing can be done even to a sub-pixel level with the red, green and blue sub pixels on an LCD screen. Fonts that can do this ultra-fine anti-aliasing are called ClearType. To turn on the rendering which makes text crisper by activating the extra rendering effort in Windows:

Here is how to activate ClearType font in Windows XP:

  1. Click Start
  2. Control Panel
  3. Appearance and Themes
  4. Display
  5. Appearance
  6. Effects
  7. Click Use the following method to smooth edges of screen fonts.
  8. Select ClearType in the list.
Here is how to activate ClearType font in Vista:
  1. Start
  2. Control Panel
  3. System and Maintenance
  4. Performance Information and Tools
  5. Adjust Visual Effects (on left)
  6. smooth edges of screen fonts
By default anti-aliasing is on. For some fonts, Vista even supports subpixel anti-aliasing called Clear Type.

You can fine tune the clear type by downloading this powertuner from Microsoft.

Corrupt Fonts

Sometimes fonts will come out too tiny to see. Likely it means you have reversed the last two parameters when you created the font, a error the compiler cannot detect since Font does not use enums, just enumerated int constants.
// OOPS, DON'T DO THIS!
component.setFont( new Font( "Dialog", 12, Font.BOLD ));

// do this instead:
component.setFont( new Font( "Dialog", Font.BOLD, 12 ));
On Windows, sometimes strange rendering problems are caused by a corrupt font cache. You can simply delete the cache, sacrifice a small reptile and reboot. Here’s how:
del C:\WINNT\System32\fntcache.dat
Other times the problem is a defective font. Before you pull your hair out, check to see if your problems go away if you try one of the standard fonts instead. Defective font problems can manifest in bizarre ways — e.g. cursor offset from where it should be, duplicate rendering and misplaced text.

Bundling Fonts In a Jar

If you want to include custom fonts in your application, you either have to get the customer to install them or employ the following trick to use them directly from a jar. This only works in Swing since AWT components are limited to the Java logical fonts.

Conserving Fonts

Font f = new Font( "Monospaced", Font.PLAIN, 12 )
is a very time consuming operation. Save your Font objects and reuse them rather than creating new ones. See FontSaver to reduce RAM usage by Java fonts.

Having too many fonts installed, (not the same thing as having too many duplicate Font objects), has several drawbacks:

You can use a tool like Adobe Type Manager to rapidly and globally install/uninstall entire constellations of fonts.

Will this character Display?

boolean Font.canDisplay( char );
will let you know if there is a glyph matching a given Unicode character in a given font. Unfortunately, it has a rather lax definition of “can display”. It will often return true and just display a blob or empty rectangle.

It is up to you to find a font that can display the character you need. Unfortunately, fonts often lie about what glyphs they can display. For example, if you ask them if they can display a euro, they say yes, then display a blob, which in their distorted view of things counts as displaying the character. Technically, canDisplay is supposed to return true for any code point in the range handled by the font, which is not very useful information.

Happily, if you specify a font not installed on the target machine, Java simply reverts to the default font. There is no mechanism similar to CSS or HTML where you can specify a list of fonts in preference order. You have to code that yourself and feed setFont a specific Font.

Changing the Default Fonts

To change the default fonts inside the AWT use code like this:
Font defaultFont = new Font( "Dialog", Font.PLAIN, 12 );
UIManager.put( "Button.font", new FontUIResource ( defaultFont ) );
You can make similar default font changes to these elements:
Button.font List.font PasswordField.font TableHeader.font ToggleButton.font
Checkbox.font Menu.font PopupMenu.font Text.font ToolBar.font
ColorChooser.font MenuBar.font ProgressBar.font TextArea.font ToolTip.font
ComboBox.font MenuItem.font RadioButton.font TextField.font Tree.font
EditorPane.font OptionPane.font ScrollPane.font TextPane.font  
Label.font Panel.font Table.font TitledBorder.font  
For Swing there is a even more sweeping system of defaults called LAF Look and Feel. see javax.swing.LookAndFeel and javax.swing.UIDefaults.
Sun’s Javadoc on the LookAndFeel class : available:
Sun’s Javadoc on the UIDefaults class : available:

The approach is to write your own Look & Feel that extends some other one, and just overrides a few font-defining methods or colour-defining methods. See this sample code for a writing a derived LAF.

Here are some resources if you want to attempt multi-lingual fonts. Prior to JDK 1.4, I only managed to get Unicode fonts to display properly with NT and Win2K and Internet Explorer. Windows 98 displays accented letters above 255 without the accents.

Font Gotchas

Books

book cover recommend book⇒Thinking with Type: A Critical Guide for Designers, Writers, Editors, & Students (Design Briefs)
 paperback
ISBN13:978-1-56898-448-3clickcounter
ISBN10:1-56898-448-0clickcounter
publisher:Princeton Architectural Press
published:2004-09-09
by:Ellen Lupton
This is not a font catalog book. It is a book about how to select the right font for the job, and about how to design type generally.
UK flag abe books.co.uk abe books.ca Canadian flag
UK flag amazon.co.uk. amazon.ca. Canadian flag
German flag abe books.de chapters.indigo.ca . Canadian flag
German flag amazon.de. abe books.com American flag
French flag abe books.fr amazon.com. American flag
French flag amazon.fr. barnes and noble.com American flag
Italian flag abe books.it powells.com American flag
Spanish flag iberlibro.com abe books anz Australian flag
book cover recommend book⇒Big Book of 5000 Fonts: (And Where to Get Them)
 hardcover
ISBN13:978-0-8230-0489-8clickcounter
ISBN10:0-8230-0489-9clickcounter
publisher:Watson-Guptill Publications
published:2002-02
by:David Carter
also includes websites with free downloadable fonts. Note the publish date. Font books in general tend to be out of date.
UK flag abe books.co.uk abe books.ca Canadian flag
UK flag amazon.co.uk. amazon.ca. Canadian flag
German flag abe books.de chapters.indigo.ca . Canadian flag
German flag amazon.de. abe books.com American flag
French flag abe books.fr amazon.com. American flag
French flag amazon.fr. barnes and noble.com American flag
Italian flag abe books.it powells.com American flag
Spanish flag iberlibro.com abe books anz Australian flag
book cover recommend book⇒Logo Font & Lettering Bible: A Comprehensive Guide to the Design, Construction and Usage of Alphabets and Symbols
 hardcover
ISBN13:978-1-58180-436-2clickcounter
ISBN10:1-58180-436-9clickcounter
publisher:How Design Books
published:2004-03
by:Leslie Cabarga
This is about how to design your owncustom fonts and logos.
UK flag abe books.co.uk abe books.ca Canadian flag
UK flag amazon.co.uk. amazon.ca. Canadian flag
German flag abe books.de chapters.indigo.ca . Canadian flag
German flag amazon.de. abe books.com American flag
French flag abe books.fr amazon.com. American flag
French flag amazon.fr. barnes and noble.com American flag
Italian flag abe books.it powells.com American flag
Spanish flag iberlibro.com abe books anz Australian flag

Learning More

Sun’s Javadoc on the Font class : available:
Sun’s Javadoc on the FontMetrics class : available:
Sun’s JDK Technote Guide on Font Configuration Files : available:

CMP homejump to top
CMP logo
feedback Please email your feedback for publication, errors, omissions, broken/redirected link reports
and suggestions to improve this page to Roedy Green : feedback email
made with CSS
HTML Checked!
ICRA ratings logo
mindprod.com IP:[65.110.21.43]
Your face IP:[38.103.63.62] Environmental holiday cards that actually help the environment
You are visitor number 70,557.
You can get a fresh copy of this page from: or possibly from your local J: drive (Java virtual drive/mindprod.com website mirror)
http://mindprod.com/jgloss/font.html J:\mindprod\jgloss\font.html