Changeset 180779 in webkit


Ignore:
Timestamp:
Feb 27, 2015 1:42:31 PM (9 years ago)
Author:
commit-queue@webkit.org
Message:

Unreviewed, rolling out r180752.
https://bugs.webkit.org/show_bug.cgi?id=142098

Causes 10 SVG test failures on Windows. (Requested by
bfulgham_ on #webkit).

Reverted changeset:

"Cache glyph widths to GlyphPages"
https://bugs.webkit.org/show_bug.cgi?id=142028
http://trac.webkit.org/changeset/180752

Location:
trunk/Source/WebCore
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r180777 r180779  
     12015-02-27  Commit Queue  <commit-queue@webkit.org>
     2
     3        Unreviewed, rolling out r180752.
     4        https://bugs.webkit.org/show_bug.cgi?id=142098
     5
     6        Causes 10 SVG test failures on Windows. (Requested by
     7        bfulgham_ on #webkit).
     8
     9        Reverted changeset:
     10
     11        "Cache glyph widths to GlyphPages"
     12        https://bugs.webkit.org/show_bug.cgi?id=142028
     13        http://trac.webkit.org/changeset/180752
     14
    1152015-02-27  David Kilzer  <ddkilzer@apple.com>
    216
  • trunk/Source/WebCore/platform/graphics/Font.cpp

    r180752 r180779  
    5555    , m_avgCharWidth(-1)
    5656    , m_platformData(platformData)
     57    , m_treatAsFixedPitch(false)
    5758    , m_isCustomFont(isCustomFont)
    5859    , m_isLoading(isLoading)
    5960    , m_isTextOrientationFallback(isTextOrientationFallback)
     61    , m_isBrokenIdeographFallback(false)
     62    , m_mathData(nullptr)
     63#if ENABLE(OPENTYPE_VERTICAL)
     64    , m_verticalData(0)
     65#endif
     66    , m_hasVerticalGlyphs(false)
    6067{
    6168    platformInit();
     
    7380    : m_platformData(FontPlatformData(fontSize, syntheticBold, syntheticItalic))
    7481    , m_svgData(WTF::move(svgData))
     82    , m_treatAsFixedPitch(false)
    7583    , m_isCustomFont(true)
     84    , m_isLoading(false)
     85    , m_isTextOrientationFallback(false)
     86    , m_isBrokenIdeographFallback(false)
     87    , m_mathData(nullptr)
     88#if ENABLE(OPENTYPE_VERTICAL)
     89    , m_verticalData(0)
     90#endif
     91    , m_hasVerticalGlyphs(false)
     92#if PLATFORM(IOS)
     93    , m_shouldNotBeUsedForArabic(false)
     94#endif
    7695{
    7796    m_svgData->initializeFont(this, fontSize);
     
    88107        Glyph digitZeroGlyph = glyphPageZero->glyphDataForCharacter(digitZeroChar).glyph;
    89108        if (digitZeroGlyph)
    90             m_avgCharWidth = computeWidthForGlyph(digitZeroGlyph);
     109            m_avgCharWidth = widthForGlyph(digitZeroGlyph);
    91110    }
    92111
     
    103122    auto* glyphPageZero = glyphPage(0);
    104123    if (!glyphPageZero) {
     124        m_spaceGlyph = 0;
     125        m_spaceWidth = 0;
     126        m_zeroGlyph = 0;
     127        m_adjustedSpaceWidth = 0;
    105128        determinePitch();
     129        m_zeroWidthSpaceGlyph = 0;
    106130        return;
    107131    }
     132
    108133    // Ask for the glyph for 0 to avoid paging in ZERO WIDTH SPACE. Control characters, including 0,
    109134    // are mapped to the ZERO WIDTH SPACE glyph.
    110135    m_zeroWidthSpaceGlyph = glyphPageZero->glyphDataForCharacter(0).glyph;
     136
    111137    // Nasty hack to determine if we should round or ceil space widths.
    112138    // If the font is monospace or fake monospace we ceil to ensure that
    113139    // every character and the space are the same width. Otherwise we round.
    114     auto spaceGlyphData = glyphPageZero->glyphDataForCharacter(' ');
    115     m_spaceGlyph = spaceGlyphData.glyph;
    116     m_spaceWidth = spaceGlyphData.width;
    117     m_fontMetrics.setZeroWidth(glyphPageZero->glyphDataForCharacter('0').width);
     140    m_spaceGlyph = glyphPageZero->glyphDataForCharacter(' ').glyph;
     141    float width = widthForGlyph(m_spaceGlyph);
     142    m_spaceWidth = width;
     143    m_zeroGlyph = glyphPageZero->glyphDataForCharacter('0').glyph;
     144    m_fontMetrics.setZeroWidth(widthForGlyph(m_zeroGlyph));
    118145    determinePitch();
    119     m_adjustedSpaceWidth = m_treatAsFixedPitch ? ceilf(m_spaceWidth) : roundf(m_spaceWidth);
    120     m_glyphZeroWidth = computeWidthForGlyph(0);
     146    m_adjustedSpaceWidth = m_treatAsFixedPitch ? ceilf(width) : roundf(width);
    121147
    122148    // Force the glyph for ZERO WIDTH SPACE to have zero width, unless it is shared with SPACE.
     
    125151    if (m_zeroWidthSpaceGlyph == m_spaceGlyph)
    126152        m_zeroWidthSpaceGlyph = 0;
    127     else {
    128         // Fixup the page zero now that we know the zero width glyph.
    129         for (unsigned i = 0; i < GlyphPage::size; ++i) {
    130             auto glyphData = m_glyphPageZero->glyphDataForIndex(i);
    131             if (glyphData.glyph == m_zeroWidthSpaceGlyph)
    132                 m_glyphPageZero->setGlyphDataForIndex(i, { glyphData.glyph, 0, glyphData.font });
    133         }
    134     }
    135     m_glyphPageZero->setImmutable();
    136153}
    137154
     
    155172}
    156173
    157 RefPtr<GlyphPage> createAndFillGlyphPage(unsigned pageNumber, const Font* font)
     174static RefPtr<GlyphPage> createAndFillGlyphPage(unsigned pageNumber, const Font* font)
    158175{
    159176#if PLATFORM(IOS)
     
    228245        return nullptr;
    229246
     247    glyphPage->setImmutable();
    230248    return glyphPage;
    231 }
    232 
    233 float Font::computeWidthForGlyph(Glyph glyph) const
    234 {
    235     if (isZeroWidthSpaceGlyph(glyph))
    236         return 0;
    237     float width;
    238     if (isSVGFont())
    239         width = m_svgData->widthForSVGGlyph(glyph, m_platformData.size());
    240 #if ENABLE(OPENTYPE_VERTICAL)
    241     else if (m_verticalData)
    242 #if USE(CG) || USE(CAIRO)
    243         width = m_verticalData->advanceHeight(this, glyph) + m_syntheticBoldOffset;
    244 #else
    245         width = m_verticalData->advanceHeight(this, glyph);
    246 #endif
    247 #endif
    248     else
    249         width = platformWidthForGlyph(glyph);
    250     return width;
    251249}
    252250
     
    256254        if (!m_glyphPageZero)
    257255            m_glyphPageZero = createAndFillGlyphPage(0, this);
    258         // Zero page is marked immutable in platformGlyphInit.
    259256        return m_glyphPageZero.get();
    260257    }
    261258    auto addResult = m_glyphPages.add(pageNumber, nullptr);
    262     auto& page = addResult.iterator->value;
    263     if (addResult.isNewEntry) {
    264         page = createAndFillGlyphPage(pageNumber, this);
    265         if (page)
    266             page->setImmutable();
    267     }
    268     return page.get();
     259    if (addResult.isNewEntry)
     260        addResult.iterator->value = createAndFillGlyphPage(pageNumber, this);
     261
     262    return addResult.iterator->value.get();
    269263}
    270264
     
    465459}
    466460
    467 void GlyphPage::setGlyphDataForIndex(unsigned index, Glyph glyph, const Font* font)
    468 {
    469     setGlyphDataForIndex(index, { glyph, font ? font->computeWidthForGlyph(glyph) : 0, font });
    470 }
    471 
    472 
    473461} // namespace WebCore
  • trunk/Source/WebCore/platform/graphics/Font.h

    r180752 r180779  
    141141
    142142    FloatRect boundsForGlyph(Glyph) const;
    143 
    144     float computeWidthForGlyph(Glyph) const;
     143    float widthForGlyph(Glyph) const;
     144    FloatRect platformBoundsForGlyph(Glyph) const;
     145    float platformWidthForGlyph(Glyph) const;
    145146
    146147    float spaceWidth() const { return m_spaceWidth; }
     
    151152        m_adjustedSpaceWidth = spaceWidth;
    152153    }
    153     float glyphZeroWidth() const { return m_glyphZeroWidth; }
    154154
    155155#if USE(CG) || USE(CAIRO)
     
    162162    void setZeroWidthSpaceGlyph(Glyph spaceGlyph) { m_zeroWidthSpaceGlyph = spaceGlyph; }
    163163    bool isZeroWidthSpaceGlyph(Glyph glyph) const { return glyph == m_zeroWidthSpaceGlyph && glyph; }
     164    Glyph zeroGlyph() const { return m_zeroGlyph; }
     165    void setZeroGlyph(Glyph zeroGlyph) { m_zeroGlyph = zeroGlyph; }
    164166
    165167    GlyphData glyphDataForCharacter(UChar32) const;
     
    226228    PassRefPtr<Font> platformCreateScaledFont(const FontDescription&, float scaleFactor) const;
    227229
    228     float platformWidthForGlyph(Glyph) const;
    229     FloatRect platformBoundsForGlyph(Glyph) const;
    230 
    231230    void removeFromSystemFallbackCache();
    232 
    233     friend RefPtr<GlyphPage> createAndFillGlyphPage(unsigned pageNumber, const Font*);
    234231
    235232#if PLATFORM(WIN)
     
    250247    mutable HashMap<unsigned, RefPtr<GlyphPage>> m_glyphPages;
    251248    mutable std::unique_ptr<GlyphMetricsMap<FloatRect>> m_glyphToBoundsMap;
    252 
    253     bool m_treatAsFixedPitch { false };
    254     bool m_isCustomFont { false }; // Whether or not we are custom font loaded via @font-face
    255     bool m_isLoading { false }; // Whether or not this custom font is still in the act of loading.
    256 
    257     bool m_isTextOrientationFallback { false };
    258     bool m_isBrokenIdeographFallback { false };
     249    mutable GlyphMetricsMap<float> m_glyphToWidthMap;
     250
     251    bool m_treatAsFixedPitch;
     252    bool m_isCustomFont; // Whether or not we are custom font loaded via @font-face
     253    bool m_isLoading; // Whether or not this custom font is still in the act of loading.
     254
     255    bool m_isTextOrientationFallback;
     256    bool m_isBrokenIdeographFallback;
    259257
    260258    bool m_isUsedInSystemFallbackCache { false };
     
    264262    RefPtr<OpenTypeVerticalData> m_verticalData;
    265263#endif
    266     bool m_hasVerticalGlyphs { false };
    267 
    268     Glyph m_spaceGlyph { 0 };
    269     float m_spaceWidth { 0 };
    270     float m_adjustedSpaceWidth { 0 };
    271 
    272     Glyph m_zeroWidthSpaceGlyph { 0 };
    273 
    274     float m_glyphZeroWidth { 0 };
     264    bool m_hasVerticalGlyphs;
     265
     266    Glyph m_spaceGlyph;
     267    float m_spaceWidth;
     268    Glyph m_zeroGlyph;
     269    float m_adjustedSpaceWidth;
     270
     271    Glyph m_zeroWidthSpaceGlyph;
    275272
    276273    struct DerivedFontData {
     
    313310#endif
    314311#if PLATFORM(IOS)
    315     bool m_shouldNotBeUsedForArabic { false };
     312    bool m_shouldNotBeUsedForArabic;
    316313#endif
    317314};
     
    336333}
    337334
     335ALWAYS_INLINE float Font::widthForGlyph(Glyph glyph) const
     336{
     337    if (isZeroWidthSpaceGlyph(glyph))
     338        return 0;
     339
     340    float width = m_glyphToWidthMap.metricsForGlyph(glyph);
     341    if (width != cGlyphSizeUnknown)
     342        return width;
     343
     344    if (isSVGFont())
     345        width = m_svgData->widthForSVGGlyph(glyph, m_platformData.size());
     346#if ENABLE(OPENTYPE_VERTICAL)
     347    else if (m_verticalData)
     348#if USE(CG) || USE(CAIRO)
     349        width = m_verticalData->advanceHeight(this, glyph) + m_syntheticBoldOffset;
     350#else
     351        width = m_verticalData->advanceHeight(this, glyph);
     352#endif
     353#endif
     354    else
     355        width = platformWidthForGlyph(glyph);
     356
     357    m_glyphToWidthMap.setMetricsForGlyph(glyph, width);
     358    return width;
     359}
     360
    338361} // namespace WebCore
    339362
  • trunk/Source/WebCore/platform/graphics/FontCascade.cpp

    r180752 r180779  
    13351335    }
    13361336    // FIXME: Use glyph bounds once they make sense for vertical fonts.
    1337     return fontData->computeWidthForGlyph(glyph) / 2;
     1337    return fontData->widthForGlyph(glyph) / 2;
    13381338}
    13391339
  • trunk/Source/WebCore/platform/graphics/FontCascadeFonts.cpp

    r180752 r180779  
    388388
    389389        glyphData = glyphDataForNormalVariant(c, description);
    390         cachedPage->setGlyphDataForCharacter(c, glyphData);
     390        cachedPage->setGlyphDataForCharacter(c, glyphData.glyph, glyphData.font);
    391391    }
    392392    return glyphData;
  • trunk/Source/WebCore/platform/graphics/GlyphPage.h

    r180752 r180779  
    4545// character.
    4646struct GlyphData {
    47     GlyphData() { }
    48     GlyphData(Glyph glyph, float width, const Font* font)
    49         : glyph(glyph)
    50         , width(width)
    51         , font(font)
    52     { }
    53 
    54     Glyph glyph { 0 };
    55     float width { 0 };
    56     const Font* font { nullptr };
     47    GlyphData(Glyph g = 0, const Font* f = 0)
     48        : glyph(g)
     49        , font(f)
     50    {
     51    }
     52    Glyph glyph;
     53    const Font* font;
    5754};
    5855
     
    113110        ASSERT_WITH_SECURITY_IMPLICATION(index < size);
    114111        Glyph glyph = m_glyphs[index];
    115         float width = m_widths[index];
    116112        if (hasPerGlyphFontData())
    117             return { glyph, width, m_perGlyphFontData[index] };
    118         return { glyph, width, glyph ? m_fontForAllGlyphs : nullptr };
     113            return GlyphData(glyph, m_perGlyphFontData[index]);
     114        return GlyphData(glyph, glyph ? m_fontForAllGlyphs : 0);
    119115    }
    120116
     
    133129    }
    134130
    135     void setGlyphDataForCharacter(UChar32 c, const GlyphData& glyphData)
     131    void setGlyphDataForCharacter(UChar32 c, Glyph g, const Font* f)
    136132    {
    137         setGlyphDataForIndex(indexForCharacter(c), glyphData);
     133        setGlyphDataForIndex(indexForCharacter(c), g, f);
    138134    }
    139135
    140     void setGlyphDataForIndex(unsigned index, Glyph, const Font*);
    141 
    142     void setGlyphDataForIndex(unsigned index, const GlyphData& glyphData)
     136    void setGlyphDataForIndex(unsigned index, Glyph glyph, const Font* font)
    143137    {
    144138        ASSERT_WITH_SECURITY_IMPLICATION(index < size);
    145139        ASSERT(!m_isImmutable);
    146 
    147         m_glyphs[index] = glyphData.glyph;
    148         m_widths[index] = glyphData.width;
     140       
     141        m_glyphs[index] = glyph;
    149142
    150143        // GlyphPage getters will always return a null Font* for glyph #0 if there's no per-glyph font array.
    151144        if (hasPerGlyphFontData()) {
    152             m_perGlyphFontData[index] =  glyphData.glyph ?  glyphData.font : 0;
     145            m_perGlyphFontData[index] = glyph ? font : 0;
    153146            return;
    154147        }
    155148
    156149        // A single-font GlyphPage already assigned m_fontForAllGlyphs in the constructor.
    157         ASSERT(!glyphData.glyph || glyphData.font == m_fontForAllGlyphs);
     150        ASSERT(!glyph || font == m_fontForAllGlyphs);
     151    }
     152
     153    void setGlyphDataForIndex(unsigned index, const GlyphData& glyphData)
     154    {
     155        setGlyphDataForIndex(index, glyphData.glyph, glyphData.font);
    158156    }
    159157
     
    171169    {
    172170        memset(m_glyphs, 0, sizeof(m_glyphs));
    173         memset(m_widths, 0, sizeof(m_widths));
    174171        if (hasPerGlyphFontData())
    175172            memset(m_perGlyphFontData, 0, sizeof(Font*) * GlyphPage::size);
     
    179176    bool hasPerGlyphFontData() const { return !m_fontForAllGlyphs; }
    180177
    181     const Font* m_fontForAllGlyphs { nullptr };
     178    const Font* m_fontForAllGlyphs;
    182179    Glyph m_glyphs[size];
    183     float m_widths[size];
    184180
    185181    bool m_isImmutable { false };
  • trunk/Source/WebCore/platform/graphics/WidthIterator.cpp

    r180752 r180779  
    192192            width = m_font->tabWidth(*font, m_run.tabSize(), m_run.xPos() + m_runWidthSoFar + widthSinceLastRounding);
    193193        else {
    194             width = glyphData.width;
     194            width = font->widthForGlyph(glyph);
    195195
    196196            // SVG uses horizontalGlyphStretch(), when textLength is used to stretch/squeeze text.
  • trunk/Source/WebCore/platform/graphics/mac/ComplexTextController.cpp

    r180752 r180779  
    639639#if PLATFORM(IOS)
    640640            if (isEmoji && advance.width)
    641                 advance.width = font.computeWidthForGlyph(glyph);
     641                advance.width = font.widthForGlyph(glyph);
    642642#endif
    643643
  • trunk/Source/WebCore/platform/graphics/mac/ComplexTextControllerCoreText.mm

    r180752 r180779  
    164164    m_glyphsVector.fill(0, m_glyphCount);
    165165    m_glyphs = m_glyphsVector.data();
    166     m_advancesVector.fill(CGSizeMake(m_font.glyphZeroWidth(), 0), m_glyphCount);
     166    m_advancesVector.fill(CGSizeMake(m_font.widthForGlyph(0), 0), m_glyphCount);
    167167    m_advances = m_advancesVector.data();
    168168}
  • trunk/Source/WebCore/rendering/mathml/RenderMathMLOperator.cpp

    r180752 r180779  
    13441344float RenderMathMLOperator::advanceForGlyph(const GlyphData& data) const
    13451345{
    1346     // FIXME: MathML code synthesizes bad GlyphDatas.
    1347     return data.width ? data.width : data.font->computeWidthForGlyph(data.glyph);
     1346    return data.font->widthForGlyph(data.glyph);
    13481347}
    13491348
  • trunk/Source/WebCore/rendering/svg/SVGTextRunRenderingContext.cpp

    r180752 r180779  
    299299    SVGFontFaceElement* fontFaceElement;
    300300    svgFontAndFontFaceElementForFontData(&primaryFont, fontFaceElement, fontElement);
    301     auto missingGlyph = fontElement->missingGlyph();
    302     return { missingGlyph, primaryFont.computeWidthForGlyph(missingGlyph), &primaryFont };
     301    return GlyphData(fontElement->missingGlyph(), &primaryFont);
    303302}
    304303
  • trunk/Source/WebCore/svg/SVGFontData.cpp

    r180752 r180779  
    8080        // Fallback if x_heightAttr is not specified for the font element.
    8181        Glyph letterXGlyph = glyphPageZero->glyphDataForCharacter('x').glyph;
    82         xHeight = letterXGlyph ? font->computeWidthForGlyph(letterXGlyph) : 2 * ascent / 3;
     82        xHeight = letterXGlyph ? font->widthForGlyph(letterXGlyph) : 2 * ascent / 3;
    8383    }
    8484
     
    100100
    101101    // Calculate space width.
    102     auto spaceGlyphData = glyphPageZero->glyphDataForCharacter(' ');
    103     font->setSpaceGlyph(spaceGlyphData.glyph);
    104     font->setSpaceWidths(spaceGlyphData.width);
     102    Glyph spaceGlyph = glyphPageZero->glyphDataForCharacter(' ').glyph;
     103    font->setSpaceGlyph(spaceGlyph);
     104    font->setSpaceWidths(font->widthForGlyph(spaceGlyph));
    105105
    106106    // Estimate average character width.
    107     auto numeralZeroGlyphData = glyphPageZero->glyphDataForCharacter('0');
    108     font->setAvgCharWidth(numeralZeroGlyphData.glyph ? numeralZeroGlyphData.width : font->spaceWidth());
     107    Glyph numeralZeroGlyph = glyphPageZero->glyphDataForCharacter('0').glyph;
     108    font->setAvgCharWidth(numeralZeroGlyph ? font->widthForGlyph(numeralZeroGlyph) : font->spaceWidth());
    109109
    110110    // Estimate maximum character width.
    111     auto letterWGlyphData = glyphPageZero->glyphDataForCharacter('W');
    112     font->setMaxCharWidth(letterWGlyphData.glyph ? letterWGlyphData.width : ascent);
     111    Glyph letterWGlyph = glyphPageZero->glyphDataForCharacter('W').glyph;
     112    font->setMaxCharWidth(letterWGlyph ? font->widthForGlyph(letterWGlyph) : ascent);
    113113}
    114114
Note: See TracChangeset for help on using the changeset viewer.