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