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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 #include "wtf/Assertions.h" | 43 #include "wtf/Assertions.h" |
44 #include "wtf/PtrUtil.h" | 44 #include "wtf/PtrUtil.h" |
45 #include "wtf/text/AtomicString.h" | 45 #include "wtf/text/AtomicString.h" |
46 #include "wtf/text/CString.h" | 46 #include "wtf/text/CString.h" |
47 #include <memory> | 47 #include <memory> |
48 #include <unicode/locid.h> | 48 #include <unicode/locid.h> |
49 | 49 |
50 #if !OS(WIN) && !OS(ANDROID) | 50 #if !OS(WIN) && !OS(ANDROID) |
51 #include "SkFontConfigInterface.h" | 51 #include "SkFontConfigInterface.h" |
52 | 52 |
53 static PassRefPtr<SkTypeface> typefaceForFontconfigInterfaceIdAndTtcIndex(int fo
ntconfigInterfaceId, int ttcIndex) | 53 static sk_sp<SkTypeface> typefaceForFontconfigInterfaceIdAndTtcIndex(int fontcon
figInterfaceId, int ttcIndex) |
54 { | 54 { |
55 SkAutoTUnref<SkFontConfigInterface> fci(SkFontConfigInterface::RefGlobal()); | 55 SkAutoTUnref<SkFontConfigInterface> fci(SkFontConfigInterface::RefGlobal()); |
56 SkFontConfigInterface::FontIdentity fontIdentity; | 56 SkFontConfigInterface::FontIdentity fontIdentity; |
57 fontIdentity.fID = fontconfigInterfaceId; | 57 fontIdentity.fID = fontconfigInterfaceId; |
58 fontIdentity.fTTCIndex = ttcIndex; | 58 fontIdentity.fTTCIndex = ttcIndex; |
59 return blink::fromSkSp(fci->makeTypeface(fontIdentity)); | 59 return fci->makeTypeface(fontIdentity); |
60 } | 60 } |
61 #endif | 61 #endif |
62 | 62 |
63 namespace blink { | 63 namespace blink { |
64 | 64 |
65 #if OS(ANDROID) || OS(LINUX) | 65 #if OS(ANDROID) || OS(LINUX) |
66 // Android special locale for retrieving the color emoji font | 66 // Android special locale for retrieving the color emoji font |
67 // based on the proposed changes in UTR #51 for introducing | 67 // based on the proposed changes in UTR #51 for introducing |
68 // an Emoji script code: | 68 // an Emoji script code: |
69 // http://www.unicode.org/reports/tr51/proposed.html#Emoji_Script | 69 // http://www.unicode.org/reports/tr51/proposed.html#Emoji_Script |
(...skipping 14 matching lines...) Expand all Loading... |
84 // Skia expects the highest array index to be the first priority. | 84 // Skia expects the highest array index to be the first priority. |
85 const LayoutLocale* contentLocale = fontDescription.locale(); | 85 const LayoutLocale* contentLocale = fontDescription.locale(); |
86 if (const LayoutLocale* hanLocale = LayoutLocale::localeForHan(contentLocale
)) | 86 if (const LayoutLocale* hanLocale = LayoutLocale::localeForHan(contentLocale
)) |
87 bcp47Locales[localeCount++] = hanLocale->localeForHanForSkFontMgr(); | 87 bcp47Locales[localeCount++] = hanLocale->localeForHanForSkFontMgr(); |
88 bcp47Locales[localeCount++] = LayoutLocale::getDefault().localeForSkFontMgr(
); | 88 bcp47Locales[localeCount++] = LayoutLocale::getDefault().localeForSkFontMgr(
); |
89 if (contentLocale) | 89 if (contentLocale) |
90 bcp47Locales[localeCount++] = contentLocale->localeForSkFontMgr(); | 90 bcp47Locales[localeCount++] = contentLocale->localeForSkFontMgr(); |
91 if (fallbackPriority == FontFallbackPriority::EmojiEmoji) | 91 if (fallbackPriority == FontFallbackPriority::EmojiEmoji) |
92 bcp47Locales[localeCount++] = kAndroidColorEmojiLocale; | 92 bcp47Locales[localeCount++] = kAndroidColorEmojiLocale; |
93 SECURITY_DCHECK(localeCount <= kMaxLocales); | 93 SECURITY_DCHECK(localeCount <= kMaxLocales); |
94 RefPtr<SkTypeface> typeface = adoptRef(fm->matchFamilyStyleCharacter(0, SkFo
ntStyle(), bcp47Locales, localeCount, c)); | 94 sk_sp<SkTypeface> typeface(fm->matchFamilyStyleCharacter(0, SkFontStyle(), b
cp47Locales, localeCount, c)); |
95 if (!typeface) | 95 if (!typeface) |
96 return emptyAtom; | 96 return emptyAtom; |
97 | 97 |
98 SkString skiaFamilyName; | 98 SkString skiaFamilyName; |
99 typeface->getFamilyName(&skiaFamilyName); | 99 typeface->getFamilyName(&skiaFamilyName); |
100 return skiaFamilyName.c_str(); | 100 return skiaFamilyName.c_str(); |
101 } | 101 } |
102 #endif | 102 #endif |
103 | 103 |
104 void FontCache::platformInit() | 104 void FontCache::platformInit() |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 if (!fontPlatformData) { | 147 if (!fontPlatformData) { |
148 DEFINE_STATIC_LOCAL(const FontFaceCreationParams, mssansserifCreationPar
ams, (AtomicString("Microsoft Sans Serif"))); | 148 DEFINE_STATIC_LOCAL(const FontFaceCreationParams, mssansserifCreationPar
ams, (AtomicString("Microsoft Sans Serif"))); |
149 fontPlatformData = getFontPlatformData(description, mssansserifCreationP
arams); | 149 fontPlatformData = getFontPlatformData(description, mssansserifCreationP
arams); |
150 } | 150 } |
151 #endif | 151 #endif |
152 | 152 |
153 ASSERT(fontPlatformData); | 153 ASSERT(fontPlatformData); |
154 return fontDataFromFontPlatformData(fontPlatformData, shouldRetain); | 154 return fontDataFromFontPlatformData(fontPlatformData, shouldRetain); |
155 } | 155 } |
156 | 156 |
157 PassRefPtr<SkTypeface> FontCache::createTypeface(const FontDescription& fontDesc
ription, const FontFaceCreationParams& creationParams, CString& name) | 157 sk_sp<SkTypeface> FontCache::createTypeface(const FontDescription& fontDescripti
on, const FontFaceCreationParams& creationParams, CString& name) |
158 { | 158 { |
159 #if !OS(WIN) && !OS(ANDROID) | 159 #if !OS(WIN) && !OS(ANDROID) |
160 if (creationParams.creationType() == CreateFontByFciIdAndTtcIndex) { | 160 if (creationParams.creationType() == CreateFontByFciIdAndTtcIndex) { |
161 if (Platform::current()->sandboxSupport()) | 161 if (Platform::current()->sandboxSupport()) |
162 return typefaceForFontconfigInterfaceIdAndTtcIndex(creationParams.fo
ntconfigInterfaceId(), creationParams.ttcIndex()); | 162 return typefaceForFontconfigInterfaceIdAndTtcIndex(creationParams.fo
ntconfigInterfaceId(), creationParams.ttcIndex()); |
163 return fromSkSp(SkTypeface::MakeFromFile(creationParams.filename().data(
), creationParams.ttcIndex())); | 163 return SkTypeface::MakeFromFile(creationParams.filename().data(), creati
onParams.ttcIndex()); |
164 } | 164 } |
165 #endif | 165 #endif |
166 | 166 |
167 AtomicString family = creationParams.family(); | 167 AtomicString family = creationParams.family(); |
168 // If we're creating a fallback font (e.g. "-webkit-monospace"), convert the
name into | 168 // If we're creating a fallback font (e.g. "-webkit-monospace"), convert the
name into |
169 // the fallback name (like "monospace") that fontconfig understands. | 169 // the fallback name (like "monospace") that fontconfig understands. |
170 if (!family.length() || family.startsWith("-webkit-")) { | 170 if (!family.length() || family.startsWith("-webkit-")) { |
171 name = getFallbackFontFamily(fontDescription).getString().utf8(); | 171 name = getFallbackFontFamily(fontDescription).getString().utf8(); |
172 } else { | 172 } else { |
173 // convert the name to utf8 | 173 // convert the name to utf8 |
174 name = family.utf8(); | 174 name = family.utf8(); |
175 } | 175 } |
176 | 176 |
177 #if OS(WIN) | 177 #if OS(WIN) |
178 if (s_sideloadedFonts) { | 178 if (s_sideloadedFonts) { |
179 HashMap<String, RefPtr<SkTypeface>>::iterator sideloadedFont = | 179 HashMap<String, sk_sp<SkTypeface>>::iterator sideloadedFont = |
180 s_sideloadedFonts->find(name.data()); | 180 s_sideloadedFonts->find(name.data()); |
181 if (sideloadedFont != s_sideloadedFonts->end()) | 181 if (sideloadedFont != s_sideloadedFonts->end()) |
182 return sideloadedFont->value; | 182 return sideloadedFont->value; |
183 } | 183 } |
184 #endif | 184 #endif |
185 | 185 |
186 #if OS(LINUX) || OS(WIN) | 186 #if OS(LINUX) || OS(WIN) |
187 // On linux if the fontManager has been overridden then we should be calling
the embedder | 187 // On linux if the fontManager has been overridden then we should be calling
the embedder |
188 // provided font Manager rather than calling SkTypeface::CreateFromName whic
h may redirect the | 188 // provided font Manager rather than calling SkTypeface::CreateFromName whic
h may redirect the |
189 // call to the default font Manager. | 189 // call to the default font Manager. |
190 // On Windows the font manager is always present. | 190 // On Windows the font manager is always present. |
191 if (m_fontManager) | 191 if (m_fontManager) |
192 return adoptRef(m_fontManager->matchFamilyStyle(name.data(), fontDescrip
tion.skiaFontStyle())); | 192 return sk_sp<SkTypeface>(m_fontManager->matchFamilyStyle(name.data(), fo
ntDescription.skiaFontStyle())); |
193 #endif | 193 #endif |
194 | 194 |
195 // FIXME: Use m_fontManager, matchFamilyStyle instead of | 195 // FIXME: Use m_fontManager, matchFamilyStyle instead of |
196 // legacyCreateTypeface on all platforms. | 196 // legacyCreateTypeface on all platforms. |
197 RefPtr<SkFontMgr> fm = adoptRef(SkFontMgr::RefDefault()); | 197 sk_sp<SkFontMgr> fm(SkFontMgr::RefDefault()); |
198 return adoptRef(fm->legacyCreateTypeface(name.data(), | 198 return sk_sp<SkTypeface>(fm->legacyCreateTypeface(name.data(), |
199 fontDescription.skiaFontStyle())); | 199 fontDescription.skiaFontStyle())); |
200 } | 200 } |
201 | 201 |
202 #if !OS(WIN) | 202 #if !OS(WIN) |
203 std::unique_ptr<FontPlatformData> FontCache::createFontPlatformData(const FontDe
scription& fontDescription, | 203 std::unique_ptr<FontPlatformData> FontCache::createFontPlatformData(const FontDe
scription& fontDescription, |
204 const FontFaceCreationParams& creationParams, float fontSize) | 204 const FontFaceCreationParams& creationParams, float fontSize) |
205 { | 205 { |
206 CString name; | 206 CString name; |
207 RefPtr<SkTypeface> tf(createTypeface(fontDescription, creationParams, name))
; | 207 sk_sp<SkTypeface> tf = createTypeface(fontDescription, creationParams, name)
; |
208 if (!tf) | 208 if (!tf) |
209 return nullptr; | 209 return nullptr; |
210 | 210 |
211 return wrapUnique(new FontPlatformData(tf, | 211 return wrapUnique(new FontPlatformData(tf, |
212 name.data(), | 212 name.data(), |
213 fontSize, | 213 fontSize, |
214 (numericFontWeight(fontDescription.weight()) > 200 + tf->fontStyle().wei
ght()) || fontDescription.isSyntheticBold(), | 214 (numericFontWeight(fontDescription.weight()) > 200 + tf->fontStyle().wei
ght()) || fontDescription.isSyntheticBold(), |
215 ((fontDescription.style() == FontStyleItalic || fontDescription.style()
== FontStyleOblique) && !tf->isItalic()) || fontDescription.isSyntheticItalic(), | 215 ((fontDescription.style() == FontStyleItalic || fontDescription.style()
== FontStyleOblique) && !tf->isItalic()) || fontDescription.isSyntheticItalic(), |
216 fontDescription.orientation())); | 216 fontDescription.orientation())); |
217 } | 217 } |
218 #endif // !OS(WIN) | 218 #endif // !OS(WIN) |
219 | 219 |
220 } // namespace blink | 220 } // namespace blink |
OLD | NEW |