JDK-8139178 : Wrong fontMetrics when printing in Landscape (OpenJDK)
  • Type: Bug
  • Component: client-libs
  • Sub-Component: 2d
  • Affected Version: 8,9,11
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: linux
  • CPU: x86_64
  • Submitted: 2015-10-02
  • Updated: 2020-09-17
  • Resolved: 2018-11-30
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 11 JDK 12 Other
11.0.4Fixed 12 b23Fixed openjdk8u232Fixed
Related Reports
Duplicate :  
Duplicate :  
Duplicate :  
Duplicate :  
Duplicate :  
Duplicate :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Description
FULL PRODUCT VERSION :
openjdk version "1.8.0_66-internal"
OpenJDK Runtime Environment (build 1.8.0_66-internal-b01)
OpenJDK 64-Bit Server VM (build 25.66-b01, mixed mode)


ADDITIONAL OS VERSION INFORMATION :
Linux xxx 4.1.0-2-amd64 #1 SMP Debian 4.1.6-1 (2015-08-23) x86_64 GNU/Linux

EXTRA RELEVANT SYSTEM CONFIGURATION :
OpenJDK 8 installed from debian testing repository and CUPS PDF printer installed.

A DESCRIPTION OF THE PROBLEM :
When printing in landscape, getting FontMetrics returns wrong font parameters - ascent=0, descent=0, height=0

REGRESSION.  Last worked in version 8u60

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Set up any printer (for example cups-pdf) and use test case in OpenJDK, OracleJDK in Linux returns valid values. When printing in Portrait, fontMetrics return valid values. It seems that in landscape mode there is some transformation on graphics object configured and it affects fontMetrics.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Valid font metrics: 
sun.font.FontDesignMetrics[font=java.awt.Font[family=Monospaced,name=Monospaced,style=plain,size=9]ascent=9, descent=3, height=12]

ACTUAL -
Incorrect font metrics: sun.font.FontDesignMetrics[font=java.awt.Font[family=Monospaced,name=Monospaced,style=plain,size=9]ascent=0, descent=0, height=0]

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.awt.*;

import javax.print.attribute.HashPrintRequestAttributeSet;
import javax.print.attribute.standard.OrientationRequested;

import java.awt.print.*;

public class LandscapeFontMetrics {

	public static void main(String args[]) throws Exception {
		PrinterJob job = PrinterJob.getPrinterJob();
		job.setPrintable(new Printable() {
			public int print(Graphics g, PageFormat pf, int page) throws PrinterException {
				if (page > 0)
					return NO_SUCH_PAGE;

				Font f = new Font(Font.MONOSPACED, Font.PLAIN, 9);
				FontMetrics fontMetrics = g.getFontMetrics(f);
				System.err.println(fontMetrics);

				assert fontMetrics.getHeight() > 0; //fails in linux openjdk 7 and 8, runs on Oracle JDK 8

				return NO_SUCH_PAGE;
			}
		});
		HashPrintRequestAttributeSet as = new HashPrintRequestAttributeSet();
		as.add(OrientationRequested.LANDSCAPE);
		job.print(as);
		System.exit(0);
	}
}

---------- END SOURCE ----------


Comments
Fix request 8u We are seeing OpenJDK8 also affected by this. The patch applies cleanly, no regressions found after running Tier1 and Tier2. The included regression test can fail depending on the default Dialog font of the system (it is know to fail with Roboto and Nimbus Sans L), but works with others like Deja Vu fonts. There are some more information about this faulty test in https://bugs.openjdk.java.net/browse/JDK-8219641
22-11-2019

Fix request for 11u: The issue affects all OpenJDK versions prior 12. The patch applies cleanly. The regression test (test/jdk/java/awt/font/Rotate/RotatedFontMetricsTest.java) fails without the patch and starts passing with the patch applied.
26-04-2019

Reproducible in jdk8GA ./java-se-8-ri/bin/java LandscapeFtMetrics sun.font.FontDesignMetrics[font=java.awt.Font[family=Monospaced,name=Monospaced,style=plain,size=9]ascent=0, descent=0, height=0]
08-08-2017

As regression labeled and introduced in 8u or 9 -- targeted to 10
17-02-2017

could you try 8 GA (latest, b132(?) ) ?
12-02-2016

It does not seem to be a regression from 8u60 [as claimed REGRESSION. Last worked in version 8u60 ] as it fails there too in mine. /export/WorkSpaces/openjdk/java-se-8u60-ri/bin/java LandscapeFontMetrics sun.font.FontDesignMetrics[font=java.awt.Font[family=Monospaced,name=Monospaced,style=plain,size=9]ascent=0, descent=0, height=0] prsadhuk@prsadhuk-VirtualBox:/export/WorkSpaces/openjdk/client/build/linux-x86-normal-server-fastdebug$ /export/WorkSpaces/openjdk/java-se-8u60-ri/bin/java -version openjdk version "1.8.0_60" OpenJDK Runtime Environment (build 1.8.0_60-b27) OpenJDK Server VM (build 25.60-b23, mixed mode)
05-11-2015

Moving to JDK project. Has a test case. Setting Fix/Version to JDK 9 for Dev evaluation. Appear to be a Oracle vs OpenJDK difference. Commentary on reasons would be valuable.
08-10-2015