Changeset 201881 in webkit


Ignore:
Timestamp:
Jun 9, 2016 1:50:44 PM (8 years ago)
Author:
fred.wang@free.fr
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.

Location:
trunk/Source/WebCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r201880 r201881  
     12016-06-09  Frederic Wang  <fred.wang@free.fr>
     2
     3        RenderMathOperator: Move calculation of preferred width into MathOperator
     4        https://bugs.webkit.org/show_bug.cgi?id=157071
     5
     6        Reviewed by Brent Fulgham.
     7
     8        No new tests, behavior is not change.
     9
     10        * rendering/mathml/MathOperator.cpp:
     11        (WebCore::MathOperator::setOperator): Introduce a style parameter and call reset.
     12        (WebCore::MathOperator::reset): New helper function to reset the operator.
     13        For now we only set the width of the base glyph and the preferred max width.
     14        (WebCore::MathOperator::calculateDisplayStyleLargeOperator): Calculate the m_maxPreferredWidth.
     15        (WebCore::MathOperator::calculateStretchyData): Change the signature of the function and directly set m_maxPreferredWidth.
     16        * rendering/mathml/MathOperator.h: Add m_maxPreferredWidth member and update some declarations.
     17        (WebCore::MathOperator::width): New helper function.
     18        (WebCore::MathOperator::maxPreferredWidth): New helper function.
     19        * rendering/mathml/RenderMathMLOperator.cpp:
     20        (WebCore::RenderMathMLOperator::computePreferredLogicalWidths): This function performs wrong
     21        operations that will be fixed in bug 152244 when we update the tests.
     22        For now, let's just use maxPreferredWidth() for non-horizontal operators.
     23        (WebCore::RenderMathMLOperator::updateStyle): Use the new signature of the functions.
     24
    1252016-06-09  Alex Christensen  <achristensen@webkit.org>
    226
  • trunk/Source/WebCore/rendering/mathml/MathOperator.cpp

    r201862 r201881  
    7676};
    7777
    78 void MathOperator::setOperator(UChar baseCharacter, Type operatorType)
     78void MathOperator::setOperator(const RenderStyle& style, UChar baseCharacter, Type operatorType)
    7979{
    8080    m_baseCharacter = baseCharacter;
    8181    m_operatorType = operatorType;
     82    reset(style);
     83}
     84
     85void MathOperator::reset(const RenderStyle& style)
     86{
     87    m_maxPreferredWidth = 0;
     88    m_width = 0;
     89
     90    // We use the base size for the calculation of the preferred width.
     91    GlyphData baseGlyph;
     92    if (!getBaseGlyph(style, baseGlyph))
     93        return;
     94    m_maxPreferredWidth = m_width = advanceWidthForGlyph(baseGlyph);
     95
     96    if (m_operatorType == Type::VerticalOperator)
     97        calculateStretchyData(style, true); // We also take into account the width of larger sizes for the calculation of the preferred width.
     98    else if (m_operatorType == Type::DisplayOperator)
     99        calculateDisplayStyleLargeOperator(style); // We can directly select the size variant and determine the final metrics.
    82100}
    83101
     
    128146        GlyphData glyphData(sizeVariant, baseGlyph.font);
    129147        setSizeVariant(glyphData);
     148        // 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/).
     149        m_maxPreferredWidth = boundsForGlyph(glyphData).width();
    130150        m_italicCorrection = glyphData.font->mathData()->getItalicCorrection(*glyphData.font, glyphData.glyph);
    131151        if (heightForGlyph(glyphData) >= displayOperatorMinHeight)
     
    236256}
    237257
    238 void MathOperator::calculateStretchyData(const RenderStyle& style, float* maximumGlyphWidth, LayoutUnit targetSize)
     258void MathOperator::calculateStretchyData(const RenderStyle& style, bool calculateMaxPreferredWidth, LayoutUnit targetSize)
    239259{
    240260    ASSERT(m_operatorType == Type::VerticalOperator || m_operatorType == Type::HorizontalOperator);
    241     ASSERT(!maximumGlyphWidth || m_operatorType == Type::VerticalOperator);
     261    ASSERT(!calculateMaxPreferredWidth || m_operatorType == Type::VerticalOperator);
    242262    bool isVertical = m_operatorType == Type::VerticalOperator;
    243263
     
    246266        return;
    247267
    248     if (!maximumGlyphWidth) {
     268    if (!calculateMaxPreferredWidth) {
    249269        // We do not stretch if the base glyph is large enough.
    250270        float baseSize = isVertical ? heightForGlyph(baseGlyph) : advanceWidthForGlyph(baseGlyph);
     
    253273    }
    254274
    255     MathOperator::GlyphAssemblyData assemblyData;
     275    GlyphAssemblyData assemblyData;
    256276    if (baseGlyph.font->mathData()) {
    257277        Vector<Glyph> sizeVariants;
     
    261281        for (auto& sizeVariant : sizeVariants) {
    262282            GlyphData glyphData(sizeVariant, baseGlyph.font);
    263             if (maximumGlyphWidth)
    264                 *maximumGlyphWidth = std::max(*maximumGlyphWidth, advanceWidthForGlyph(glyphData));
     283            if (calculateMaxPreferredWidth)
     284                m_maxPreferredWidth = std::max<LayoutUnit>(m_maxPreferredWidth, advanceWidthForGlyph(glyphData));
    265285            else {
    266286                setSizeVariant(glyphData);
    267                 float size = isVertical ? heightForGlyph(glyphData) : advanceWidthForGlyph(glyphData);
     287                LayoutUnit size = isVertical ? heightForGlyph(glyphData) : advanceWidthForGlyph(glyphData);
    268288                if (size >= targetSize)
    269289                    return;
     
    304324
    305325    // If we are measuring the maximum width, verify each component.
    306     if (maximumGlyphWidth) {
    307         *maximumGlyphWidth = std::max(*maximumGlyphWidth, advanceWidthForGlyph(assemblyData.topOrRight));
    308         *maximumGlyphWidth = std::max(*maximumGlyphWidth, advanceWidthForGlyph(assemblyData.extension));
    309         *maximumGlyphWidth = std::max(*maximumGlyphWidth, advanceWidthForGlyph(assemblyData.middle));
    310         *maximumGlyphWidth = std::max(*maximumGlyphWidth, advanceWidthForGlyph(assemblyData.bottomOrLeft));
     326    if (calculateMaxPreferredWidth) {
     327        m_maxPreferredWidth = std::max<LayoutUnit>(m_maxPreferredWidth, advanceWidthForGlyph(assemblyData.topOrRight));
     328        m_maxPreferredWidth = std::max<LayoutUnit>(m_maxPreferredWidth, advanceWidthForGlyph(assemblyData.extension));
     329        m_maxPreferredWidth = std::max<LayoutUnit>(m_maxPreferredWidth, advanceWidthForGlyph(assemblyData.middle));
     330        m_maxPreferredWidth = std::max<LayoutUnit>(m_maxPreferredWidth, advanceWidthForGlyph(assemblyData.bottomOrLeft));
    311331        return;
    312332    }
  • trunk/Source/WebCore/rendering/mathml/MathOperator.h

    r201862 r201881  
    4242    MathOperator() { }
    4343    enum class Type { UndefinedOperator, DisplayOperator, VerticalOperator, HorizontalOperator };
    44     void setOperator(UChar baseCharacter, Type);
     44    void setOperator(const RenderStyle&, UChar baseCharacter, Type);
     45    void reset(const RenderStyle&);
    4546
     47    LayoutUnit width() const { return m_width; }
     48    LayoutUnit maxPreferredWidth() const { return m_maxPreferredWidth; }
    4649    LayoutUnit italicCorrection() const { return m_italicCorrection; }
    4750
     
    7275    void setGlyphAssembly(const GlyphAssemblyData&);
    7376    void calculateDisplayStyleLargeOperator(const RenderStyle&);
    74     void calculateStretchyData(const RenderStyle&, float* maximumGlyphWidth, LayoutUnit targetSize = 0);
     77    void calculateStretchyData(const RenderStyle&, bool calculateMaxPreferredWidth, LayoutUnit targetSize = 0);
    7578    bool calculateGlyphAssemblyFallback(const RenderStyle&, const Vector<OpenTypeMathData::AssemblyPart>&, GlyphAssemblyData&) const;
    7679
     
    8184    void paintHorizontalGlyphAssembly(const RenderStyle&, PaintInfo&, const LayoutPoint&);
    8285
    83     UChar m_baseCharacter = 0;
     86    UChar m_baseCharacter { 0 };
    8487    Type m_operatorType { Type::UndefinedOperator };
    85     StretchType m_stretchType = StretchType::Unstretched;
     88    StretchType m_stretchType { StretchType::Unstretched };
    8689    union {
    8790        GlyphData m_variant;
    8891        GlyphAssemblyData m_assembly;
    8992    };
    90     LayoutUnit m_width = 0;
    91     LayoutUnit m_ascent = 0;
    92     LayoutUnit m_descent = 0;
    93     LayoutUnit m_italicCorrection = 0;
     93    LayoutUnit m_maxPreferredWidth { 0 };
     94    LayoutUnit m_width { 0 };
     95    LayoutUnit m_ascent { 0 };
     96    LayoutUnit m_descent { 0 };
     97    LayoutUnit m_italicCorrection { 0 };
    9498};
    9599
  • trunk/Source/WebCore/rendering/mathml/RenderMathMLOperator.cpp

    r201862 r201881  
    268268    }
    269269
     270    // FIXME: We should not use stretchSize during the preferred width calculation nor should we leave logical width dirty (http://webkit.org/b/152244).
    270271    MathOperator::Type type;
    271272    if (isLargeOperatorInDisplayStyle())
     
    273274    else
    274275        type = m_isVertical ? MathOperator::Type::VerticalOperator : MathOperator::Type::HorizontalOperator;
    275     m_mathOperator.setOperator(m_textContent, type);
    276     GlyphData baseGlyph;
    277     float maximumGlyphWidth = m_mathOperator.getBaseGlyph(style(), baseGlyph) ? advanceWidthForGlyph(baseGlyph) : 0;
     276    m_mathOperator.setOperator(style(), m_textContent, type);
     277    float maximumGlyphWidth;
    278278    if (!m_isVertical) {
     279        maximumGlyphWidth = m_mathOperator.width();
    279280        if (maximumGlyphWidth < stretchSize())
    280281            maximumGlyphWidth = stretchSize();
    281         m_maxPreferredLogicalWidth = m_leadingSpace + maximumGlyphWidth + m_trailingSpace;
    282         m_minPreferredLogicalWidth = m_maxPreferredLogicalWidth;
    283         return;
    284     }
    285     if (isLargeOperatorInDisplayStyle()) {
    286         // 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/).
    287         m_mathOperator.calculateDisplayStyleLargeOperator(style());
    288         if (m_mathOperator.m_stretchType == MathOperator::StretchType::SizeVariant)
    289             maximumGlyphWidth = boundsForGlyph(m_mathOperator.m_variant).width();
    290     } else {
    291         // 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).
    292         m_mathOperator.calculateStretchyData(style(), &maximumGlyphWidth);
    293     }
     282    } else
     283        maximumGlyphWidth = m_mathOperator.maxPreferredWidth();
    294284    m_maxPreferredLogicalWidth = m_minPreferredLogicalWidth = m_leadingSpace + maximumGlyphWidth + m_trailingSpace;
    295285}
     
    380370    else
    381371        type = m_isVertical ? MathOperator::Type::VerticalOperator : MathOperator::Type::HorizontalOperator;
    382     m_mathOperator.setOperator(m_textContent, type);
     372    m_mathOperator.setOperator(style(), m_textContent, type);
    383373    if (m_isVertical && isLargeOperatorInDisplayStyle())
    384374        m_mathOperator.calculateDisplayStyleLargeOperator(style());
    385375    else {
    386         m_mathOperator.calculateStretchyData(style(), nullptr, stretchSize());
     376        m_mathOperator.calculateStretchyData(style(), false, stretchSize());
    387377        if (!m_mathOperator.isStretched())
    388378            return;
Note: See TracChangeset for help on using the changeset viewer.