Need know how java picks up correct font for multilingual text?

Hi, there!

I did a little Swing (jdk 1.5 on Windows XP) JTextArea and put in utf-8 characters of Japanese, Chinese, English (I am not sure if the English characters were of UTF-8 though because I typed in directly). All the text were rendered correctly. I know that this is because the OS has fonts in jre fonts/fallback. But what I don't understand is

1) How does Java pick up correct font without me specifying font name in the program?

2) If I use Microsoft IME to input characters (what charset? - I don't know), will it always work as long as there is font for the language in the directory in the Windows platform?

3) Must I specify font name in jdk 1.4?

Thanks in advance for any replies!

Nate

[747 byte] By [NateMiddleWesta] at [2007-11-27 6:53:34]
# 1

hi!

there is a default font for the UIManager, you can always override that. but how java would know which font you need unless you tell that. and how java would know which font will support which char? so it is you who knows it. so you need to specify that to java.

regards

Aniruddha

Aniruddha-Herea at 2007-7-12 18:28:21 > top of Java-index,Desktop,I18N...
# 2

I appreciate the reply. I don't believe I specified which font to use for a certain language anywhere, but for some reason Java 1.5 figured that out. I just want to find out how, from the OS code page, jvm setting, ...? Java 1.4 could not do it.Understanding the underlying mechanism would help me greatly in developing a Swing application supporting multiple languages.

thanks, Nate

NateMiddleWesta at 2007-7-12 18:28:21 > top of Java-index,Desktop,I18N...
# 3

Hi Nate,

The 2D font architecture was redesigned in JDK 5 to render multilingual text. That's why you see the font.properties was renamed to fontconfig.properties. The configs basically have the information of the installed fonts in the underlying OS. So as long as your application uses the logical fonts in Swing, Java tries to select the suitable OS font for multilingual texts to be rendered.

Naoto

naotoa at 2007-7-12 18:28:21 > top of Java-index,Desktop,I18N...
# 4

Hello! Thanks for answering my questions.

In my Swing application (java 5 on Windows), the default font is "dialog" and the encoding of the input text is utf-8. I am able to mix Chinese, English, Japanese and Russian text in one text area and they all appear great. I understand it gets the correct font(s) from the underlying OS since I use logical font. My question is, does the Swing application use one physical font or four fonts since I used four languages (although the charset is utf-8). I believe it uses one. Then which physical font? I have the following entry in the java 5 font config file:

sequence.allfonts.UTF-8.hi=alphabetic/1252,devanagari,dingbats,symbol

Thanks, Nate

NateMiddleWesta at 2007-7-12 18:28:21 > top of Java-index,Desktop,I18N...
# 5

Actually, whether it uses one physical font or four physical fonts depends on the text you want to draw. If the glyphs used for drawing the text are contained in one physical font, it simply uses the font, otherwise, it fall back to the next phisical font in the lookup sequence.

For more detail, please take a look at the following document for the font configuration. It explains how JDK maps a logical font to a sequence of physical fonts and their files.

http://java.sun.com/j2se/1.5.0/docs/guide/intl/fontconfig.html

Naoto

naotoa at 2007-7-12 18:28:21 > top of Java-index,Desktop,I18N...