8017773: OpenJDK7 returns incorrect TrueType font metrics
authorysuenaga
Tue, 23 Sep 2014 15:48:16 -0700
changeset 27053 b8def728da69
parent 27052 0b783c32e5c2
child 27054 fd70c32a67ab
8017773: OpenJDK7 returns incorrect TrueType font metrics Reviewed-by: prr, bae
jdk/src/java.desktop/share/native/libfontmanager/freetypeScaler.c
--- a/jdk/src/java.desktop/share/native/libfontmanager/freetypeScaler.c	Tue Sep 23 07:13:34 2014 +0400
+++ b/jdk/src/java.desktop/share/native/libfontmanager/freetypeScaler.c	Tue Sep 23 15:48:16 2014 -0700
@@ -425,7 +425,6 @@
     jobject metrics;
     jfloat ax, ay, dx, dy, bx, by, lx, ly, mx, my;
     jfloat f0 = 0.0;
-    FT_Pos bmodifier = 0;
     FTScalerContext *context =
         (FTScalerContext*) jlong_to_ptr(pScalerContext);
     FTScalerInfo *scalerInfo =
@@ -458,43 +457,38 @@
        So, we have to do adust them explicitly and stay consistent with what
        freetype does to outlines. */
 
-    /* For bolding glyphs are not just widened. Height is also changed
-       (see ftsynth.c).
-
-       TODO: In vertical direction we could do better job and adjust metrics
-       proportionally to glyoh shape. */
-    if (context->doBold) {
-        bmodifier = FT_MulFix(
-                       scalerInfo->face->units_per_EM,
-                       scalerInfo->face->size->metrics.y_scale)/24;
-    }
-
 
     /**** Note: only some metrics are affected by styling ***/
 
+    /* See https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=657854 */
+#define FT_MulFixFloatShift6(a, b) (((float) (a)) * ((float) (b)) / 65536.0 / 64.0)
+
+    /*
+     * See FreeType source code: src/base/ftobjs.c ft_recompute_scaled_metrics()
+     * http://icedtea.classpath.org/bugzilla/show_bug.cgi?id=1659
+     */
     /* ascent */
     ax = 0;
-    ay = -(jfloat) FT26Dot6ToFloat(FT_MulFix(
-                       ((jlong) scalerInfo->face->ascender + bmodifier/2),
+    ay = -(jfloat) (FT_MulFixFloatShift6(
+                       ((jlong) scalerInfo->face->ascender),
                        (jlong) scalerInfo->face->size->metrics.y_scale));
     /* descent */
     dx = 0;
-    dy = -(jfloat) FT26Dot6ToFloat(FT_MulFix(
-                       ((jlong) scalerInfo->face->descender + bmodifier/2),
+    dy = -(jfloat) (FT_MulFixFloatShift6(
+                       ((jlong) scalerInfo->face->descender),
                        (jlong) scalerInfo->face->size->metrics.y_scale));
     /* baseline */
     bx = by = 0;
 
     /* leading */
     lx = 0;
-    ly = (jfloat) FT26Dot6ToFloat(FT_MulFix(
-                      (jlong) scalerInfo->face->height + bmodifier,
+    ly = (jfloat) (FT_MulFixFloatShift6(
+                      (jlong) scalerInfo->face->height,
                       (jlong) scalerInfo->face->size->metrics.y_scale))
                   + ay - dy;
     /* max advance */
     mx = (jfloat) FT26Dot6ToFloat(
                      scalerInfo->face->size->metrics.max_advance +
-                     2*bmodifier +
                      OBLIQUE_MODIFIER(scalerInfo->face->size->metrics.height));
     my = 0;