Difference between revisions of "Java Runtime Environment fonts"

From ArchWiki
Jump to: navigation, search
m (moving deletion mark to the relevant section)
 
(27 intermediate revisions by 12 users not shown)
Line 1: Line 1:
[[Category:Fonts]]  
+
[[Category:Fonts]]
{{Article summary start}}
+
[[ja:Java ランタイム環境のフォント]]
{{Article summary text|Instructions are given to improve the display of fonts in Java applications when using Oracle's Java Runtime Environment}}
+
[[ru:Java Runtime Environment fonts]]
{{Article summary heading|Related}}
+
{{Related articles start}}
{{Article summary wiki|Fonts}}: Information on adding fonts and font recommendations
+
{{Related|Fonts}}
{{Article summary wiki|Font Configuration}}: Font setup and beautification
+
{{Related|Font configuration}}
{{Article summary wiki|MS Fonts}}: Adding Microsoft fonts and mimicking Windows' font settings
+
{{Related|MS Fonts}}
{{Article summary wiki|X Logical Font Description}}: The core X server font system
+
{{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 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.
  
Line 14: Line 13:
  
 
==Anti-aliasing==
 
==Anti-aliasing==
[http://en.wikipedia.org/wiki/Antialiased_font Anti-aliasing] of fonts is available with Oracle Java 1.6 on Linux. To do this on a per user basis, add the following line to the user's {{ic|~/.bashrc}}.
+
=== Basic settings ===
  
export _JAVA_OPTIONS='-Dawt.useSystemAAFontSettings=''setting'''
+
[[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}}:
  
{{Note|'''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.}}
+
_JAVA_OPTIONS='-Dawt.useSystemAAFontSettings=''setting'''
  
Replace {{Ic|''setting''}} with one of the following seven values:
+
Where {{Ic|''setting''}} is one of the values:
  
:*{{Ic|off}} or {{Ic|false}} or {{Ic|default}} No anti-aliasing
+
{| class="wikitable"
:*{{Ic|on}} Full anti-aliasing
+
! Setting
:*{{Ic|gasp}} Use the font's built-in hinting instructions
+
! Description
:*{{Ic|lcd}} or {{Ic|lcd_hrgb}} Anti-aliasing tuned for many popular LCD monitors
+
|-
:*{{Ic|lcd_hbgr}} – Alternative LCD monitor setting
+
| {{Ic|off}}, {{Ic|false}}, {{Ic|default}}
:*{{Ic|lcd_vrgb}} – Alternative LCD monitor setting
+
| No anti-aliasing
:*{{Ic|lcd_vbgr}} Alternative LCD monitor setting
+
|-
 +
| {{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
 +
|}
  
The {{Ic|gasp}} and {{Ic|lcd}} settings work well in many instances.
+
The {{Ic|gasp}} and {{Ic|lcd}} settings work well in many instances.  
  
Optionally to use GTK look and feel, add the following line to .bashrc instead. Note that the Java options described above and this one 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.
+
To optionally to use GTK look and feel, add the following line instead:
  
  export _JAVA_OPTIONS='-Dswing.defaultlaf=com.sun.java.swing.plaf.gtk.GTKLookAndFeel' ''
+
  _JAVA_OPTIONS='-Dswing.defaultlaf=com.sun.java.swing.plaf.gtk.GTKLookAndFeel' ''
  
For the above change to take effect, {{ic|~/.bashrc}} must be ''sourced'' as the normal user.
+
{{Note|
  $ source ~/.bashrc
+
* 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 sizesSome 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.
 +
}}
  
Open a new instance of a Java application to test the changes made.
+
Specify the variable on the command line before the executable to try the new configuration:
  
==Font selection==
+
_JAVA_OPTIONS=''options'' ''exectuable''
  
===TrueType fonts===
+
Re-login for the changes to take effect.
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|~/.bashrc}} to enable these fonts.
+
export JAVA_FONTS=/usr/share/fonts/TTF
+
  
''Source'' {{ic|~/.bashrc}} as the normal user for the change to take effect.
+
=== Font hinting ===
$ source ~/.bashrc
+
  
===Default fonts===
+
Some java applications are subject to system font hinting changes. Consider choosing one of the following environment variables before launching a java app:
  
{{deletion|reason=These fontconfig files in recent version of JRe are obsolete. See http://bugs.sun.com/view_bug.do?bug_id=7013646.}}
+
export FT2_SUBPIXEL_HINTING=0  # Classic mode
 +
export FT2_SUBPIXEL_HINTING=1  # Infinality mode
 +
export FT2_SUBPIXEL_HINTING=2  # Default mode
  
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 {{ic|fontconfig.properties}}.
+
For example, the value of <tt>0</tt> makes freetype use non-bold fonts (at least for some apps).
  
As root, change directory to {{ic|/opt/java/jre/lib}}. Copy {{ic|fontconfig.properties.src}} to {{ic|fontconfig.properties}}. Then, as root, open the new {{ic|fontconfig.properties}} in an editor.
+
=== OpenJDK patch ===
# cd /opt/java/jre/lib
+
 
# cp fontconfig.properties.src 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]]:
# nano fontconfig.properties
+
* Patched '''OpenJDK7''' is available as {{AUR|jre7-openjdk-infinality}} (<tt>--enable-infinality=yes</tt>)
 +
* Patched '''OpenJDK8''' is available as {{AUR|jre8-openjdk-infinality}} (also available from [[Unofficial user repositories#infinality-bundle|Infinality unofficial repository]])
 +
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===
  
{{Note|Encodings other than ''Latin-1,'' or ''ISO-8859-1,'' are shown in other {{ic|fontconfig.properties.*.src}} files in {{ic|/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 {{ic|fontconfig.properties}}.}}
+
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.
  
The Java font names in the configuration file are in the form of {{Ic|genericFontName.style.subset}}, for example, {{Ic|serif.plain.latin-1}}. These generic fonts are mapped to the installed fonts using [[X Logical Font Description|''X'' ''l''ogical ''f''ont ''d''escription]] (XLFD) names. The {{Ic|%d}}, in the example below, is used as a placeholder in the XLFD name for the point size. The Java application replaces {{Ic|%d}} at runtime.
+
  JAVA_FONTS=/usr/share/fonts/TTF
  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 {{Pkg|xorg-xfontsel}} package.}}
+
Relogin for the change to take effect.
  
Change the Lucida fonts named in the {{ic|fontconfig.properties}} file to your selected fonts using the XLFD names. Below is an excerpt of a {{ic|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 {{ic|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 15:14, 8 July 2016

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 exectuable 

Re-login for the changes to take effect.

Font hinting

Some java applications are subject to system font hinting changes. Consider choosing one of the following environment variables before launching a java app:

export FT2_SUBPIXEL_HINTING=0  # Classic mode
export FT2_SUBPIXEL_HINTING=1  # Infinality mode
export FT2_SUBPIXEL_HINTING=2  # Default mode

For example, the value of 0 makes freetype use non-bold fonts (at least for some apps).

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/