Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(949)

Side by Side Diff: third_party/WebKit/Source/platform/fonts/skia/FontCacheSkia.cpp

Issue 1685053002: blink fonts: Load Android SkFontMgr on Linux. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@windows_change
Patch Set: Rebase. Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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
109 #if OS(ANDROID) || OS(LINUX)
110 // This function is called on android or when we are emulating android fonts on linux and the
111 // embedder has overriden the default fontManager with WebFontRendering::setSkia FontMgr.
112 // static
113 AtomicString FontCache::getFamilyNameForCharacter(SkFontMgr* fm, UChar32 c, cons t FontDescription& fontDescription)
114 {
115 ASSERT(fm);
116
117 const char* bcp47Locales[2];
118 int localeCount = 0;
119 CString defaultLocale = toSkFontMgrLocale(defaultLanguage());
120 bcp47Locales[localeCount++] = defaultLocale.data();
121 CString fontLocale;
122 if (!fontDescription.locale().isEmpty()) {
123 fontLocale = toSkFontMgrLocale(fontDescription.locale());
124 bcp47Locales[localeCount++] = fontLocale.data();
125 }
126 RefPtr<SkTypeface> typeface = adoptRef(fm->matchFamilyStyleCharacter(0, SkFo ntStyle(), bcp47Locales, localeCount, c));
127 if (!typeface)
128 return emptyAtom;
129
130 SkString skiaFamilyName;
131 typeface->getFamilyName(&skiaFamilyName);
132 return skiaFamilyName.c_str();
133 }
134 #endif
135
90 void FontCache::platformInit() 136 void FontCache::platformInit()
91 { 137 {
92 } 138 }
93 139
94 PassRefPtr<SimpleFontData> FontCache::fallbackOnStandardFontStyle( 140 PassRefPtr<SimpleFontData> FontCache::fallbackOnStandardFontStyle(
95 const FontDescription& fontDescription, UChar32 character) 141 const FontDescription& fontDescription, UChar32 character)
96 { 142 {
97 FontDescription substituteDescription(fontDescription); 143 FontDescription substituteDescription(fontDescription);
98 substituteDescription.setStyle(FontStyleNormal); 144 substituteDescription.setStyle(FontStyleNormal);
99 substituteDescription.setWeight(FontWeightNormal); 145 substituteDescription.setWeight(FontWeightNormal);
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 } 266 }
221 267
222 if (m_fontManager) { 268 if (m_fontManager) {
223 return adoptRef(useDirectWrite() 269 return adoptRef(useDirectWrite()
224 ? m_fontManager->matchFamilyStyle(name.data(), fontStyle(fontDescrip tion)) 270 ? m_fontManager->matchFamilyStyle(name.data(), fontStyle(fontDescrip tion))
225 : m_fontManager->legacyCreateTypeface(name.data(), style) 271 : m_fontManager->legacyCreateTypeface(name.data(), style)
226 ); 272 );
227 } 273 }
228 #endif 274 #endif
229 275
276 #if OS(LINUX)
277 // On linux if the fontManager has been overridden then we should be calling the embedder
278 // provided font Manager rather than calling SkTypeface::CreateFromName whic h may redirect the
279 // call to the default font Manager.
280 if (m_fontManager)
281 return adoptRef(m_fontManager->legacyCreateTypeface(name.data(), style)) ;
bungeman-chromium 2016/02/29 22:48:50 This is a little bit sneaky, but I think this shou
Khushal 2016/03/01 18:52:43 You're right, I was trying to be consistent with t
282 #endif
283
230 // FIXME: Use m_fontManager, SkFontStyle and matchFamilyStyle instead of 284 // FIXME: Use m_fontManager, SkFontStyle and matchFamilyStyle instead of
231 // CreateFromName on all platforms. 285 // CreateFromName on all platforms.
232 return adoptRef(SkTypeface::CreateFromName(name.data(), static_cast<SkTypefa ce::Style>(style))); 286 return adoptRef(SkTypeface::CreateFromName(name.data(), static_cast<SkTypefa ce::Style>(style)));
233 } 287 }
234 288
235 #if !OS(WIN) 289 #if !OS(WIN)
236 PassOwnPtr<FontPlatformData> FontCache::createFontPlatformData(const FontDescrip tion& fontDescription, 290 PassOwnPtr<FontPlatformData> FontCache::createFontPlatformData(const FontDescrip tion& fontDescription,
237 const FontFaceCreationParams& creationParams, float fontSize) 291 const FontFaceCreationParams& creationParams, float fontSize)
238 { 292 {
239 CString name; 293 CString name;
240 RefPtr<SkTypeface> tf(createTypeface(fontDescription, creationParams, name)) ; 294 RefPtr<SkTypeface> tf(createTypeface(fontDescription, creationParams, name)) ;
241 if (!tf) 295 if (!tf)
242 return nullptr; 296 return nullptr;
243 297
244 return adoptPtr(new FontPlatformData(tf, 298 return adoptPtr(new FontPlatformData(tf,
245 name.data(), 299 name.data(),
246 fontSize, 300 fontSize,
247 (fontDescription.weight() >= FontWeight600 && !tf->isBold()) || fontDesc ription.isSyntheticBold(), 301 (fontDescription.weight() >= FontWeight600 && !tf->isBold()) || fontDesc ription.isSyntheticBold(),
248 ((fontDescription.style() == FontStyleItalic || fontDescription.style() == FontStyleOblique) && !tf->isItalic()) || fontDescription.isSyntheticItalic(), 302 ((fontDescription.style() == FontStyleItalic || fontDescription.style() == FontStyleOblique) && !tf->isItalic()) || fontDescription.isSyntheticItalic(),
249 fontDescription.orientation(), 303 fontDescription.orientation(),
250 fontDescription.useSubpixelPositioning())); 304 fontDescription.useSubpixelPositioning()));
251 } 305 }
252 #endif // !OS(WIN) 306 #endif // !OS(WIN)
253 307
254 } // namespace blink 308 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698