| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2006, 2007, 2008, 2009 Google Inc. All rights reserved. | 2 * Copyright (c) 2006, 2007, 2008, 2009 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 | 60 |
| 61 namespace blink { | 61 namespace blink { |
| 62 | 62 |
| 63 #if OS(ANDROID) || OS(LINUX) | 63 #if OS(ANDROID) || OS(LINUX) |
| 64 // Android special locale for retrieving the color emoji font | 64 // Android special locale for retrieving the color emoji font |
| 65 // based on the proposed changes in UTR #51 for introducing | 65 // based on the proposed changes in UTR #51 for introducing |
| 66 // an Emoji script code: | 66 // an Emoji script code: |
| 67 // http://www.unicode.org/reports/tr51/proposed.html#Emoji_Script | 67 // http://www.unicode.org/reports/tr51/proposed.html#Emoji_Script |
| 68 static const char* kAndroidColorEmojiLocale = "und-Zsye"; | 68 static const char* kAndroidColorEmojiLocale = "und-Zsye"; |
| 69 | 69 |
| 70 // SkFontMgr requires script-based locale names, like "zh-Hant" and "zh-Hans", | |
| 71 // instead of "zh-CN" and "zh-TW". | |
| 72 static CString toSkFontMgrLocale(const String& locale) | |
| 73 { | |
| 74 if (!locale.startsWith("zh", TextCaseInsensitive)) | |
| 75 return locale.ascii(); | |
| 76 | |
| 77 switch (localeToScriptCodeForFontSelection(locale)) { | |
| 78 case USCRIPT_SIMPLIFIED_HAN: | |
| 79 return "zh-Hans"; | |
| 80 case USCRIPT_TRADITIONAL_HAN: | |
| 81 return "zh-Hant"; | |
| 82 default: | |
| 83 return locale.ascii(); | |
| 84 } | |
| 85 } | |
| 86 | |
| 87 // This function is called on android or when we are emulating android fonts on
linux and the | 70 // This function is called on android or when we are emulating android fonts on
linux and the |
| 88 // embedder has overriden the default fontManager with WebFontRendering::setSkia
FontMgr. | 71 // embedder has overriden the default fontManager with WebFontRendering::setSkia
FontMgr. |
| 89 // static | 72 // static |
| 90 AtomicString FontCache::getFamilyNameForCharacter(SkFontMgr* fm, UChar32 c, cons
t FontDescription& fontDescription, FontFallbackPriority fallbackPriority) | 73 AtomicString FontCache::getFamilyNameForCharacter(SkFontMgr* fm, UChar32 c, cons
t FontDescription& fontDescription, FontFallbackPriority fallbackPriority) |
| 91 { | 74 { |
| 92 ASSERT(fm); | 75 ASSERT(fm); |
| 93 | 76 |
| 94 const size_t kMaxLocales = 4; | 77 const size_t kMaxLocales = 4; |
| 95 const char* bcp47Locales[kMaxLocales]; | 78 const char* bcp47Locales[kMaxLocales]; |
| 96 size_t localeCount = 0; | 79 size_t localeCount = 0; |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 if (!fontPlatformData) { | 147 if (!fontPlatformData) { |
| 165 DEFINE_STATIC_LOCAL(const FontFaceCreationParams, mssansserifCreationPar
ams, (AtomicString("Microsoft Sans Serif"))); | 148 DEFINE_STATIC_LOCAL(const FontFaceCreationParams, mssansserifCreationPar
ams, (AtomicString("Microsoft Sans Serif"))); |
| 166 fontPlatformData = getFontPlatformData(description, mssansserifCreationP
arams); | 149 fontPlatformData = getFontPlatformData(description, mssansserifCreationP
arams); |
| 167 } | 150 } |
| 168 #endif | 151 #endif |
| 169 | 152 |
| 170 ASSERT(fontPlatformData); | 153 ASSERT(fontPlatformData); |
| 171 return fontDataFromFontPlatformData(fontPlatformData, shouldRetain); | 154 return fontDataFromFontPlatformData(fontPlatformData, shouldRetain); |
| 172 } | 155 } |
| 173 | 156 |
| 174 #if OS(WIN) || OS(LINUX) | |
| 175 static inline SkFontStyle fontStyle(const FontDescription& fontDescription) | |
| 176 { | |
| 177 int width = static_cast<int>(fontDescription.stretch()); | |
| 178 int weight = (fontDescription.weight() - FontWeight100 + 1) * 100; | |
| 179 SkFontStyle::Slant slant = fontDescription.style() == FontStyleItalic | |
| 180 ? SkFontStyle::kItalic_Slant | |
| 181 : SkFontStyle::kUpright_Slant; | |
| 182 return SkFontStyle(weight, width, slant); | |
| 183 } | |
| 184 | |
| 185 static_assert(static_cast<int>(FontStretchUltraCondensed) == static_cast<int>(Sk
FontStyle::kUltraCondensed_Width), | |
| 186 "FontStretchUltraCondensed should map to kUltraCondensed_Width"); | |
| 187 static_assert(static_cast<int>(FontStretchNormal) == static_cast<int>(SkFontStyl
e::kNormal_Width), | |
| 188 "FontStretchNormal should map to kNormal_Width"); | |
| 189 static_assert(static_cast<int>(FontStretchUltraExpanded) == static_cast<int>(SkF
ontStyle::kUltaExpanded_Width), | |
| 190 "FontStretchUltraExpanded should map to kUltaExpanded_Width"); | |
| 191 #endif | |
| 192 | |
| 193 PassRefPtr<SkTypeface> FontCache::createTypeface(const FontDescription& fontDesc
ription, const FontFaceCreationParams& creationParams, CString& name) | 157 PassRefPtr<SkTypeface> FontCache::createTypeface(const FontDescription& fontDesc
ription, const FontFaceCreationParams& creationParams, CString& name) |
| 194 { | 158 { |
| 195 #if !OS(WIN) && !OS(ANDROID) | 159 #if !OS(WIN) && !OS(ANDROID) |
| 196 if (creationParams.creationType() == CreateFontByFciIdAndTtcIndex) { | 160 if (creationParams.creationType() == CreateFontByFciIdAndTtcIndex) { |
| 197 if (Platform::current()->sandboxSupport()) | 161 if (Platform::current()->sandboxSupport()) |
| 198 return typefaceForFontconfigInterfaceIdAndTtcIndex(creationParams.fo
ntconfigInterfaceId(), creationParams.ttcIndex()); | 162 return typefaceForFontconfigInterfaceIdAndTtcIndex(creationParams.fo
ntconfigInterfaceId(), creationParams.ttcIndex()); |
| 199 return adoptRef(SkTypeface::CreateFromFile(creationParams.filename().dat
a(), creationParams.ttcIndex())); | 163 return adoptRef(SkTypeface::CreateFromFile(creationParams.filename().dat
a(), creationParams.ttcIndex())); |
| 200 } | 164 } |
| 201 #endif | 165 #endif |
| 202 | 166 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 213 #if OS(WIN) | 177 #if OS(WIN) |
| 214 if (s_sideloadedFonts) { | 178 if (s_sideloadedFonts) { |
| 215 HashMap<String, RefPtr<SkTypeface>>::iterator sideloadedFont = | 179 HashMap<String, RefPtr<SkTypeface>>::iterator sideloadedFont = |
| 216 s_sideloadedFonts->find(name.data()); | 180 s_sideloadedFonts->find(name.data()); |
| 217 if (sideloadedFont != s_sideloadedFonts->end()) | 181 if (sideloadedFont != s_sideloadedFonts->end()) |
| 218 return sideloadedFont->value; | 182 return sideloadedFont->value; |
| 219 } | 183 } |
| 220 | 184 |
| 221 if (m_fontManager) { | 185 if (m_fontManager) { |
| 222 return adoptRef(useDirectWrite() | 186 return adoptRef(useDirectWrite() |
| 223 ? m_fontManager->matchFamilyStyle(name.data(), fontStyle(fontDescrip
tion)) | 187 ? m_fontManager->matchFamilyStyle(name.data(), fontDescription.skiaF
ontStyle()) |
| 224 : m_fontManager->legacyCreateTypeface(name.data(), fontStyle(fontDes
cription)) | 188 : m_fontManager->legacyCreateTypeface(name.data(), fontDescription.s
kiaFontStyle())); |
| 225 ); | |
| 226 } | 189 } |
| 227 #endif | 190 #endif |
| 228 | 191 |
| 229 #if OS(LINUX) | 192 #if OS(LINUX) |
| 230 // On linux if the fontManager has been overridden then we should be calling
the embedder | 193 // On linux if the fontManager has been overridden then we should be calling
the embedder |
| 231 // provided font Manager rather than calling SkTypeface::CreateFromName whic
h may redirect the | 194 // provided font Manager rather than calling SkTypeface::CreateFromName whic
h may redirect the |
| 232 // call to the default font Manager. | 195 // call to the default font Manager. |
| 233 if (m_fontManager) | 196 if (m_fontManager) |
| 234 return adoptRef(m_fontManager->matchFamilyStyle(name.data(), fontStyle(f
ontDescription))); | 197 return adoptRef(m_fontManager->matchFamilyStyle(name.data(), fontDescrip
tion.skiaFontStyle())); |
| 235 #endif | 198 #endif |
| 236 | 199 |
| 237 // FIXME: Use m_fontManager, SkFontStyle and matchFamilyStyle instead of | 200 // FIXME: Use m_fontManager, SkFontStyle and matchFamilyStyle instead of |
| 238 // CreateFromName on all platforms. | 201 // CreateFromName on all platforms. |
| 239 int style = SkTypeface::kNormal; | 202 int style = SkTypeface::kNormal; |
| 240 if (fontDescription.weight() >= FontWeight600) | 203 if (fontDescription.weight() >= FontWeight600) |
| 241 style |= SkTypeface::kBold; | 204 style |= SkTypeface::kBold; |
| 242 if (fontDescription.style()) | 205 if (fontDescription.style()) |
| 243 style |= SkTypeface::kItalic; | 206 style |= SkTypeface::kItalic; |
| 244 return adoptRef(SkTypeface::CreateFromName(name.data(), static_cast<SkTypefa
ce::Style>(style))); | 207 return adoptRef(SkTypeface::CreateFromName(name.data(), static_cast<SkTypefa
ce::Style>(style))); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 257 name.data(), | 220 name.data(), |
| 258 fontSize, | 221 fontSize, |
| 259 (fontDescription.weight() >= FontWeight600 && !tf->isBold()) || fontDesc
ription.isSyntheticBold(), | 222 (fontDescription.weight() >= FontWeight600 && !tf->isBold()) || fontDesc
ription.isSyntheticBold(), |
| 260 ((fontDescription.style() == FontStyleItalic || fontDescription.style()
== FontStyleOblique) && !tf->isItalic()) || fontDescription.isSyntheticItalic(), | 223 ((fontDescription.style() == FontStyleItalic || fontDescription.style()
== FontStyleOblique) && !tf->isItalic()) || fontDescription.isSyntheticItalic(), |
| 261 fontDescription.orientation(), | 224 fontDescription.orientation(), |
| 262 fontDescription.useSubpixelPositioning())); | 225 fontDescription.useSubpixelPositioning())); |
| 263 } | 226 } |
| 264 #endif // !OS(WIN) | 227 #endif // !OS(WIN) |
| 265 | 228 |
| 266 } // namespace blink | 229 } // namespace blink |
| OLD | NEW |