Java Runtime Environment fonts: Difference between revisions

From ArchWiki
m (Add Chinese translation)
m (→‎Running an xsettings daemon: style: term italic)
 
(27 intermediate revisions by 8 users not shown)
Line 6: Line 6:
{{Related|Fonts}}
{{Related|Fonts}}
{{Related|Font configuration}}
{{Related|Font configuration}}
{{Related|MS Fonts}}
{{Related|Microsoft fonts}}
{{Related|X Logical Font Description}}
{{Related|X Logical Font Description}}
{{Related articles 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.


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 ==
=== Basic settings ===


[[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}}:
[[wikipedia:Font rasterization|Anti-aliasing]] of fonts is available with Oracle Java 1.6 and OpenJDK on Linux.
 
=== Running an xsettings daemon ===
 
Java tries to get the system defaults through ''xsettings''. On [[GNOME]] you do not have to do anything, {{ic|gnome-settings-daemon}} is already running. Otherwise [[Xsettingsd]] is a lightweight alternative.
 
=== Overriding the automatically picked up settings ===
 
If you do not want to run an xsettings daemon, or the fonts still look ugly, there is also an [[environment variable]] to configure anti-aliasing:


  _JAVA_OPTIONS='-Dawt.useSystemAAFontSettings=''setting'''
  _JAVA_OPTIONS='-Dawt.useSystemAAFontSettings=''setting'''


Where {{Ic|''setting''}} is one of the values:
Where {{ic|''setting''}} is one of the values:


{| class="wikitable"
{| class="wikitable"
Line 26: Line 33:
! Description
! Description
|-
|-
| {{Ic|off}}, {{Ic|false}}, {{Ic|default}}
| {{ic|off}}, {{ic|false}}, {{ic|default}}
| No anti-aliasing
| No anti-aliasing
|-
|-
| {{Ic|on}}
| {{ic|on}}
| Full anti-aliasing
| Full anti-aliasing
|-
|-
| {{Ic|gasp}}
| {{ic|gasp}}
| Use the font's built-in hinting instructions
| Use the font's built-in hinting instructions
|-
|-
| {{Ic|lcd}}, {{Ic|lcd_hrgb}}
| {{ic|lcd}}, {{ic|lcd_hrgb}}
| Anti-aliasing tuned for many popular LCD monitors
| Anti-aliasing tuned for many popular LCD monitors
|-
|-
| {{Ic|lcd_hbgr}}, {{Ic|lcd_vrgb}}, {{Ic|lcd_vbgr}}
| {{ic|lcd_hbgr}}, {{ic|lcd_vrgb}}, {{ic|lcd_vbgr}}
| Alternative LCD monitor setting
| 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.  


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


  _JAVA_OPTIONS='-Dswing.defaultlaf=com.sun.java.swing.plaf.gtk.GTKLookAndFeel' ''
  _JAVA_OPTIONS='-Dswing.defaultlaf=com.sun.java.swing.plaf.gtk.GTKLookAndFeel' ''
Line 53: Line 60:
}}
}}


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


_JAVA_OPTIONS=''options'' ''executable''
=== 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 [[environment variable]]:


=== OpenJDK patch ===
JAVA_FONTS=/usr/share/fonts/TTF
 
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===
=== Fixing tofu ===


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.
Place font files in {{ic|/usr/lib/jvm/java-8-openjdk/jre/lib/fonts/fallback/}}. Create it if needed.


JAVA_FONTS=/usr/share/fonts/TTF
Substitute the {{ic|/usr/lib/jvm/java-8-openjdk}} for the {{ic|$JAVA_HOME}} of the JRE you are actually using. Note that the feature is removed since Oracle Java 9, as Oracle [https://bugs.java.com/bugdatabase/view_bug?bug_id=8039273 considers it a bug] to encourage users to change {{ic|lib}}, moved the configuration files to {{ic|conf}} and called the fallback functionality a "mis-feature". The specific function providing this behavior is {{ic|sun.awt.FontConfiguration.getInstalledFallbackFonts}}, and OpenJDK seems to still have it.


Relogin for the change to take effect.
Doing so makes Java always add the fonts in this directory into the fallback sequence to look for character shapes (glyphs) in. This way, no matter what fonts the application has asked for, these additional fonts will provide the missing glyphs when needed.


===Fixing Mojibake (For JRE8)===
== See also ==
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/
* [https://docs.oracle.com/en/java/javase/11/intl/font-configuration-files.html Java Font Configuration Files] (Java 11); [https://docs.oracle.com/javase/8/docs/technotes/guides/intl/fontconfig.html Java 8]

Latest revision as of 08:02, 23 April 2024

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

Anti-aliasing of fonts is available with Oracle Java 1.6 and OpenJDK on Linux.

Running an xsettings daemon

Java tries to get the system defaults through xsettings. On GNOME you do not have to do anything, gnome-settings-daemon is already running. Otherwise Xsettingsd is a lightweight alternative.

Overriding the automatically picked up settings

If you do not want to run an xsettings daemon, or the fonts still look ugly, there is also an environment variable to configure anti-aliasing:

_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 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.

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 environment variable:

JAVA_FONTS=/usr/share/fonts/TTF

Fixing tofu

Place font files in /usr/lib/jvm/java-8-openjdk/jre/lib/fonts/fallback/. Create it if needed.

Substitute the /usr/lib/jvm/java-8-openjdk for the $JAVA_HOME of the JRE you are actually using. Note that the feature is removed since Oracle Java 9, as Oracle considers it a bug to encourage users to change lib, moved the configuration files to conf and called the fallback functionality a "mis-feature". The specific function providing this behavior is sun.awt.FontConfiguration.getInstalledFallbackFonts, and OpenJDK seems to still have it.

Doing so makes Java always add the fonts in this directory into the fallback sequence to look for character shapes (glyphs) in. This way, no matter what fonts the application has asked for, these additional fonts will provide the missing glyphs when needed.

See also