Changeset 200185 in webkit


Ignore:
Timestamp:
Apr 28, 2016 5:09:38 AM (8 years ago)
Author:
fred.wang@free.fr
Message:

RenderMathMLOperator refactoring: introduce getBaseGlyph and remove parameter from getDisplayStyleLargeOperator
https://bugs.webkit.org/show_bug.cgi?id=156910

Reviewed by Alejandro G. Castro.

No new tests, the behavior is not changed.

  • rendering/mathml/RenderMathMLOperator.cpp:

(WebCore::RenderMathMLOperator::italicCorrection): We do not need to pass m_textContent
to getDisplayStyleLargeOperator.
(WebCore::RenderMathMLOperator::computePreferredLogicalWidths): We use getBaseGlyph and do
not pass m_textContent to getDisplayStyleLargeOperator or findStretchyData.
(WebCore::RenderMathMLOperator::getBaseGlyph): Introduce a helper function to retrieve the
base glyph and do some validity checks.
(WebCore::RenderMathMLOperator::getDisplayStyleLargeOperator): We remove the character
parameter as it is always m_textContent.
We use getBaseGlyph and replace primaryFont with baseGlyph.font.
(WebCore::RenderMathMLOperator::findStretchyData): Ditto.
(WebCore::RenderMathMLOperator::updateStyle): We do not pass m_textContent to
getDisplayStyleLargeOperator or findStretchyData.

  • rendering/mathml/RenderMathMLOperator.h: Declare getBaseGlyph and remove the parameter

from getDisplayStyleLargeOperator and findStretchyData.

Location:
trunk/Source
Files:
5 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r200184 r200185  
     12016-04-28  Frederic Wang  <fred.wang@free.fr>
     2
     3        RenderMathMLOperator refactoring: introduce getBaseGlyph and remove parameter from getDisplayStyleLargeOperator
     4        https://bugs.webkit.org/show_bug.cgi?id=156910
     5
     6        Reviewed by Alejandro G. Castro.
     7
     8        No new tests, the behavior is not changed.
     9
     10        * rendering/mathml/RenderMathMLOperator.cpp:
     11        (WebCore::RenderMathMLOperator::italicCorrection): We do not need to pass m_textContent
     12        to getDisplayStyleLargeOperator.
     13        (WebCore::RenderMathMLOperator::computePreferredLogicalWidths): We use getBaseGlyph and do
     14        not pass m_textContent to getDisplayStyleLargeOperator or findStretchyData.
     15        (WebCore::RenderMathMLOperator::getBaseGlyph): Introduce a helper function to retrieve the
     16        base glyph and do some validity checks.
     17        (WebCore::RenderMathMLOperator::getDisplayStyleLargeOperator): We remove the character
     18        parameter as it is always m_textContent.
     19        We use getBaseGlyph and replace primaryFont with baseGlyph.font.
     20        (WebCore::RenderMathMLOperator::findStretchyData): Ditto.
     21        (WebCore::RenderMathMLOperator::updateStyle): We do not pass m_textContent to
     22        getDisplayStyleLargeOperator or findStretchyData.
     23        * rendering/mathml/RenderMathMLOperator.h: Declare getBaseGlyph and remove the parameter
     24        from getDisplayStyleLargeOperator and findStretchyData.
     25
    1262016-04-28  Carlos Garcia Campos  <cgarcia@igalia.com>
    227
  • trunk/Source/WebCore/rendering/mathml/RenderMathMLOperator.cpp

    r200041 r200185  
    208208        const auto& primaryFont = style().fontCascade().primaryFont();
    209209        if (auto* mathData = primaryFont.mathData()) {
    210             StretchyData largeOperator = getDisplayStyleLargeOperator(m_textContent);
     210            StretchyData largeOperator = getDisplayStyleLargeOperator();
    211211            return mathData->getItalicCorrection(primaryFont, largeOperator.variant().glyph);
    212212        }
     
    307307    }
    308308
    309     GlyphData data = style().fontCascade().glyphDataForCharacter(m_textContent, !style().isLeftToRightDirection());
    310     float maximumGlyphWidth = advanceWidthForGlyph(data);
     309    GlyphData baseGlyph;
     310    float maximumGlyphWidth = getBaseGlyph(style(), baseGlyph) ? advanceWidthForGlyph(baseGlyph) : 0;
    311311    if (!m_isVertical) {
    312312        if (maximumGlyphWidth < stretchSize())
     
    318318    if (isLargeOperatorInDisplayStyle()) {
    319319        // 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/).
    320         StretchyData largeOperator = getDisplayStyleLargeOperator(m_textContent);
     320        StretchyData largeOperator = getDisplayStyleLargeOperator();
    321321        if (largeOperator.mode() == DrawSizeVariant)
    322322            maximumGlyphWidth = boundsForGlyph(largeOperator.variant()).width();
    323323    } else {
    324324        // 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).
    325         findStretchyData(m_textContent, &maximumGlyphWidth);
     325        findStretchyData(&maximumGlyphWidth);
    326326    }
    327327    m_maxPreferredLogicalWidth = m_minPreferredLogicalWidth = m_leadingSpace + maximumGlyphWidth + m_trailingSpace;
     
    385385    RenderMathMLBlock::styleDidChange(diff, oldStyle);
    386386    updateOperatorProperties();
     387}
     388
     389bool RenderMathMLOperator::getBaseGlyph(const RenderStyle& style, GlyphData& baseGlyph) const
     390{
     391    baseGlyph = style.fontCascade().glyphDataForCharacter(m_textContent, !style.isLeftToRightDirection());
     392    return baseGlyph.isValid() && baseGlyph.font == &style.fontCascade().primaryFont();
    387393}
    388394
     
    497503}
    498504
    499 RenderMathMLOperator::StretchyData RenderMathMLOperator::getDisplayStyleLargeOperator(UChar character) const
     505RenderMathMLOperator::StretchyData RenderMathMLOperator::getDisplayStyleLargeOperator() const
    500506{
    501507    StretchyData data;
     
    503509    ASSERT(m_isVertical && isLargeOperatorInDisplayStyle());
    504510
    505     const auto& primaryFont = style().fontCascade().primaryFont();
    506     GlyphData baseGlyph = style().fontCascade().glyphDataForCharacter(character, !style().isLeftToRightDirection());
    507     if (!primaryFont.mathData() || baseGlyph.font != &primaryFont || !baseGlyph.font || !baseGlyph.glyph)
     511    GlyphData baseGlyph;
     512    if (!getBaseGlyph(style(), baseGlyph) || !baseGlyph.font->mathData())
    508513        return data;
    509514
     
    512517
    513518    // The value of displayOperatorMinHeight is sometimes too small, so we ensure that it is at least \sqrt{2} times the size of the base glyph.
    514     float displayOperatorMinHeight = std::max(baseGlyph.font->boundsForGlyph(baseGlyph.glyph).height() * sqrtOfTwoFloat, primaryFont.mathData()->getMathConstant(primaryFont, OpenTypeMathData::DisplayOperatorMinHeight));
    515 
    516     primaryFont.mathData()->getMathVariants(baseGlyph.glyph, true, sizeVariants, assemblyParts);
     519    float displayOperatorMinHeight = std::max(baseGlyph.font->boundsForGlyph(baseGlyph.glyph).height() * sqrtOfTwoFloat, baseGlyph.font->mathData()->getMathConstant(*baseGlyph.font, OpenTypeMathData::DisplayOperatorMinHeight));
     520
     521    baseGlyph.font->mathData()->getMathVariants(baseGlyph.glyph, true, sizeVariants, assemblyParts);
    517522
    518523    // We choose the first size variant that is larger than the expected displayOperatorMinHeight and otherwise fallback to the largest variant.
     
    520525        GlyphData sizeVariant;
    521526        sizeVariant.glyph = variant;
    522         sizeVariant.font = &primaryFont;
     527        sizeVariant.font = baseGlyph.font;
    523528        data.setSizeVariantMode(sizeVariant);
    524529        if (boundsForGlyph(sizeVariant).height() >= displayOperatorMinHeight)
     
    528533}
    529534
    530 RenderMathMLOperator::StretchyData RenderMathMLOperator::findStretchyData(UChar character, float* maximumGlyphWidth)
     535RenderMathMLOperator::StretchyData RenderMathMLOperator::findStretchyData(float* maximumGlyphWidth)
    531536{
    532537    ASSERT(!maximumGlyphWidth || m_isVertical);
     
    535540    StretchyData assemblyData;
    536541
    537     const auto& primaryFont = style().fontCascade().primaryFont();
    538     GlyphData baseGlyph = style().fontCascade().glyphDataForCharacter(character, !style().isLeftToRightDirection());
     542    GlyphData baseGlyph;
     543    if (!getBaseGlyph(style(), baseGlyph))
     544        return data;
    539545   
    540     if (primaryFont.mathData() && baseGlyph.font == &primaryFont) {
     546    if (baseGlyph.font->mathData()) {
    541547        Vector<Glyph> sizeVariants;
    542548        Vector<OpenTypeMathData::AssemblyPart> assemblyParts;
    543         primaryFont.mathData()->getMathVariants(baseGlyph.glyph, m_isVertical, sizeVariants, assemblyParts);
     549        baseGlyph.font->mathData()->getMathVariants(baseGlyph.glyph, m_isVertical, sizeVariants, assemblyParts);
    544550        // We verify the size variants.
    545551        for (auto& variant : sizeVariants) {
    546552            GlyphData sizeVariant;
    547553            sizeVariant.glyph = variant;
    548             sizeVariant.font = &primaryFont;
     554            sizeVariant.font = baseGlyph.font;
    549555            if (maximumGlyphWidth)
    550556                *maximumGlyphWidth = std::max(*maximumGlyphWidth, advanceWidthForGlyph(sizeVariant));
     
    568574        const unsigned maxIndex = WTF_ARRAY_LENGTH(stretchyCharacters);
    569575        for (unsigned index = 0; index < maxIndex; ++index) {
    570             if (stretchyCharacters[index].character == character) {
     576            if (stretchyCharacters[index].character == m_textContent) {
    571577                stretchyCharacter = &stretchyCharacters[index];
    572578                if (!style().isLeftToRightDirection() && index < leftRightPairsCount * 2) {
     
    642648
    643649    if (m_isVertical && isLargeOperatorInDisplayStyle())
    644         m_stretchyData = getDisplayStyleLargeOperator(m_textContent);
     650        m_stretchyData = getDisplayStyleLargeOperator();
    645651    else {
    646652        // We do not stretch if the base glyph is large enough.
     
    649655        if (stretchSize() <= baseSize)
    650656            return;
    651         m_stretchyData = findStretchyData(m_textContent, nullptr);
     657        m_stretchyData = findStretchyData(nullptr);
    652658    }
    653659
  • trunk/Source/WebCore/rendering/mathml/RenderMathMLOperator.h

    r200041 r200185  
    142142    bool shouldAllowStretching() const;
    143143
     144    bool getBaseGlyph(const RenderStyle&, GlyphData&) const;
    144145    bool getGlyphAssemblyFallBack(Vector<OpenTypeMathData::AssemblyPart>, StretchyData&) const;
    145     StretchyData getDisplayStyleLargeOperator(UChar) const;
    146     StretchyData findStretchyData(UChar, float* maximumGlyphWidth);
     146    StretchyData getDisplayStyleLargeOperator() const;
     147    StretchyData findStretchyData(float* maximumGlyphWidth);
    147148
    148149    enum GlyphPaintTrimming {
Note: See TracChangeset for help on using the changeset viewer.