PassRefPtr<SimpleFontData> FontCache::fallbackFontForCharacter(const FontDescription& fontDescription, UChar32 c, const SimpleFontData*) { AtomicString familyName = getFamilyNameForCharacter(c, fontDescription.script()); if (familyName.isEmpty()) return getLastResortFallbackFont(fontDescription, DoNotRetain); return fontDataFromFontPlatformData(getFontPlatformData(fontDescription, FontFaceCreationParams(familyName)), DoNotRetain); }
PassRefPtr<SimpleFontData> FontCache::fallbackFontForCharacter(const FontDescription& fontDescription, UChar32 c, const SimpleFontData*, FontFallbackPriority fallbackPriority) { RefPtr<SkFontMgr> fm = adoptRef(SkFontMgr::RefDefault()); AtomicString familyName = getFamilyNameForCharacter(fm.get(), c, fontDescription, fallbackPriority); if (familyName.isEmpty()) return getLastResortFallbackFont(fontDescription, DoNotRetain); return fontDataFromFontPlatformData(getFontPlatformData(fontDescription, FontFaceCreationParams(familyName)), DoNotRetain); }
// static AtomicString FontCache::getGenericFamilyNameForScript(const AtomicString& familyName, UScriptCode script) { // This is a hack to use the preferred font for CJK scripts. // FIXME: Use new Skia API once Android system supports per-family and per-script fallback fonts. UChar32 examplerChar; switch (script) { case USCRIPT_SIMPLIFIED_HAN: case USCRIPT_TRADITIONAL_HAN: case USCRIPT_KATAKANA_OR_HIRAGANA: examplerChar = 0x4E00; // A common character in Japanese and Chinese. break; case USCRIPT_HANGUL: examplerChar = 0xAC00; break; default: // For other scripts, use the default generic family mapping logic. return familyName; } return getFamilyNameForCharacter(examplerChar, script); }
// static AtomicString FontCache::getGenericFamilyNameForScript(const AtomicString& familyName, const FontDescription& fontDescription) { // This is a hack to use the preferred font for CJK scripts. // FIXME: Use new Skia API once Android system supports per-family and per-script fallback fonts. UChar32 examplerChar; switch (fontDescription.script()) { case USCRIPT_SIMPLIFIED_HAN: case USCRIPT_TRADITIONAL_HAN: case USCRIPT_KATAKANA_OR_HIRAGANA: examplerChar = 0x4E00; // A common character in Japanese and Chinese. break; case USCRIPT_HANGUL: examplerChar = 0xAC00; break; default: // For other scripts, use the default generic family mapping logic. return familyName; } RefPtr<SkFontMgr> fm = adoptRef(SkFontMgr::RefDefault()); return getFamilyNameForCharacter(fm.get(), examplerChar, fontDescription, FontFallbackPriority::Text); }