views:

132

answers:

1

I have the following issue using java 1.4

I try to display a very simple HTML document in a JTextPane that contains chinese characters.

If the locale used when launching the java virtual machine is user.language=zh and user.country=CN the graphical characters are rendered correctly.

For any other locale, the characters are rendered as squares.

The difference I see is that java 1.4 uses a different font.properties file for each locale. In this particular case, the font.properties.zh file contains an extra entry:

dialog.plain.0=Arial,ANSI_CHARSET 
**dialog.plain.1=\u5b8b\u4f53,GB2312_CHARSET**
dialog.plain.1=WingDings,SYMBOL_CHARSET
dialog.plain.2=Symbol,SYMBOL_CHARSET

Now, this entry is not available for the other locales.

The problem I have, is that I need to be able to render this string while using any locale. Furthermore, I can't modify the font.properties file to add extra entries as I have no control on the JVM used by the client.

In Java 1.5 this problem does not occur.

Is there any way to add this mapping programmatically? Is there any other solution?

A: 

Apparently the answer is....

Not possible for java 1.4 as per this url:

http://java.sun.com/javase/technologies/core/basic/intl/faq.jsp#desktop-rendering

Using logical font names:

  • Advantages: These font names are guaranteed to work anywhere, and they enable text rendering in at least the language that the host operating system is localized for (often a much larger range of languages).

  • Disadvantages: The physical fonts used for rendering the text vary between different implementations, host operating systems, and locales, so an application can not achieve the same look everywhere. Also, the mapping mechanisms occasionally limit the range of characters that can be rendered. The latter used to be a big problem on JRE versions before 5.0: for example, Japanese text could only be rendered on Japanese localized host operating systems, not on other localized systems even if Japanese fonts have been installed. For applications using 2D font rendering, this problem is much rarer with JRE version 5.0, because the mapping mechanism now generally recognizes and uses fonts for all supported writing systems if they are installed.

The only possible way seems to set a font that has known support for extended graphical characters in a hard-coded way, in the component.

Mario Ortegón