Difference between revisions of "Java Runtime Environment fonts"

From ArchWiki
Jump to: navigation, search
m (Letter case in headings; now follows Wikipedia MOS)
(fix ja link)
 
(55 intermediate revisions by 25 users not shown)
Line 1: Line 1:
[[Category:Fonts (English)]]
+
[[Category:Fonts]]
[[Category:HOWTOs (English)]]
+
[[ja:Java 実行環境のフォント]]
{{Article summary start}}
+
[[ru:Java Runtime Environment fonts]]
{{Article summary text|Instructions are given to improve the display of fonts in Java applications when using Sun Microsystem's Java Runtime Environment.}}
+
{{Related articles start}}
{{Article summary heading|Related articles}}
+
{{Related|Fonts}}
{{Article summary wiki|Font Configuration}}
+
{{Related|Font configuration}}
{{Article summary wiki|Fonts}}
+
{{Related|MS Fonts}}
{{Article summary wiki|MS Fonts}}
+
{{Related|X Logical Font Description}}
{{Article summary end}}
+
{{Related articles end}}
 
+
Some users may find the default Java fonts or the display mode of fonts in Java applications to be unpleasant. Several methods to improve the font display in the Oracle Java Runtime Environment (JRE) are available. These methods may be used separately, but many users will find they achieve better results by combining them.
Some users may find the default Java fonts or the display mode of fonts in Java applications to be unpleasant. Several methods to improve the font display in the [http://java.sun.com/javase/6/docs/technotes/guides/index.html#jre-jdk Sun Java Runtime Environment (JRE)] are available. These methods may be used separately, but many users will find they achieve better results by combining them.
 
  
 
TrueType fonts appear to be the best supported format for use with Java.
 
TrueType fonts appear to be the best supported format for use with Java.
  
 
==Anti-aliasing==
 
==Anti-aliasing==
[http://en.wikipedia.org/wiki/Antialiased_font Anti-aliasing] 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 {{Filename|~/.bashrc}}.
+
=== Basic settings ===
  export _JAVA_OPTIONS='-Dawt.useSystemAAFontSettings=''setting'''
+
 
Replace {{Codeline|''setting''}} with one of the following seven values: {{sn|'''TrueType''' fonts contain a ''g''rid-fitting ''a''nd ''s''can-conversion ''p''rocedure ([http://www.microsoft.com/typography/otspec/gasp.htm GASP]) table with the font creator's recommendations for the font's display at different point sizes.  Some sizes are recommended to be fully anti-aliased, others are to be hinted, and some sizes are recommended to be displayed as bitmaps. Combinations are sometimes used for font display at certain point sizes.}}
+
[[wikipedia:Font rasterization|Anti-aliasing]] of fonts is available with Oracle Java 1.6 and OpenJDK on Linux. To do this system-wide, add the following line to {{ic|/etc/environment}}:
 +
 
 +
  _JAVA_OPTIONS='-Dawt.useSystemAAFontSettings=''setting'''
 +
 
 +
Where {{Ic|''setting''}} is one of the values:
 +
 
 +
{| class="wikitable"
 +
! Setting
 +
! Description
 +
|-
 +
| {{Ic|off}}, {{Ic|false}}, {{Ic|default}}
 +
| No anti-aliasing
 +
|-
 +
| {{Ic|on}}
 +
| Full anti-aliasing
 +
|-
 +
| {{Ic|gasp}}
 +
| Use the font's built-in hinting instructions
 +
|-
 +
| {{Ic|lcd}}, {{Ic|lcd_hrgb}}
 +
| Anti-aliasing tuned for many popular LCD monitors
 +
|-
 +
| {{Ic|lcd_hbgr}}, {{Ic|lcd_vrgb}}, {{Ic|lcd_vbgr}}
 +
| Alternative LCD monitor setting
 +
|}
  
:*{{Codeline|off}} or {{Codeline|false}} or {{Codeline|default}} -- No anti-aliasing
+
The {{Ic|gasp}} and {{Ic|lcd}} settings work well in many instances.
:*{{Codeline|on}} -- Full anti-aliasing
 
:*{{Codeline|gasp}} -- Use the font's built-in hinting instructions
 
:*{{Codeline|lcd}} or {{Codeline|lcd_hrgb}} -- Anti-aliasing tuned for many popular LCD monitors
 
:*{{Codeline|lcd_hbgr}} -- Alternative LCD monitor setting
 
:*{{Codeline|lcd_vrgb}} -- Alternative LCD monitor setting
 
:*{{Codeline|lcd_vbgr}} -- Alternative LCD monitor setting
 
  
The {{Codeline|gasp}} and {{Codeline|lcd}} settings work well in many instances.
+
To optionally to use GTK look and feel, add the following line instead:
  
For the above change to take effect, {{Filename|~/.bashrc}} must be ''sourced'' as the normal user.
+
_JAVA_OPTIONS='-Dswing.defaultlaf=com.sun.java.swing.plaf.gtk.GTKLookAndFeel' ''
$ source ~/.bashrc
 
Open a new instance of a Java application to test the changes made.
 
  
==Font selection==
+
{{Note|
 +
* The described Java options only work for applications that draw their GUI in Java, like Jdownloader, and not for applications which utilize Java as backend only, like Openoffice.org and Matlab.
 +
* '''TrueType''' fonts contain a '''g'''rid-fitting '''a'''nd '''s'''can-conversion '''p'''rocedure (''GASP'') table with the designer's recommendations for the font's display at different point sizes.  Some sizes are recommended to be fully anti-aliased, others are to be hinted, and some are to be displayed as bitmaps. Combinations are sometimes used for certain point sizes.
 +
}}
  
===TrueType fonts===
+
Specify the variable on the command line before the executable to try the new configuration:
Some Java applications may specify use of a particular TrueType font; these applications must be made aware of the directory path to the desired font. TrueType fonts are installed in the directory {{Filename|/usr/share/fonts/TTF}}. Add the following line to {{Filename|~/.bashrc}} to enable these fonts.
 
export JAVA_FONTS=/usr/share/fonts/TTF
 
  
''Source'' {{Filename|~/.bashrc}} as the normal user for the change to take effect.
+
_JAVA_OPTIONS=''options'' ''executable''  
$ source ~/.bashrc
 
  
===Default fonts===
+
Re-login for the changes to take effect.
The ''Lucida'' fonts distributed with the Sun JRE are the default for Java applications that do not specify a different font's use. The Lucida fonts were designed for low resolution displays and printers, many users will wish to use other fonts. The default Java fonts can be changed on a system-wide basis by the creation or editing of a file named {{Filename|fontconfig.properties}}.
 
  
As root, change directory to {{Filename|/opt/java/jre/lib}}. Copy {{Filename|fontconfig.properties.src}} to {{Filename|fontconfig.properties}}. Then, as root, open the new {{Filename|fontconfig.properties}} in an editor.
+
=== OpenJDK patch ===
# cd /opt/java/jre/lib
 
# cp fontconfig.properties.src fontconfig.properties
 
# nano fontconfig.properties
 
  
{{Note|Encodings other than ''Latin-1,'' or [http://en.wikipedia.org/wiki/ISO/IEC_8859-1 ISO-8859-1], are shown in other {{Filename|fontconfig.properties.*.src}} files in {{Filename|/opt/java/jre/lib}}. Some users will find these files to be better sources to use for editing. In all cases the edited file should be saved as {{Filename|fontconfig.properties}}.}}
+
Even with anti-aliasing enforced through Java options, the resulting anti-aliasing may be inferior to native applications. This can be remedied with a patch to OpenJDK, available in the [[AUR]]:
 +
* Patched '''OpenJDK7''' is available as {{AUR|jre7-openjdk-infinality}} (<tt>--enable-infinality=yes</tt>)
 +
* Patched '''OpenJDK8''' is available as {{AUR|jre8-openjdk-infinality}}
 +
The patched version obtains the per-family FreeType rendering/loading flags from fontconfig instead of using OpenJDK heuristics. Although this is an [[Infinality]] package, the patches themselves don't actually depend on {{AUR|fontconfig-infinality}} since only vanilla {{Pkg|fontconfig}} APIs are used.
  
 +
==Font selection==
 +
 +
===TrueType fonts===
  
The Java font names in the configuration file are in the form of {{Codeline|genericFontName.style.subset}}, for example, {{Codeline|serif.plain.latin-1}}. These generic fonts are mapped to the installed fonts using ''X'' ''l''ogical ''f''ont ''d''escription ([http://en.wikipedia.org/wiki/X_logical_font_description XLFD]) names. The {{Codeline|%d}}, in the example below, is used as a placeholder in the XLFD name for the point size. The Java application replaces {{Codeline|%d}} at runtime.
+
Some Java applications may specify use of a particular TrueType font; these applications must be made aware of the directory path to the desired font. TrueType fonts are installed in the directory {{ic|/usr/share/fonts/TTF}}. Add the following line to {{ic|/etc/environment}} to enable these fonts.
serif.plain.latin-1=-b&h-lucidabright-medium-r-normal--*-%d-*-*-p-*-iso8859-1
 
  
{{Tip|The utility, ''xfontsel,'' may be used to display fonts and to discover their XLFD names. Xfontsel is part of the {{Package Official|xorg-utils}} package.}}
+
JAVA_FONTS=/usr/share/fonts/TTF
  
 +
Relogin for the change to take effect.
  
Change the Lucida fonts named in the {{Filename|fontconfig.properties}} file to your selected fonts using the XLFD names. Below is an excerpt of a {{Filename|fontconfig.properties}} file after modifications have been made. The Lucida fonts have been replaced by ''DejaVu'' fonts.
+
===Fixing Mojibake (For JRE8)===
# Version -- a version number is required.
+
Place font files under the directory below. Create the directory if it does not exist.
# IMPORTANT -- Do not delete the next line. Ever.
 
version=1
 
 
# Component Font Mappings
 
# gen_name.style.subset=
 
#      -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-o-normal-*-*-%d-*-*-p-*-iso8859-1
 
  
After the changes have been saved to {{Codeline|fontconfig.properties}}, the editor may be closed and the user should drop root privileges. Open a new instance of a Java application to test the changes.
+
/usr/lib/jvm/java-8-openjdk/jre/lib/fonts/fallback/

Latest revision as of 12:38, 8 March 2018

Some users may find the default Java fonts or the display mode of fonts in Java applications to be unpleasant. Several methods to improve the font display in the Oracle Java Runtime Environment (JRE) are available. These methods may be used separately, but many users will find they achieve better results by combining them.

TrueType fonts appear to be the best supported format for use with Java.

Anti-aliasing

Basic settings

Anti-aliasing of fonts is available with Oracle Java 1.6 and OpenJDK on Linux. To do this system-wide, add the following line to /etc/environment:

_JAVA_OPTIONS='-Dawt.useSystemAAFontSettings=setting'

Where setting is one of the values:

Setting Description
off, false, default No anti-aliasing
on Full anti-aliasing
gasp Use the font's built-in hinting instructions
lcd, lcd_hrgb Anti-aliasing tuned for many popular LCD monitors
lcd_hbgr, lcd_vrgb, lcd_vbgr Alternative LCD monitor setting

The gasp and lcd settings work well in many instances.

To optionally to use GTK look and feel, add the following line instead:

_JAVA_OPTIONS='-Dswing.defaultlaf=com.sun.java.swing.plaf.gtk.GTKLookAndFeel' 
Note:
  • The described Java options only work for applications that draw their GUI in Java, like Jdownloader, and not for applications which utilize Java as backend only, like Openoffice.org and Matlab.
  • TrueType fonts contain a grid-fitting and scan-conversion procedure (GASP) table with the designer's recommendations for the font's display at different point sizes. Some sizes are recommended to be fully anti-aliased, others are to be hinted, and some are to be displayed as bitmaps. Combinations are sometimes used for certain point sizes.

Specify the variable on the command line before the executable to try the new configuration:

_JAVA_OPTIONS=options executable 

Re-login for the changes to take effect.

OpenJDK patch

Even with anti-aliasing enforced through Java options, the resulting anti-aliasing may be inferior to native applications. This can be remedied with a patch to OpenJDK, available in the AUR:

The patched version obtains the per-family FreeType rendering/loading flags from fontconfig instead of using OpenJDK heuristics. Although this is an Infinality package, the patches themselves don't actually depend on fontconfig-infinalityAUR since only vanilla fontconfig APIs are used.

Font selection

TrueType fonts

Some Java applications may specify use of a particular TrueType font; these applications must be made aware of the directory path to the desired font. TrueType fonts are installed in the directory /usr/share/fonts/TTF. Add the following line to /etc/environment to enable these fonts.

JAVA_FONTS=/usr/share/fonts/TTF

Relogin for the change to take effect.

Fixing Mojibake (For JRE8)

Place font files under the directory below. Create the directory if it does not exist.

/usr/lib/jvm/java-8-openjdk/jre/lib/fonts/fallback/