Changeset 203073 in webkit


Ignore:
Timestamp:
Jul 11, 2016 11:42:22 AM (8 years ago)
Author:
fred.wang@free.fr
Message:

Use Stack* parameters from the OpenType MATH table
https://bugs.webkit.org/show_bug.cgi?id=155714

Patch by Frederic Wang <fwang@igalia.com> on 2016-07-11
Reviewed by Brent Fulgham.

Source/WebCore:

Test: mathml/mathml-in-html5/frac-parameters-2.html

  • rendering/mathml/RenderMathMLFraction.cpp:

(WebCore::RenderMathMLFraction::updateFromElement): Set the stack parameters when
the line thickness is zero.
(WebCore::RenderMathMLFraction::layoutBlock): Correctly set the <mfrac> ascent and
the denominator vertical offset when the line thickness is zero.
(WebCore::RenderMathMLFraction::paint): Early return when we actually do not need to
paint any fraction bar.

  • rendering/mathml/RenderMathMLFraction.h: Define an isStack helper function and define

members corresponding to stack parameters.

LayoutTests:

We import a test from the MathML in HTML5 test suite to verify Stack* parameters.

  • imported/mathml-in-html5/fonts/math/stack-axisheight7000.woff: Added.
  • imported/mathml-in-html5/fonts/math/stack-bottomdisplaystyleshiftdown5000.woff: Added.
  • imported/mathml-in-html5/fonts/math/stack-bottomshiftdown6000.woff: Added.
  • imported/mathml-in-html5/fonts/math/stack-displaystylegapmin4000.woff: Added.
  • imported/mathml-in-html5/fonts/math/stack-gapmin8000.woff: Added.
  • imported/mathml-in-html5/fonts/math/stack-topdisplaystyleshiftup3000.woff: Added.
  • imported/mathml-in-html5/fonts/math/stack-topshiftup9000.woff: Added.
  • imported/mathml-in-html5/mathml/presentation-markup/fractions/frac-parameters-2-expected.txt: Added.
  • imported/mathml-in-html5/mathml/presentation-markup/fractions/frac-parameters-2.html: Added.
Location:
trunk
Files:
9 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r203072 r203073  
     12016-07-11  Frederic Wang  <fwang@igalia.com>
     2
     3        Use Stack* parameters from the OpenType MATH table
     4        https://bugs.webkit.org/show_bug.cgi?id=155714
     5
     6        Reviewed by Brent Fulgham.
     7
     8        We import a test from the MathML in HTML5 test suite to verify Stack* parameters.
     9
     10        * imported/mathml-in-html5/fonts/math/stack-axisheight7000.woff: Added.
     11        * imported/mathml-in-html5/fonts/math/stack-bottomdisplaystyleshiftdown5000.woff: Added.
     12        * imported/mathml-in-html5/fonts/math/stack-bottomshiftdown6000.woff: Added.
     13        * imported/mathml-in-html5/fonts/math/stack-displaystylegapmin4000.woff: Added.
     14        * imported/mathml-in-html5/fonts/math/stack-gapmin8000.woff: Added.
     15        * imported/mathml-in-html5/fonts/math/stack-topdisplaystyleshiftup3000.woff: Added.
     16        * imported/mathml-in-html5/fonts/math/stack-topshiftup9000.woff: Added.
     17        * imported/mathml-in-html5/mathml/presentation-markup/fractions/frac-parameters-2-expected.txt: Added.
     18        * imported/mathml-in-html5/mathml/presentation-markup/fractions/frac-parameters-2.html: Added.
     19
    1202016-07-11  Frederic Wang  <fwang@igalia.com>
    221
  • trunk/Source/WebCore/ChangeLog

    r203072 r203073  
     12016-07-11  Frederic Wang  <fwang@igalia.com>
     2
     3        Use Stack* parameters from the OpenType MATH table
     4        https://bugs.webkit.org/show_bug.cgi?id=155714
     5
     6        Reviewed by Brent Fulgham.
     7
     8        Test: mathml/mathml-in-html5/frac-parameters-2.html
     9
     10        * rendering/mathml/RenderMathMLFraction.cpp:
     11        (WebCore::RenderMathMLFraction::updateFromElement): Set the stack parameters when
     12        the line thickness is zero.
     13        (WebCore::RenderMathMLFraction::layoutBlock): Correctly set the <mfrac> ascent and
     14        the denominator vertical offset when the line thickness is zero.
     15        (WebCore::RenderMathMLFraction::paint): Early return when we actually do not need to
     16        paint any fraction bar.
     17        * rendering/mathml/RenderMathMLFraction.h: Define an isStack helper function and define
     18        members corresponding to stack parameters.
     19
    1202016-07-11  Frederic Wang  <fwang@igalia.com>
    221
  • trunk/Source/WebCore/rendering/mathml/RenderMathMLFraction.cpp

    r202979 r203073  
    111111
    112112    // We now know whether we should layout as a normal fraction or as a stack (fraction without bar) and so determine the relevant constants.
    113     // FIXME: If m_lineThickness == 0, we should read Stack* parameters. See http://wkb.ug/122297
    114113    bool display = mathMLStyle()->displayStyle();
    115     if (mathData) {
    116         m_numeratorGapMin = mathData->getMathConstant(primaryFont, display ? OpenTypeMathData::FractionNumDisplayStyleGapMin : OpenTypeMathData::FractionNumeratorGapMin);
    117         m_denominatorGapMin = mathData->getMathConstant(primaryFont, display ? OpenTypeMathData::FractionDenomDisplayStyleGapMin : OpenTypeMathData::FractionDenominatorGapMin);
    118         m_numeratorMinShiftUp = mathData->getMathConstant(primaryFont, display ? OpenTypeMathData::FractionNumeratorDisplayStyleShiftUp : OpenTypeMathData::FractionNumeratorShiftUp);
    119         m_denominatorMinShiftDown = mathData->getMathConstant(primaryFont, display ? OpenTypeMathData::FractionDenominatorDisplayStyleShiftDown : OpenTypeMathData::FractionDenominatorShiftDown);
     114    if (isStack()) {
     115        if (mathData) {
     116            m_gapMin = mathData->getMathConstant(primaryFont, display ? OpenTypeMathData::StackDisplayStyleGapMin : OpenTypeMathData::StackGapMin);
     117            m_topShiftUp = mathData->getMathConstant(primaryFont, display ? OpenTypeMathData::StackTopDisplayStyleShiftUp : OpenTypeMathData::StackTopShiftUp);
     118            m_bottomShiftDown = mathData->getMathConstant(primaryFont, display ? OpenTypeMathData::StackBottomDisplayStyleShiftDown : OpenTypeMathData::StackBottomShiftDown);
     119        } else {
     120            // We use the values suggested in the MATH table specification.
     121            m_gapMin = m_denominatorGapMin = display ? 7 * ruleThicknessFallback() : 3 * ruleThicknessFallback();
     122
     123            // The MATH table specification does not suggest any values for shifts, so we leave them at zero.
     124            m_topShiftUp = m_bottomShiftDown = 0;
     125        }
    120126    } else {
    121         // The MATH table specification suggests default rule thickness or (in displaystyle) 3 times default rule thickness for the gaps.
    122         m_numeratorGapMin = m_denominatorGapMin = display ? 3 * ruleThicknessFallback() : ruleThicknessFallback();
    123 
    124         // The MATH table specification does not suggest any values for shifts, so we leave them at zero.
    125         m_numeratorMinShiftUp = m_denominatorMinShiftDown = 0;
     127        if (mathData) {
     128            m_numeratorGapMin = mathData->getMathConstant(primaryFont, display ? OpenTypeMathData::FractionNumDisplayStyleGapMin : OpenTypeMathData::FractionNumeratorGapMin);
     129            m_denominatorGapMin = mathData->getMathConstant(primaryFont, display ? OpenTypeMathData::FractionDenomDisplayStyleGapMin : OpenTypeMathData::FractionDenominatorGapMin);
     130            m_numeratorMinShiftUp = mathData->getMathConstant(primaryFont, display ? OpenTypeMathData::FractionNumeratorDisplayStyleShiftUp : OpenTypeMathData::FractionNumeratorShiftUp);
     131            m_denominatorMinShiftDown = mathData->getMathConstant(primaryFont, display ? OpenTypeMathData::FractionDenominatorDisplayStyleShiftDown : OpenTypeMathData::FractionDenominatorShiftDown);
     132        } else {
     133            // The MATH table specification suggests default rule thickness or (in displaystyle) 3 times default rule thickness for the gaps.
     134            m_numeratorGapMin = m_denominatorGapMin = display ? 3 * ruleThicknessFallback() : ruleThicknessFallback();
     135
     136            // The MATH table specification does not suggest any values for shifts, so we leave them at zero.
     137            m_numeratorMinShiftUp = m_denominatorMinShiftDown = 0;
     138        }
    126139    }
    127140
     
    203216
    204217    LayoutUnit numeratorAscent = ascentForChild(numerator());
    205     verticalOffset += std::max(numerator().logicalHeight() + m_numeratorGapMin + m_lineThickness / 2, numeratorAscent + m_numeratorMinShiftUp); // This is the middle of the fraction bar.
    206     m_ascent = verticalOffset + mathAxisHeight();
    207 
     218    LayoutUnit numeratorDescent = numerator().logicalHeight() - numeratorAscent;
    208219    LayoutUnit denominatorAscent = ascentForChild(denominator());
    209220    LayoutUnit denominatorDescent = denominator().logicalHeight() - denominatorAscent;
    210     verticalOffset += std::max(m_lineThickness / 2 + m_denominatorGapMin, m_denominatorMinShiftDown - denominatorAscent);
     221    if (isStack()) {
     222        LayoutUnit topShiftUp = m_topShiftUp;
     223        LayoutUnit bottomShiftDown = m_bottomShiftDown;
     224        LayoutUnit gap = topShiftUp - numeratorDescent + bottomShiftDown - denominatorAscent;
     225        if (gap < m_gapMin) {
     226            // If the gap is not large enough, we increase the shifts by the same value.
     227            LayoutUnit delta = (m_gapMin - gap) / 2;
     228            topShiftUp += delta;
     229            bottomShiftDown += delta;
     230        }
     231        verticalOffset += numeratorAscent + topShiftUp; // This is the middle of the stack gap.
     232        m_ascent = verticalOffset + mathAxisHeight();
     233        verticalOffset += bottomShiftDown - denominatorAscent;
     234    } else {
     235        verticalOffset += std::max(numerator().logicalHeight() + m_numeratorGapMin + m_lineThickness / 2, numeratorAscent + m_numeratorMinShiftUp); // This is the middle of the fraction bar.
     236        m_ascent = verticalOffset + mathAxisHeight();
     237        verticalOffset += std::max(m_lineThickness / 2 + m_denominatorGapMin, m_denominatorMinShiftDown - denominatorAscent);
     238    }
     239
    211240    LayoutPoint denominatorLocation(horizontalOffset(denominator(), m_denominatorAlign), verticalOffset);
    212241    denominator().setLocation(denominatorLocation);
     
    221250{
    222251    RenderMathMLBlock::paint(info, paintOffset);
    223     if (info.context().paintingDisabled() || info.phase != PaintPhaseForeground || style().visibility() != VISIBLE || !isValid())
     252    if (info.context().paintingDisabled() || info.phase != PaintPhaseForeground || style().visibility() != VISIBLE || !isValid() || isStack())
    224253        return;
    225254
  • trunk/Source/WebCore/rendering/mathml/RenderMathMLFraction.h

    r202979 r203073  
    5858    void styleDidChange(StyleDifference, const RenderStyle* oldStyle) final;
    5959
     60    bool isStack() const { return !m_lineThickness; }
    6061    bool isValid() const;
    6162    RenderBox& numerator() const;
     
    7071
    7172    LayoutUnit m_ascent;
    72     LayoutUnit m_defaultLineThickness = 1;
     73    LayoutUnit m_defaultLineThickness { 1 };
    7374    LayoutUnit m_lineThickness;
    74     LayoutUnit m_numeratorGapMin;
     75    union {
     76        LayoutUnit m_numeratorGapMin;
     77        LayoutUnit m_gapMin;
     78    };
    7579    LayoutUnit m_denominatorGapMin;
    76     LayoutUnit m_numeratorMinShiftUp;
    77     LayoutUnit m_denominatorMinShiftDown;
    78     FractionAlignment m_numeratorAlign = FractionAlignmentCenter;
    79     FractionAlignment m_denominatorAlign = FractionAlignmentCenter;
     80    union {
     81        LayoutUnit m_numeratorMinShiftUp;
     82        LayoutUnit m_topShiftUp;
     83    };
     84    union {
     85        LayoutUnit m_denominatorMinShiftDown;
     86        LayoutUnit m_bottomShiftDown;
     87    };
     88    FractionAlignment m_numeratorAlign { FractionAlignmentCenter };
     89    FractionAlignment m_denominatorAlign { FractionAlignmentCenter };
    8090};
    8191
Note: See TracChangeset for help on using the changeset viewer.