changeset 305:4092c04aeae7

6697721: OpenJDK: rotated text baseline different between TextLayout and drawString Reviewed-by: prr, igor Contributed-by: dougfelt@yahoo.com
author prr
date Tue, 13 May 2008 16:56:22 -0700
parents 57bcfeb3d8d8
children be7daefad89f
files src/share/native/sun/font/freetypeScaler.c test/java/awt/Graphics2D/DrawString/RotTransText.java
diffstat 2 files changed, 30 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/native/sun/font/freetypeScaler.c	Tue May 13 16:49:21 2008 -0700
+++ b/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);
+        double advh = FTFixedToFloat(ftglyph->linearHoriAdvance);
+        glyphInfo->advanceX =
+            (float) (advh * FTFixedToFloat(context->transform.xx));
+        glyphInfo->advanceY =
+            (float) (advh * FTFixedToFloat(context->transform.xy));
     } else {
-        glyphInfo->advanceX =
-           (float) ROUND(FT26Dot6ToFloat(ftglyph->advance.x));
-        glyphInfo->advanceY =
-           (float) ROUND(FT26Dot6ToFloat(-ftglyph->advance.y));
+        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/test/java/awt/Graphics2D/DrawString/RotTransText.java	Tue May 13 16:49:21 2008 -0700
+++ b/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";