Title: [201881] trunk/Source/WebCore
Revision
201881
Author
[email protected]
Date
2016-06-09 13:50:44 -0700 (Thu, 09 Jun 2016)

Log Message

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.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (201880 => 201881)


--- 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)
@@ -1,3 +1,27 @@
+2016-06-09  Frederic Wang  <[email protected]>
+
+        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.
+
 2016-06-09  Alex Christensen  <[email protected]>
 
         Clean up WebSocket code

Modified: trunk/Source/WebCore/rendering/mathml/MathOperator.cpp (201880 => 201881)


--- 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)
@@ -75,12 +75,30 @@
     { 0x222b, 0x2320, 0x23ae, 0x2321, 0x0    } // integral sign
 };
 
-void MathOperator::setOperator(UChar baseCharacter, Type operatorType)
+void MathOperator::setOperator(const RenderStyle& style, UChar baseCharacter, Type operatorType)
 {
     m_baseCharacter = baseCharacter;
     m_operatorType = operatorType;
+    reset(style);
 }
 
+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.
+}
+
 LayoutUnit MathOperator::stretchSize() const
 {
     ASSERT(m_operatorType == Type::VerticalOperator || m_operatorType == Type::HorizontalOperator);
@@ -127,6 +145,8 @@
     for (auto& sizeVariant : sizeVariants) {
         GlyphData glyphData(sizeVariant, baseGlyph.font);
         setSizeVariant(glyphData);
+        // 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();
         m_italicCorrection = glyphData.font->mathData()->getItalicCorrection(*glyphData.font, glyphData.glyph);
         if (heightForGlyph(glyphData) >= displayOperatorMinHeight)
             break;
@@ -235,24 +255,24 @@
     return true;
 }
 
-void MathOperator::calculateStretchyData(const RenderStyle& style, float* maximumGlyphWidth, LayoutUnit targetSize)
+void MathOperator::calculateStretchyData(const RenderStyle& style, bool calculateMaxPreferredWidth, LayoutUnit targetSize)
 {
     ASSERT(m_operatorType == Type::VerticalOperator || m_operatorType == Type::HorizontalOperator);
-    ASSERT(!maximumGlyphWidth || m_operatorType == Type::VerticalOperator);
+    ASSERT(!calculateMaxPreferredWidth || m_operatorType == Type::VerticalOperator);
     bool isVertical = m_operatorType == Type::VerticalOperator;
 
     GlyphData baseGlyph;
     if (!getBaseGlyph(style, baseGlyph))
         return;
 
-    if (!maximumGlyphWidth) {
+    if (!calculateMaxPreferredWidth) {
         // We do not stretch if the base glyph is large enough.
         float baseSize = isVertical ? heightForGlyph(baseGlyph) : advanceWidthForGlyph(baseGlyph);
         if (targetSize <= baseSize)
             return;
     }
 
-    MathOperator::GlyphAssemblyData assemblyData;
+    GlyphAssemblyData assemblyData;
     if (baseGlyph.font->mathData()) {
         Vector<Glyph> sizeVariants;
         Vector<OpenTypeMathData::AssemblyPart> assemblyParts;
@@ -260,11 +280,11 @@
         // We verify the size variants.
         for (auto& sizeVariant : sizeVariants) {
             GlyphData glyphData(sizeVariant, baseGlyph.font);
-            if (maximumGlyphWidth)
-                *maximumGlyphWidth = std::max(*maximumGlyphWidth, advanceWidthForGlyph(glyphData));
+            if (calculateMaxPreferredWidth)
+                m_maxPreferredWidth = std::max<LayoutUnit>(m_maxPreferredWidth, advanceWidthForGlyph(glyphData));
             else {
                 setSizeVariant(glyphData);
-                float size = isVertical ? heightForGlyph(glyphData) : advanceWidthForGlyph(glyphData);
+                LayoutUnit size = isVertical ? heightForGlyph(glyphData) : advanceWidthForGlyph(glyphData);
                 if (size >= targetSize)
                     return;
             }
@@ -303,11 +323,11 @@
     }
 
     // If we are measuring the maximum width, verify each component.
-    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));
+    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));
         return;
     }
 

Modified: trunk/Source/WebCore/rendering/mathml/MathOperator.h (201880 => 201881)


--- 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)
@@ -41,8 +41,11 @@
 public:
     MathOperator() { }
     enum class Type { UndefinedOperator, DisplayOperator, VerticalOperator, HorizontalOperator };
-    void setOperator(UChar baseCharacter, Type);
+    void setOperator(const RenderStyle&, UChar baseCharacter, Type);
+    void reset(const RenderStyle&);
 
+    LayoutUnit width() const { return m_width; }
+    LayoutUnit maxPreferredWidth() const { return m_maxPreferredWidth; }
     LayoutUnit italicCorrection() const { return m_italicCorrection; }
 
     bool isStretched() const { return m_stretchType != StretchType::Unstretched; }
@@ -71,7 +74,7 @@
     void setSizeVariant(const GlyphData&);
     void setGlyphAssembly(const GlyphAssemblyData&);
     void calculateDisplayStyleLargeOperator(const RenderStyle&);
-    void calculateStretchyData(const RenderStyle&, float* maximumGlyphWidth, LayoutUnit targetSize = 0);
+    void calculateStretchyData(const RenderStyle&, bool calculateMaxPreferredWidth, LayoutUnit targetSize = 0);
     bool calculateGlyphAssemblyFallback(const RenderStyle&, const Vector<OpenTypeMathData::AssemblyPart>&, GlyphAssemblyData&) const;
 
     LayoutRect paintGlyph(const RenderStyle&, PaintInfo&, const GlyphData&, const LayoutPoint& origin, GlyphPaintTrimming);
@@ -80,17 +83,18 @@
     void paintVerticalGlyphAssembly(const RenderStyle&, PaintInfo&, const LayoutPoint&);
     void paintHorizontalGlyphAssembly(const RenderStyle&, PaintInfo&, const LayoutPoint&);
 
-    UChar m_baseCharacter = 0;
+    UChar m_baseCharacter { 0 };
     Type m_operatorType { Type::UndefinedOperator };
-    StretchType m_stretchType = StretchType::Unstretched;
+    StretchType m_stretchType { StretchType::Unstretched };
     union {
         GlyphData m_variant;
         GlyphAssemblyData m_assembly;
     };
-    LayoutUnit m_width = 0;
-    LayoutUnit m_ascent = 0;
-    LayoutUnit m_descent = 0;
-    LayoutUnit m_italicCorrection = 0;
+    LayoutUnit m_maxPreferredWidth { 0 };
+    LayoutUnit m_width { 0 };
+    LayoutUnit m_ascent { 0 };
+    LayoutUnit m_descent { 0 };
+    LayoutUnit m_italicCorrection { 0 };
 };
 
 }

Modified: trunk/Source/WebCore/rendering/mathml/RenderMathMLOperator.cpp (201880 => 201881)


--- 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)
@@ -267,30 +267,20 @@
         return;
     }
 
+    // FIXME: We should not use stretchSize during the preferred width calculation nor should we leave logical width dirty (http://webkit.org/b/152244).
     MathOperator::Type type;
     if (isLargeOperatorInDisplayStyle())
         type = MathOperator::Type::DisplayOperator;
     else
         type = m_isVertical ? MathOperator::Type::VerticalOperator : MathOperator::Type::HorizontalOperator;
-    m_mathOperator.setOperator(m_textContent, type);
-    GlyphData baseGlyph;
-    float maximumGlyphWidth = m_mathOperator.getBaseGlyph(style(), baseGlyph) ? advanceWidthForGlyph(baseGlyph) : 0;
+    m_mathOperator.setOperator(style(), m_textContent, type);
+    float maximumGlyphWidth;
     if (!m_isVertical) {
+        maximumGlyphWidth = m_mathOperator.width();
         if (maximumGlyphWidth < stretchSize())
             maximumGlyphWidth = stretchSize();
-        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);
-    }
+    } else
+        maximumGlyphWidth = m_mathOperator.maxPreferredWidth();
     m_maxPreferredLogicalWidth = m_minPreferredLogicalWidth = m_leadingSpace + maximumGlyphWidth + m_trailingSpace;
 }
 
@@ -379,11 +369,11 @@
         type = MathOperator::Type::DisplayOperator;
     else
         type = m_isVertical ? MathOperator::Type::VerticalOperator : MathOperator::Type::HorizontalOperator;
-    m_mathOperator.setOperator(m_textContent, type);
+    m_mathOperator.setOperator(style(), m_textContent, type);
     if (m_isVertical && isLargeOperatorInDisplayStyle())
         m_mathOperator.calculateDisplayStyleLargeOperator(style());
     else {
-        m_mathOperator.calculateStretchyData(style(), nullptr, stretchSize());
+        m_mathOperator.calculateStretchyData(style(), false, stretchSize());
         if (!m_mathOperator.isStretched())
             return;
     }
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to