JDK-8073400 : Some Monospaced logical fonts have a different width
  • Type: Bug
  • Component: client-libs
  • Sub-Component: 2d
  • Affected Version: 8u31,9
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: windows
  • Submitted: 2015-02-18
  • Updated: 2016-07-21
  • Resolved: 2016-04-01
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 7 JDK 8 JDK 9
7u111Fixed 8u102Fixed 9 b116Fixed
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.
Comments
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.
01-04-2016

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.
01-04-2016