6697721: OpenJDK: rotated text baseline different between TextLayout and drawString
authorprr
Tue, 13 May 2008 16:56:22 -0700
changeset 554 88eb2812c2a4
parent 553 38a9503f374d
child 555 2f69b02943f8
6697721: OpenJDK: rotated text baseline different between TextLayout and drawString Reviewed-by: prr, igor Contributed-by: dougfelt@yahoo.com
jdk/src/share/native/sun/font/freetypeScaler.c
jdk/test/java/awt/Graphics2D/DrawString/RotTransText.java
--- a/jdk/src/share/native/sun/font/freetypeScaler.c	Tue May 13 16:49:21 2008 -0700
+++ b/jdk/src/share/native/sun/font/freetypeScaler.c	Tue May 13 16:56:22 2008 -0700
@@ -368,7 +368,7 @@
         //text can not be smaller than 1 point
         ptsz = 1.0;
     }
-    context->ptsz = (((int) ptsz) << 6);
+    context->ptsz = (int)(ptsz * 64);
     context->transform.xx =  FloatToFTFixed((float)dmat[0]/ptsz);
     context->transform.yx = -FloatToFTFixed((float)dmat[1]/ptsz);
     context->transform.xy = -FloatToFTFixed((float)dmat[2]/ptsz);
@@ -779,13 +779,24 @@
     }
 
     if (context->fmType == TEXT_FM_ON) {
-        glyphInfo->advanceX = FT26Dot6ToFloat(ftglyph->advance.x);
-        glyphInfo->advanceY = FT26Dot6ToFloat(-ftglyph->advance.y);
-    } else {
+        double advh = FTFixedToFloat(ftglyph->linearHoriAdvance);
         glyphInfo->advanceX =
-           (float) ROUND(FT26Dot6ToFloat(ftglyph->advance.x));
+            (float) (advh * FTFixedToFloat(context->transform.xx));
         glyphInfo->advanceY =
-           (float) ROUND(FT26Dot6ToFloat(-ftglyph->advance.y));
+            (float) (advh * FTFixedToFloat(context->transform.xy));
+    } else {
+        if (!ftglyph->advance.y) {
+            glyphInfo->advanceX =
+                (float) ROUND(FT26Dot6ToFloat(ftglyph->advance.x));
+            glyphInfo->advanceY = 0;
+        } else if (!ftglyph->advance.x) {
+            glyphInfo->advanceX = 0;
+            glyphInfo->advanceY =
+                (float) ROUND(FT26Dot6ToFloat(-ftglyph->advance.y));
+        } else {
+            glyphInfo->advanceX = FT26Dot6ToFloat(ftglyph->advance.x);
+            glyphInfo->advanceY = FT26Dot6ToFloat(-ftglyph->advance.y);
+        }
     }
 
     if (imageSize == 0) {
--- a/jdk/test/java/awt/Graphics2D/DrawString/RotTransText.java	Tue May 13 16:49:21 2008 -0700
+++ b/jdk/test/java/awt/Graphics2D/DrawString/RotTransText.java	Tue May 13 16:56:22 2008 -0700
@@ -38,12 +38,24 @@
 
     public static void main(String[] args) {
 
+        testIt(false);
+        testIt(true);
+
+    }
+
+    public static void testIt(boolean fmOn) {
+
         int wid=400, hgt=400;
         BufferedImage bi =
             new BufferedImage(wid, hgt, BufferedImage.TYPE_INT_RGB);
 
         Graphics2D g2d = bi.createGraphics();
 
+        if (fmOn) {
+            g2d.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS,
+                                 RenderingHints.VALUE_FRACTIONALMETRICS_ON);
+        }
+
         int x=130, y=130;
         String s = "Text";