Skip to content
Permalink
Browse files
MathOperator: Add fallback mechanisms for stretching and mirroring ra…
…dical symbols

https://bugs.webkit.org/show_bug.cgi?id=156836

Source/WebCore:

Patch by Frederic Wang <fwang@igalia.com> on 2016-06-17
Reviewed by Sergio Villar Senin.

Some platforms do not have OpenType MATH fonts pre-installed and thus can not draw stretchy
operators using size variants or glyph assembly. This is especially problematic for the
radical symbol which is used to write roots. Currently, we have some fallback code to draw
that symbol using graphical primitives but it is a bit complex and makes the style of radical
inconsistent with the font used. We solve these issues by just scaling the base glyph via a
scale transform. Such scale transform is also used to mirror the radical symbol so that we
have some support for right-to-left roots until we can do glyph-level mirroring
via the OpenType rtlm feature.

Test: mathml/radical-fallback.html

* rendering/mathml/MathOperator.cpp: Add a constant for the code point U+221A of the radical.
(WebCore::MathOperator::reset): In general, we don't need any vertical scaling for radical
symbols so m_radicalVerticalScale is initialized to 1.
(WebCore::MathOperator::calculateStretchyData): If we don't have a font with a MATH table and we
try streching a radical, then we update the vertical metrics to match the target size and
set m_radicalVerticalScale to the value necessary to make the base glyph scaled to that size.
(WebCore::MathOperator::paint): For a radical operator, we may apply a scale transform of
parameters (radicalHorizontalScale, m_radicalVerticalScale) in order to support RTL
mirroring or vertical stretching.
* rendering/mathml/MathOperator.h: We add a m_radicalVerticalScale member to indicate the
scaling to apply to the base radical glyph when the stretchy fallback is necessary.
(WebCore::MathOperator::isStretched): The operator is also considered stretched when the
m_radicalVerticalScale is applied to the base size.
* rendering/mathml/RenderMathMLRadicalOperator.cpp: Remove code specific to the old fallback mechanism.
* rendering/mathml/RenderMathMLRadicalOperator.h: Ditto.

LayoutTests:

Reviewed by Sergio Villar Senin.

We add a pixel test to verify the result of stretching a radical operator.
We test RTL/LTR direction as well as default/sans-serif font in order to check the fallback code.

* mathml/radical-fallback.html: Added.
* platform/gtk/mathml/radical-fallback-expected.png: Added.
* platform/gtk/mathml/radical-fallback-expected.txt: Added.
* platform/ios-simulator/mathml/radical-fallback-expected.txt: Added.
* platform/mac/mathml/radical-fallback-expected.png: Added.
* platform/mac/mathml/radical-fallback-expected.txt: Added.
* platform/ios-simulator/mathml/presentation/roots.txt: Updated.

Canonical link: https://commits.webkit.org/176939@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@202161 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
fred-wang committed Jun 17, 2016
1 parent 33db285 commit 3bcc6099a548bcbf3817d9e4af396db24da1682c
Showing 14 changed files with 475 additions and 341 deletions.
@@ -1,3 +1,21 @@
2016-06-17 Frederic Wang <fred.wang@free.fr>

MathOperator: Add fallback mechanisms for stretching and mirroring radical symbols
https://bugs.webkit.org/show_bug.cgi?id=156836

Reviewed by Sergio Villar Senin.

We add a pixel test to verify the result of stretching a radical operator.
We test RTL/LTR direction as well as default/sans-serif font in order to check the fallback code.

* mathml/radical-fallback.html: Added.
* platform/gtk/mathml/radical-fallback-expected.png: Added.
* platform/gtk/mathml/radical-fallback-expected.txt: Added.
* platform/ios-simulator/mathml/radical-fallback-expected.txt: Added.
* platform/mac/mathml/radical-fallback-expected.png: Added.
* platform/mac/mathml/radical-fallback-expected.txt: Added.
* platform/ios-simulator/mathml/presentation/roots.txt: Updated.

2016-06-16 Commit Queue <commit-queue@webkit.org>

Unreviewed, rolling out r202147.
@@ -0,0 +1,29 @@
<!DOCTYPE html>
<html>
<head>
<title>Radical fallback</title>
<meta charset="utf-8"/>
</head>
<body>

<!-- This pixel test verifies stretching of radical operators with either
the default MathML font or a sans-serif font. The latter is likely
to require a fallback mechanism ascsans-serif are generally not math
fonts and so can not stretch radicals. -->

<p>Large LTR radicals:
<math>
<msqrt><mspace height="5em"/></msqrt>
<msqrt style="font-family: sans-serif"><mspace height="5em"/></msqrt>
</math>
</p>

<p>Large RTL radicals:
<math dir="rtl">
<msqrt><mspace height="5em"/></msqrt>
<msqrt style="font-family: sans-serif"><mspace height="5em"/></msqrt>
</math>
</p>

</body>
</html>
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -0,0 +1,51 @@
layer at (0,0) size 800x600
RenderView at (0,0) size 800x600
layer at (0,0) size 800x222
RenderBlock {HTML} at (0,0) size 800x222
RenderBody {BODY} at (8,16) size 784x190
RenderBlock {P} at (0,0) size 784x87
RenderText {#text} at (0,70) size 132x17
text run at (0,70) width 132: "Large LTR radicals: "
RenderMathMLMath {math} at (132,0) size 28x85 [padding: 0 1 0 1]
RenderMathMLSquareRoot {msqrt} at (1,2) size 17x83
RenderMathMLBlock (anonymous, flex) at (0,0) size 17x83
RenderMathMLRadicalOperator (anonymous) at (0,0) size 17x83
RenderMathMLBlock (anonymous, flex) at (0,0) size 13x82
RenderBlock (anonymous) at (0,0) size 13x82
RenderText at (0,-56) size 13x106
text run at (0,-56) width 13: "\x{221A}"
RenderMathMLRootWrapper at (17,2) size 0x81
RenderMathMLSpace {mspace} at (0,0) size 0x80
RenderMathMLSquareRoot {msqrt} at (18,0) size 9x84
RenderMathMLBlock (anonymous, flex) at (0,0) size 9x84
RenderMathMLRadicalOperator (anonymous) at (0,0) size 9x84
RenderMathMLBlock (anonymous, flex) at (0,0) size 9x83
RenderBlock (anonymous) at (0,0) size 9x83
RenderText at (0,-1) size 9x17
text run at (0,-1) width 9: "\x{221A}"
RenderMathMLRootWrapper at (9,3) size 0x81
RenderMathMLSpace {mspace} at (0,0) size 0x80
RenderText {#text} at (0,0) size 0x0
RenderBlock {P} at (0,103) size 784x87
RenderText {#text} at (0,70) size 132x17
text run at (0,70) width 132: "Large RTL radicals: "
RenderMathMLMath {math} at (132,0) size 28x85 [padding: 0 1 0 1]
RenderMathMLSquareRoot {msqrt} at (10,2) size 17x83
RenderMathMLBlock (anonymous, flex) at (0,0) size 17x83
RenderMathMLRadicalOperator (anonymous) at (0,0) size 17x83
RenderMathMLBlock (anonymous, flex) at (4,0) size 13x82
RenderBlock (anonymous) at (0,0) size 13x82
RenderText at (0,-56) size 13x106
text run at (0,-56) width 13 RTL: "\x{221A}"
RenderMathMLRootWrapper at (0,2) size 0x81
RenderMathMLSpace {mspace} at (0,0) size 0x80
RenderMathMLSquareRoot {msqrt} at (1,0) size 9x84
RenderMathMLBlock (anonymous, flex) at (0,0) size 9x84
RenderMathMLRadicalOperator (anonymous) at (0,0) size 9x84
RenderMathMLBlock (anonymous, flex) at (0,0) size 9x83
RenderBlock (anonymous) at (0,0) size 9x83
RenderText at (0,-1) size 9x17
text run at (0,-1) width 9 RTL: "\x{221A}"
RenderMathMLRootWrapper at (0,3) size 0x81
RenderMathMLSpace {mspace} at (0,0) size 0x80
RenderText {#text} at (0,0) size 0x0

0 comments on commit 3bcc609

Please sign in to comment.