changeset 10995:3f3c201e0b0f

8147476: Rendering issues with MathML token elements Reviewed-by: arajkumar, kcr Contributed-by: guy.abossolo.foh@scientificware.com
author arajkumar
date Thu, 19 Jul 2018 11:22:59 +0530
parents b23139c6417f
children 393bbb76e7de
files modules/javafx.web/src/main/java/com/sun/javafx/webkit/prism/WCFontImpl.java modules/javafx.web/src/main/java/com/sun/webkit/graphics/WCFont.java modules/javafx.web/src/main/java/com/sun/webkit/perf/WCFontPerfLogger.java modules/javafx.web/src/main/native/Source/WebCore/platform/graphics/java/FontJava.cpp modules/javafx.web/src/test/java/test/javafx/scene/web/MathMLRenderTest.java
diffstat 5 files changed, 74 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/modules/javafx.web/src/main/java/com/sun/javafx/webkit/prism/WCFontImpl.java	Wed Jul 18 07:17:21 2018 -0700
+++ b/modules/javafx.web/src/main/java/com/sun/javafx/webkit/prism/WCFontImpl.java	Thu Jul 19 11:22:59 2018 +0530
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -160,6 +160,12 @@
         return getFontStrike().getFontResource().getAdvance(glyph, font.getSize());
     }
 
+    @Override public float[] getGlyphBoundingBox(int glyph) {
+        float[] bb = new float[4];
+        bb = getFontStrike().getFontResource().getGlyphBoundingBox(glyph, font.getSize(), bb);
+        return new float[]{bb[0], -bb[3], bb[2], bb[3] - bb[1]};
+    }
+
     @Override public float getXHeight() {
         return getFontStrike().getMetrics().getXHeight();
     }
--- a/modules/javafx.web/src/main/java/com/sun/webkit/graphics/WCFont.java	Wed Jul 18 07:17:21 2018 -0700
+++ b/modules/javafx.web/src/main/java/com/sun/webkit/graphics/WCFont.java	Thu Jul 19 11:22:59 2018 +0530
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -42,6 +42,8 @@
 
     public abstract double getGlyphWidth(int glyph);
 
+    public abstract float[] getGlyphBoundingBox(int glyph);
+
     public abstract double[] getStringBounds(String str, int from, int to,
                                              boolean rtl);
 
--- a/modules/javafx.web/src/main/java/com/sun/webkit/perf/WCFontPerfLogger.java	Wed Jul 18 07:17:21 2018 -0700
+++ b/modules/javafx.web/src/main/java/com/sun/webkit/perf/WCFontPerfLogger.java	Thu Jul 19 11:22:59 2018 +0530
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -101,6 +101,13 @@
         return res;
     }
 
+    public float[] getGlyphBoundingBox(int glyph) {
+        logger.resumeCount("GETGLYPHBOUNDINGBOX");
+        float[] res = fnt.getGlyphBoundingBox(glyph);
+        logger.suspendCount("GETGLYPHBOUNDINGBOX");
+        return res;
+    }
+
     public double getStringWidth(String str) {
         logger.resumeCount("GETSTRINGLENGTH");
         double res = fnt.getStringWidth(str);
--- a/modules/javafx.web/src/main/native/Source/WebCore/platform/graphics/java/FontJava.cpp	Wed Jul 18 07:17:21 2018 -0700
+++ b/modules/javafx.web/src/main/native/Source/WebCore/platform/graphics/java/FontJava.cpp	Thu Jul 19 11:22:59 2018 +0530
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -140,9 +140,24 @@
     return res;
 }
 
-FloatRect Font::platformBoundsForGlyph(Glyph) const
+FloatRect Font::platformBoundsForGlyph(Glyph c) const
 {
-    return FloatRect(); //That is OK! platformWidthForGlyph impl is enough.
+    JNIEnv* env = WebCore_GetJavaEnv();
+
+    RefPtr<RQRef> jFont = m_platformData.nativeFontData();
+    if (!jFont) {
+        return {};
+    }
+
+    static jmethodID getGlyphBoundingBox_mID = env->GetMethodID(PG_GetFontClass(env), "getGlyphBoundingBox", "(I)[F");
+    ASSERT(getGlyphBoundingBox_mID);
+
+    jfloatArray boundingBox = (jfloatArray)env->CallObjectMethod(*jFont, getGlyphBoundingBox_mID, (jint)c);
+    jfloat *bBox = env->GetFloatArrayElements(boundingBox,0);
+    auto bb = FloatRect { bBox[0], bBox[1], bBox[2], bBox[3] };
+    env->ReleaseFloatArrayElements(boundingBox, bBox, 0);
+    CheckAndClearException(env);
+    return bb;
 }
 
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/modules/javafx.web/src/test/java/test/javafx/scene/web/MathMLRenderTest.java	Thu Jul 19 11:22:59 2018 +0530
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package test.javafx.scene.web;
+
+import static org.junit.Assert.assertTrue;
+import org.junit.Test;
+
+public class MathMLRenderTest extends TestBase {
+
+    @Test public void testTokenHeight() throws Exception {
+        loadContent("<!doctype html><html><body><math><mo>=</mo></math></body></html>");
+        int height = (int) executeScript("document.getElementsByTagName('mo')[0].clientHeight");
+        assertTrue("MathML token height is lesser than expected " + height, height > 1);
+    }
+}