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

Log Message

Introduce MathOperator::Type
https://bugs.webkit.org/show_bug.cgi?id=156950

Patch by Frederic Wang <[email protected]> on 2016-06-09
Reviewed by Sergio Villar Senin.

No new tests, behavior is not change.

An enum Type is introduced in MathOperator in order to indicate
which kind of stretching is requested. In follow-up work, this will
allow to just call setOperator and stretchTo without having to
explicitly call calculateDisplayStyleLargeOperator or calculateStretchyData.

* rendering/mathml/MathOperator.cpp:
(WebCore::MathOperator::setOperator): Use Type instead of a boolean.
(WebCore::MathOperator::setGlyphAssembly): Add an assert to ensure that the function is correctly used.
(WebCore::MathOperator::calculateDisplayStyleLargeOperator): Ditto, this makes the assert more accurate.
(WebCore::MathOperator::calculateStretchyData): Ditto and replace m_isVertical with a local isVertical variable.
(WebCore::MathOperator::fillWithVerticalExtensionGlyph): Ditto.
(WebCore::MathOperator::fillWithHorizontalExtensionGlyph): Ditto.
(WebCore::MathOperator::paintVerticalGlyphAssembly): Ditto.
(WebCore::MathOperator::paintHorizontalGlyphAssembly): Ditto.
* rendering/mathml/MathOperator.h: Add the Type enum.
(WebCore::MathOperator::stretchSize): Use Type instead of a boolean and add an
assert to ensure that the function is correctly used.
* rendering/mathml/RenderMathMLOperator.cpp:
(WebCore::RenderMathMLOperator::computePreferredLogicalWidths): Call setOperator with the correct value.
(WebCore::RenderMathMLOperator::updateStyle): Ditto.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (201861 => 201862)


--- trunk/Source/WebCore/ChangeLog	2016-06-09 12:59:40 UTC (rev 201861)
+++ trunk/Source/WebCore/ChangeLog	2016-06-09 14:50:19 UTC (rev 201862)
@@ -1,3 +1,33 @@
+2016-06-09  Frederic Wang  <[email protected]>
+
+        Introduce MathOperator::Type
+        https://bugs.webkit.org/show_bug.cgi?id=156950
+
+        Reviewed by Sergio Villar Senin.
+
+        No new tests, behavior is not change.
+
+        An enum Type is introduced in MathOperator in order to indicate
+        which kind of stretching is requested. In follow-up work, this will
+        allow to just call setOperator and stretchTo without having to
+        explicitly call calculateDisplayStyleLargeOperator or calculateStretchyData.
+
+        * rendering/mathml/MathOperator.cpp:
+        (WebCore::MathOperator::setOperator): Use Type instead of a boolean.
+        (WebCore::MathOperator::setGlyphAssembly): Add an assert to ensure that the function is correctly used.
+        (WebCore::MathOperator::calculateDisplayStyleLargeOperator): Ditto, this makes the assert more accurate.
+        (WebCore::MathOperator::calculateStretchyData): Ditto and replace m_isVertical with a local isVertical variable.
+        (WebCore::MathOperator::fillWithVerticalExtensionGlyph): Ditto.
+        (WebCore::MathOperator::fillWithHorizontalExtensionGlyph): Ditto.
+        (WebCore::MathOperator::paintVerticalGlyphAssembly): Ditto.
+        (WebCore::MathOperator::paintHorizontalGlyphAssembly): Ditto.
+        * rendering/mathml/MathOperator.h: Add the Type enum.
+        (WebCore::MathOperator::stretchSize): Use Type instead of a boolean and add an
+        assert to ensure that the function is correctly used.
+        * rendering/mathml/RenderMathMLOperator.cpp:
+        (WebCore::RenderMathMLOperator::computePreferredLogicalWidths): Call setOperator with the correct value.
+        (WebCore::RenderMathMLOperator::updateStyle): Ditto.
+
 2016-06-09  Commit Queue  <[email protected]>
 
         Unreviewed, rolling out r201810.

Modified: trunk/Source/WebCore/rendering/mathml/MathOperator.cpp (201861 => 201862)


--- trunk/Source/WebCore/rendering/mathml/MathOperator.cpp	2016-06-09 12:59:40 UTC (rev 201861)
+++ trunk/Source/WebCore/rendering/mathml/MathOperator.cpp	2016-06-09 14:50:19 UTC (rev 201862)
@@ -75,12 +75,18 @@
     { 0x222b, 0x2320, 0x23ae, 0x2321, 0x0    } // integral sign
 };
 
-void MathOperator::setOperator(UChar baseCharacter, bool isVertical)
+void MathOperator::setOperator(UChar baseCharacter, Type operatorType)
 {
     m_baseCharacter = baseCharacter;
-    m_isVertical = isVertical;
+    m_operatorType = operatorType;
 }
 
+LayoutUnit MathOperator::stretchSize() const
+{
+    ASSERT(m_operatorType == Type::VerticalOperator || m_operatorType == Type::HorizontalOperator);
+    return m_operatorType == Type::VerticalOperator ? m_ascent + m_descent : m_width;
+}
+
 bool MathOperator::getBaseGlyph(const RenderStyle& style, GlyphData& baseGlyph) const
 {
     baseGlyph = style.fontCascade().glyphDataForCharacter(m_baseCharacter, !style.isLeftToRightDirection());
@@ -97,13 +103,14 @@
 
 void MathOperator::setGlyphAssembly(const GlyphAssemblyData& assemblyData)
 {
+    ASSERT(m_operatorType == Type::VerticalOperator || m_operatorType == Type::HorizontalOperator);
     m_stretchType = StretchType::GlyphAssembly;
     m_assembly = assemblyData;
 }
 
 void MathOperator::calculateDisplayStyleLargeOperator(const RenderStyle& style)
 {
-    ASSERT(m_isVertical);
+    ASSERT(m_operatorType == Type::DisplayOperator);
 
     GlyphData baseGlyph;
     if (!getBaseGlyph(style, baseGlyph) || !baseGlyph.font->mathData())
@@ -230,7 +237,9 @@
 
 void MathOperator::calculateStretchyData(const RenderStyle& style, float* maximumGlyphWidth, LayoutUnit targetSize)
 {
-    ASSERT(!maximumGlyphWidth || m_isVertical);
+    ASSERT(m_operatorType == Type::VerticalOperator || m_operatorType == Type::HorizontalOperator);
+    ASSERT(!maximumGlyphWidth || m_operatorType == Type::VerticalOperator);
+    bool isVertical = m_operatorType == Type::VerticalOperator;
 
     GlyphData baseGlyph;
     if (!getBaseGlyph(style, baseGlyph))
@@ -238,7 +247,7 @@
 
     if (!maximumGlyphWidth) {
         // We do not stretch if the base glyph is large enough.
-        float baseSize = m_isVertical ? heightForGlyph(baseGlyph) : advanceWidthForGlyph(baseGlyph);
+        float baseSize = isVertical ? heightForGlyph(baseGlyph) : advanceWidthForGlyph(baseGlyph);
         if (targetSize <= baseSize)
             return;
     }
@@ -247,7 +256,7 @@
     if (baseGlyph.font->mathData()) {
         Vector<Glyph> sizeVariants;
         Vector<OpenTypeMathData::AssemblyPart> assemblyParts;
-        baseGlyph.font->mathData()->getMathVariants(baseGlyph.glyph, m_isVertical, sizeVariants, assemblyParts);
+        baseGlyph.font->mathData()->getMathVariants(baseGlyph.glyph, isVertical, sizeVariants, assemblyParts);
         // We verify the size variants.
         for (auto& sizeVariant : sizeVariants) {
             GlyphData glyphData(sizeVariant, baseGlyph.font);
@@ -255,7 +264,7 @@
                 *maximumGlyphWidth = std::max(*maximumGlyphWidth, advanceWidthForGlyph(glyphData));
             else {
                 setSizeVariant(glyphData);
-                float size = m_isVertical ? heightForGlyph(glyphData) : advanceWidthForGlyph(glyphData);
+                float size = isVertical ? heightForGlyph(glyphData) : advanceWidthForGlyph(glyphData);
                 if (size >= targetSize)
                     return;
             }
@@ -265,7 +274,7 @@
         if (!calculateGlyphAssemblyFallback(style, assemblyParts, assemblyData))
             return;
     } else {
-        if (!m_isVertical)
+        if (!isVertical)
             return;
 
         // If the font does not have a MATH table, we fallback to the Unicode-only constructions.
@@ -303,7 +312,7 @@
     }
 
     // We ensure that the size is large enough to avoid glyph overlaps.
-    float minSize = m_isVertical ?
+    float minSize = isVertical ?
         heightForGlyph(assemblyData.topOrRight) + heightForGlyph(assemblyData.middle) + heightForGlyph(assemblyData.bottomOrLeft)
         : advanceWidthForGlyph(assemblyData.bottomOrLeft) + advanceWidthForGlyph(assemblyData.middle) + advanceWidthForGlyph(assemblyData.topOrRight);
     if (minSize > targetSize)
@@ -366,7 +375,7 @@
 
 void MathOperator::fillWithVerticalExtensionGlyph(const RenderStyle& style, PaintInfo& info, const LayoutPoint& from, const LayoutPoint& to)
 {
-    ASSERT(m_isVertical);
+    ASSERT(m_operatorType == Type::VerticalOperator);
     ASSERT(m_stretchType == StretchType::GlyphAssembly);
     ASSERT(m_assembly.extension.isValid());
     ASSERT(from.y() <= to.y());
@@ -404,7 +413,7 @@
 
 void MathOperator::fillWithHorizontalExtensionGlyph(const RenderStyle& style, PaintInfo& info, const LayoutPoint& from, const LayoutPoint& to)
 {
-    ASSERT(!m_isVertical);
+    ASSERT(m_operatorType == Type::HorizontalOperator);
     ASSERT(m_stretchType == StretchType::GlyphAssembly);
     ASSERT(m_assembly.extension.isValid());
     ASSERT(from.x() <= to.x());
@@ -440,7 +449,7 @@
 
 void MathOperator::paintVerticalGlyphAssembly(const RenderStyle& style, PaintInfo& info, const LayoutPoint& paintOffset)
 {
-    ASSERT(m_isVertical);
+    ASSERT(m_operatorType == Type::VerticalOperator);
     ASSERT(m_stretchType == StretchType::GlyphAssembly);
     ASSERT(m_assembly.topOrRight.isValid());
     ASSERT(m_assembly.bottomOrLeft.isValid());
@@ -472,7 +481,7 @@
 
 void MathOperator::paintHorizontalGlyphAssembly(const RenderStyle& style, PaintInfo& info, const LayoutPoint& paintOffset)
 {
-    ASSERT(!m_isVertical);
+    ASSERT(m_operatorType == Type::HorizontalOperator);
     ASSERT(m_stretchType == StretchType::GlyphAssembly);
     ASSERT(m_assembly.bottomOrLeft.isValid());
     ASSERT(m_assembly.topOrRight.isValid());

Modified: trunk/Source/WebCore/rendering/mathml/MathOperator.h (201861 => 201862)


--- trunk/Source/WebCore/rendering/mathml/MathOperator.h	2016-06-09 12:59:40 UTC (rev 201861)
+++ trunk/Source/WebCore/rendering/mathml/MathOperator.h	2016-06-09 14:50:19 UTC (rev 201862)
@@ -40,7 +40,8 @@
 class MathOperator {
 public:
     MathOperator() { }
-    void setOperator(UChar baseCharacter, bool isVertical);
+    enum class Type { UndefinedOperator, DisplayOperator, VerticalOperator, HorizontalOperator };
+    void setOperator(UChar baseCharacter, Type);
 
     LayoutUnit italicCorrection() const { return m_italicCorrection; }
 
@@ -65,7 +66,7 @@
         TrimLeftAndRight
     };
 
-    LayoutUnit stretchSize() const { return m_isVertical ? m_ascent + m_descent : m_width; };
+    LayoutUnit stretchSize() const;
     bool getBaseGlyph(const RenderStyle&, GlyphData&) const;
     void setSizeVariant(const GlyphData&);
     void setGlyphAssembly(const GlyphAssemblyData&);
@@ -80,7 +81,7 @@
     void paintHorizontalGlyphAssembly(const RenderStyle&, PaintInfo&, const LayoutPoint&);
 
     UChar m_baseCharacter = 0;
-    bool m_isVertical = false;
+    Type m_operatorType { Type::UndefinedOperator };
     StretchType m_stretchType = StretchType::Unstretched;
     union {
         GlyphData m_variant;

Modified: trunk/Source/WebCore/rendering/mathml/RenderMathMLOperator.cpp (201861 => 201862)


--- trunk/Source/WebCore/rendering/mathml/RenderMathMLOperator.cpp	2016-06-09 12:59:40 UTC (rev 201861)
+++ trunk/Source/WebCore/rendering/mathml/RenderMathMLOperator.cpp	2016-06-09 14:50:19 UTC (rev 201862)
@@ -267,7 +267,12 @@
         return;
     }
 
-    m_mathOperator.setOperator(m_textContent, m_isVertical);
+    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;
     if (!m_isVertical) {
@@ -369,7 +374,12 @@
     if (!shouldAllowStretching())
         return;
 
-    m_mathOperator.setOperator(m_textContent, m_isVertical);
+    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);
     if (m_isVertical && isLargeOperatorInDisplayStyle())
         m_mathOperator.calculateDisplayStyleLargeOperator(style());
     else {
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to