From ArchWiki
Revision as of 19:30, 7 September 2009 by Thisoldman (talk | contribs) (This is a test page! Materials copyrighted by Sun Microsystems may be present.)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Java (Sun) Fonts

Users may find the default Java fonts and their display in Java applications unpleasant. Several methods to improve font display in the Sun Java Runtime Environment (JRE)[1] are available. The methods may be used separately, but many users will find better results by combining them.


Anti-aliasing[2] of fonts is available with Sun Java 1.6 on Linux. To do this on a per user basis, add the following line to the user's ~/.bashrc.

export _JAVA_OPTIONS='-Dawt.useSystemAAFontSettings=gasp'

The value, gasp, is one of seven possible settings for -Dawt.useSystemAAFontSettings.[3] These are:

  • off or false or default (equivalent values for no anti-aliasing)Template:Sn
  • on
  • gasp
  • lcd or lcd_hrgb (equivalent values)
  • lcd_hbgr
  • lcd_vrgb
  • lcd_vbgr

The gasp and lcd settings work well in many instances.

For the above change to take effect, ~/.bashrc must be sourced.

$ source ~/.bashrc

Open a new instance of a Java application to test the changes made.

Font Selection

The Lucida fonts[4] distributed with the Sun JRE are used by many Java applications by default. These fonts were designed for low resolution CRT displays and printers.[5] Many users will wish to use other fonts. TrueType fonts appear to be the best supported format in Java.

Java applications that specify use of a TrueType font other than Lucida must find the path to that font. TrueType fonts are located in the directory /usr/share/fonts/TTF. Add the following line to ~/.bashrc to enable these fonts.

export JAVA_FONTS=/usr/share/fonts/TTF

Source ~/.bashrc for the change to take effect.

$ source ~/.bashrc

Applications that don't specify a font will use the default Lucida fonts unless directed to other fonts. Default Java fonts can be specified by the user by creation or editing of a file named /opt/java/jre/lib/

As root, change directory to /opt/java/jre/lib and copy to and then, still as root, open in an editor.

# cd /opt/java/jre/lib
# cp
# nano      ## Editor is the user's choice.
Note: Other encodings than Latin-1, or ISO 8859-1,[6] are shown in the RedHat,[7] SuSE,[8] Sun[9] and Turbo[10]*.src files. Some users will find these files to be better sources for editing than the simple file used in this article. In all cases the edited file should be saved as

Here is an excerpt of the unedited file:

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

--- [Omitted] ---


--- [Omitted] ---

The Java fonts are mapped to TrueType fonts using X Logical Font Description (XLFD)[11] conventions. The %d is used as a placeholder in the font description for the point size. The Java application will replace %d at runtime.

You may find the utility, xfontsel, useful to display fonts and to discover their XLFD name. Xfontsel is part of the xorg-utils package.

Below is an entire file after modifications have been completed. All the Lucida fonts have been replaced by variations of DejaVu[12] fonts. Because the DejaVu fonts don't have italic versions, the oblique versions were substituted for them; -o- replaces -i- in the XLFD.

# /opt/java/jre/lib/
# 2009-09-05

# Version -- a version number is required.
# IMPORTANT -- Do not delete the next line. Ever.

# Component Font Mappings
#       -fndry-fmly-wght-slant-sWdth-adstyle-pxlsz-ptSz-resx-resy-spc-avgWdth-rgstry-encdng

serif.plain.latin-1=-misc-dejavu serif-medium-r-normal-*-*-%d-*-*-p-*-iso8859-1
serif.bold.latin-1=-misc-dejavu serif-bold-r-normal-*-*-%d-*-*-p-*-iso8859-1
serif.italic.latin-1=-misc-dejavu serif-medium-i-normal-*-*-%d-*-*-p-*-iso8859-1
serif.bolditalic.latin-1=-misc-dejavu serif-bold-i-normal-*-*-%d-*-*-p-*-iso8859-1

sansserif.plain.latin-1=-misc-dejavu sans-medium-r-normal-*-*-%d-*-*-p-*-iso8859-1
sansserif.bold.latin-1=-misc-dejavu sans-bold-r-normal-*-*-%d-*-*-p-*-iso8859-1
sansserif.italic.latin-1=-misc-dejavu sans-medium-o-normal-*-*-%d-*-*-p-*-iso8859-1
sansserif.bolditalic.latin-1=-misc-dejavu sans-bold-o-normal-*-*-%d-*-*-p-*-iso8859-1

monospaced.plain.latin-1=-misc-dejavu sans mono-medium-r-normal-*-*-%d-*-*-m-*-iso8859-1
monospaced.bold.latin-1=-misc-dejavu sans mono-bold-r-normal-*-*-%d-*-*-m-*-iso8859-1
monospaced.italic.latin-1=-misc-dejavu sans mono-medium-o-normal-*-*-%d-*-*-m-*-iso8859-1
monospaced.bolditalic.latin-1=-misc-dejavu sans mono-bold-o-normal-*-*-%d-*-*-m-*-iso8859-1

dialog.plain.latin-1=-misc-dejavu sans-medium-r-normal-*-*-%d-*-*-p-*-iso8859-1
dialog.bold.latin-1=-misc-dejavu sans-bold-r-normal-*-*-%d-*-*-p-*-iso8859-1
dialog.italic.latin-1=-misc-dejavu sans-medium-o-normal-*-*-%d-*-*-p-*-iso8859-1
dialog.bolditalic.latin-1=-misc-dejavu sans-bold-o-normal-*-*-%d-*-*-p-*-iso8859-1

dialoginput.plain.latin-1=-misc-dejavu sans mono-medium-r-normal-*-*-%d-*-*-m-*-iso8859-1
dialoginput.bold.latin-1=-misc-dejavu sans mono-bold-r-normal-*-*-%d-*-*-m-*-iso8859-1
dialoginput.italic.latin-1=-misc-dejavu sans mono-medium-o-normal-*-*-%d-*-*-m-*-iso8859-1
dialoginput.bolditalic.latin-1=-misc-dejavu sans mono-bold-o-normal-*-*-%d-*-*-m-*-iso8859-1

# Search Sequences


# Font Paths

# Exclusion Ranges

# Font File Names

After the changes have been saved to the editor may be closed and the user should drop root privileges. Open a new instance of a Java application to test the changes.