Changeset 201862 in webkit


Ignore:
Timestamp:
Jun 9, 2016 7:50:19 AM (8 years ago)
Author:
fred.wang@free.fr
Message:

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

Patch by Frederic Wang <fwang@igalia.com> 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.

Location:
trunk/Source/WebCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r201861 r201862  
     12016-06-09  Frederic Wang  <fwang@igalia.com>
     2
     3        Introduce MathOperator::Type
     4        https://bugs.webkit.org/show_bug.cgi?id=156950
     5
     6        Reviewed by Sergio Villar Senin.
     7
     8        No new tests, behavior is not change.
     9
     10        An enum Type is introduced in MathOperator in order to indicate
     11        which kind of stretching is requested. In follow-up work, this will
     12        allow to just call setOperator and stretchTo without having to
     13        explicitly call calculateDisplayStyleLargeOperator or calculateStretchyData.
     14
     15        * rendering/mathml/MathOperator.cpp:
     16        (WebCore::MathOperator::setOperator): Use Type instead of a boolean.
     17        (WebCore::MathOperator::setGlyphAssembly): Add an assert to ensure that the function is correctly used.
     18        (WebCore::MathOperator::calculateDisplayStyleLargeOperator): Ditto, this makes the assert more accurate.
     19        (WebCore::MathOperator::calculateStretchyData): Ditto and replace m_isVertical with a local isVertical variable.
     20        (WebCore::MathOperator::fillWithVerticalExtensionGlyph): Ditto.
     21        (WebCore::MathOperator::fillWithHorizontalExtensionGlyph): Ditto.
     22        (WebCore::MathOperator::paintVerticalGlyphAssembly): Ditto.
     23        (WebCore::MathOperator::paintHorizontalGlyphAssembly): Ditto.
     24        * rendering/mathml/MathOperator.h: Add the Type enum.
     25        (WebCore::MathOperator::stretchSize): Use Type instead of a boolean and add an
     26        assert to ensure that the function is correctly used.
     27        * rendering/mathml/RenderMathMLOperator.cpp:
     28        (WebCore::RenderMathMLOperator::computePreferredLogicalWidths): Call setOperator with the correct value.
     29        (WebCore::RenderMathMLOperator::updateStyle): Ditto.
     30
    1312016-06-09  Commit Queue  <commit-queue@webkit.org>
    232
  • trunk/Source/WebCore/rendering/mathml/MathOperator.cpp

    r201854 r201862  
    7676};
    7777
    78 void MathOperator::setOperator(UChar baseCharacter, bool isVertical)
     78void MathOperator::setOperator(UChar baseCharacter, Type operatorType)
    7979{
    8080    m_baseCharacter = baseCharacter;
    81     m_isVertical = isVertical;
     81    m_operatorType = operatorType;
     82}
     83
     84LayoutUnit MathOperator::stretchSize() const
     85{
     86    ASSERT(m_operatorType == Type::VerticalOperator || m_operatorType == Type::HorizontalOperator);
     87    return m_operatorType == Type::VerticalOperator ? m_ascent + m_descent : m_width;
    8288}
    8389
     
    98104void MathOperator::setGlyphAssembly(const GlyphAssemblyData& assemblyData)
    99105{
     106    ASSERT(m_operatorType == Type::VerticalOperator || m_operatorType == Type::HorizontalOperator);
    100107    m_stretchType = StretchType::GlyphAssembly;
    101108    m_assembly = assemblyData;
     
    104111void MathOperator::calculateDisplayStyleLargeOperator(const RenderStyle& style)
    105112{
    106     ASSERT(m_isVertical);
     113    ASSERT(m_operatorType == Type::DisplayOperator);
    107114
    108115    GlyphData baseGlyph;
     
    231238void MathOperator::calculateStretchyData(const RenderStyle& style, float* maximumGlyphWidth, LayoutUnit targetSize)
    232239{
    233     ASSERT(!maximumGlyphWidth || m_isVertical);
     240    ASSERT(m_operatorType == Type::VerticalOperator || m_operatorType == Type::HorizontalOperator);
     241    ASSERT(!maximumGlyphWidth || m_operatorType == Type::VerticalOperator);
     242    bool isVertical = m_operatorType == Type::VerticalOperator;
    234243
    235244    GlyphData baseGlyph;
     
    239248    if (!maximumGlyphWidth) {
    240249        // We do not stretch if the base glyph is large enough.
    241         float baseSize = m_isVertical ? heightForGlyph(baseGlyph) : advanceWidthForGlyph(baseGlyph);
     250        float baseSize = isVertical ? heightForGlyph(baseGlyph) : advanceWidthForGlyph(baseGlyph);
    242251        if (targetSize <= baseSize)
    243252            return;
     
    248257        Vector<Glyph> sizeVariants;
    249258        Vector<OpenTypeMathData::AssemblyPart> assemblyParts;
    250         baseGlyph.font->mathData()->getMathVariants(baseGlyph.glyph, m_isVertical, sizeVariants, assemblyParts);
     259        baseGlyph.font->mathData()->getMathVariants(baseGlyph.glyph, isVertical, sizeVariants, assemblyParts);
    251260        // We verify the size variants.
    252261        for (auto& sizeVariant : sizeVariants) {
     
    256265            else {
    257266                setSizeVariant(glyphData);
    258                 float size = m_isVertical ? heightForGlyph(glyphData) : advanceWidthForGlyph(glyphData);
     267                float size = isVertical ? heightForGlyph(glyphData) : advanceWidthForGlyph(glyphData);
    259268                if (size >= targetSize)
    260269                    return;
     
    266275            return;
    267276    } else {
    268         if (!m_isVertical)
     277        if (!isVertical)
    269278            return;
    270279
     
    304313
    305314    // We ensure that the size is large enough to avoid glyph overlaps.
    306     float minSize = m_isVertical ?
     315    float minSize = isVertical ?
    307316        heightForGlyph(assemblyData.topOrRight) + heightForGlyph(assemblyData.middle) + heightForGlyph(assemblyData.bottomOrLeft)
    308317        : advanceWidthForGlyph(assemblyData.bottomOrLeft) + advanceWidthForGlyph(assemblyData.middle) + advanceWidthForGlyph(assemblyData.topOrRight);
     
    367376void MathOperator::fillWithVerticalExtensionGlyph(const RenderStyle& style, PaintInfo& info, const LayoutPoint& from, const LayoutPoint& to)
    368377{
    369     ASSERT(m_isVertical);
     378    ASSERT(m_operatorType == Type::VerticalOperator);
    370379    ASSERT(m_stretchType == StretchType::GlyphAssembly);
    371380    ASSERT(m_assembly.extension.isValid());
     
    405414void MathOperator::fillWithHorizontalExtensionGlyph(const RenderStyle& style, PaintInfo& info, const LayoutPoint& from, const LayoutPoint& to)
    406415{
    407     ASSERT(!m_isVertical);
     416    ASSERT(m_operatorType == Type::HorizontalOperator);
    408417    ASSERT(m_stretchType == StretchType::GlyphAssembly);
    409418    ASSERT(m_assembly.extension.isValid());
     
    441450void MathOperator::paintVerticalGlyphAssembly(const RenderStyle& style, PaintInfo& info, const LayoutPoint& paintOffset)
    442451{
    443     ASSERT(m_isVertical);
     452    ASSERT(m_operatorType == Type::VerticalOperator);
    444453    ASSERT(m_stretchType == StretchType::GlyphAssembly);
    445454    ASSERT(m_assembly.topOrRight.isValid());
     
    473482void MathOperator::paintHorizontalGlyphAssembly(const RenderStyle& style, PaintInfo& info, const LayoutPoint& paintOffset)
    474483{
    475     ASSERT(!m_isVertical);
     484    ASSERT(m_operatorType == Type::HorizontalOperator);
    476485    ASSERT(m_stretchType == StretchType::GlyphAssembly);
    477486    ASSERT(m_assembly.bottomOrLeft.isValid());
  • trunk/Source/WebCore/rendering/mathml/MathOperator.h

    r201854 r201862  
    4141public:
    4242    MathOperator() { }
    43     void setOperator(UChar baseCharacter, bool isVertical);
     43    enum class Type { UndefinedOperator, DisplayOperator, VerticalOperator, HorizontalOperator };
     44    void setOperator(UChar baseCharacter, Type);
    4445
    4546    LayoutUnit italicCorrection() const { return m_italicCorrection; }
     
    6667    };
    6768
    68     LayoutUnit stretchSize() const { return m_isVertical ? m_ascent + m_descent : m_width; };
     69    LayoutUnit stretchSize() const;
    6970    bool getBaseGlyph(const RenderStyle&, GlyphData&) const;
    7071    void setSizeVariant(const GlyphData&);
     
    8182
    8283    UChar m_baseCharacter = 0;
    83     bool m_isVertical = false;
     84    Type m_operatorType { Type::UndefinedOperator };
    8485    StretchType m_stretchType = StretchType::Unstretched;
    8586    union {
  • trunk/Source/WebCore/rendering/mathml/RenderMathMLOperator.cpp

    r201854 r201862  
    268268    }
    269269
    270     m_mathOperator.setOperator(m_textContent, m_isVertical);
     270    MathOperator::Type type;
     271    if (isLargeOperatorInDisplayStyle())
     272        type = MathOperator::Type::DisplayOperator;
     273    else
     274        type = m_isVertical ? MathOperator::Type::VerticalOperator : MathOperator::Type::HorizontalOperator;
     275    m_mathOperator.setOperator(m_textContent, type);
    271276    GlyphData baseGlyph;
    272277    float maximumGlyphWidth = m_mathOperator.getBaseGlyph(style(), baseGlyph) ? advanceWidthForGlyph(baseGlyph) : 0;
     
    370375        return;
    371376
    372     m_mathOperator.setOperator(m_textContent, m_isVertical);
     377    MathOperator::Type type;
     378    if (isLargeOperatorInDisplayStyle())
     379        type = MathOperator::Type::DisplayOperator;
     380    else
     381        type = m_isVertical ? MathOperator::Type::VerticalOperator : MathOperator::Type::HorizontalOperator;
     382    m_mathOperator.setOperator(m_textContent, type);
    373383    if (m_isVertical && isLargeOperatorInDisplayStyle())
    374384        m_mathOperator.calculateDisplayStyleLargeOperator(style());
Note: See TracChangeset for help on using the changeset viewer.