GlyphData FontCascadeFonts::glyphDataForCharacter(UChar32 c, const FontDescription& description, FontVariant variant) { ASSERT(isMainThread()); ASSERT(variant != AutoVariant); if (variant != NormalVariant) return glyphDataForVariant(c, description, variant, 0); const unsigned pageNumber = c / GlyphPage::size; RefPtr<GlyphPage>& cachedPage = pageNumber ? m_cachedPages.add(pageNumber, nullptr).iterator->value : m_cachedPageZero; if (!cachedPage) cachedPage = glyphPageFromFontRanges(pageNumber, realizeFallbackRangesAt(description, 0)); GlyphData glyphData = cachedPage ? cachedPage->glyphDataForCharacter(c) : GlyphData(); if (!glyphData.glyph) { if (!cachedPage) cachedPage = GlyphPage::createForMixedFonts(); else if (cachedPage->isImmutable()) cachedPage = GlyphPage::createCopyForMixedFonts(*cachedPage); glyphData = glyphDataForNormalVariant(c, description); cachedPage->setGlyphDataForCharacter(c, glyphData.glyph, glyphData.font); } return glyphData; }
GlyphData FontCascadeFonts::glyphDataForCharacter(UChar32 c, const FontCascadeDescription& description, FontVariant variant) { ASSERT(isMainThread()); ASSERT(variant != AutoVariant); if (variant != NormalVariant) return glyphDataForVariant(c, description, variant, 0); const unsigned pageNumber = c / GlyphPage::size; auto& cacheEntry = pageNumber ? m_cachedPages.add(pageNumber, GlyphPageCacheEntry()).iterator->value : m_cachedPageZero; // Initialize cache with a full page of glyph mappings from a single font. if (cacheEntry.isNull()) cacheEntry.setSingleFontPage(glyphPageFromFontRanges(pageNumber, realizeFallbackRangesAt(description, 0))); GlyphData glyphData = cacheEntry.glyphDataForCharacter(c); if (!glyphData.glyph) { // No glyph, resolve per-character. glyphData = glyphDataForNormalVariant(c, description); // Cache the results. cacheEntry.setGlyphDataForCharacter(c, glyphData); } return glyphData; }