const FontData* FontCache::getFontData(const Font& font, int& familyIndex) { FontPlatformData* result = 0; int startIndex = familyIndex; const FontFamily* startFamily = &font.fontDescription().family(); for (int i = 0; startFamily && i < startIndex; i++) startFamily = startFamily->next(); const FontFamily* currFamily = startFamily; while (currFamily && !result) { familyIndex++; if (currFamily->family().length()) result = getCachedFontPlatformData(font.fontDescription(), currFamily->family()); currFamily = currFamily->next(); } if (!currFamily) familyIndex = cAllFamiliesScanned; if (!result) // We didn't find a font. Try to find a similar font using our own specific knowledge about our platform. // For example on OS X, we know to map any families containing the words Arabic, Pashto, or Urdu to the // Geeza Pro font. result = getSimilarFontPlatformData(font); if (!result && startIndex == 0) // We still don't have a result. Hand back our last resort fallback font. We only do the last resort fallback // when trying to find the primary font. Otherwise our fallback will rely on the actual characters used. result = getLastResortFallbackFont(font); // Now that we have a result, we need to go from FontPlatformData -> FontData. return getCachedFontData(result); }
PassRefPtr<SimpleFontData> FontCache::getFontDataForCharacters(const Font& font, const UChar* characters, int length) { RefPtr<SimpleFontData> fontData = 0; fontData = getCachedFontData(font.fontDescription(), font.family().family(), false, DoNotRetain); if (!fontData->containsCharacters(characters, length)) fontData = getSimilarFontPlatformData(font); if (!fontData->containsCharacters(characters, length)) fontData = getLastResortFallbackFont(font.fontDescription()); ASSERT(fontData); return fontData.release(); }
const SimpleFontData* FontCache::getFontDataForCharacters(const Font& font, const UChar* characters, int length) { SimpleFontData* fontData = 0; fontData = getCachedFontData(font.fontDescription(), font.family().family()); if (!fontData->containsCharacters(characters, length)) fontData = getSimilarFontPlatformData(font); if (!fontData->containsCharacters(characters, length)) fontData = getLastResortFallbackFont(font.fontDescription()); ASSERT(fontData); return fontData; }
const FontData* FontCache::getFontData(const Font& font, int& familyIndex, FontSelector* fontSelector) { FontPlatformData* result = 0; int startIndex = familyIndex; const FontFamily* startFamily = &font.fontDescription().family(); for (int i = 0; startFamily && i < startIndex; i++) startFamily = startFamily->next(); const FontFamily* currFamily = startFamily; while (currFamily && !result) { familyIndex++; if (currFamily->family().length()) { if (fontSelector) { FontData* data = fontSelector->getFontData(font.fontDescription(), currFamily->family()); if (data) return data; } result = getCachedFontPlatformData(font.fontDescription(), currFamily->family()); } currFamily = currFamily->next(); } if (!currFamily) familyIndex = cAllFamiliesScanned; if (!result) { // We didn't find a font. Try to find a similar font using our own specific knowledge about our platform. // For example on OS X, we know to map any families containing the words Arabic, Pashto, or Urdu to the // Geeza Pro font. //+ 4/27/09 CSidhall - The old code created a new fontPlatfromData here but left the pointer to leak. // We will use the exising font cache to store it in so that we can collect it. // There might be some risk if fontPlatformData gets added from another location with the same // key value. This would overwrite the mapped value, causing a leak. Have not seen this to occur in // however while testing several sites. // Original code: // result = getSimilarFontPlatformData(font); // New code: // Verify that we don't have one already in the cache (the familyIndex might have skipped this step) const FontDescription& fontDescription = font.fontDescription(); // Use first font family as default name for the key const AtomicString& familyName = font.fontDescription().family().family(); result = getCachedFontPlatformData(fontDescription, familyName); if(!result) { // No default font was found so should be safe to add to key location result = getSimilarFontPlatformData(font); FontPlatformDataCacheKey key(familyName, fontDescription.computedPixelSize(), fontDescription.weight(), fontDescription.italic(), fontDescription.usePrinterFont(), fontDescription.renderingMode()); gFontPlatformDataCache->set(key,result); } //- CS } if (!result && startIndex == 0) { // If it's the primary font that we couldn't find, we try the following. In all other cases, we will // just use per-character system fallback. if (fontSelector) { // Try the user's preferred standard font. if (FontData* data = fontSelector->getFontData(font.fontDescription(), "-webkit-standard")) return data; } // Still no result. Hand back our last resort fallback font. result = getLastResortFallbackFont(font.fontDescription()); } // Now that we have a result, we need to go from FontPlatformData -> FontData. return getCachedFontData(result); }