Changeset 189539 in webkit


Ignore:
Timestamp:
Sep 9, 2015 5:26:08 AM (9 years ago)
Author:
Antti Koivisto
Message:

Split mixed font GlyphPage functionality to separate class
https://bugs.webkit.org/show_bug.cgi?id=148965

Reviewed by Myles Maxfield.

Currently GlyphPage class is used for both immutable single font case (in Font) and
for caching mixed font mappings (in FontCascadeFonts). It is cleaner to use separate
classed for these cases. This will also make future improvements easier.

  • platform/graphics/Font.cpp:

(WebCore::Font::~Font):
(WebCore::fillGlyphPage):
(WebCore::createAndFillGlyphPage):
(WebCore::Font::glyphPage):
(WebCore::Font::glyphForCharacter):
(WebCore::Font::glyphDataForCharacter):

  • platform/graphics/Font.h:
  • platform/graphics/FontCascadeFonts.cpp:

(WebCore::MixedFontGlyphPage::MixedFontGlyphPage):
(WebCore::MixedFontGlyphPage::glyphDataForCharacter):
(WebCore::MixedFontGlyphPage::setGlyphDataForCharacter):
(WebCore::MixedFontGlyphPage::setGlyphDataForIndex):

Mixed font pages are now an implementation detail of FontCascadeFonts.

(WebCore::FontCascadeFonts::GlyphPageCacheEntry::glyphDataForCharacter):
(WebCore::FontCascadeFonts::GlyphPageCacheEntry::setGlyphDataForCharacter):
(WebCore::FontCascadeFonts::GlyphPageCacheEntry::setSingleFontPage):

Cache entry is either shared single font GlyphPage or mutable MixedFontGlyphPage.

(WebCore::FontCascadeFonts::FontCascadeFonts):
(WebCore::FontCascadeFonts::glyphDataForCharacter):
(WebCore::FontCascadeFonts::pruneSystemFallbacks):

  • platform/graphics/FontCascadeFonts.h:

(WebCore::FontCascadeFonts::GlyphPageCacheEntry::isNull):
(WebCore::FontCascadeFonts::GlyphPageCacheEntry::isMixedFont):

  • platform/graphics/GlyphPage.h:

GlyphPage is now for single font mappings only.
Use regular allocation instead of variable size tricks.
It is always immutable after initialization (though currently a setter is still needed).

(WebCore::GlyphPage::create):
(WebCore::GlyphPage::~GlyphPage):
(WebCore::GlyphPage::count):
(WebCore::GlyphPage::indexForCharacter):
(WebCore::GlyphPage::glyphDataForCharacter):
(WebCore::GlyphPage::glyphForCharacter):
(WebCore::GlyphPage::glyphDataForIndex):
(WebCore::GlyphPage::glyphForIndex):
(WebCore::GlyphPage::setGlyphForIndex):
(WebCore::GlyphPage::font):
(WebCore::GlyphPage::GlyphPage):
(WebCore::GlyphPage::createForMixedFonts): Deleted.
(WebCore::GlyphPage::createCopyForMixedFonts): Deleted.
(WebCore::GlyphPage::createForSingleFont): Deleted.
(WebCore::GlyphPage::isImmutable): Deleted.
(WebCore::GlyphPage::setImmutable): Deleted.
(WebCore::GlyphPage::glyphAt): Deleted.
(WebCore::GlyphPage::fontForCharacter): Deleted.
(WebCore::GlyphPage::setGlyphDataForCharacter): Deleted.
(WebCore::GlyphPage::setGlyphDataForIndex): Deleted.
(WebCore::GlyphPage::hasPerGlyphFontData): Deleted.

  • platform/graphics/freetype/GlyphPageTreeNodeFreeType.cpp:

(WebCore::GlyphPage::fill):

  • platform/graphics/mac/GlyphPageMac.cpp:

(WebCore::GlyphPage::fill):

  • platform/graphics/opentype/OpenTypeVerticalData.cpp:

(WebCore::OpenTypeVerticalData::substituteWithVerticalGlyphs):

  • platform/graphics/win/GlyphPageTreeNodeCGWin.cpp:

(WebCore::GlyphPage::fill):

  • platform/graphics/win/GlyphPageTreeNodeCairoWin.cpp:

(WebCore::GlyphPage::fill):

  • svg/SVGFontData.cpp:

(WebCore::SVGFontData::applySVGGlyphSelection):
(WebCore::SVGFontData::fillSVGGlyphPage):
(WebCore::SVGFontData::fillBMPGlyphs):
(WebCore::SVGFontData::fillNonBMPGlyphs):

  • svg/SVGFontData.h:

(WebCore::SVGFontData::verticalAdvanceY):

Location:
trunk/Source/WebCore
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r189538 r189539  
     12015-09-09  Antti Koivisto  <antti@apple.com>
     2
     3        Split mixed font GlyphPage functionality to separate class
     4        https://bugs.webkit.org/show_bug.cgi?id=148965
     5
     6        Reviewed by Myles Maxfield.
     7
     8        Currently GlyphPage class is used for both immutable single font case (in Font) and
     9        for caching mixed font mappings (in FontCascadeFonts). It is cleaner to use separate
     10        classed for these cases. This will also make future improvements easier.
     11
     12        * platform/graphics/Font.cpp:
     13        (WebCore::Font::~Font):
     14        (WebCore::fillGlyphPage):
     15        (WebCore::createAndFillGlyphPage):
     16        (WebCore::Font::glyphPage):
     17        (WebCore::Font::glyphForCharacter):
     18        (WebCore::Font::glyphDataForCharacter):
     19        * platform/graphics/Font.h:
     20        * platform/graphics/FontCascadeFonts.cpp:
     21        (WebCore::MixedFontGlyphPage::MixedFontGlyphPage):
     22        (WebCore::MixedFontGlyphPage::glyphDataForCharacter):
     23        (WebCore::MixedFontGlyphPage::setGlyphDataForCharacter):
     24        (WebCore::MixedFontGlyphPage::setGlyphDataForIndex):
     25
     26            Mixed font pages are now an implementation detail of FontCascadeFonts.
     27
     28        (WebCore::FontCascadeFonts::GlyphPageCacheEntry::glyphDataForCharacter):
     29        (WebCore::FontCascadeFonts::GlyphPageCacheEntry::setGlyphDataForCharacter):
     30        (WebCore::FontCascadeFonts::GlyphPageCacheEntry::setSingleFontPage):
     31
     32            Cache entry is either shared single font GlyphPage or mutable MixedFontGlyphPage.
     33
     34        (WebCore::FontCascadeFonts::FontCascadeFonts):
     35        (WebCore::FontCascadeFonts::glyphDataForCharacter):
     36        (WebCore::FontCascadeFonts::pruneSystemFallbacks):
     37        * platform/graphics/FontCascadeFonts.h:
     38        (WebCore::FontCascadeFonts::GlyphPageCacheEntry::isNull):
     39        (WebCore::FontCascadeFonts::GlyphPageCacheEntry::isMixedFont):
     40        * platform/graphics/GlyphPage.h:
     41
     42            GlyphPage is now for single font mappings only.
     43            Use regular allocation instead of variable size tricks.
     44            It is always immutable after initialization (though currently a setter is still needed).
     45
     46        (WebCore::GlyphPage::create):
     47        (WebCore::GlyphPage::~GlyphPage):
     48        (WebCore::GlyphPage::count):
     49        (WebCore::GlyphPage::indexForCharacter):
     50        (WebCore::GlyphPage::glyphDataForCharacter):
     51        (WebCore::GlyphPage::glyphForCharacter):
     52        (WebCore::GlyphPage::glyphDataForIndex):
     53        (WebCore::GlyphPage::glyphForIndex):
     54        (WebCore::GlyphPage::setGlyphForIndex):
     55        (WebCore::GlyphPage::font):
     56        (WebCore::GlyphPage::GlyphPage):
     57        (WebCore::GlyphPage::createForMixedFonts): Deleted.
     58        (WebCore::GlyphPage::createCopyForMixedFonts): Deleted.
     59        (WebCore::GlyphPage::createForSingleFont): Deleted.
     60        (WebCore::GlyphPage::isImmutable): Deleted.
     61        (WebCore::GlyphPage::setImmutable): Deleted.
     62        (WebCore::GlyphPage::glyphAt): Deleted.
     63        (WebCore::GlyphPage::fontForCharacter): Deleted.
     64        (WebCore::GlyphPage::setGlyphDataForCharacter): Deleted.
     65        (WebCore::GlyphPage::setGlyphDataForIndex): Deleted.
     66        (WebCore::GlyphPage::hasPerGlyphFontData): Deleted.
     67        * platform/graphics/freetype/GlyphPageTreeNodeFreeType.cpp:
     68        (WebCore::GlyphPage::fill):
     69        * platform/graphics/mac/GlyphPageMac.cpp:
     70        (WebCore::GlyphPage::fill):
     71        * platform/graphics/opentype/OpenTypeVerticalData.cpp:
     72        (WebCore::OpenTypeVerticalData::substituteWithVerticalGlyphs):
     73        * platform/graphics/win/GlyphPageTreeNodeCGWin.cpp:
     74        (WebCore::GlyphPage::fill):
     75        * platform/graphics/win/GlyphPageTreeNodeCairoWin.cpp:
     76        (WebCore::GlyphPage::fill):
     77        * svg/SVGFontData.cpp:
     78        (WebCore::SVGFontData::applySVGGlyphSelection):
     79        (WebCore::SVGFontData::fillSVGGlyphPage):
     80        (WebCore::SVGFontData::fillBMPGlyphs):
     81        (WebCore::SVGFontData::fillNonBMPGlyphs):
     82        * svg/SVGFontData.h:
     83        (WebCore::SVGFontData::verticalAdvanceY):
     84
    1852015-09-09  Manuel Rego Casasnovas  <rego@igalia.com>
    286
  • trunk/Source/WebCore/platform/graphics/Font.cpp

    r189466 r189539  
    150150}
    151151
    152 static bool fillGlyphPage(GlyphPage& pageToFill, UChar* buffer, unsigned bufferLength, const Font* font)
     152static bool fillGlyphPage(GlyphPage& pageToFill, UChar* buffer, unsigned bufferLength, const Font& font)
    153153{
    154154#if ENABLE(SVG_FONTS)
    155     if (auto* svgData = font->svgData())
    156         return svgData->fillSVGGlyphPage(&pageToFill, buffer, bufferLength, font);
    157 #endif
    158     bool hasGlyphs = pageToFill.fill(buffer, bufferLength, font);
     155    if (auto* svgData = font.svgData())
     156        return svgData->fillSVGGlyphPage(&pageToFill, buffer, bufferLength);
     157#endif
     158    bool hasGlyphs = pageToFill.fill(buffer, bufferLength, &font);
    159159#if ENABLE(OPENTYPE_VERTICAL)
    160     if (hasGlyphs && font->verticalData())
    161         font->verticalData()->substituteWithVerticalGlyphs(font, &pageToFill);
     160    if (hasGlyphs && font.verticalData())
     161        font.verticalData()->substituteWithVerticalGlyphs(&font, &pageToFill);
    162162#endif
    163163    return hasGlyphs;
    164164}
    165165
    166 static RefPtr<GlyphPage> createAndFillGlyphPage(unsigned pageNumber, const Font* font)
     166static RefPtr<GlyphPage> createAndFillGlyphPage(unsigned pageNumber, const Font& font)
    167167{
    168168#if PLATFORM(IOS)
     
    170170    // Once we have the fix for <rdar://problem/9823975> then remove this code together with Font::shouldNotBeUsedForArabic()
    171171    // in <rdar://problem/12096835>.
    172     if (pageNumber == 6 && font->shouldNotBeUsedForArabic())
     172    if (pageNumber == 6 && font.shouldNotBeUsedForArabic())
    173173        return nullptr;
    174174#endif
     
    227227    // Success is not guaranteed. For example, Times fails to fill page 260, giving glyph data
    228228    // for only 128 out of 256 characters.
    229     RefPtr<GlyphPage> glyphPage = GlyphPage::createForSingleFont(font);
    230 
    231     bool haveGlyphs = fillGlyphPage(*glyphPage, buffer, bufferLength, font);
     229    Ref<GlyphPage> glyphPage = GlyphPage::create(font);
     230
     231    bool haveGlyphs = fillGlyphPage(glyphPage, buffer, bufferLength, font);
    232232    if (!haveGlyphs)
    233233        return nullptr;
    234234
    235     glyphPage->setImmutable();
    236     return glyphPage;
     235    return WTF::move(glyphPage);
    237236}
    238237
     
    241240    if (!pageNumber) {
    242241        if (!m_glyphPageZero)
    243             m_glyphPageZero = createAndFillGlyphPage(0, this);
     242            m_glyphPageZero = createAndFillGlyphPage(0, *this);
    244243        return m_glyphPageZero.get();
    245244    }
    246245    auto addResult = m_glyphPages.add(pageNumber, nullptr);
    247246    if (addResult.isNewEntry)
    248         addResult.iterator->value = createAndFillGlyphPage(pageNumber, this);
     247        addResult.iterator->value = createAndFillGlyphPage(pageNumber, *this);
    249248
    250249    return addResult.iterator->value.get();
     
    256255    if (!page)
    257256        return 0;
    258     return page->glyphAt(character % GlyphPage::size);
     257    return page->glyphForCharacter(character);
    259258}
    260259
  • trunk/Source/WebCore/platform/graphics/Font.h

    r189465 r189539  
    7777        virtual void initializeFont(Font*, float fontSize) = 0;
    7878        virtual float widthForSVGGlyph(Glyph, float fontSize) const = 0;
    79         virtual bool fillSVGGlyphPage(GlyphPage*, UChar* buffer, unsigned bufferLength, const Font*) const = 0;
     79        virtual bool fillSVGGlyphPage(GlyphPage*, UChar* buffer, unsigned bufferLength) const = 0;
    8080    };
    8181
  • trunk/Source/WebCore/platform/graphics/FontCascadeFonts.cpp

    r187569 r189539  
    3636namespace WebCore {
    3737
     38class MixedFontGlyphPage {
     39    WTF_MAKE_FAST_ALLOCATED;
     40public:
     41    MixedFontGlyphPage(const GlyphPage* initialPage)
     42    {
     43        if (initialPage) {
     44            for (unsigned i = 0; i < GlyphPage::size; ++i)
     45                setGlyphDataForIndex(i, initialPage->glyphDataForIndex(i));
     46        }
     47    }
     48
     49    GlyphData glyphDataForCharacter(UChar32 c) const
     50    {
     51        unsigned index = GlyphPage::indexForCharacter(c);
     52        ASSERT_WITH_SECURITY_IMPLICATION(index < GlyphPage::size);
     53        return { m_glyphs[index], m_fonts[index] };
     54    }
     55
     56    void setGlyphDataForCharacter(UChar32 c, GlyphData glyphData)
     57    {
     58        setGlyphDataForIndex(GlyphPage::indexForCharacter(c), glyphData);
     59    }
     60
     61private:
     62    void setGlyphDataForIndex(unsigned index, const GlyphData& glyphData)
     63    {
     64        ASSERT_WITH_SECURITY_IMPLICATION(index < GlyphPage::size);
     65        m_glyphs[index] = glyphData.glyph;
     66        m_fonts[index] = glyphData.font;
     67    }
     68
     69    Glyph m_glyphs[GlyphPage::size] { };
     70    const Font* m_fonts[GlyphPage::size] { };
     71};
     72
     73GlyphData FontCascadeFonts::GlyphPageCacheEntry::glyphDataForCharacter(UChar32 character)
     74{
     75    ASSERT(!(m_singleFont && m_mixedFont));
     76    if (m_singleFont)
     77        return m_singleFont->glyphDataForCharacter(character);
     78    if (m_mixedFont)
     79        return m_mixedFont->glyphDataForCharacter(character);
     80    return 0;
     81}
     82
     83void FontCascadeFonts::GlyphPageCacheEntry::setGlyphDataForCharacter(UChar32 character, GlyphData glyphData)
     84{
     85    ASSERT(!glyphDataForCharacter(character).glyph);
     86    if (!m_mixedFont) {
     87        m_mixedFont = std::make_unique<MixedFontGlyphPage>(m_singleFont.get());
     88        m_singleFont = nullptr;
     89    }
     90    m_mixedFont->setGlyphDataForCharacter(character, glyphData);
     91}
     92
     93void FontCascadeFonts::GlyphPageCacheEntry::setSingleFontPage(RefPtr<GlyphPage>&& page)
     94{
     95    ASSERT(isNull());
     96    m_singleFont = page;
     97}
    3898
    3999FontCascadeFonts::FontCascadeFonts(RefPtr<FontSelector>&& fontSelector)
     
    372432    const unsigned pageNumber = c / GlyphPage::size;
    373433
    374     RefPtr<GlyphPage>& cachedPage = pageNumber ? m_cachedPages.add(pageNumber, nullptr).iterator->value : m_cachedPageZero;
    375     if (!cachedPage)
    376         cachedPage = glyphPageFromFontRanges(pageNumber, realizeFallbackRangesAt(description, 0));
    377 
    378     GlyphData glyphData = cachedPage ? cachedPage->glyphDataForCharacter(c) : GlyphData();
     434    auto& cacheEntry = pageNumber ? m_cachedPages.add(pageNumber, GlyphPageCacheEntry()).iterator->value : m_cachedPageZero;
     435
     436    // Initialize cache with a full page of glyph mappings from a single font.
     437    if (cacheEntry.isNull())
     438        cacheEntry.setSingleFontPage(glyphPageFromFontRanges(pageNumber, realizeFallbackRangesAt(description, 0)));
     439
     440    GlyphData glyphData = cacheEntry.glyphDataForCharacter(c);
    379441    if (!glyphData.glyph) {
    380         if (!cachedPage)
    381             cachedPage = GlyphPage::createForMixedFonts();
    382         else if (cachedPage->isImmutable())
    383             cachedPage = GlyphPage::createCopyForMixedFonts(*cachedPage);
    384 
     442        // No glyph, resolve per-character.
    385443        glyphData = glyphDataForNormalVariant(c, description);
    386         cachedPage->setGlyphDataForCharacter(c, glyphData.glyph, glyphData.font);
    387     }
     444        // Cache the results.
     445        cacheEntry.setGlyphDataForCharacter(c, glyphData);
     446    }
     447
    388448    return glyphData;
    389449}
     
    394454        return;
    395455    // Mutable glyph pages may reference fallback fonts.
    396     if (m_cachedPageZero && !m_cachedPageZero->isImmutable())
    397         m_cachedPageZero = nullptr;
     456    if (m_cachedPageZero.isMixedFont())
     457        m_cachedPageZero = { };
    398458    m_cachedPages.removeIf([](decltype(m_cachedPages)::KeyValuePairType& keyAndValue) {
    399         return !keyAndValue.value->isImmutable();
     459        return keyAndValue.value.isMixedFont();
    400460    });
    401461    m_systemFallbackFontSet.clear();
  • trunk/Source/WebCore/platform/graphics/FontCascadeFonts.h

    r187569 r189539  
    3636namespace WebCore {
    3737
    38 class GraphicsContext;
    39 class IntRect;
    4038class FontDescription;
    4139class FontPlatformData;
    4240class FontSelector;
     41class GraphicsContext;
     42class IntRect;
     43class MixedFontGlyphPage;
    4344
    4445class FontCascadeFonts : public RefCounted<FontCascadeFonts> {
     
    8384    unsigned m_lastRealizedFallbackIndex { 0 };
    8485
    85     RefPtr<GlyphPage> m_cachedPageZero;
    86     HashMap<int, RefPtr<GlyphPage>> m_cachedPages;
     86    class GlyphPageCacheEntry {
     87    public:
     88        GlyphData glyphDataForCharacter(UChar32);
     89
     90        void setSingleFontPage(RefPtr<GlyphPage>&&);
     91        void setGlyphDataForCharacter(UChar32, GlyphData);
     92
     93        bool isNull() const { return !m_singleFont && !m_mixedFont; }
     94        bool isMixedFont() const { return !!m_mixedFont; }
     95   
     96    private:
     97        // Only one of these is non-null.
     98        RefPtr<GlyphPage> m_singleFont;
     99        std::unique_ptr<MixedFontGlyphPage> m_mixedFont;
     100    };
     101
     102    GlyphPageCacheEntry m_cachedPageZero;
     103    HashMap<int, GlyphPageCacheEntry> m_cachedPages;
    87104
    88105    HashSet<RefPtr<Font>> m_systemFallbackFontSet;
  • trunk/Source/WebCore/platform/graphics/GlyphPage.h

    r189466 r189539  
    5454};
    5555
    56 #if COMPILER(MSVC)
    57 #pragma warning(push)
    58 #pragma warning(disable: 4200) // Disable "zero-sized array in struct/union" warning
    59 #endif
    60 
    6156// A GlyphPage contains a fixed-size set of GlyphData mappings for a contiguous
    6257// range of characters in the Unicode code space. GlyphPages are indexed
    6358// starting from 0 and incrementing for each 256 glyphs.
    64 //
    65 // One page may actually include glyphs from other fonts if the characters are
    66 // missing in the primary font.
    6759class GlyphPage : public RefCounted<GlyphPage> {
    6860public:
    69     static PassRefPtr<GlyphPage> createForMixedFonts()
     61    static Ref<GlyphPage> create(const Font& font)
    7062    {
    71         void* slot = fastMalloc(sizeof(GlyphPage) + sizeof(Font*) * GlyphPage::size);
    72         return adoptRef(new (NotNull, slot) GlyphPage(nullptr));
    73     }
    74 
    75     static PassRefPtr<GlyphPage> createCopyForMixedFonts(const GlyphPage& original)
    76     {
    77         RefPtr<GlyphPage> page = createForMixedFonts();
    78         for (unsigned i = 0; i < GlyphPage::size; ++i)
    79             page->setGlyphDataForIndex(i, original.glyphDataForIndex(i));
    80         return page.release();
    81     }
    82 
    83     static PassRefPtr<GlyphPage> createForSingleFont(const Font* font)
    84     {
    85         ASSERT(font);
    86         return adoptRef(new GlyphPage(font));
     63        return adoptRef(*new GlyphPage(font));
    8764    }
    8865
     
    9269    }
    9370
    94     bool isImmutable() const { return m_isImmutable; }
    95     void setImmutable() { m_isImmutable = true; }
    96 
    9771    static unsigned count() { return s_count; }
    9872
    9973    static const size_t size = 256; // Covers Latin-1 in a single page.
    100     static_assert((!(0xD800 % size)) && (!(0xDC00 % size)) && (!(0xE000 % size)), "GlyphPages must never straddle code-unit length boundaries");
    10174    static unsigned indexForCharacter(UChar32 c) { return c % GlyphPage::size; }
    10275
    103     ALWAYS_INLINE GlyphData glyphDataForCharacter(UChar32 c) const
     76    GlyphData glyphDataForCharacter(UChar32 c) const
    10477    {
    10578        return glyphDataForIndex(indexForCharacter(c));
    10679    }
    10780
    108     ALWAYS_INLINE GlyphData glyphDataForIndex(unsigned index) const
     81    Glyph glyphForCharacter(UChar32 c) const
    10982    {
    110         ASSERT_WITH_SECURITY_IMPLICATION(index < size);
    111         Glyph glyph = m_glyphs[index];
    112         if (hasPerGlyphFontData())
    113             return GlyphData(glyph, m_perGlyphFontData[index]);
    114         return GlyphData(glyph, glyph ? m_fontForAllGlyphs : 0);
     83        return glyphForIndex(indexForCharacter(c));
    11584    }
    11685
    117     ALWAYS_INLINE Glyph glyphAt(unsigned index) const
     86    GlyphData glyphDataForIndex(unsigned index) const
     87    {
     88        Glyph glyph = glyphForIndex(index);
     89        return GlyphData(glyph, glyph ? &m_font : nullptr);
     90    }
     91
     92    Glyph glyphForIndex(unsigned index) const
    11893    {
    11994        ASSERT_WITH_SECURITY_IMPLICATION(index < size);
     
    12196    }
    12297
    123     ALWAYS_INLINE const Font* fontForCharacter(UChar32 c) const
     98    // FIXME: Pages are immutable after initialization. This should be private.
     99    void setGlyphForIndex(unsigned index, Glyph glyph)
    124100    {
    125         unsigned index = indexForCharacter(c);
    126         if (hasPerGlyphFontData())
    127             return m_perGlyphFontData[index];
    128         return m_glyphs[index] ? m_fontForAllGlyphs : 0;
     101        ASSERT_WITH_SECURITY_IMPLICATION(index < size);
     102        m_glyphs[index] = glyph;
    129103    }
    130104
    131     void setGlyphDataForCharacter(UChar32 c, Glyph g, const Font* f)
     105    const Font& font() const
    132106    {
    133         setGlyphDataForIndex(indexForCharacter(c), g, f);
    134     }
    135 
    136     void setGlyphDataForIndex(unsigned index, Glyph glyph, const Font* font)
    137     {
    138         ASSERT_WITH_SECURITY_IMPLICATION(index < size);
    139         ASSERT(!m_isImmutable);
    140        
    141         m_glyphs[index] = glyph;
    142 
    143         // GlyphPage getters will always return a null Font* for glyph #0 if there's no per-glyph font array.
    144         if (hasPerGlyphFontData()) {
    145             m_perGlyphFontData[index] = glyph ? font : 0;
    146             return;
    147         }
    148 
    149         // A single-font GlyphPage already assigned m_fontForAllGlyphs in the constructor.
    150         ASSERT(!glyph || font == m_fontForAllGlyphs);
    151     }
    152 
    153     void setGlyphDataForIndex(unsigned index, const GlyphData& glyphData)
    154     {
    155         setGlyphDataForIndex(index, glyphData.glyph, glyphData.font);
     107        return m_font;
    156108    }
    157109
     
    160112
    161113private:
    162     explicit GlyphPage(const Font* fontForAllGlyphs)
    163         : m_fontForAllGlyphs(fontForAllGlyphs)
     114    explicit GlyphPage(const Font& font)
     115        : m_font(font)
    164116    {
    165         memset(m_glyphs, 0, sizeof(m_glyphs));
    166         if (hasPerGlyphFontData())
    167             memset(m_perGlyphFontData, 0, sizeof(Font*) * GlyphPage::size);
    168117        ++s_count;
    169118    }
    170119
    171     bool hasPerGlyphFontData() const { return !m_fontForAllGlyphs; }
    172 
    173     const Font* m_fontForAllGlyphs;
    174     Glyph m_glyphs[size];
    175 
    176     bool m_isImmutable { false };
    177     // NOTE: This array has (GlyphPage::size) elements if m_fontForAllGlyphs is null.
    178     const Font* m_perGlyphFontData[0];
     120    const Font& m_font;
     121    Glyph m_glyphs[size] { };
    179122
    180123    WEBCORE_EXPORT static unsigned s_count;
    181124};
    182125
    183 #if COMPILER(MSVC)
    184 #pragma warning(pop)
    185 #endif
    186 
    187126} // namespace WebCore
    188127
  • trunk/Source/WebCore/platform/graphics/freetype/GlyphPageTreeNodeFreeType.cpp

    r189465 r189539  
    5858        Glyph glyph = FcFreeTypeCharIndex(face, character);
    5959        if (!glyph)
    60             setGlyphDataForIndex(i, 0, 0);
     60            setGlyphForIndex(i, 0);
    6161        else {
    62             setGlyphDataForIndex(i, glyph, fontData);
     62            setGlyphForIndex(i, glyph);
    6363            haveGlyphs = true;
    6464        }
  • trunk/Source/WebCore/platform/graphics/mac/GlyphPageMac.cpp

    r189466 r189539  
    6161bool GlyphPage::fill(UChar* buffer, unsigned bufferLength, const Font* fontData)
    6262{
    63     bool haveGlyphs = false;
     63    ASSERT(fontData == &font());
     64    ASSERT(bufferLength == GlyphPage::size || bufferLength == 2 * GlyphPage::size);
    6465
    6566    Vector<CGGlyph, 512> glyphs(bufferLength);
     67    unsigned glyphStep;
    6668    if (!shouldUseCoreText(buffer, bufferLength, fontData)) {
    6769        // We pass in either 256 or 512 UTF-16 characters: 256 for U+FFFF and less, 512 (double character surrogates)
     
    7072        // this should not happen as the only time we pass in 512 characters is when they are surrogates.
    7173        CGFontGetGlyphsForUnichars(fontData->platformData().cgFont(), buffer, glyphs.data(), bufferLength);
    72         for (unsigned i = 0; i < GlyphPage::size; ++i) {
    73             if (!glyphs[i])
    74                 setGlyphDataForIndex(i, 0, 0);
    75             else {
    76                 setGlyphDataForIndex(i, glyphs[i], fontData);
    77                 haveGlyphs = true;
    78             }
    79         }
     74        glyphStep = 1;
    8075    } else {
    8176        // Because we know the implementation of shouldUseCoreText(), if the font isn't for text combine and it isn't a system font,
     
    8580        else
    8681            CTFontGetVerticalGlyphsForCharacters(fontData->platformData().ctFont(), buffer, glyphs.data(), bufferLength);
     82
    8783        // When buffer consists of surrogate pairs, CTFontGetVerticalGlyphsForCharacters and CTFontGetGlyphsForCharacters
    8884        // place the glyphs at indices corresponding to the first character of each pair.
    89         ASSERT(bufferLength == GlyphPage::size || bufferLength == 2 * GlyphPage::size);
    90         unsigned glyphStep = bufferLength / GlyphPage::size;
    91         for (unsigned i = 0; i < GlyphPage::size; ++i) {
    92             if (!glyphs[i * glyphStep])
    93                 setGlyphDataForIndex(i, 0, 0);
    94             else {
    95                 setGlyphDataForIndex(i, glyphs[i * glyphStep], fontData);
    96                 haveGlyphs = true;
    97             }
     85        glyphStep = bufferLength / GlyphPage::size;
     86    }
     87
     88    bool haveGlyphs = false;
     89    for (unsigned i = 0; i < GlyphPage::size; ++i) {
     90        if (glyphs[i * glyphStep]) {
     91            setGlyphForIndex(i, glyphs[i * glyphStep]);
     92            haveGlyphs = true;
    9893        }
    9994    }
    100 
    10195    return haveGlyphs;
    10296}
  • trunk/Source/WebCore/platform/graphics/opentype/OpenTypeVerticalData.cpp

    r189465 r189539  
    543543
    544544    for (unsigned index = 0; index < GlyphPage::size; ++index) {
    545         Glyph glyph = glyphPage->glyphAt(index);
     545        Glyph glyph = glyphPage->glyphForIndex(index);
    546546        if (glyph) {
    547             ASSERT(glyphPage->glyphDataForIndex(index).font == font);
     547            ASSERT_UNUSED(font, &glyphPage->font() == font);
    548548            Glyph to = map.get(glyph);
    549549            if (to)
    550                 glyphPage->setGlyphDataForIndex(index, to, font);
     550                glyphPage->setGlyphForIndex(index, to);
    551551        }
    552552    }
  • trunk/Source/WebCore/platform/graphics/win/GlyphPageTreeNodeCGWin.cpp

    r189465 r189539  
    4848        Glyph glyph = localGlyphBuffer[i];
    4949        if (!glyph)
    50             setGlyphDataForIndex(i, 0, 0);
     50            setGlyphForIndex(i, 0);
    5151        else {
    52             setGlyphDataForIndex(i, glyph, fontData);
     52            setGlyphForIndex(i, glyph);
    5353            haveGlyphs = true;
    5454        }
  • trunk/Source/WebCore/platform/graphics/win/GlyphPageTreeNodeCairoWin.cpp

    r189465 r189539  
    5555            Glyph glyph = localGlyphBuffer[i];
    5656            if (glyph == 0xffff)
    57                 setGlyphDataForIndex(i, 0, 0);
     57                setGlyphForIndex(i, 0);
    5858            else {
    59                 setGlyphDataForIndex(i, glyph, fontData);
     59                setGlyphForIndex(i, glyph);
    6060                haveGlyphs = true;
    6161            }
  • trunk/Source/WebCore/svg/SVGFontData.cpp

    r189465 r189539  
    205205}
    206206
    207 bool SVGFontData::fillSVGGlyphPage(GlyphPage* pageToFill, UChar* buffer, unsigned bufferLength, const Font* font) const
    208 {
    209     ASSERT(font->isCustomFont());
    210     ASSERT(font->isSVGFont());
    211 
     207bool SVGFontData::fillSVGGlyphPage(GlyphPage* pageToFill, UChar* buffer, unsigned bufferLength) const
     208{
    212209    SVGFontFaceElement* fontFaceElement = this->svgFontFaceElement();
    213210    ASSERT(fontFaceElement);
     
    217214
    218215    if (bufferLength == GlyphPage::size)
    219         return fillBMPGlyphs(fontElement, pageToFill, buffer, font);
     216        return fillBMPGlyphs(fontElement, pageToFill, buffer);
    220217
    221218    ASSERT(bufferLength == 2 * GlyphPage::size);
    222     return fillNonBMPGlyphs(fontElement, pageToFill, buffer, font);
    223 }
    224 
    225 bool SVGFontData::fillBMPGlyphs(SVGFontElement* fontElement, GlyphPage* pageToFill, UChar* buffer, const Font* font) const
     219    return fillNonBMPGlyphs(fontElement, pageToFill, buffer);
     220}
     221
     222bool SVGFontData::fillBMPGlyphs(SVGFontElement* fontElement, GlyphPage* pageToFill, UChar* buffer) const
    226223{
    227224    bool haveGlyphs = false;
     
    231228        fontElement->collectGlyphsForString(lookupString, glyphs);
    232229        if (glyphs.isEmpty()) {
    233             pageToFill->setGlyphDataForIndex(i, 0, 0);
     230            pageToFill->setGlyphForIndex(i, 0);
    234231            continue;
    235232        }
     
    240237        // only possible within the context of a string (eg. arabic form matching).
    241238        haveGlyphs = true;
    242         pageToFill->setGlyphDataForIndex(i, glyphs.first().tableEntry, font);
     239        pageToFill->setGlyphForIndex(i, glyphs.first().tableEntry);
    243240        glyphs.clear();
    244241    }
     
    247244}
    248245
    249 bool SVGFontData::fillNonBMPGlyphs(SVGFontElement* fontElement, GlyphPage* pageToFill, UChar* buffer, const Font* font) const
     246bool SVGFontData::fillNonBMPGlyphs(SVGFontElement* fontElement, GlyphPage* pageToFill, UChar* buffer) const
    250247{
    251248    bool haveGlyphs = false;
     
    256253        fontElement->collectGlyphsForString(lookupString, glyphs);
    257254        if (glyphs.isEmpty()) {
    258             pageToFill->setGlyphDataForIndex(i, 0, 0);
     255            pageToFill->setGlyphForIndex(i, 0);
    259256            continue;
    260257        }
     
    265262        // only possible within the context of a string (eg. arabic form matching).
    266263        haveGlyphs = true;
    267         pageToFill->setGlyphDataForIndex(i, glyphs.first().tableEntry, font);
     264        pageToFill->setGlyphForIndex(i, glyphs.first().tableEntry);
    268265        glyphs.clear();
    269266    }
  • trunk/Source/WebCore/svg/SVGFontData.h

    r189465 r189539  
    3636    virtual void initializeFont(Font*, float fontSize) override;
    3737    virtual float widthForSVGGlyph(Glyph, float fontSize) const override;
    38     virtual bool fillSVGGlyphPage(GlyphPage*, UChar* buffer, unsigned bufferLength, const Font*) const override;
     38    virtual bool fillSVGGlyphPage(GlyphPage*, UChar* buffer, unsigned bufferLength) const override;
    3939
    4040    bool applySVGGlyphSelection(WidthIterator&, GlyphData&, bool mirror, int currentCharacter, unsigned& advanceLength, String& normalizedSpacesStringCache) const;
     
    5151
    5252private:
    53     bool fillBMPGlyphs(SVGFontElement*, GlyphPage*, UChar* buffer, const Font*) const;
    54     bool fillNonBMPGlyphs(SVGFontElement*, GlyphPage*, UChar* buffer, const Font*) const;
     53    bool fillBMPGlyphs(SVGFontElement*, GlyphPage*, UChar* buffer) const;
     54    bool fillNonBMPGlyphs(SVGFontElement*, GlyphPage*, UChar* buffer) const;
    5555
    5656    bool applyTransforms(GlyphBufferGlyph*, GlyphBufferAdvance*, size_t, TypesettingFeatures) const = delete;
Note: See TracChangeset for help on using the changeset viewer.