Skip to content
This repository has been archived by the owner on Jun 24, 2021. It is now read-only.

JDK-8147476 : Rendering issues with MathML token elements. #117

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How often this method will be called from native? Is it too frequent? Too much of call to this function will leave a plenty of garbages. If it is too much, probably consider having static member similar like WCBufferedContext class.

Copy link
Contributor Author

@scientificware scientificware Jun 21, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, this method seems often used, I think that WebCore displays the mathematics words glyph by glyph due the nature of these words (frequently 1 or 2 characters) and over all because some of theses glyphs don't respect ascent and descent. But I made no test.

My purpose was simply to repair MathML rendering with a minimum of changes, not improve performances or memory usage. I think you are far more qualified than me to appreciate that. So I'm rely on you.

Do you means that, that all variables not directly used by others method of the class or not directly called could be declare private and static.
float[] bb in getGlyphBoundingBox(int glyph), for example ?
In this case, it should be interresting to test all methods ?
May be you already did that ?

Or I can not declare this variable and code like that :

return  new float[]{
getFontStrike().getFontResource().getGlyphBoundingBox(glyph, font.getSize())[0],
-getFontStrike().getFontResource().getGlyphBoundingBox(glyph, font.getSize())[3], 
getFontStrike().getFontResource().getGlyphBoundingBox(glyph, font.getSize())[2], 
getFontStrike().getFontResource().getGlyphBoundingBox(glyph, font.getSize())[3]
- getFontStrike().getFontResource().getGlyphBoundingBox(glyph, font.getSize())[1]};

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok.

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();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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<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;
}

}
Original file line number Diff line number Diff line change
@@ -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);
}
}