<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[201881] trunk/Source/WebCore</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/201881">201881</a></dd>
<dt>Author</dt> <dd>fred.wang@free.fr</dd>
<dt>Date</dt> <dd>2016-06-09 13:50:44 -0700 (Thu, 09 Jun 2016)</dd>
</dl>
<h3>Log Message</h3>
<pre>RenderMathOperator: Move calculation of preferred width into MathOperator
https://bugs.webkit.org/show_bug.cgi?id=157071
Reviewed by Brent Fulgham.
No new tests, behavior is not change.
* rendering/mathml/MathOperator.cpp:
(WebCore::MathOperator::setOperator): Introduce a style parameter and call reset.
(WebCore::MathOperator::reset): New helper function to reset the operator.
For now we only set the width of the base glyph and the preferred max width.
(WebCore::MathOperator::calculateDisplayStyleLargeOperator): Calculate the m_maxPreferredWidth.
(WebCore::MathOperator::calculateStretchyData): Change the signature of the function and directly set m_maxPreferredWidth.
* rendering/mathml/MathOperator.h: Add m_maxPreferredWidth member and update some declarations.
(WebCore::MathOperator::width): New helper function.
(WebCore::MathOperator::maxPreferredWidth): New helper function.
* rendering/mathml/RenderMathMLOperator.cpp:
(WebCore::RenderMathMLOperator::computePreferredLogicalWidths): This function performs wrong
operations that will be fixed in bug 152244 when we update the tests.
For now, let's just use maxPreferredWidth() for non-horizontal operators.
(WebCore::RenderMathMLOperator::updateStyle): Use the new signature of the functions.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCorerenderingmathmlMathOperatorcpp">trunk/Source/WebCore/rendering/mathml/MathOperator.cpp</a></li>
<li><a href="#trunkSourceWebCorerenderingmathmlMathOperatorh">trunk/Source/WebCore/rendering/mathml/MathOperator.h</a></li>
<li><a href="#trunkSourceWebCorerenderingmathmlRenderMathMLOperatorcpp">trunk/Source/WebCore/rendering/mathml/RenderMathMLOperator.cpp</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (201880 => 201881)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2016-06-09 20:10:30 UTC (rev 201880)
+++ trunk/Source/WebCore/ChangeLog        2016-06-09 20:50:44 UTC (rev 201881)
</span><span class="lines">@@ -1,3 +1,27 @@
</span><ins>+2016-06-09 Frederic Wang <fred.wang@free.fr>
+
+ RenderMathOperator: Move calculation of preferred width into MathOperator
+ https://bugs.webkit.org/show_bug.cgi?id=157071
+
+ Reviewed by Brent Fulgham.
+
+ No new tests, behavior is not change.
+
+ * rendering/mathml/MathOperator.cpp:
+ (WebCore::MathOperator::setOperator): Introduce a style parameter and call reset.
+ (WebCore::MathOperator::reset): New helper function to reset the operator.
+ For now we only set the width of the base glyph and the preferred max width.
+ (WebCore::MathOperator::calculateDisplayStyleLargeOperator): Calculate the m_maxPreferredWidth.
+ (WebCore::MathOperator::calculateStretchyData): Change the signature of the function and directly set m_maxPreferredWidth.
+ * rendering/mathml/MathOperator.h: Add m_maxPreferredWidth member and update some declarations.
+ (WebCore::MathOperator::width): New helper function.
+ (WebCore::MathOperator::maxPreferredWidth): New helper function.
+ * rendering/mathml/RenderMathMLOperator.cpp:
+ (WebCore::RenderMathMLOperator::computePreferredLogicalWidths): This function performs wrong
+ operations that will be fixed in bug 152244 when we update the tests.
+ For now, let's just use maxPreferredWidth() for non-horizontal operators.
+ (WebCore::RenderMathMLOperator::updateStyle): Use the new signature of the functions.
+
</ins><span class="cx"> 2016-06-09 Alex Christensen <achristensen@webkit.org>
</span><span class="cx">
</span><span class="cx"> Clean up WebSocket code
</span></span></pre></div>
<a id="trunkSourceWebCorerenderingmathmlMathOperatorcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/rendering/mathml/MathOperator.cpp (201880 => 201881)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/rendering/mathml/MathOperator.cpp        2016-06-09 20:10:30 UTC (rev 201880)
+++ trunk/Source/WebCore/rendering/mathml/MathOperator.cpp        2016-06-09 20:50:44 UTC (rev 201881)
</span><span class="lines">@@ -75,12 +75,30 @@
</span><span class="cx"> { 0x222b, 0x2320, 0x23ae, 0x2321, 0x0 } // integral sign
</span><span class="cx"> };
</span><span class="cx">
</span><del>-void MathOperator::setOperator(UChar baseCharacter, Type operatorType)
</del><ins>+void MathOperator::setOperator(const RenderStyle& style, UChar baseCharacter, Type operatorType)
</ins><span class="cx"> {
</span><span class="cx"> m_baseCharacter = baseCharacter;
</span><span class="cx"> m_operatorType = operatorType;
</span><ins>+ reset(style);
</ins><span class="cx"> }
</span><span class="cx">
</span><ins>+void MathOperator::reset(const RenderStyle& style)
+{
+ m_maxPreferredWidth = 0;
+ m_width = 0;
+
+ // We use the base size for the calculation of the preferred width.
+ GlyphData baseGlyph;
+ if (!getBaseGlyph(style, baseGlyph))
+ return;
+ m_maxPreferredWidth = m_width = advanceWidthForGlyph(baseGlyph);
+
+ if (m_operatorType == Type::VerticalOperator)
+ calculateStretchyData(style, true); // We also take into account the width of larger sizes for the calculation of the preferred width.
+ else if (m_operatorType == Type::DisplayOperator)
+ calculateDisplayStyleLargeOperator(style); // We can directly select the size variant and determine the final metrics.
+}
+
</ins><span class="cx"> LayoutUnit MathOperator::stretchSize() const
</span><span class="cx"> {
</span><span class="cx"> ASSERT(m_operatorType == Type::VerticalOperator || m_operatorType == Type::HorizontalOperator);
</span><span class="lines">@@ -127,6 +145,8 @@
</span><span class="cx"> for (auto& sizeVariant : sizeVariants) {
</span><span class="cx"> GlyphData glyphData(sizeVariant, baseGlyph.font);
</span><span class="cx"> setSizeVariant(glyphData);
</span><ins>+ // Large operators in STIX Word have incorrect advance width, causing misplacement of superscript, so we use the glyph bound instead (http://sourceforge.net/p/stixfonts/tracking/49/).
+ m_maxPreferredWidth = boundsForGlyph(glyphData).width();
</ins><span class="cx"> m_italicCorrection = glyphData.font->mathData()->getItalicCorrection(*glyphData.font, glyphData.glyph);
</span><span class="cx"> if (heightForGlyph(glyphData) >= displayOperatorMinHeight)
</span><span class="cx"> break;
</span><span class="lines">@@ -235,24 +255,24 @@
</span><span class="cx"> return true;
</span><span class="cx"> }
</span><span class="cx">
</span><del>-void MathOperator::calculateStretchyData(const RenderStyle& style, float* maximumGlyphWidth, LayoutUnit targetSize)
</del><ins>+void MathOperator::calculateStretchyData(const RenderStyle& style, bool calculateMaxPreferredWidth, LayoutUnit targetSize)
</ins><span class="cx"> {
</span><span class="cx"> ASSERT(m_operatorType == Type::VerticalOperator || m_operatorType == Type::HorizontalOperator);
</span><del>- ASSERT(!maximumGlyphWidth || m_operatorType == Type::VerticalOperator);
</del><ins>+ ASSERT(!calculateMaxPreferredWidth || m_operatorType == Type::VerticalOperator);
</ins><span class="cx"> bool isVertical = m_operatorType == Type::VerticalOperator;
</span><span class="cx">
</span><span class="cx"> GlyphData baseGlyph;
</span><span class="cx"> if (!getBaseGlyph(style, baseGlyph))
</span><span class="cx"> return;
</span><span class="cx">
</span><del>- if (!maximumGlyphWidth) {
</del><ins>+ if (!calculateMaxPreferredWidth) {
</ins><span class="cx"> // We do not stretch if the base glyph is large enough.
</span><span class="cx"> float baseSize = isVertical ? heightForGlyph(baseGlyph) : advanceWidthForGlyph(baseGlyph);
</span><span class="cx"> if (targetSize <= baseSize)
</span><span class="cx"> return;
</span><span class="cx"> }
</span><span class="cx">
</span><del>- MathOperator::GlyphAssemblyData assemblyData;
</del><ins>+ GlyphAssemblyData assemblyData;
</ins><span class="cx"> if (baseGlyph.font->mathData()) {
</span><span class="cx"> Vector<Glyph> sizeVariants;
</span><span class="cx"> Vector<OpenTypeMathData::AssemblyPart> assemblyParts;
</span><span class="lines">@@ -260,11 +280,11 @@
</span><span class="cx"> // We verify the size variants.
</span><span class="cx"> for (auto& sizeVariant : sizeVariants) {
</span><span class="cx"> GlyphData glyphData(sizeVariant, baseGlyph.font);
</span><del>- if (maximumGlyphWidth)
- *maximumGlyphWidth = std::max(*maximumGlyphWidth, advanceWidthForGlyph(glyphData));
</del><ins>+ if (calculateMaxPreferredWidth)
+ m_maxPreferredWidth = std::max<LayoutUnit>(m_maxPreferredWidth, advanceWidthForGlyph(glyphData));
</ins><span class="cx"> else {
</span><span class="cx"> setSizeVariant(glyphData);
</span><del>- float size = isVertical ? heightForGlyph(glyphData) : advanceWidthForGlyph(glyphData);
</del><ins>+ LayoutUnit size = isVertical ? heightForGlyph(glyphData) : advanceWidthForGlyph(glyphData);
</ins><span class="cx"> if (size >= targetSize)
</span><span class="cx"> return;
</span><span class="cx"> }
</span><span class="lines">@@ -303,11 +323,11 @@
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> // If we are measuring the maximum width, verify each component.
</span><del>- if (maximumGlyphWidth) {
- *maximumGlyphWidth = std::max(*maximumGlyphWidth, advanceWidthForGlyph(assemblyData.topOrRight));
- *maximumGlyphWidth = std::max(*maximumGlyphWidth, advanceWidthForGlyph(assemblyData.extension));
- *maximumGlyphWidth = std::max(*maximumGlyphWidth, advanceWidthForGlyph(assemblyData.middle));
- *maximumGlyphWidth = std::max(*maximumGlyphWidth, advanceWidthForGlyph(assemblyData.bottomOrLeft));
</del><ins>+ if (calculateMaxPreferredWidth) {
+ m_maxPreferredWidth = std::max<LayoutUnit>(m_maxPreferredWidth, advanceWidthForGlyph(assemblyData.topOrRight));
+ m_maxPreferredWidth = std::max<LayoutUnit>(m_maxPreferredWidth, advanceWidthForGlyph(assemblyData.extension));
+ m_maxPreferredWidth = std::max<LayoutUnit>(m_maxPreferredWidth, advanceWidthForGlyph(assemblyData.middle));
+ m_maxPreferredWidth = std::max<LayoutUnit>(m_maxPreferredWidth, advanceWidthForGlyph(assemblyData.bottomOrLeft));
</ins><span class="cx"> return;
</span><span class="cx"> }
</span><span class="cx">
</span></span></pre></div>
<a id="trunkSourceWebCorerenderingmathmlMathOperatorh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/rendering/mathml/MathOperator.h (201880 => 201881)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/rendering/mathml/MathOperator.h        2016-06-09 20:10:30 UTC (rev 201880)
+++ trunk/Source/WebCore/rendering/mathml/MathOperator.h        2016-06-09 20:50:44 UTC (rev 201881)
</span><span class="lines">@@ -41,8 +41,11 @@
</span><span class="cx"> public:
</span><span class="cx"> MathOperator() { }
</span><span class="cx"> enum class Type { UndefinedOperator, DisplayOperator, VerticalOperator, HorizontalOperator };
</span><del>- void setOperator(UChar baseCharacter, Type);
</del><ins>+ void setOperator(const RenderStyle&, UChar baseCharacter, Type);
+ void reset(const RenderStyle&);
</ins><span class="cx">
</span><ins>+ LayoutUnit width() const { return m_width; }
+ LayoutUnit maxPreferredWidth() const { return m_maxPreferredWidth; }
</ins><span class="cx"> LayoutUnit italicCorrection() const { return m_italicCorrection; }
</span><span class="cx">
</span><span class="cx"> bool isStretched() const { return m_stretchType != StretchType::Unstretched; }
</span><span class="lines">@@ -71,7 +74,7 @@
</span><span class="cx"> void setSizeVariant(const GlyphData&);
</span><span class="cx"> void setGlyphAssembly(const GlyphAssemblyData&);
</span><span class="cx"> void calculateDisplayStyleLargeOperator(const RenderStyle&);
</span><del>- void calculateStretchyData(const RenderStyle&, float* maximumGlyphWidth, LayoutUnit targetSize = 0);
</del><ins>+ void calculateStretchyData(const RenderStyle&, bool calculateMaxPreferredWidth, LayoutUnit targetSize = 0);
</ins><span class="cx"> bool calculateGlyphAssemblyFallback(const RenderStyle&, const Vector<OpenTypeMathData::AssemblyPart>&, GlyphAssemblyData&) const;
</span><span class="cx">
</span><span class="cx"> LayoutRect paintGlyph(const RenderStyle&, PaintInfo&, const GlyphData&, const LayoutPoint& origin, GlyphPaintTrimming);
</span><span class="lines">@@ -80,17 +83,18 @@
</span><span class="cx"> void paintVerticalGlyphAssembly(const RenderStyle&, PaintInfo&, const LayoutPoint&);
</span><span class="cx"> void paintHorizontalGlyphAssembly(const RenderStyle&, PaintInfo&, const LayoutPoint&);
</span><span class="cx">
</span><del>- UChar m_baseCharacter = 0;
</del><ins>+ UChar m_baseCharacter { 0 };
</ins><span class="cx"> Type m_operatorType { Type::UndefinedOperator };
</span><del>- StretchType m_stretchType = StretchType::Unstretched;
</del><ins>+ StretchType m_stretchType { StretchType::Unstretched };
</ins><span class="cx"> union {
</span><span class="cx"> GlyphData m_variant;
</span><span class="cx"> GlyphAssemblyData m_assembly;
</span><span class="cx"> };
</span><del>- LayoutUnit m_width = 0;
- LayoutUnit m_ascent = 0;
- LayoutUnit m_descent = 0;
- LayoutUnit m_italicCorrection = 0;
</del><ins>+ LayoutUnit m_maxPreferredWidth { 0 };
+ LayoutUnit m_width { 0 };
+ LayoutUnit m_ascent { 0 };
+ LayoutUnit m_descent { 0 };
+ LayoutUnit m_italicCorrection { 0 };
</ins><span class="cx"> };
</span><span class="cx">
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceWebCorerenderingmathmlRenderMathMLOperatorcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/rendering/mathml/RenderMathMLOperator.cpp (201880 => 201881)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/rendering/mathml/RenderMathMLOperator.cpp        2016-06-09 20:10:30 UTC (rev 201880)
+++ trunk/Source/WebCore/rendering/mathml/RenderMathMLOperator.cpp        2016-06-09 20:50:44 UTC (rev 201881)
</span><span class="lines">@@ -267,30 +267,20 @@
</span><span class="cx"> return;
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+ // FIXME: We should not use stretchSize during the preferred width calculation nor should we leave logical width dirty (http://webkit.org/b/152244).
</ins><span class="cx"> MathOperator::Type type;
</span><span class="cx"> if (isLargeOperatorInDisplayStyle())
</span><span class="cx"> type = MathOperator::Type::DisplayOperator;
</span><span class="cx"> else
</span><span class="cx"> type = m_isVertical ? MathOperator::Type::VerticalOperator : MathOperator::Type::HorizontalOperator;
</span><del>- m_mathOperator.setOperator(m_textContent, type);
- GlyphData baseGlyph;
- float maximumGlyphWidth = m_mathOperator.getBaseGlyph(style(), baseGlyph) ? advanceWidthForGlyph(baseGlyph) : 0;
</del><ins>+ m_mathOperator.setOperator(style(), m_textContent, type);
+ float maximumGlyphWidth;
</ins><span class="cx"> if (!m_isVertical) {
</span><ins>+ maximumGlyphWidth = m_mathOperator.width();
</ins><span class="cx"> if (maximumGlyphWidth < stretchSize())
</span><span class="cx"> maximumGlyphWidth = stretchSize();
</span><del>- m_maxPreferredLogicalWidth = m_leadingSpace + maximumGlyphWidth + m_trailingSpace;
- m_minPreferredLogicalWidth = m_maxPreferredLogicalWidth;
- return;
- }
- if (isLargeOperatorInDisplayStyle()) {
- // Large operators in STIX Word have incorrect advance width, causing misplacement of superscript, so we use the glyph bound instead (http://sourceforge.net/p/stixfonts/tracking/49/).
- m_mathOperator.calculateDisplayStyleLargeOperator(style());
- if (m_mathOperator.m_stretchType == MathOperator::StretchType::SizeVariant)
- maximumGlyphWidth = boundsForGlyph(m_mathOperator.m_variant).width();
- } else {
- // FIXME: some glyphs (e.g. the one for "FRACTION SLASH" in the STIX Math font or large operators) have a width that depends on the height, resulting in large gaps (https://bugs.webkit.org/show_bug.cgi?id=130326).
- m_mathOperator.calculateStretchyData(style(), &maximumGlyphWidth);
- }
</del><ins>+ } else
+ maximumGlyphWidth = m_mathOperator.maxPreferredWidth();
</ins><span class="cx"> m_maxPreferredLogicalWidth = m_minPreferredLogicalWidth = m_leadingSpace + maximumGlyphWidth + m_trailingSpace;
</span><span class="cx"> }
</span><span class="cx">
</span><span class="lines">@@ -379,11 +369,11 @@
</span><span class="cx"> type = MathOperator::Type::DisplayOperator;
</span><span class="cx"> else
</span><span class="cx"> type = m_isVertical ? MathOperator::Type::VerticalOperator : MathOperator::Type::HorizontalOperator;
</span><del>- m_mathOperator.setOperator(m_textContent, type);
</del><ins>+ m_mathOperator.setOperator(style(), m_textContent, type);
</ins><span class="cx"> if (m_isVertical && isLargeOperatorInDisplayStyle())
</span><span class="cx"> m_mathOperator.calculateDisplayStyleLargeOperator(style());
</span><span class="cx"> else {
</span><del>- m_mathOperator.calculateStretchyData(style(), nullptr, stretchSize());
</del><ins>+ m_mathOperator.calculateStretchyData(style(), false, stretchSize());
</ins><span class="cx"> if (!m_mathOperator.isStretched())
</span><span class="cx"> return;
</span><span class="cx"> }
</span></span></pre>
</div>
</div>
</body>
</html>