Enable display of Vietnamese on Java components on Linux

Trên Linux, cho Java 1.4.2 trở về trước, để cho phép hiển thị chữ Việt mà không cần phải programmatically đặt font cho từng component, ta có thể chỉnh/thay file font.properties file dưới jre/lib subdirectory như sau:

# @(#)font.properties.linux    1.7 02/03/07
#
# Copyright 2002 Sun Microsystems, Inc. All rights reserved.
#

# Component Font Mappings
#
serif.0=-b&h-lucidabright-medium-r-normal--*-%d-*-*-p-*-iso8859-1
serif.1=--standard symbols l-medium-r-normal--*-%d-*-*-p-*-urw-fontspecific
serif.2=-monotype-Times New Roman-medium-r-normal--*-%d-*-*-p-*-iso10646-1

serif.italic.0=-b&h-lucidabright-medium-i-normal--*-%d-*-*-p-*-iso8859-1
serif.italic.1=--standard symbols l-medium-r-normal--*-%d-*-*-p-*-urw-fontspecific
serif.italic.2=-monotype-Times New Roman-medium-i-normal--*-%d-*-*-p-*-iso10646-1

serif.bold.0=-b&h-lucidabright-demibold-r-normal--*-%d-*-*-p-*-iso8859-1
serif.bold.1=--standard symbols l-medium-r-normal--*-%d-*-*-p-*-urw-fontspecific
serif.bold.2=-monotype-Times New Roman-bold-r-normal--*-%d-*-*-p-*-iso10646-1

serif.bolditalic.0=-b&h-lucidabright-demibold-i-normal--*-%d-*-*-p-*-iso8859-1
serif.bolditalic.1=--standard symbols l-medium-r-normal--*-%d-*-*-p-*-urw-fontspecific
serif.bolditalic.2=-monotype-Times New Roman-bold-i-normal--*-%d-*-*-p-*-iso10646-1

sansserif.0=-b&h-lucidasans-medium-r-normal-sans-*-%d-*-*-p-*-iso8859-1
sansserif.1=--standard symbols l-medium-r-normal--*-%d-*-*-p-*-urw-fontspecific
sansserif.2=-monotype-Arial-medium-r-normal--*-%d-*-*-p-*-iso10646-1

sansserif.italic.0=-b&h-lucidasans-medium-i-normal-sans-*-%d-*-*-p-*-iso8859-1
sansserif.italic.1=--standard symbols l-medium-r-normal--*-%d-*-*-p-*-urw-fontspecific
sansserif.italic.2=-monotype-Arial-medium-i-normal--*-%d-*-*-p-*-iso10646-1

sansserif.bold.0=-b&h-lucidasans-bold-r-normal-sans-*-%d-*-*-p-*-iso8859-1
sansserif.bold.1=--standard symbols l-medium-r-normal--*-%d-*-*-p-*-urw-fontspecific
sansserif.bold.2=-monotype-Arial-bold-r-normal--*-%d-*-*-p-*-iso10646-1

sansserif.bolditalic.0=-b&h-lucidasans-bold-i-normal-sans-*-%d-*-*-p-*-iso8859-1
sansserif.bolditalic.1=--standard symbols l-medium-r-normal--*-%d-*-*-p-*-urw-fontspecific
sansserif.bolditalic.2=-monotype-Arial-bold-i-normal--*-%d-*-*-p-*-iso10646-1

monospaced.0=-b&h-lucidatypewriter-medium-r-normal-sans-*-%d-*-*-m-*-iso8859-1
monospaced.1=--standard symbols l-medium-r-normal--*-%d-*-*-p-*-urw-fontspecific
monospaced.2=-monotype-Courier New-medium-r-normal--*-%d-*-*-m-*-iso10646-1

monospaced.italic.0=-b&h-lucidatypewriter-medium-i-normal-sans-*-%d-*-*-m-*-iso8859-1
monospaced.italic.1=--standard symbols l-medium-r-normal--*-%d-*-*-p-*-urw-fontspecific
monospaced.italic.2=-monotype-Courier New-medium-i-normal--*-%d-*-*-m-*-iso10646-1

monospaced.bold.0=-b&h-lucidatypewriter-bold-r-normal-sans-*-%d-*-*-m-*-iso8859-1
monospaced.bold.1=--standard symbols l-medium-r-normal--*-%d-*-*-p-*-urw-fontspecific
monospaced.bold.2=-monotype-Courier New-bold-r-normal--*-%d-*-*-m-*-iso10646-1

monospaced.bolditalic.0=-b&h-lucidatypewriter-bold-i-normal-sans-*-%d-*-*-m-*-iso8859-1
monospaced.bolditalic.1=--standard symbols l-medium-r-normal--*-%d-*-*-p-*-urw-fontspecific
monospaced.bolditalic.2=-monotype-Courier New-bold-i-normal--*-%d-*-*-m-*-iso10646-1

dialog.0=-b&h-lucidasans-medium-r-normal-sans-*-%d-*-*-p-*-iso8859-1
dialog.1=--standard symbols l-medium-r-normal--*-%d-*-*-p-*-urw-fontspecific
dialog.2=-monotype-Arial-medium-r-normal--*-%d-*-*-p-*-iso10646-1

dialog.italic.0=-b&h-lucidasans-medium-i-normal-sans-*-%d-*-*-p-*-iso8859-1
dialog.italic.1=--standard symbols l-medium-r-normal--*-%d-*-*-p-*-urw-fontspecific
dialog.italic.2=-monotype-Arial-medium-i-normal--*-%d-*-*-p-*-iso10646-1

dialog.bold.0=-b&h-lucidasans-bold-r-normal-sans-*-%d-*-*-p-*-iso8859-1
dialog.bold.1=--standard symbols l-medium-r-normal--*-%d-*-*-p-*-urw-fontspecific
dialog.bold.2=-monotype-Arial-bold-r-normal--*-%d-*-*-p-*-iso10646-1

dialog.bolditalic.0=-b&h-lucidasans-bold-i-normal-sans-*-%d-*-*-p-*-iso8859-1
dialog.bolditalic.1=--standard symbols l-medium-r-normal--*-%d-*-*-p-*-urw-fontspecific
dialog.bolditalic.2=-monotype-Arial-bold-i-normal--*-%d-*-*-p-*-iso10646-1

dialoginput.0=-b&h-lucidatypewriter-medium-r-normal-sans-*-%d-*-*-m-*-iso8859-1
dialoginput.1=--standard symbols l-medium-r-normal--*-%d-*-*-p-*-urw-fontspecific
dialoginput.2=-monotype-Courier New-medium-r-normal--*-%d-*-*-m-*-iso10646-1

dialoginput.italic.0=-b&h-lucidatypewriter-medium-i-normal-sans-*-%d-*-*-m-*-iso8859-1
dialoginput.italic.1=--standard symbols l-medium-r-normal--*-%d-*-*-p-*-urw-fontspecific
dialoginput.italic.2=-monotype-Courier New-medium-i-normal--0-0-0-0-m-0-iso10646-1

dialoginput.bold.0=-b&h-lucidatypewriter-bold-r-normal-sans-*-%d-*-*-m-*-iso8859-1
dialoginput.bold.1=--standard symbols l-medium-r-normal--*-%d-*-*-p-*-urw-fontspecific
dialoginput.bold.2=-monotype-Courier New-bold-r-normal--*-%d-*-*-m-*-iso10646-1

dialoginput.bolditalic.0=-b&h-lucidatypewriter-bold-i-normal-sans-*-%d-*-*-m-*-iso8859-1
dialoginput.bolditalic.1=--standard symbols l-medium-r-normal--*-%d-*-*-p-*-urw-fontspecific
dialoginput.bolditalic.2=-monotype-Courier New-bold-i-normal--*-%d-*-*-m-*-iso10646-1

# Missing Glyph Character
#
default.char=274f

# Component Font Character Encodings
#
fontcharset.serif.0=sun.io.CharToByteISO8859_1
fontcharset.serif.1=sun.awt.CharToByteSymbol

fontcharset.sansserif.0=sun.io.CharToByteISO8859_1
fontcharset.sansserif.1=sun.awt.CharToByteSymbol

fontcharset.monospaced.0=sun.io.CharToByteISO8859_1
fontcharset.monospaced.1=sun.awt.CharToByteSymbol

fontcharset.dialog.0=sun.io.CharToByteISO8859_1
fontcharset.dialog.1=sun.awt.CharToByteSymbol

fontcharset.dialoginput.0=sun.io.CharToByteISO8859_1
fontcharset.dialoginput.1=sun.awt.CharToByteSymbol

# Exclusion Ranges
#

# XFontSet Information
#
fontset.serif.plain=\
-b&h-lucidabright-medium-r-normal--*-%d-*-*-p-*-iso8859-1,\
-monotype-Times New Roman-medium-r-normal--*-%d-*-*-p-*-iso10646-1

fontset.serif.italic=\
-b&h-lucidabright-medium-i-normal--*-%d-*-*-p-*-iso8859-1,\
-monotype-Times New Roman-medium-i-normal--*-%d-*-*-p-*-iso10646-1

fontset.serif.bold=\
-b&h-lucidabright-demibold-r-normal--*-%d-*-*-p-*-iso8859-1,\
-monotype-Times New Roman-bold-r-normal--*-%d-*-*-p-*-iso10646-1

fontset.serif.bolditalic=\
-b&h-lucidabright-demibold-i-normal--*-%d-*-*-p-*-iso8859-1,\
-monotype-Times New Roman-bold-i-normal--*-%d-*-*-p-*-iso10646-1

fontset.sansserif.plain=\
-b&h-lucida-medium-r-normal-sans-*-%d-*-*-p-*-iso8859-1,\
-monotype-Arial-medium-r-normal--*-%d-*-*-p-*-iso10646-1

fontset.sansserif.italic=\
-b&h-lucida-medium-i-normal-sans-*-%d-*-*-p-*-iso8859-1,\
-monotype-Arial-medium-i-normal--*-%d-*-*-p-*-iso10646-1

fontset.sansserif.bold=\
-b&h-lucida-bold-r-normal-sans-*-%d-*-*-p-*-iso8859-1,\
-monotype-Arial-bold-r-normal--*-%d-*-*-p-*-iso10646-1

fontset.sansserif.bolditalic=\
-b&h-lucida-bold-i-normal-sans-*-%d-*-*-p-*-iso8859-1,\
-monotype-Arial-bold-i-normal--*-%d-*-*-p-*-iso10646-1

fontset.monospaced.plain=\
-b&h-lucidatypewriter-medium-r-normal-sans-*-%d-*-*-m-*-iso8859-1,\
-monotype-Courier New-medium-r-normal--*-%d-*-*-m-*-iso10646-1

fontset.monospaced.italic=\
-b&h-lucidatypewriter-medium-r-normal-sans-*-%d-*-*-m-*-iso8859-1,\
-monotype-Courier New-medium-i-normal--*-%d-*-*-m-*-iso10646-1

fontset.monospaced.bold=\
-b&h-lucidatypewriter-bold-r-normal-sans-*-%d-*-*-m-*-iso8859-1,\
-monotype-Courier New-bold-r-normal--*-%d-*-*-m-*-iso10646-1

fontset.monospaced.bolditalic=\
-b&h-lucidatypewriter-bold-r-normal-sans-*-%d-*-*-m-*-iso8859-1,\
-monotype-Courier New-bold-i-normal--*-%d-*-*-m-*-iso10646-1

fontset.dialog.italic=\
-b&h-lucida-medium-i-normal-sans-*-%d-*-*-p-*-iso8859-1,\
-monotype-Arial-medium-i-normal--*-%d-*-*-p-*-iso10646-1

fontset.dialog.bold=\
-b&h-lucida-bold-r-normal-sans-*-%d-*-*-p-*-iso8859-1,\
-monotype-Arial-bold-r-normal--*-%d-*-*-p-*-iso10646-1

fontset.dialog.bolditalic=\
-b&h-lucida-bold-i-normal-sans-*-%d-*-*-p-*-iso8859-1,\
-monotype-Arial-bold-i-normal--*-%d-*-*-p-*-iso10646-1

fontset.dialog.plain=\
-b&h-lucida-medium-r-normal-sans-*-%d-*-*-p-*-iso8859-1,\
-monotype-Arial-medium-r-normal--*-%d-*-*-p-*-iso10646-1

fontset.dialoginput.italic=\
-b&h-lucidatypewriter-medium-r-normal-sans-*-%d-*-*-m-*-iso8859-1,\
-monotype-Courier New-medium-i-normal--0-0-0-0-m-0-iso10646-1

fontset.dialoginput.bold=\
-b&h-lucidatypewriter-bold-r-normal-sans-*-%d-*-*-m-*-iso8859-1,\
-monotype-Courier New-bold-r-normal--*-%d-*-*-m-*-iso10646-1

fontset.dialoginput.bolditalic=\
-b&h-lucidatypewriter-bold-r-normal-sans-*-%d-*-*-m-*-iso8859-1,\
-monotype-Courier New-bold-i-normal--*-%d-*-*-m-*-iso10646-1

fontset.dialoginput.plain=\
-b&h-lucidatypewriter-medium-r-normal-sans-*-%d-*-*-m-*-iso8859-1,\
-monotype-Courier New-medium-r-normal--*-%d-*-*-m-*-iso10646-1

fontset.default=\
-b&h-lucida-medium-r-normal-sans-*-%d-*-*-p-*-iso8859-1,\
-microsoft-Tahoma-medium-r-normal--*-%d-*-*-p-*-iso10646-1

# appendedfontpath=/usr/share/fonts/truetype
# or set JAVA_FONTS environment variable to appropriate font path
# (Unicode truetype font folder) and export it

Dĩ nhiên, các Windows Unicode TrueType fonts được sử dụng -- Times New Roman, Arial, Courier New, và Tahoma -- đã phải được cài vào system, chép vào thư mục /usr/share/fonts/TrueType, chẳng hạn. Về cách thức cài fonts trên Linux, xin tham khảo http://vnlinux.org.

Tài liệu tham khảo:

http://java.sun.com/j2se/1.4.2/docs/guide/intl/fontprop.html
http://java.sun.com/j2se/1.3/docs/guide/intl/fontprop.html
http://www.joconner.com/javai18n/articles/TextDisplay.html


Java 1.5.0 vẫn chưa mặc định hỗ trợ hiển thị TV trên Swing components trong Linux. Sau đây là giải pháp. Tạo 1 text file có tên fontconfig.OC.Version.properties rồi copy vào <jdkhome>/jre/lib directory. OC là tên của operating system (hệ điều hành); cho Linux, những giá trị hợp lệ là "Sun", "RedHat", "Turbo", "SuSE". Còn Version là version của HĐH đó. Ví dụ, cho Fedora Core 4, tên file sẽ là fontconfig.RedHat.4.properties.

Nội dung của file:

# @(#)linux.fontconfig.properties	1.2 03/10/28
#
# Copyright 2003 Sun Microsystems, Inc. All rights reserved.
#

# Version

version=1

# Component Font Mappings

serif.plain.latin-1=-b&h-lucidabright-medium-r-normal--*-%d-*-*-p-*-iso8859-1
serif.bold.latin-1=-b&h-lucidabright-demibold-r-normal--*-%d-*-*-p-*-iso8859-1
serif.italic.latin-1=-b&h-lucidabright-medium-i-normal--*-%d-*-*-p-*-iso8859-1
serif.bolditalic.latin-1=-b&h-lucidabright-demibold-i-normal--*-%d-*-*-p-*-iso8859-1
serif.plain.vietnamese=-monotype-times new roman-medium-r-normal--*-%d-*-*-p-*-iso10646-1
serif.bold.vietnamese=-monotype-times new roman-bold-r-normal--*-%d-*-*-p-*-iso10646-1
serif.italic.vietnamese=-monotype-times new roman-medium-i-normal--*-%d-*-*-p-*-iso10646-1
serif.bolditalic.vietnamese=-monotype-times new roman-bold-i-normal--*-%d-*-*-p-*-iso10646-1

sansserif.plain.latin-1=-b&h-lucidasans-medium-r-normal-sans-*-%d-*-*-p-*-iso8859-1
sansserif.bold.latin-1=-b&h-lucidasans-bold-r-normal-sans-*-%d-*-*-p-*-iso8859-1
sansserif.italic.latin-1=-b&h-lucidasans-medium-i-normal-sans-*-%d-*-*-p-*-iso8859-1
sansserif.bolditalic.latin-1=-b&h-lucidasans-bold-i-normal-sans-*-%d-*-*-p-*-iso8859-1
sansserif.plain.vietnamese=-monotype-arial-medium-r-normal--*-%d-*-*-p-*-iso10646-1
sansserif.bold.vietnamese=-monotype-arial-bold-r-normal--*-%d-*-*-p-*-iso10646-1
sansserif.italic.vietnamese=-monotype-arial-medium-i-normal--*-%d-*-*-p-*-iso10646-1
sansserif.bolditalic.vietnamese=-monotype-arial-bold-i-normal--*-%d-*-*-p-*-iso10646-1

monospaced.plain.latin-1=-b&h-lucidatypewriter-medium-r-normal-sans-*-%d-*-*-m-*-iso8859-1
monospaced.bold.latin-1=-b&h-lucidatypewriter-bold-r-normal-sans-*-%d-*-*-m-*-iso8859-1
monospaced.italic.latin-1=-b&h-lucidatypewriter-medium-i-normal-sans-*-%d-*-*-m-*-iso8859-1
monospaced.bolditalic.latin-1=-b&h-lucidatypewriter-bold-i-normal-sans-*-%d-*-*-m-*-iso8859-1
monospaced.plain.vietnamese=-monotype-courier new-medium-r-normal--*-%d-*-*-m-*-iso10646-1
monospaced.bold.vietnamese=-monotype-courier new-bold-r-normal--*-%d-*-*-m-*-iso10646-1
monospaced.italic.vietnamese=-monotype-courier new-medium-i-normal--*-%d-*-*-m-*-iso10646-1
monospaced.bolditalic.vietnamese=-monotype-courier new-bold-i-normal--*-%d-*-*-m-*-iso10646-1

dialog.plain.latin-1=-b&h-lucidasans-medium-r-normal-sans-*-%d-*-*-p-*-iso8859-1
dialog.bold.latin-1=-b&h-lucidasans-bold-r-normal-sans-*-%d-*-*-p-*-iso8859-1
dialog.italic.latin-1=-b&h-lucidasans-medium-i-normal-sans-*-%d-*-*-p-*-iso8859-1
dialog.bolditalic.latin-1=-b&h-lucidasans-bold-i-normal-sans-*-%d-*-*-p-*-iso8859-1
dialog.plain.vietnamese=-monotype-arial-medium-r-normal--*-%d-*-*-p-*-iso10646-1
dialog.bold.vietnamese=-monotype-arial-bold-r-normal--*-%d-*-*-p-*-iso10646-1
dialog.italic.vietnamese=-monotype-arial-medium-i-normal--*-%d-*-*-p-*-iso10646-1
dialog.bolditalic.vietnamese=-monotype-arial-bold-i-normal--*-%d-*-*-p-*-iso10646-1

dialoginput.plain.latin-1=-b&h-lucidatypewriter-medium-r-normal-sans-*-%d-*-*-m-*-iso8859-1
dialoginput.bold.latin-1=-b&h-lucidatypewriter-bold-r-normal-sans-*-%d-*-*-m-*-iso8859-1
dialoginput.italic.latin-1=-b&h-lucidatypewriter-medium-i-normal-sans-*-%d-*-*-m-*-iso8859-1
dialoginput.bolditalic.latin-1=-b&h-lucidatypewriter-bold-i-normal-sans-*-%d-*-*-m-*-iso8859-1
dialoginput.plain.vietnamese=-monotype-courier new-medium-r-normal--*-%d-*-*-m-*-iso10646-1
dialoginput.bold.vietnamese=-monotype-courier new-bold-r-normal--*-%d-*-*-m-*-iso10646-1
dialoginput.italic.vietnamese=-monotype-courier new-medium-i-normal--0-0-0-0-m-0-iso10646-1
dialoginput.bolditalic.vietnamese=-monotype-courier new-bold-i-normal--*-%d-*-*-m-*-iso10646-1

# Search Sequences
sequence.allfonts=latin-1,vietnamese

# Exclusion Ranges
exclusion.vietnamese=0250-1e9f,1f00-20aa,20ad-ffff

# Font File Names

hoặc chỉ đơn giản là:

# @(#)linux.fontconfig.properties	1.2 03/10/28
#
# Copyright 2003 Sun Microsystems, Inc. All rights reserved.
#

# Version
version=1

# Component Font Mappings
allfonts.vietnamese=-microsoft-tahoma-medium-r-normal--*-%d-*-*-p-*-iso10646-1

# Search Sequences
sequence.allfonts=vietnamese

# Exclusion Ranges
exclusion.vietnamese=0250-1e9f,1f00-20aa,20ad-ffff

# Font File Names
Tham khảo:

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