diff --git a/modules/javafx.web/src/main/java/com/sun/javafx/webkit/prism/WCFontImpl.java b/modules/javafx.web/src/main/java/com/sun/javafx/webkit/prism/WCFontImpl.java index 150c42d1b9..107a33a5bd 100644 --- a/modules/javafx.web/src/main/java/com/sun/javafx/webkit/prism/WCFontImpl.java +++ b/modules/javafx.web/src/main/java/com/sun/javafx/webkit/prism/WCFontImpl.java @@ -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 @@ private FontStrike getFontStrike() 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(); } diff --git a/modules/javafx.web/src/main/java/com/sun/webkit/graphics/WCFont.java b/modules/javafx.web/src/main/java/com/sun/webkit/graphics/WCFont.java index bcaf414758..dc8adeb706 100644 --- a/modules/javafx.web/src/main/java/com/sun/webkit/graphics/WCFont.java +++ b/modules/javafx.web/src/main/java/com/sun/webkit/graphics/WCFont.java @@ -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 WCGlyphBuffer getGlyphsAndAdvances(String str, int from, public abstract double getGlyphWidth(int glyph); + public abstract float[] getGlyphBoundingBox(int glyph); + public abstract double[] getStringBounds(String str, int from, int to, boolean rtl); diff --git a/modules/javafx.web/src/main/java/com/sun/webkit/perf/WCFontPerfLogger.java b/modules/javafx.web/src/main/java/com/sun/webkit/perf/WCFontPerfLogger.java index 63d3a56364..13ae3fa144 100644 --- a/modules/javafx.web/src/main/java/com/sun/webkit/perf/WCFontPerfLogger.java +++ b/modules/javafx.web/src/main/java/com/sun/webkit/perf/WCFontPerfLogger.java @@ -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 @@ public double getGlyphWidth(int glyph) { 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); diff --git a/modules/javafx.web/src/main/native/Source/WebCore/platform/graphics/java/FontJava.cpp b/modules/javafx.web/src/main/native/Source/WebCore/platform/graphics/java/FontJava.cpp index 1f797c1a39..03b0a67149 100644 --- a/modules/javafx.web/src/main/native/Source/WebCore/platform/graphics/java/FontJava.cpp +++ b/modules/javafx.web/src/main/native/Source/WebCore/platform/graphics/java/FontJava.cpp @@ -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 @@ float Font::platformWidthForGlyph(Glyph c) const 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 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; } } diff --git a/modules/javafx.web/src/test/java/test/javafx/scene/web/MathMLRenderTest.java b/modules/javafx.web/src/test/java/test/javafx/scene/web/MathMLRenderTest.java new file mode 100644 index 0000000000..ae375280f8 --- /dev/null +++ b/modules/javafx.web/src/test/java/test/javafx/scene/web/MathMLRenderTest.java @@ -0,0 +1,85 @@ +/* + * 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 { + + // Document test + String mathmlContent + = "" + + " " + + " x" + + " =" + + " " + + " " + + " " + + " b" + + " ±" + + " " + + " " + + " " + + " b" + + " 2" + + " " + + " " + + " 4" + + " a" + + " c" + + " " + + " " + + " " + + " " + + " 2" + + " a" + + " " + + " " + + " " + + ""; + + String htmlBody = "" + + "" + + " " + + "

" + + mathmlContent + + "

" + + " " + + ""; + + loadContent(htmlBody); + + int height = (int) executeScript( + "elements = document.getElementsByTagName('mo');" + + "element = elements[0].clientHeight;" + ); + + assertTrue("MathML token height must be greater than " + height, height > 1); + } +}