JDK-8214374 : incorrect Glyph positioning in GlyphVector when AffineTransform Y-axis inverted
  • 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-26
  • Updated: 2018-12-09
  • Resolved: 2018-12-09
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 13
13Resolved
Related Reports
Duplicate :  
Description
ADDITIONAL SYSTEM INFORMATION :
only tested on Windows 10 but I doubt this bug is system-dependent. Default runtime settings.

A DESCRIPTION OF THE PROBLEM :
java.awt.Font.createGlyphVector(FontRenderContext, String) returns a GlyphVector with glyphs severely incorrectly positioned when:

1.) FontRenderContext instance's AffineTransform is inverted on Y-Axis and is rotated
--e.g. AffineTransform tf = AffineTransform.getScaleInstance(1, -1); tf.rotate(1, 1);

2.) FontRenderContext's useFractionalMetrics is true

REGRESSION : Last worked in version 10.0.2

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
run this code:

public static void main(String[] args)
	{	
		AffineTransform transform = AffineTransform.getScaleInstance(1, -1);
		transform.rotate(1, 1);
		FontRenderContext frc = new FontRenderContext(transform, true, true);
		Font font = new Font("SansSerif", 0, 12);
		GlyphVector gv = font.createGlyphVector(frc, "scooby dooby doo");
		System.out.println(gv.getVisualBounds());		
	}

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
java.awt.geom.Rectangle2D$Float[x=0.37565047,y=-8.595767,w=96.350075,h=11.136932]
ACTUAL -
java.awt.geom.Rectangle2D$Float[x=0.17677669,y=-96.97646,w=6.032505,h=97.10905]

---------- BEGIN SOURCE ----------
package test;

import java.awt.Font;
import java.awt.font.FontRenderContext;
import java.awt.font.GlyphVector;
import java.awt.geom.AffineTransform;

public class TestFontGlyphVectorBug
{
	public static void main(String[] args)
	{	
		AffineTransform transform = AffineTransform.getScaleInstance(1, -1);
		transform.rotate(1, 1);
		FontRenderContext frc = new FontRenderContext(transform, true, true);
		Font font = new Font("SansSerif", 0, 12);
		GlyphVector gv = font.createGlyphVector(frc, "scooby dooby doo");
		System.out.println(gv.getVisualBounds());		
	}
}
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
Well, I assume the results from Font.createGlyphVector() are SUPPOSED to be identical whether your FontRenderContext's transform is Matrix A, or A.scale(1,-1), so you could check for a y-axis inverted transform, and if so, scale it by (1,-1). But you shouldn't have to do that. You should just be able to use whatever the Graphics2D instance gives you.


FREQUENCY : always



Comments
Another duplicate of JDK-8199537
09-12-2018

With AffineTransform Y-axis inverted, incorrect Glyph positioning displayed. Checked this for reported versions and could confirm this as a regression introduced in JDK 11. Results: ========== 8u191: OK 10.0.2: OK 11: Fail 11.0.1: Fail 12 ea b20: Fail To verify, run the attached test case with respective JDK versions. JDK-11 ======= $ java TestFontGlyphVectorBug java.awt.geom.Rectangle2D$Float[x=0.17677669,y=-96.97646,w=6.032505,h=97.10905]4395,w=44.0,h=10.863281] Preferred size: java.awt.Dimension[width=40,height=11] JDK 10.0.2: ============== $ java TestFontGlyphVectorBug java.awt.geom.Rectangle2D$Float[x=0.37565047,y=-8.595767,w=96.350075,h=11.136932]
27-11-2018