JDK-8213985 : Graphics2D.getFontMetrics().getStringBounds(...).getBounds() gets modified after applying Graphics2D.rotate(...) transform
  • Type: Bug
  • Component: client-libs
  • Sub-Component: 2d
  • Affected Version: 11.0.1
  • Priority: P4
  • Status: Open
  • Resolution: Unresolved
  • OS: windows
  • Submitted: 2018-11-16
  • Updated: 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.
Other
tbdUnresolved
Related Reports
Relates :  
Relates :  
Description
1. Running on eclipse (using jdk-1.8.0_172) 'Graphics2D.getFontMetrics().getStringBounds(...).getBounds()'  remains same before and after applying rotate() transform.
2. While using jdk-11.01 , 'Graphics2D.getFontMetrics().getStringBounds(...).getBounds()'  is modified after applying rotate() transform.
3. It maybe related to https://bugs.openjdk.java.net/browse/JDK-8205046 and https://bugs.openjdk.java.net/browse/JMC-6207

Comments
This looks like another duplicate of https://bugs.openjdk.java.net/browse/JDK-8139178
30-11-2018

Code Snippet: private AffineTransform getTitleTransform( Graphics2D ctx, Rectangle targetArea, AffineTransform originalTrans, AffineTransform labelTrans) { ctx.setTransform(originalTrans); ctx.translate(targetArea.x, targetArea.y + targetArea.height / 2); ctx.rotate(-Math.PI / 2); AffineTransform titleTrans = ctx.getTransform(); ctx.setTransform(labelTrans); return titleTrans; } private void paintTitle(Graphics2D ctx, AffineTransform labelTrans, AffineTransform titleTrans) { //titlebounds before rotation Rectangle titleBounds1 = ctx.getFontMetrics().getStringBounds(getTitle(), ctx).getBounds(); ctx.setTransform(titleTrans); . . . //titleBounds after rotation Rectangle titleBounds = ctx.getFontMetrics().getStringBounds(getTitle(), ctx).getBounds(); . . . int yPosition = -titleBounds.y; // print title text ctx.drawString(getTitle(), -titleBounds.width / 2, yPosition); . . } 1. In graph y-axis-vertical title is clearly visible using jdk-8 , while title is not visible or cropped in jdk-11.01 2. (output in jdk1.8.0_172): titleBounds1 : [x=0,y=-11, width=14, height=19] titleBounds : [x=0,y=-11, width=14, height=19] 3. (output in jdk11.0.1): titleBounds1: [x=0,y=-11,width=14,height=14] titleBounds: [x=0,y=0,width=14,height=0]
16-11-2018