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 13 matching lines...) Expand all Loading... | |
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 */ | 29 */ |
30 | 30 |
31 #include "SkFontMgr.h" | 31 #include "SkFontMgr.h" |
32 #include "SkStream.h" | 32 #include "SkStream.h" |
33 #include "SkTypeface.h" | 33 #include "SkTypeface.h" |
34 #include "platform/Language.h" | |
34 #include "platform/fonts/AlternateFontFamily.h" | 35 #include "platform/fonts/AlternateFontFamily.h" |
35 #include "platform/fonts/FontCache.h" | 36 #include "platform/fonts/FontCache.h" |
36 #include "platform/fonts/FontDescription.h" | 37 #include "platform/fonts/FontDescription.h" |
37 #include "platform/fonts/FontFaceCreationParams.h" | 38 #include "platform/fonts/FontFaceCreationParams.h" |
38 #include "platform/fonts/SimpleFontData.h" | 39 #include "platform/fonts/SimpleFontData.h" |
39 #include "public/platform/Platform.h" | 40 #include "public/platform/Platform.h" |
40 #include "public/platform/linux/WebSandboxSupport.h" | 41 #include "public/platform/linux/WebSandboxSupport.h" |
41 #include "wtf/Assertions.h" | 42 #include "wtf/Assertions.h" |
42 #include "wtf/text/AtomicString.h" | 43 #include "wtf/text/AtomicString.h" |
43 #include "wtf/text/CString.h" | 44 #include "wtf/text/CString.h" |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
80 SkAutoTUnref<SkFontConfigInterface> fci(SkFontConfigInterface::RefGlobal()); | 81 SkAutoTUnref<SkFontConfigInterface> fci(SkFontConfigInterface::RefGlobal()); |
81 SkFontConfigInterface::FontIdentity fontIdentity; | 82 SkFontConfigInterface::FontIdentity fontIdentity; |
82 fontIdentity.fID = fontconfigInterfaceId; | 83 fontIdentity.fID = fontconfigInterfaceId; |
83 fontIdentity.fTTCIndex = ttcIndex; | 84 fontIdentity.fTTCIndex = ttcIndex; |
84 return adoptRef(fci->createTypeface(fontIdentity)); | 85 return adoptRef(fci->createTypeface(fontIdentity)); |
85 } | 86 } |
86 #endif | 87 #endif |
87 | 88 |
88 namespace blink { | 89 namespace blink { |
89 | 90 |
91 // SkFontMgr requires script-based locale names, like "zh-Hant" and "zh-Hans", | |
92 // instead of "zh-CN" and "zh-TW". | |
93 static CString toSkFontMgrLocale(const String& locale) | |
94 { | |
95 if (!locale.startsWith("zh", TextCaseInsensitive)) | |
96 return locale.ascii(); | |
97 | |
98 switch (localeToScriptCodeForFontSelection(locale)) { | |
99 case USCRIPT_SIMPLIFIED_HAN: | |
100 return "zh-Hans"; | |
101 case USCRIPT_TRADITIONAL_HAN: | |
102 return "zh-Hant"; | |
103 default: | |
104 return locale.ascii(); | |
105 } | |
106 } | |
107 | |
108 #if OS(ANDROID) || OS(LINUX) | |
eae
2016/02/17 23:52:10
Do we need this on Android? The only caller I can
Khushal
2016/02/18 00:46:37
Android calls it from FontCacheAndroid. The implem
| |
109 AtomicString FontCache::getFamilyNameForCharacter(SkFontMgr* fm, UChar32 c, cons t FontDescription& fontDescription) | |
110 { | |
111 ASSERT(fm); | |
112 const char* bcp47Locales[2]; | |
113 int localeCount = 0; | |
114 CString defaultLocale = toSkFontMgrLocale(defaultLanguage()); | |
115 bcp47Locales[localeCount++] = defaultLocale.data(); | |
116 CString fontLocale; | |
117 if (!fontDescription.locale().isEmpty()) { | |
118 fontLocale = toSkFontMgrLocale(fontDescription.locale()); | |
119 bcp47Locales[localeCount++] = fontLocale.data(); | |
120 } | |
121 RefPtr<SkTypeface> typeface = adoptRef(fm->matchFamilyStyleCharacter(0, SkFo ntStyle(), bcp47Locales, localeCount, c)); | |
122 if (!typeface) | |
123 return emptyAtom; | |
124 | |
125 SkString skiaFamilyName; | |
126 typeface->getFamilyName(&skiaFamilyName); | |
127 return skiaFamilyName.c_str(); | |
128 } | |
129 #endif | |
130 | |
90 void FontCache::platformInit() | 131 void FontCache::platformInit() |
91 { | 132 { |
92 } | 133 } |
93 | 134 |
94 PassRefPtr<SimpleFontData> FontCache::fallbackOnStandardFontStyle( | 135 PassRefPtr<SimpleFontData> FontCache::fallbackOnStandardFontStyle( |
95 const FontDescription& fontDescription, UChar32 character) | 136 const FontDescription& fontDescription, UChar32 character) |
96 { | 137 { |
97 FontDescription substituteDescription(fontDescription); | 138 FontDescription substituteDescription(fontDescription); |
98 substituteDescription.setStyle(FontStyleNormal); | 139 substituteDescription.setStyle(FontStyleNormal); |
99 substituteDescription.setWeight(FontWeightNormal); | 140 substituteDescription.setWeight(FontWeightNormal); |
100 | 141 |
101 FontFaceCreationParams creationParams(substituteDescription.family().family( )); | 142 FontFaceCreationParams creationParams(substituteDescription.family().family( )); |
102 FontPlatformData* substitutePlatformData = getFontPlatformData(substituteDes cription, creationParams); | 143 FontPlatformData* substitutePlatformData = getFontPlatformData(substituteDes cription, creationParams); |
103 if (substitutePlatformData && substitutePlatformData->fontContainsCharacter( character)) { | 144 if (substitutePlatformData && substitutePlatformData->fontContainsCharacter( character)) { |
104 FontPlatformData platformData = FontPlatformData(*substitutePlatformData ); | 145 FontPlatformData platformData = FontPlatformData(*substitutePlatformData ); |
105 platformData.setSyntheticBold(fontDescription.weight() >= FontWeight600) ; | 146 platformData.setSyntheticBold(fontDescription.weight() >= FontWeight600) ; |
106 platformData.setSyntheticItalic(fontDescription.style() == FontStyleItal ic || fontDescription.style() == FontStyleOblique); | 147 platformData.setSyntheticItalic(fontDescription.style() == FontStyleItal ic || fontDescription.style() == FontStyleOblique); |
107 return fontDataFromFontPlatformData(&platformData, DoNotRetain); | 148 return fontDataFromFontPlatformData(&platformData, DoNotRetain); |
108 } | 149 } |
109 | 150 |
110 return nullptr; | 151 return nullptr; |
111 } | 152 } |
112 | 153 |
113 #if !OS(WIN) && !OS(ANDROID) | 154 #if !OS(WIN) && !OS(ANDROID) |
114 PassRefPtr<SimpleFontData> FontCache::fallbackFontForCharacter(const FontDescrip tion& fontDescription, UChar32 c, const SimpleFontData*) | 155 PassRefPtr<SimpleFontData> FontCache::fallbackFontForCharacter(const FontDescrip tion& fontDescription, UChar32 c, const SimpleFontData*) |
115 { | 156 { |
157 #if OS(LINUX) | |
158 // Try the SkFontMgr first if we have one. | |
159 if (m_fontManager) { | |
eae
2016/02/17 23:52:10
When would we not have a font manager? On windows
Khushal
2016/02/18 00:46:37
On linux the default font manager is backed by an
| |
160 AtomicString familyName = getFamilyNameForCharacter(m_fontManager.get(), c, fontDescription); | |
161 if (familyName.isEmpty()) | |
162 return getLastResortFallbackFont(fontDescription, DoNotRetain); | |
163 return fontDataFromFontPlatformData(getFontPlatformData(fontDescription, FontFaceCreationParams(familyName)), DoNotRetain); | |
164 } | |
165 #endif | |
166 | |
116 // First try the specified font with standard style & weight. | 167 // First try the specified font with standard style & weight. |
117 if (fontDescription.style() == FontStyleItalic | 168 if (fontDescription.style() == FontStyleItalic |
118 || fontDescription.weight() >= FontWeight600) { | 169 || fontDescription.weight() >= FontWeight600) { |
119 RefPtr<SimpleFontData> fontData = fallbackOnStandardFontStyle( | 170 RefPtr<SimpleFontData> fontData = fallbackOnStandardFontStyle( |
120 fontDescription, c); | 171 fontDescription, c); |
121 if (fontData) | 172 if (fontData) |
122 return fontData; | 173 return fontData; |
123 } | 174 } |
124 | 175 |
125 FontCache::PlatformFallbackFont fallbackFont; | 176 FontCache::PlatformFallbackFont fallbackFont; |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
270 } | 321 } |
271 | 322 |
272 if (m_fontManager) { | 323 if (m_fontManager) { |
273 return adoptRef(useDirectWrite() | 324 return adoptRef(useDirectWrite() |
274 ? m_fontManager->matchFamilyStyle(name.data(), fontStyle(fontDescrip tion)) | 325 ? m_fontManager->matchFamilyStyle(name.data(), fontStyle(fontDescrip tion)) |
275 : m_fontManager->legacyCreateTypeface(name.data(), style) | 326 : m_fontManager->legacyCreateTypeface(name.data(), style) |
276 ); | 327 ); |
277 } | 328 } |
278 #endif | 329 #endif |
279 | 330 |
331 #if OS(LINUX) | |
332 if (m_fontManager) | |
333 return adoptRef(m_fontManager->legacyCreateTypeface(name.data(), style)) ; | |
334 #endif | |
335 | |
280 // FIXME: Use m_fontManager, SkFontStyle and matchFamilyStyle instead of | 336 // FIXME: Use m_fontManager, SkFontStyle and matchFamilyStyle instead of |
281 // CreateFromName on all platforms. | 337 // CreateFromName on all platforms. |
282 return adoptRef(SkTypeface::CreateFromName(name.data(), static_cast<SkTypefa ce::Style>(style))); | 338 return adoptRef(SkTypeface::CreateFromName(name.data(), static_cast<SkTypefa ce::Style>(style))); |
283 } | 339 } |
284 | 340 |
285 #if !OS(WIN) | 341 #if !OS(WIN) |
286 PassOwnPtr<FontPlatformData> FontCache::createFontPlatformData(const FontDescrip tion& fontDescription, | 342 PassOwnPtr<FontPlatformData> FontCache::createFontPlatformData(const FontDescrip tion& fontDescription, |
287 const FontFaceCreationParams& creationParams, float fontSize) | 343 const FontFaceCreationParams& creationParams, float fontSize) |
288 { | 344 { |
289 CString name; | 345 CString name; |
290 RefPtr<SkTypeface> tf(createTypeface(fontDescription, creationParams, name)) ; | 346 RefPtr<SkTypeface> tf(createTypeface(fontDescription, creationParams, name)) ; |
291 if (!tf) | 347 if (!tf) |
292 return nullptr; | 348 return nullptr; |
293 | 349 |
294 return adoptPtr(new FontPlatformData(tf, | 350 return adoptPtr(new FontPlatformData(tf, |
295 name.data(), | 351 name.data(), |
296 fontSize, | 352 fontSize, |
297 (fontDescription.weight() >= FontWeight600 && !tf->isBold()) || fontDesc ription.isSyntheticBold(), | 353 (fontDescription.weight() >= FontWeight600 && !tf->isBold()) || fontDesc ription.isSyntheticBold(), |
298 ((fontDescription.style() == FontStyleItalic || fontDescription.style() == FontStyleOblique) && !tf->isItalic()) || fontDescription.isSyntheticItalic(), | 354 ((fontDescription.style() == FontStyleItalic || fontDescription.style() == FontStyleOblique) && !tf->isItalic()) || fontDescription.isSyntheticItalic(), |
299 fontDescription.orientation(), | 355 fontDescription.orientation(), |
300 fontDescription.useSubpixelPositioning())); | 356 fontDescription.useSubpixelPositioning())); |
301 } | 357 } |
302 #endif // !OS(WIN) | 358 #endif // !OS(WIN) |
303 | 359 |
304 } // namespace blink | 360 } // namespace blink |
OLD | NEW |