JDK-8213453 : Incorrect FontMetrics on Windows via PrinterJob Graphics
  • Type: Bug
  • Component: client-libs
  • Sub-Component: 2d
  • Affected Version: 11,12
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_10
  • CPU: x86_64
  • Submitted: 2018-11-01
  • Updated: 2018-11-08
  • Resolved: 2018-11-08
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 12
12Resolved
Related Reports
Duplicate :  
Description
A DESCRIPTION OF THE PROBLEM :
This has been reported on AdoptOpenJDK community. 
https://github.com/AdoptOpenJDK/openjdk-build/issues/443

But the latest Oracle/OpenJDK 11.0.1 have also this problem. 

On Windows, the FontMetrics returned from Graphics.getFontMetrics(Font) within a PrinterJob are incorrect if the PageFormat has had the orientation explicitly set to PageFormat.LANDSCAPE or PageFormat.REVERSE_LANDSCAPE. The issue is not present when explicitly setting the orientation to PageFormat.PORTRAIT. 

fontMetrics.getHeight()) always returns 0. 

int i= 20;
Font font = new Font("Monospaced", 0, i);
FontMetrics fontMetrics = graphics.getFontMetrics(font);
System.out.println("font size=" + i + " FontMetrics.getHeight(): " + fontMetrics.getHeight());

REGRESSION : Last worked in version 8u191

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Use this program.

https://github.com/AdoptOpenJDK/openjdk-build/files/2287290/JPSFontMetrics.zip

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
fontMetrics.getHeight()) should return a correct value.
ACTUAL -
fontMetrics.getHeight()) should return 0 if PageFormat.LANDSCAPE or PageFormat.REVERSE_LANDSCAPE is set.

---------- BEGIN SOURCE ----------
See this program.

https://github.com/AdoptOpenJDK/openjdk-build/files/2287290/JPSFontMetrics.zip
---------- END SOURCE ----------

FREQUENCY : always



Comments
This is a duplicate of an issue in the freetype code that has been reported before. I'll hunt down the earlier bug report(s).
07-11-2018

fontMetrics.getHeight()) return an incorrect value if the PageFormat has had the orientation explicitly set to PageFormat.LANDSCAPE or PageFormat.REVERSE_LANDSCAPE. This is a regression introduced in JDK 11. Results: ======== 8u191: OK 9: OK 10.0.2: OK 11: Fail 12 ea b18: Fail To verify, run the attached test case with respective JDK versions. Result with JDK 10.0.2: $ java JPSFontMetrics font size=1 FontMetrics.getHeight(): 2 font size=2 FontMetrics.getHeight(): 3 font size=3 FontMetrics.getHeight(): 4 font size=4 FontMetrics.getHeight(): 6 font size=5 FontMetrics.getHeight(): 7 Result with JDK 11: $ java JPSFontMetrics font size=1 FontMetrics.getHeight(): 0 font size=2 FontMetrics.getHeight(): 0 font size=3 FontMetrics.getHeight(): 0 font size=4 FontMetrics.getHeight(): 0 font size=5 FontMetrics.getHeight(): 0
07-11-2018