views:

678

answers:

2

I've looked at the java documentation and scoured the net for information on java's support for international characters with specific fonts (such as Monospace), but haven't been able to get a clear concrete answer.

There has been a change between java 1.4 and java 1.5/1.6. For example, in java 1.4 if you set the font on a JTextArea to Monospace, it won't be able to handle foreign characters (get rectangles instead), but in java 1.5/1.6 it seems to work fine.

Are these differences/improved support clearly documented anywhere?

Thanks

+2  A: 

From Internationalization Enhancements:

Multilingual Text Rendering

To render multilingual text, using logical fonts, 2D now takes advantage of installed host OS fonts for all supported writing systems. For example, if you run in a Thai locale environment, but have Korean fonts installed, both Thai and Korean are rendered. The JRE now also automatically detects physical fonts that are installed into its lib/fonts/fallback directory and adds these physical fonts to all logical fonts for 2D rendering.

Use of Unicode APIs on Windows

AWT now uses the Unicode APIs on Windows 2000/XP. As a result, some of its components can handle text without being restricted by Windows locale settings. For example, AWT text components can accept and display text in the Devanagari writing system regardless of the Windows locale settings. (emphasis mine)

Brandon DuRette
A: 

How "foreign" are these characters? Most Latin-based fonts can handle at least the accented letters and other characters in the upper half of ISO-8859-1, but I don't think you can reasonably count on support for anything beyond that.

Your best bet is usually to let the user choose from a list of supported fonts, which you retrieve from the underlying OS. If can't do that, or don't want to, you can take the CSS approach: iterate through a list of acceptable fonts and use the first one you find installed.

To populate the list, just Google for "programmer fonts" or "monospaced fonts". I never liked any of Java's logical fonts, especially Monospace, which is either Courier or Courier New on a Windows box. I quit using it years ago.

Alan Moore