Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-7175487

Cannot customize font configuration on Linux

    XMLWordPrintable

    Details

    • Subcomponent:
      2d
    • Resolved In Build:
      b131
    • CPU:
      generic
    • OS:
      linux

      Description

      SYNOPSIS
      --------
      Cannot customise font configuration with Java 7 on Linux

      OPERATING SYSTEM
      ----------------
      Linux

      FULL JDK VERSION
      ----------------
      Java 7 onwards

      PROBLEM DESCRIPTION
      -------------------
      We are unable to customize logical fonts with Java 7 on Linux.

      With Java 6 we are able to customize the fontconfig.properties file, but with Java 7 we are not able to customize the fontconfig.properties files, as per the following documentation:

      --------
      Support for Linux and Solaris 11 fonts

      Historically, the logical fonts for the JDK were statically specified in a fontconfig.properties file. However, on the various implementations of Linux, there is no consistency in the presence of fonts. So, without custom files, Asian (CJK) text, etc, would not be rendered. In JDK 7, on Linux, and for Solaris 11, in the absence of a customized fontconfig.properties file for the OS version, the default behavior is to use the system libfontconfig to select fonts to use for the logical fonts. In this case, the logical fonts will reflect the fonts used by the Gnome/KDE desktop applications which use the same platform library. For more information, see Fontconfig on freedesktop.org.
      --------
      http://docs.oracle.com/javase/7/docs/webnotes/adoptionGuide/index.html#swing

      This documentation states that for operating systems which do no have a customized fontconfig.properties file, logical fonts will be defined by libfontconfig. However, if we make changes to the OS font configuration those changes are not picked up by the JDK.

      TESTCASE
      --------
      import java.awt.*;

      public class TestFonts extends Canvas {
          public static void main (String args[]) {
              TestFonts tf = new TestFonts();
              tf.doit();
          }

          public TestFonts() {
          }

          public void doit() {
              Font font = new Font("Monospaced", Font.PLAIN, 12);
              FontMetrics fm = getFontMetrics(font);
              int[] widths = fm.getWidths();
              int charWidth = widths[65]; // Y8741 use 'A' char for width calculation
              int charHeight = fm.getHeight();
              int charDescent = fm.getDescent();
              System.out.println("family="+font.getFamily()+",name="+font.getFontName());
              System.out.println("charWidth ="+charWidth+" charHeight="+charHeight+" charDescent="+charDescent);
          }
      }

      REPRODUCTION INSTRUCTIONS
      -------------------------
      The following tests assume that your Linux installation has the font "Courier New" located at /usr/share/fonts/courier/cour.ttf.

      Test 1: Confirm customized fontconfig.properties does not work in Java 7
      ========================================================================

      1. Run class TestFonts, expected output: (exact output may vary)

         # /jre/bin/java TestFonts
         family=Monospaced,name=Monospaced.plain
         charWidth =7 charHeight=15 charDescent=3

      2. Backup and remove /jre/lib/fontconfig.*

      3. Create the file:

         /jre/lib/fontconfig.<OS version>.properties
         
         with the contents below. We were running on SUSE 11, so I created the
         file "fontconfig.SuSE.11.properties".

         --------
         version 1

         monospaced.plain.latin-1=-monotype-courier new-medium-r-normal--*-%d-*-*-m-*-iso8859-1

         sequence.allfonts=latin-1

         awtfontpath.latin-1=/usr/share/fonts/courier/cour.ttf
         --------

      4. Run class TestFonts and note that the value of charWidth, charHeight,
         charDescent is the same as step 1 => fontconfig.properties does not
         change the phyiscal font of "Monospaced"

      EXPECTED:
         # /jre/bin/java TestFonts
         family=Monospaced,name=Monospaced.plain
         charWidth =7 charHeight=14 charDescent=4

      ACTUAL:
         # /jre/bin/java TestFonts
         family=Monospaced,name=Monospaced.plain
         charWidth =7 charHeight=15 charDescent=3


      Test 2: Confirm libfontconfig changes are not picked up by Java 7, in the absence of a customized fontconfig.properties file
      ===================================================================================


      1. Run class TestFonts, expected output: (exact output may vary)

         # /jre/bin/java TestFonts
         family=Monospaced,name=Monospaced.plain
         charWidth =7 charHeight=15 charDescent=3

      2. Create ~/.fonts.conf with the following contents:

         --------
         <?xml version="1.0"?>
         <!DOCTYPE fontconfig SYSTEM "fonts.dtd">
         <fontconfig>
                 <alias binding="strong">
                         <family>Monospaced</family>
                         <prefer>
                                 <family>Courier New</family>
                         </prefer>
                 </alias>
         </fontconfig>
         --------

      3. Run fc-match to verify libfontconfig should select "Courier New" for
         monospace

         # fc-match monospace
         cour.ttf: "Courier New" "Normal"

      4. Run class TestFonts and note that the value of charWidth, charHeight,
         charDescent is the same as step 1 => OS libfontconfig settings do not
         change the phyiscal font of "Monospaced"

      EXPECTED:
         # /jre/bin/java TestFonts
         family=Monospaced,name=Monospaced.plain
         charWidth =7 charHeight=14 charDescent=4

      ACTUAL:
         # /jre/bin/java TestFonts
         family=Monospaced,name=Monospaced.plain
         charWidth =7 charHeight=15 charDescent=3

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              prr Philip Race
              Reporter:
              dkorbel David Korbel (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              8 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: