Skip to main content

Internationalization 101: Setting up a fallback font

Posted by joconner on September 12, 2006 at 11:12 PM PDT

The Problem
Have you ever seen a desktop application that displays question marks or maybe block symbols instead of the correct characters? You know the characters: ???? or □□□□. Maybe you have localized your app to Japanese or Chinese, and those characters just aren't displayed properly.

The most likely cause of the problem is that you don't have a font capable of displaying the character. The J2SE 5.0 environment has reasonable localized mappings for most host platforms. The mappings allows the JRE to quickly find fonts for the various characters you might want. It maps characters to the fonts that contain the correct glyphs. However, your system may not have a font for every character you want to use. For me, this happens most often on development machines that aren't using a localized operating system for the target locale. However, I've noticed this same problem with some of the new supplementary characters in the Unicode standard, and those characters aren't really common in any locale. For example, Etruscan or Gothic characters just don't show up in common, everyday text...but hey, when you need them, you'll be glad to know you can display them.

The Solution
The solution is to install a capable font. You may have to purchase or create your own font for your particular needs, especially if you need supplementary characters. Regardless how you get the font, you have to install it. You have a choice of course:

  1. Embed the font within your application's jar file. Note: this option added after original post
  2. install the font into the host font system and use it by its explicit font name
  3. tweak the font configuration files to map your installed host font to a logical font...messy and not recommended.
  4. install the font as a "fallback" font in your JRE.

Installing a Fallback Font
Adding the font to the JRE's fallback directory might be the simplest solution if you just want to display rarely used characters. A fallback font is the last option for the JRE when it tries to find a character glyph. After searching all the typical places for a glyph, the JRE looks in the fallback directory. It will search the fallback directory and use the first font that contains the needed glyph.

Create a fallback font by adding your font to the "fallback" directory:


This directory may not exist on your system. So just create it if it's not already there.

The Results
In the following screenshots, I display some Gothic characters without a fallback and then with a fallback. A font called Code 2001 provides most of the Unicode plane 1 supplementary characters. I've used it for the screen shots here. Fallback fonts aren't always pretty. In fact, they can be downright ugly...but what do you expect from something called a fallback font?


Image 1. No fallback font is available.

Image 2. The fallback font displays the Gothic characters.

The JRE uses fallback fonts to display characters when no other appropriate font can be found on your host system. Place your fallback fonts in the jre/lib/fonts/fallback directory. Fallback fonts are your JRE's last resort, so make sure those fonts have the characters you need in a crunch.

More tips?
If you have more tips for getting the most out of your JRE, let me know. I especially like tips that help me internationalize applications. And if I post your tip here, I'll be sure to give you full credit for the idea! You can reach me at john @ joconner dot com.

Related Topics >>


&nbsp;I have a problem. I tried to make my app ...

I have a problem. I tried to make my app programmatically copy the fallback font to <JRE_INSTALL_DIR>/jre/lib/fonts/fallback.

It worked well if the jre is not in C drive. But if the jre is in C: drive in Windows or default location in Mac OS or Linux, the code will throw FileNotFoundException due to permission denied by the OS.

Is there any solutions? Do I have to ask users to manually copy the font?

Or is there a way to make Java search for the fallback font in application directory?