LayoutTests/ChangeLog

 12016-03-18 Frederic Wang <fwang@igalia.com>
 2
 3 Use OpenType MATH constant AxisHeight.
 4 https://bugs.webkit.org/show_bug.cgi?id=133567
 5
 6 Reviewed by NOBODY (OOPS!).
 7
 8 We add a simple reftest to verify that the AxisHeight parameter is used to align the middle of <mtable> elements.
 9
 10 * mathml/opentype/axisheight7000.woff: Added.
 11 * mathml/opentype/table-align-axis-expected.html: Added.
 12 * mathml/opentype/table-align-axis.html: Added.
 13
1142016-03-17 Frederic Wang <fwang@igalia.com>
215
316 Add support for mathvariants that cannot be emulated via CSS.

LayoutTests/mathml/opentype/axisheight7000.woff

Binary file, nothing to see here

LayoutTests/mathml/opentype/table-align-axis-expected.html

 1<html>
 2 <head>
 3 <title>table align axis</title>
 4 <meta charset="utf-8">
 5 <style type="text/css">
 6 /* For Latin Modern Math
 7 AxisHeight = 7000 * 5 / 1000 = 35px;
 8 */
 9 @font-face {
 10 font-family: axisheight;
 11 src: url("axisheight7000.woff");
 12 }
 13 math {
 14 font-family: axisheight;
 15 font-size: 5px;
 16 }
 17 </style>
 18 </head>
 19 <body>
 20
 21 <div style="position: absolute; left: 0px; top: -35px;">
 22 <math>
 23 <mspace height="100px" depth="100px" width="1px" mathbackground="black"/>
 24 <mspace width="100px" height="2px" depth="2px" mathbackground="green"/>
 25 </math>
 26 </div>
 27
 28 </body>
 29</html>

LayoutTests/mathml/opentype/table-align-axis.html

 1<html>
 2 <head>
 3 <title>table align axis</title>
 4 <meta charset="utf-8">
 5 <style type="text/css">
 6 /* For Latin Modern Math
 7 AxisHeight = 7000 * 5 / 1000 = 35px;
 8 */
 9 @font-face {
 10 font-family: axisheight;
 11 src: url("axisheight7000.woff");
 12 }
 13 math {
 14 font-family: axisheight;
 15 font-size: 5px;
 16 }
 17 </style>
 18 </head>
 19 <body>
 20
 21 <!-- This test passes if the red bar is hidden by the green bar -->
 22 <div style="position: absolute; left: 0px; top: 0px;">
 23 <math>
 24 <mspace height="100px" depth="100px" width="1px"/>
 25 <mtable>
 26 <mtr><mtd><mspace width="50px"/></mtd></mtr>
 27 <mtr><mtd><mspace mathbackground="red" width="50px" height="1px" depth="1px"/></mtd></mtr>
 28 <mtr><mtd><mspace width="50px"/></mtd></mtr>
 29 </mfrac>
 30 </math>
 31 </div>
 32
 33 <!-- This green bar is moved up by AxisHeight and is a bit thicker than the red bar to tolerate rounding errors. -->
 34 <div style="position: absolute; left: 0px; top: -35px;">
 35 <math>
 36 <mspace height="100px" depth="100px" width="1px" mathbackground="black"/>
 37 <mspace width="100px" height="2px" depth="2px" mathbackground="green"/>
 38 </math>
 39 </div>
 40
 41 </body>
 42</html>

Source/WebCore/ChangeLog

 12016-03-18 Frederic Wang <fwang@igalia.com>
 2
 3 Use OpenType MATH constant AxisHeight.
 4 https://bugs.webkit.org/show_bug.cgi?id=133567
 5
 6 Reviewed by NOBODY (OOPS!).
 7
 8 Test: mathml/opentype/table-align-axis.html
 9
 10 We make RenderMathMLTable use the OpenType MATH constant AxisHeight.
 11 This is the only remaining case to handle since RenderMathMLFraction and RenderMathMLOperator already use that constant.
 12
 13 * rendering/mathml/RenderMathMLBlock.cpp: Make RenderMathMLTable use the math axis for its vertical alignment and update a bit the comments.
 14 (WebCore::axisHeight): Move the code in a static function that can be called by RenderMathMLBlock and RenderMathMLTable.
 15 (WebCore::RenderMathMLBlock::getMathAxisHeight): Use axisHeight.
 16 (WebCore::RenderMathMLTable::firstLineBaseline): Ditto.
 17
1182016-03-17 Frederic Wang <fwang@igalia.com>
219
320 Add support for mathvariants that cannot be emulated via CSS.

Source/WebCore/rendering/mathml/RenderMathMLBlock.cpp

@@bool RenderMathMLBlock::isChildAllowed(const RenderObject& child, const RenderSt
6767 return is<Element>(child.node());
6868}
6969
70 LayoutUnit RenderMathMLBlock::getMathAxisHeight() const
 70static LayoutUnit axisHeight(const RenderStyle& style)
7171{
72  const auto& primaryFont = style().fontCascade().primaryFont();
 72 // If we have a MATH table we just return the AxisHeight constant.
 73 const auto& primaryFont = style.fontCascade().primaryFont();
7374 if (auto* mathData = primaryFont.mathData())
7475 return mathData->getMathConstant(primaryFont, OpenTypeMathData::AxisHeight);
7576
76  return style().fontMetrics().xHeight() / 2;
 77 // Otherwise, the idea is to try and use the middle of operators as the math axis which we thus approximate by "half of the x-height".
 78 // Note that Gecko has a slower but more accurate version that measures half of the height of U+2212 MINUS SIGN.
 79 return style.fontMetrics().xHeight() / 2;
 80}
 81
 82LayoutUnit RenderMathMLBlock::getMathAxisHeight() const
 83{
 84 return axisHeight(style());
7785}
7886
7987LayoutUnit RenderMathMLBlock::mirrorIfNeeded(LayoutUnit horizontalOffset, LayoutUnit boxWidth) const

@@bool parseMathMLNamedSpace(const String& string, LayoutUnit& lengthValue, const
304312
305313Optional<int> RenderMathMLTable::firstLineBaseline() const
306314{
307  // In legal MathML, we'll have a MathML parent. That RenderFlexibleBox parent will use our firstLineBaseline() for baseline alignment, per
308  // http://dev.w3.org/csswg/css3-flexbox/#flex-baselines. We want to vertically center an <mtable>, such as a matrix. Essentially the whole <mtable> element fits on a
309  // single line, whose baseline gives this centering. This is different than RenderTable::firstLineBoxBaseline, which returns the baseline of the first row of a <table>.
310  return (logicalHeight() + style().fontMetrics().xHeight()) / 2;
 315 // By default the vertical center of <mtable> is aligned on the math axis.
 316 // This is different than RenderTable::firstLineBoxBaseline, which returns the baseline of the first row of a <table>.
 317 return Optional<int>(logicalHeight() / 2 + axisHeight(style()));
311318}
312319
313320void RenderMathMLBlock::layoutItems(bool relayoutChildren)