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

Side by Side Diff: third_party/WebKit/Source/platform/fonts/win/FontFallbackWin.cpp

Issue 2215543002: Remove unnecessary font loading when loading font fallbacks. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove scriptMonospaceFontMap Created 4 years, 4 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2006, 2007, 2008, 2009, 2010, 2012 Google Inc. All rights reser ved. 2 * Copyright (c) 2006, 2007, 2008, 2009, 2010, 2012 Google Inc. All rights reser ved.
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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 if (equalIgnoringCase(family, AtomicString::fromUTF8(actualFamily.fStrin g.c_str()))) { 61 if (equalIgnoringCase(family, AtomicString::fromUTF8(actualFamily.fStrin g.c_str()))) {
62 matchesRequestedFamily = true; 62 matchesRequestedFamily = true;
63 break; 63 break;
64 } 64 }
65 } 65 }
66 actualFamilies->unref(); 66 actualFamilies->unref();
67 67
68 return matchesRequestedFamily; 68 return matchesRequestedFamily;
69 } 69 }
70 70
71 struct FontMapping {
72 const UChar* familyName;
73 const UChar** candidateFamilyNames;
74 };
71 // A simple mapping from UScriptCode to family name. This is a sparse array, 75 // A simple mapping from UScriptCode to family name. This is a sparse array,
72 // which works well since the range of UScriptCode values is small. 76 // which works well since the range of UScriptCode values is small.
73 typedef const UChar* ScriptToFontMap[USCRIPT_CODE_LIMIT]; 77 typedef FontMapping ScriptToFontMap[USCRIPT_CODE_LIMIT];
74 78
75 void initializeScriptMonospaceFontMap(ScriptToFontMap& scriptFontMap, SkFontMgr* fontManager) 79 const UChar* findMonospaceFontForScript(UScriptCode script)
76 { 80 {
77 struct FontMap { 81 struct FontMap {
78 UScriptCode script; 82 UScriptCode script;
79 const UChar* family; 83 const UChar* family;
80 }; 84 };
81 85
82 static const FontMap fontMap[] = { 86 static const FontMap fontMap[] = {
83 { USCRIPT_HEBREW, L"courier new" }, 87 { USCRIPT_HEBREW, L"courier new" },
84 { USCRIPT_ARABIC, L"courier new" }, 88 { USCRIPT_ARABIC, L"courier new" },
85 }; 89 };
86 90
87 for (size_t i = 0; i < WTF_ARRAY_LENGTH(fontMap); ++i) 91 for (const auto& fontFamily : fontMap) {
88 scriptFontMap[fontMap[i].script] = fontMap[i].family; 92 if (fontFamily.script == script)
93 return fontFamily.family;
94 }
95 return nullptr;
89 } 96 }
90 97
91 void initializeScriptFontMap(ScriptToFontMap& scriptFontMap, SkFontMgr* fontMana ger) 98 void initializeScriptFontMap(ScriptToFontMap& scriptFontMap)
92 { 99 {
93 struct FontMap {
94 UScriptCode script;
95 const UChar* family;
96 };
97
98 static const FontMap fontMap[] = {
99 { USCRIPT_LATIN, L"Times New Roman" },
100 { USCRIPT_GREEK, L"Times New Roman" },
101 { USCRIPT_CYRILLIC, L"Times New Roman" },
102 // For USCRIPT_COMMON, we map blocks to scripts when
103 // that makes sense.
104 };
105
106 struct ScriptToFontFamilies { 100 struct ScriptToFontFamilies {
107 UScriptCode script; 101 UScriptCode script;
108 const UChar** families; 102 const UChar** families;
109 }; 103 };
110 104
111 // For the following scripts, multiple fonts may be listed. They are tried 105 // For the following scripts, multiple fonts may be listed. They are tried
112 // in order. The first slot is preferred but the font may not be available, 106 // in order. The first slot is preferred but the font may not be available,
113 // if so the remaining slots are tried in order. 107 // if so the remaining slots are tried in order.
114 // In general the order is the Windows 10 font follow by the 8.1, 8.0 and 108 // In general the order is the Windows 10 font follow by the 8.1, 8.0 and
115 // finally the font for Windows 7. 109 // finally the font for Windows 7.
116 // For scripts where an optional or region specific font may be available 110 // For scripts where an optional or region specific font may be available
117 // that should be listed before the generic one. 111 // that should be listed before the generic one.
118 // Based on the "Script and Font Support in Windows" MSDN documentation [1] 112 // Based on the "Script and Font Support in Windows" MSDN documentation [1]
119 // with overrides and additional fallbacks as needed. 113 // with overrides and additional fallbacks as needed.
120 // 1: https://msdn.microsoft.com/en-us/goglobal/bb688099.aspx 114 // 1: https://msdn.microsoft.com/en-us/goglobal/bb688099.aspx
121 static const UChar* arabicFonts[] = { L"Tahoma", L"Segoe UI", 0 }; 115 static const UChar* arabicFonts[] = { L"Tahoma", L"Segoe UI", 0 };
122 static const UChar* armenianFonts[] = { L"Segoe UI", L"Sylfaen", 0 }; 116 static const UChar* armenianFonts[] = { L"Segoe UI", L"Sylfaen", 0 };
123 static const UChar* bengaliFonts[] = { L"Nirmala UI", L"Vrinda", 0 }; 117 static const UChar* bengaliFonts[] = { L"Nirmala UI", L"Vrinda", 0 };
124 static const UChar* brahmiFonts[] = { L"Segoe UI Historic", 0 }; 118 static const UChar* brahmiFonts[] = { L"Segoe UI Historic", 0 };
125 static const UChar* brailleFonts[] = { L"Segoe UI Symbol", 0 }; 119 static const UChar* brailleFonts[] = { L"Segoe UI Symbol", 0 };
126 static const UChar* bugineseFonts[] = { L"Leelawadee UI", 0 }; 120 static const UChar* bugineseFonts[] = { L"Leelawadee UI", 0 };
127 static const UChar* canadianAaboriginalFonts[] = { L"Gadugi", 121 static const UChar* canadianAaboriginalFonts[] = { L"Gadugi",
128 L"Euphemia", 0 }; 122 L"Euphemia", 0 };
129 static const UChar* carianFonts[] = { L"Segoe UI Historic", 0 }; 123 static const UChar* carianFonts[] = { L"Segoe UI Historic", 0 };
130 static const UChar* cherokeeFonts[] = { L"Gadugi", L"Plantagenet", 0 }; 124 static const UChar* cherokeeFonts[] = { L"Gadugi", L"Plantagenet", 0 };
131 static const UChar* copticFonts[] = { L"Segoe UI Symbol", 0 }; 125 static const UChar* copticFonts[] = { L"Segoe UI Symbol", 0 };
132 static const UChar* cuneiformFonts[] = { L"Segoe UI Historic", 0 }; 126 static const UChar* cuneiformFonts[] = { L"Segoe UI Historic", 0 };
133 static const UChar* cypriotFonts[] = { L"Segoe UI Historic", 0 }; 127 static const UChar* cypriotFonts[] = { L"Segoe UI Historic", 0 };
128 static const UChar* cyrillicFonts[] = { L"Times New Roman", 0 };
134 static const UChar* deseretFonts[] = { L"Segoe UI Symbol", 0 }; 129 static const UChar* deseretFonts[] = { L"Segoe UI Symbol", 0 };
135 static const UChar* devanagariFonts[] = { L"Nirmala UI", L"Mangal", 0 }; 130 static const UChar* devanagariFonts[] = { L"Nirmala UI", L"Mangal", 0 };
136 static const UChar* egyptianHieroglyphsFonts[] = { L"Segoe UI Historic", 131 static const UChar* egyptianHieroglyphsFonts[] = { L"Segoe UI Historic",
137 0 }; 132 0 };
138 static const UChar* ethiopicFonts[] = { L"Nyala", L"Abyssinica SIL", 133 static const UChar* ethiopicFonts[] = { L"Nyala", L"Abyssinica SIL",
139 L"Ethiopia Jiret", L"Visual Geez Unicode", L"GF Zemen Unicode", 134 L"Ethiopia Jiret", L"Visual Geez Unicode", L"GF Zemen Unicode",
140 L"Ebrima", 0 }; 135 L"Ebrima", 0 };
141 static const UChar* georgianFonts[] = { L"Sylfaen", L"Segoe UI", 0 }; 136 static const UChar* georgianFonts[] = { L"Sylfaen", L"Segoe UI", 0 };
142 static const UChar* glagoliticFonts[] = { L"Segoe UI Historic", 137 static const UChar* glagoliticFonts[] = { L"Segoe UI Historic",
143 L"Segoe UI Symbol", 0 }; 138 L"Segoe UI Symbol", 0 };
144 static const UChar* gothicFonts[] = { L"Segoe UI Historic", 139 static const UChar* gothicFonts[] = { L"Segoe UI Historic",
145 L"Segoe UI Symbol", 0 }; 140 L"Segoe UI Symbol", 0 };
141 static const UChar* greekFonts[] = { L"Times New Roman", 0 };
146 static const UChar* gujaratiFonts[] = { L"Nirmala UI", L"Shruti", 0 }; 142 static const UChar* gujaratiFonts[] = { L"Nirmala UI", L"Shruti", 0 };
147 static const UChar* gurmukhiFonts[] = { L"Nirmala UI", L"Raavi", 0 }; 143 static const UChar* gurmukhiFonts[] = { L"Nirmala UI", L"Raavi", 0 };
148 static const UChar* hangulFonts[] = { L"Malgun Gothic", L"Gulim", 0 }; 144 static const UChar* hangulFonts[] = { L"Malgun Gothic", L"Gulim", 0 };
149 static const UChar* hebrewFonts[] = { L"David", L"Segoe UI", 0 }; 145 static const UChar* hebrewFonts[] = { L"David", L"Segoe UI", 0 };
150 static const UChar* imperialAramaicFonts[] = { L"Segoe UI Historic", 0 }; 146 static const UChar* imperialAramaicFonts[] = { L"Segoe UI Historic", 0 };
151 static const UChar* inscriptionalPahlaviFonts[] = { L"Segoe UI Historic", 147 static const UChar* inscriptionalPahlaviFonts[] = { L"Segoe UI Historic",
152 0 }; 148 0 };
153 static const UChar* inscriptionalParthianFonts[] = { L"Segoe UI Historic", 149 static const UChar* inscriptionalParthianFonts[] = { L"Segoe UI Historic",
154 0 }; 150 0 };
155 static const UChar* javaneseFonts[] = { L"Javanese Text", 0 }; 151 static const UChar* javaneseFonts[] = { L"Javanese Text", 0 };
156 static const UChar* kannadaFonts[] = { L"Tunga", L"Nirmala UI", 0 }; 152 static const UChar* kannadaFonts[] = { L"Tunga", L"Nirmala UI", 0 };
157 static const UChar* katakanaOrHiraganaFonts[] = { L"Meiryo", L"Yu Gothic", 153 static const UChar* katakanaOrHiraganaFonts[] = { L"Meiryo", L"Yu Gothic",
158 L"MS PGothic", L"Microsoft YaHei", 0 }; 154 L"MS PGothic", L"Microsoft YaHei", 0 };
159 static const UChar* kharoshthiFonts[] = { L"Segoe UI Historic", 0 }; 155 static const UChar* kharoshthiFonts[] = { L"Segoe UI Historic", 0 };
160 // Try Khmer OS before Vista fonts as it goes along better with Latin 156 // Try Khmer OS before Vista fonts as it goes along better with Latin
161 // and looks better/larger for the same size. 157 // and looks better/larger for the same size.
162 static const UChar* khmerFonts[] = { L"Leelawadee UI", L"Khmer UI", 158 static const UChar* khmerFonts[] = { L"Leelawadee UI", L"Khmer UI",
163 L"Khmer OS", L"MoolBoran", L"DaunPenh", 0 }; 159 L"Khmer OS", L"MoolBoran", L"DaunPenh", 0 };
164 static const UChar* laoFonts[] = { L"Leelawadee UI", L"Lao UI", 160 static const UChar* laoFonts[] = { L"Leelawadee UI", L"Lao UI",
165 L"DokChampa", L"Saysettha OT", L"Phetsarath OT", L"Code2000", 0 }; 161 L"DokChampa", L"Saysettha OT", L"Phetsarath OT", L"Code2000", 0 };
162 static const UChar* latinFonts[] = { L"Times New Roman", 0 };
166 static const UChar* lisuFonts[] = { L"Segoe UI", 0 }; 163 static const UChar* lisuFonts[] = { L"Segoe UI", 0 };
167 static const UChar* lycianFonts[] = { L"Segoe UI Historic", 0 }; 164 static const UChar* lycianFonts[] = { L"Segoe UI Historic", 0 };
168 static const UChar* lydianFonts[] = { L"Segoe UI Historic", 0 }; 165 static const UChar* lydianFonts[] = { L"Segoe UI Historic", 0 };
169 static const UChar* malayalamFonts[] = { L"Nirmala UI", L"Kartika", 0 }; 166 static const UChar* malayalamFonts[] = { L"Nirmala UI", L"Kartika", 0 };
170 static const UChar* meroiticCursiveFonts[] = { L"Segoe UI Historic", 167 static const UChar* meroiticCursiveFonts[] = { L"Segoe UI Historic",
171 L"Segoe UI Symbol", 0 }; 168 L"Segoe UI Symbol", 0 };
172 static const UChar* mongolianFonts[] = { L"Mongolian Baiti", 0 }; 169 static const UChar* mongolianFonts[] = { L"Mongolian Baiti", 0 };
173 static const UChar* myanmarFonts[] = { L"Myanmar Text", L"Padauk", 170 static const UChar* myanmarFonts[] = { L"Myanmar Text", L"Padauk",
174 L"Parabaik", L"Myanmar3", L"Code2000", 0 }; 171 L"Parabaik", L"Myanmar3", L"Code2000", 0 };
175 static const UChar* newTaiLueFonts[] = { L"Microsoft New Tai Lue", 0 }; 172 static const UChar* newTaiLueFonts[] = { L"Microsoft New Tai Lue", 0 };
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 { USCRIPT_BENGALI, bengaliFonts }, 216 { USCRIPT_BENGALI, bengaliFonts },
220 { USCRIPT_BRAHMI, brahmiFonts }, 217 { USCRIPT_BRAHMI, brahmiFonts },
221 { USCRIPT_BRAILLE, brailleFonts }, 218 { USCRIPT_BRAILLE, brailleFonts },
222 { USCRIPT_BUGINESE, bugineseFonts }, 219 { USCRIPT_BUGINESE, bugineseFonts },
223 { USCRIPT_CANADIAN_ABORIGINAL, canadianAaboriginalFonts }, 220 { USCRIPT_CANADIAN_ABORIGINAL, canadianAaboriginalFonts },
224 { USCRIPT_CARIAN, carianFonts }, 221 { USCRIPT_CARIAN, carianFonts },
225 { USCRIPT_CHEROKEE, cherokeeFonts }, 222 { USCRIPT_CHEROKEE, cherokeeFonts },
226 { USCRIPT_COPTIC, copticFonts }, 223 { USCRIPT_COPTIC, copticFonts },
227 { USCRIPT_CUNEIFORM, cuneiformFonts }, 224 { USCRIPT_CUNEIFORM, cuneiformFonts },
228 { USCRIPT_CYPRIOT, cypriotFonts }, 225 { USCRIPT_CYPRIOT, cypriotFonts },
226 { USCRIPT_CYRILLIC, cyrillicFonts },
229 { USCRIPT_DESERET, deseretFonts }, 227 { USCRIPT_DESERET, deseretFonts },
230 { USCRIPT_DEVANAGARI, devanagariFonts }, 228 { USCRIPT_DEVANAGARI, devanagariFonts },
231 { USCRIPT_EGYPTIAN_HIEROGLYPHS, egyptianHieroglyphsFonts }, 229 { USCRIPT_EGYPTIAN_HIEROGLYPHS, egyptianHieroglyphsFonts },
232 { USCRIPT_ETHIOPIC, ethiopicFonts }, 230 { USCRIPT_ETHIOPIC, ethiopicFonts },
233 { USCRIPT_GEORGIAN, georgianFonts }, 231 { USCRIPT_GEORGIAN, georgianFonts },
234 { USCRIPT_GLAGOLITIC, glagoliticFonts }, 232 { USCRIPT_GLAGOLITIC, glagoliticFonts },
235 { USCRIPT_GOTHIC, gothicFonts }, 233 { USCRIPT_GOTHIC, gothicFonts },
234 { USCRIPT_GREEK, greekFonts },
236 { USCRIPT_GUJARATI, gujaratiFonts }, 235 { USCRIPT_GUJARATI, gujaratiFonts },
237 { USCRIPT_GURMUKHI, gurmukhiFonts }, 236 { USCRIPT_GURMUKHI, gurmukhiFonts },
238 { USCRIPT_HANGUL, hangulFonts }, 237 { USCRIPT_HANGUL, hangulFonts },
239 { USCRIPT_HEBREW, hebrewFonts }, 238 { USCRIPT_HEBREW, hebrewFonts },
240 { USCRIPT_HIRAGANA, katakanaOrHiraganaFonts }, 239 { USCRIPT_HIRAGANA, katakanaOrHiraganaFonts },
241 { USCRIPT_IMPERIAL_ARAMAIC, imperialAramaicFonts }, 240 { USCRIPT_IMPERIAL_ARAMAIC, imperialAramaicFonts },
242 { USCRIPT_INSCRIPTIONAL_PAHLAVI, inscriptionalPahlaviFonts }, 241 { USCRIPT_INSCRIPTIONAL_PAHLAVI, inscriptionalPahlaviFonts },
243 { USCRIPT_INSCRIPTIONAL_PARTHIAN, inscriptionalParthianFonts }, 242 { USCRIPT_INSCRIPTIONAL_PARTHIAN, inscriptionalParthianFonts },
244 { USCRIPT_JAVANESE, javaneseFonts }, 243 { USCRIPT_JAVANESE, javaneseFonts },
245 { USCRIPT_KANNADA, kannadaFonts }, 244 { USCRIPT_KANNADA, kannadaFonts },
246 { USCRIPT_KATAKANA, katakanaOrHiraganaFonts }, 245 { USCRIPT_KATAKANA, katakanaOrHiraganaFonts },
247 { USCRIPT_KATAKANA_OR_HIRAGANA, katakanaOrHiraganaFonts }, 246 { USCRIPT_KATAKANA_OR_HIRAGANA, katakanaOrHiraganaFonts },
248 { USCRIPT_KHAROSHTHI, kharoshthiFonts }, 247 { USCRIPT_KHAROSHTHI, kharoshthiFonts },
249 { USCRIPT_KHMER, khmerFonts }, 248 { USCRIPT_KHMER, khmerFonts },
250 { USCRIPT_LAO, laoFonts }, 249 { USCRIPT_LAO, laoFonts },
250 { USCRIPT_LATIN, latinFonts },
251 { USCRIPT_LISU, lisuFonts }, 251 { USCRIPT_LISU, lisuFonts },
252 { USCRIPT_LYCIAN, lycianFonts }, 252 { USCRIPT_LYCIAN, lycianFonts },
253 { USCRIPT_LYDIAN, lydianFonts }, 253 { USCRIPT_LYDIAN, lydianFonts },
254 { USCRIPT_MALAYALAM, malayalamFonts }, 254 { USCRIPT_MALAYALAM, malayalamFonts },
255 { USCRIPT_MEROITIC_CURSIVE, meroiticCursiveFonts }, 255 { USCRIPT_MEROITIC_CURSIVE, meroiticCursiveFonts },
256 { USCRIPT_MONGOLIAN, mongolianFonts }, 256 { USCRIPT_MONGOLIAN, mongolianFonts },
257 { USCRIPT_MYANMAR, myanmarFonts }, 257 { USCRIPT_MYANMAR, myanmarFonts },
258 { USCRIPT_NEW_TAI_LUE, newTaiLueFonts }, 258 { USCRIPT_NEW_TAI_LUE, newTaiLueFonts },
259 { USCRIPT_NKO, nkoFonts }, 259 { USCRIPT_NKO, nkoFonts },
260 { USCRIPT_OGHAM, oghamFonts }, 260 { USCRIPT_OGHAM, oghamFonts },
(...skipping 17 matching lines...) Expand all
278 { USCRIPT_TELUGU, teluguFonts }, 278 { USCRIPT_TELUGU, teluguFonts },
279 { USCRIPT_THAANA, thaanaFonts }, 279 { USCRIPT_THAANA, thaanaFonts },
280 { USCRIPT_THAI, thaiFonts }, 280 { USCRIPT_THAI, thaiFonts },
281 { USCRIPT_TIBETAN, tibetanFonts }, 281 { USCRIPT_TIBETAN, tibetanFonts },
282 { USCRIPT_TIFINAGH, tifinaghFonts }, 282 { USCRIPT_TIFINAGH, tifinaghFonts },
283 { USCRIPT_TRADITIONAL_HAN, traditionalHanFonts }, 283 { USCRIPT_TRADITIONAL_HAN, traditionalHanFonts },
284 { USCRIPT_VAI, vaiFonts }, 284 { USCRIPT_VAI, vaiFonts },
285 { USCRIPT_YI, yiFonts } 285 { USCRIPT_YI, yiFonts }
286 }; 286 };
287 287
288 for (size_t i = 0; i < WTF_ARRAY_LENGTH(fontMap); ++i) 288 for (const auto& fontFamily : scriptToFontFamilies) {
289 scriptFontMap[fontMap[i].script] = fontMap[i].family; 289 scriptFontMap[fontFamily.script].candidateFamilyNames = fontFamily.famil ies;
290
291 // FIXME: Instead of scanning the hard-coded list, we have to
292 // use EnumFont* to 'inspect' fonts to pick up fonts covering scripts
293 // when it's possible (e.g. using OS/2 table). If we do that, this
294 // had better be pulled out of here.
295 for (size_t i = 0; i < WTF_ARRAY_LENGTH(scriptToFontFamilies); ++i) {
296 UScriptCode script = scriptToFontFamilies[i].script;
297 scriptFontMap[script] = 0;
298 const UChar** familyPtr = scriptToFontFamilies[i].families;
299 while (*familyPtr) {
300 if (isFontPresent(*familyPtr, fontManager)) {
301 scriptFontMap[script] = *familyPtr;
302 break;
303 }
304 ++familyPtr;
305 }
306 } 290 }
307 291
308 // Initialize the locale-dependent mapping from system locale. 292 // Initialize the locale-dependent mapping from system locale.
309 UScriptCode hanScript = LayoutLocale::getSystem().scriptForHan(); 293 UScriptCode hanScript = LayoutLocale::getSystem().scriptForHan();
310 if (const UChar* localeFamily = scriptFontMap[hanScript]) 294 DCHECK(hanScript != USCRIPT_HAN);
311 scriptFontMap[USCRIPT_HAN] = localeFamily; 295 if (scriptFontMap[hanScript].candidateFamilyNames) {
296 scriptFontMap[USCRIPT_HAN].candidateFamilyNames = scriptFontMap[hanScrip t].candidateFamilyNames;
297 }
298 }
299
300 void findFirstExistingCandidateFont(FontMapping& scriptFontMapping, SkFontMgr* f ontManager)
301 {
302 for (const UChar** familyPtr = scriptFontMapping.candidateFamilyNames; *fami lyPtr; familyPtr++) {
303 if (isFontPresent(*familyPtr, fontManager)) {
304 scriptFontMapping.familyName = *familyPtr;
305 break;
306 }
307 }
308 scriptFontMapping.candidateFamilyNames = nullptr;
312 } 309 }
313 310
314 // There are a lot of characters in USCRIPT_COMMON that can be covered 311 // There are a lot of characters in USCRIPT_COMMON that can be covered
315 // by fonts for scripts closely related to them. See 312 // by fonts for scripts closely related to them. See
316 // http://unicode.org/cldr/utility/list-unicodeset.jsp?a=[:Script=Common:] 313 // http://unicode.org/cldr/utility/list-unicodeset.jsp?a=[:Script=Common:]
317 // FIXME: make this more efficient with a wider coverage 314 // FIXME: make this more efficient with a wider coverage
318 UScriptCode getScriptBasedOnUnicodeBlock(int ucs4) 315 UScriptCode getScriptBasedOnUnicodeBlock(int ucs4)
319 { 316 {
320 UBlockCode block = ublock_getCode(ucs4); 317 UBlockCode block = ublock_getCode(ucs4);
321 switch (block) { 318 switch (block) {
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
429 // - Consider using UnicodeSet (or UnicodeMap) converted from 426 // - Consider using UnicodeSet (or UnicodeMap) converted from
430 // GLYPHSET (BMP) or directly read from truetype cmap tables to 427 // GLYPHSET (BMP) or directly read from truetype cmap tables to
431 // keep track of which character is supported by which font 428 // keep track of which character is supported by which font
432 // - Update script_font_cache in response to WM_FONTCHANGE 429 // - Update script_font_cache in response to WM_FONTCHANGE
433 430
434 const UChar* getFontFamilyForScript(UScriptCode script, 431 const UChar* getFontFamilyForScript(UScriptCode script,
435 FontDescription::GenericFamilyType generic, 432 FontDescription::GenericFamilyType generic,
436 SkFontMgr* fontManager) 433 SkFontMgr* fontManager)
437 { 434 {
438 static ScriptToFontMap scriptFontMap; 435 static ScriptToFontMap scriptFontMap;
439 static ScriptToFontMap scriptMonospaceFontMap;
440 static bool initialized = false; 436 static bool initialized = false;
441 if (!initialized) { 437 if (!initialized) {
442 initializeScriptFontMap(scriptFontMap, fontManager); 438 initializeScriptFontMap(scriptFontMap);
443 initializeScriptMonospaceFontMap(scriptMonospaceFontMap, fontManager);
444 initialized = true; 439 initialized = true;
445 } 440 }
441
446 if (script == USCRIPT_INVALID_CODE) 442 if (script == USCRIPT_INVALID_CODE)
447 return 0; 443 return 0;
448 ASSERT(script < USCRIPT_CODE_LIMIT); 444 ASSERT(script < USCRIPT_CODE_LIMIT);
449 if (generic == FontDescription::MonospaceFamily && scriptMonospaceFontMap[sc ript]) 445 if (generic == FontDescription::MonospaceFamily) {
450 return scriptMonospaceFontMap[script]; 446 const UChar* monospaceFamily = findMonospaceFontForScript(script);
451 return scriptFontMap[script]; 447 if (monospaceFamily)
448 return monospaceFamily;
449 }
450 if (scriptFontMap[script].candidateFamilyNames)
451 findFirstExistingCandidateFont(scriptFontMap[script], fontManager);
452 return scriptFontMap[script].familyName;
452 } 453 }
453 454
454 // FIXME: 455 // FIXME:
455 // - Handle 'Inherited', 'Common' and 'Unknown' 456 // - Handle 'Inherited', 'Common' and 'Unknown'
456 // (see http://www.unicode.org/reports/tr24/#Usage_Model ) 457 // (see http://www.unicode.org/reports/tr24/#Usage_Model )
457 // For 'Inherited' and 'Common', perhaps we need to 458 // For 'Inherited' and 'Common', perhaps we need to
458 // accept another parameter indicating the previous family 459 // accept another parameter indicating the previous family
459 // and just return it. 460 // and just return it.
460 // - All the characters (or characters up to the point a single 461 // - All the characters (or characters up to the point a single
461 // font can cover) need to be taken into account 462 // font can cover) need to be taken into account
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
524 family = L"lucida sans unicode"; 525 family = L"lucida sans unicode";
525 } 526 }
526 } 527 }
527 528
528 if (scriptChecked) 529 if (scriptChecked)
529 *scriptChecked = script; 530 *scriptChecked = script;
530 return family; 531 return family;
531 } 532 }
532 533
533 } // namespace blink 534 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698