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

Some Monospaced logical fonts have a different width

    Details

    • Subcomponent:
      2d
    • Resolved In Build:
      b116
    • OS:
      windows

      Backports

        Description

        On Windows some characters (in particular, left and right double quotation marks) have width differing from other characters' widths, when Monospaced logical font is used.

          Activity

          Hide
          dmarkov Dmitry Markov added a comment - - edited
          Test case to reproduce the issue is provided below:

          import java.awt.*;
          import java.awt.font.FontRenderContext;

          public class MonospacedTest {
              public static void main(String[] args) {
                  Font font = new Font(Font.MONOSPACED, Font.PLAIN, 12);
                  System.out.println("'a' width: " + getCharWidth(font, 'a'));
                  System.out.println("'\u201c' width: " + getCharWidth(font, '\u201c'));
              }

              private static double getCharWidth(Font font, char c) {
                  return font.getStringBounds(new char[]{c}, 0, 1, new
                           FontRenderContext(null, false, false)).getWidth();
                  }
          }

          On Windows result is:
          'a' width: 7.0
          '¿' width: 5.0

          Expected result is the same width for both characters.

          Please note: the problem is not reproducible on Linux and MacOSX.
          Show
          dmarkov Dmitry Markov added a comment - - edited Test case to reproduce the issue is provided below: import java.awt.*; import java.awt.font.FontRenderContext; public class MonospacedTest {     public static void main(String[] args) {         Font font = new Font(Font.MONOSPACED, Font.PLAIN, 12);         System.out.println("'a' width: " + getCharWidth(font, 'a'));         System.out.println("'\u201c' width: " + getCharWidth(font, '\u201c'));     }     private static double getCharWidth(Font font, char c) {         return font.getStringBounds(new char[]{c}, 0, 1, new                  FontRenderContext(null, false, false)).getWidth();         } } On Windows result is: 'a' width: 7.0 '¿' width: 5.0 Expected result is the same width for both characters. Please note: the problem is not reproducible on Linux and MacOSX.
          Hide
          dmarkov Dmitry Markov added a comment - - edited
          Problem description:
          On Windows some characters (in particular, left and right double quotation marks) have width differing from other characters' widths, when Monospaced logical font is used.
          The default monospaced font for windows platform is Courier New. It contains the desired characters, (i.e. '\u201c' and '\u201d'). However the characters are in 'exclusion ranges' for this font due to settings in windows.fontconfig.properties. So when we try to obtain glyphs for these characters and calculate their bounds, we fallback to another font (Lucida) and use its glyphs. That's why the width is different.

          Fix:
          Remove the following set of characters u2018 - u201F from the exclusion range.
          Show
          dmarkov Dmitry Markov added a comment - - edited Problem description: On Windows some characters (in particular, left and right double quotation marks) have width differing from other characters' widths, when Monospaced logical font is used. The default monospaced font for windows platform is Courier New. It contains the desired characters, (i.e. '\u201c' and '\u201d'). However the characters are in 'exclusion ranges' for this font due to settings in windows.fontconfig.properties. So when we try to obtain glyphs for these characters and calculate their bounds, we fallback to another font (Lucida) and use its glyphs. That's why the width is different. Fix: Remove the following set of characters u2018 - u201F from the exclusion range.
          Hide
          hgupdate HG Updates added a comment -
          URL: http://hg.openjdk.java.net/jdk9/client/jdk/rev/0643c56e3c86
          User: dmarkov
          Date: 2016-04-01 08:27:32 +0000
          Show
          hgupdate HG Updates added a comment - URL: http://hg.openjdk.java.net/jdk9/client/jdk/rev/0643c56e3c86 User: dmarkov Date: 2016-04-01 08:27:32 +0000
          Hide
          hgupdate HG Updates added a comment -
          URL: http://hg.openjdk.java.net/jdk9/jdk9/jdk/rev/0643c56e3c86
          User: lana
          Date: 2016-04-27 18:46:47 +0000
          Show
          hgupdate HG Updates added a comment - URL: http://hg.openjdk.java.net/jdk9/jdk9/jdk/rev/0643c56e3c86 User: lana Date: 2016-04-27 18:46:47 +0000

            People

            • Assignee:
              dmarkov Dmitry Markov
              Reporter:
              shadowbug Shadow Bug
            • Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: