| OLD | NEW |
| 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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 } | 62 } |
| 63 actualFamilies->unref(); | 63 actualFamilies->unref(); |
| 64 | 64 |
| 65 return matchesRequestedFamily; | 65 return matchesRequestedFamily; |
| 66 } | 66 } |
| 67 | 67 |
| 68 // A simple mapping from UScriptCode to family name. This is a sparse array, | 68 // A simple mapping from UScriptCode to family name. This is a sparse array, |
| 69 // which works well since the range of UScriptCode values is small. | 69 // which works well since the range of UScriptCode values is small. |
| 70 typedef const UChar* ScriptToFontMap[USCRIPT_CODE_LIMIT]; | 70 typedef const UChar* ScriptToFontMap[USCRIPT_CODE_LIMIT]; |
| 71 | 71 |
| 72 void initializeScriptMonospaceFontMap(ScriptToFontMap& scriptFontMap, SkFontMgr*
fontManager) |
| 73 { |
| 74 struct FontMap { |
| 75 UScriptCode script; |
| 76 const UChar* family; |
| 77 }; |
| 78 |
| 79 static const FontMap fontMap[] = { |
| 80 { USCRIPT_HEBREW, L"courier new" }, |
| 81 { USCRIPT_ARABIC, L"courier new" }, |
| 82 }; |
| 83 |
| 84 for (size_t i = 0; i < WTF_ARRAY_LENGTH(fontMap); ++i) |
| 85 scriptFontMap[fontMap[i].script] = fontMap[i].family; |
| 86 } |
| 87 |
| 72 void initializeScriptFontMap(ScriptToFontMap& scriptFontMap, SkFontMgr* fontMana
ger) | 88 void initializeScriptFontMap(ScriptToFontMap& scriptFontMap, SkFontMgr* fontMana
ger) |
| 73 { | 89 { |
| 74 struct FontMap { | 90 struct FontMap { |
| 75 UScriptCode script; | 91 UScriptCode script; |
| 76 const UChar* family; | 92 const UChar* family; |
| 77 }; | 93 }; |
| 78 | 94 |
| 79 static const FontMap fontMap[] = { | 95 static const FontMap fontMap[] = { |
| 80 {USCRIPT_LATIN, L"times new roman"}, | 96 {USCRIPT_LATIN, L"times new roman"}, |
| 81 {USCRIPT_GREEK, L"times new roman"}, | 97 {USCRIPT_GREEK, L"times new roman"}, |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 252 // - Consider using UnicodeSet (or UnicodeMap) converted from | 268 // - Consider using UnicodeSet (or UnicodeMap) converted from |
| 253 // GLYPHSET (BMP) or directly read from truetype cmap tables to | 269 // GLYPHSET (BMP) or directly read from truetype cmap tables to |
| 254 // keep track of which character is supported by which font | 270 // keep track of which character is supported by which font |
| 255 // - Update script_font_cache in response to WM_FONTCHANGE | 271 // - Update script_font_cache in response to WM_FONTCHANGE |
| 256 | 272 |
| 257 const UChar* getFontFamilyForScript(UScriptCode script, | 273 const UChar* getFontFamilyForScript(UScriptCode script, |
| 258 FontDescription::GenericFamilyType generic, | 274 FontDescription::GenericFamilyType generic, |
| 259 SkFontMgr* fontManager) | 275 SkFontMgr* fontManager) |
| 260 { | 276 { |
| 261 static ScriptToFontMap scriptFontMap; | 277 static ScriptToFontMap scriptFontMap; |
| 278 static ScriptToFontMap scriptMonospaceFontMap; |
| 262 static bool initialized = false; | 279 static bool initialized = false; |
| 263 if (!initialized) { | 280 if (!initialized) { |
| 264 initializeScriptFontMap(scriptFontMap, fontManager); | 281 initializeScriptFontMap(scriptFontMap, fontManager); |
| 282 initializeScriptMonospaceFontMap(scriptMonospaceFontMap, fontManager); |
| 265 initialized = true; | 283 initialized = true; |
| 266 } | 284 } |
| 267 if (script == USCRIPT_INVALID_CODE) | 285 if (script == USCRIPT_INVALID_CODE) |
| 268 return 0; | 286 return 0; |
| 269 ASSERT(script < USCRIPT_CODE_LIMIT); | 287 ASSERT(script < USCRIPT_CODE_LIMIT); |
| 288 if (generic == FontDescription::MonospaceFamily && scriptMonospaceFontMap[sc
ript]) |
| 289 return scriptMonospaceFontMap[script]; |
| 270 return scriptFontMap[script]; | 290 return scriptFontMap[script]; |
| 271 } | 291 } |
| 272 | 292 |
| 273 // FIXME: | 293 // FIXME: |
| 274 // - Handle 'Inherited', 'Common' and 'Unknown' | 294 // - Handle 'Inherited', 'Common' and 'Unknown' |
| 275 // (see http://www.unicode.org/reports/tr24/#Usage_Model ) | 295 // (see http://www.unicode.org/reports/tr24/#Usage_Model ) |
| 276 // For 'Inherited' and 'Common', perhaps we need to | 296 // For 'Inherited' and 'Common', perhaps we need to |
| 277 // accept another parameter indicating the previous family | 297 // accept another parameter indicating the previous family |
| 278 // and just return it. | 298 // and just return it. |
| 279 // - All the characters (or characters up to the point a single | 299 // - All the characters (or characters up to the point a single |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 322 family = L"lucida sans unicode"; | 342 family = L"lucida sans unicode"; |
| 323 } | 343 } |
| 324 } | 344 } |
| 325 | 345 |
| 326 if (scriptChecked) | 346 if (scriptChecked) |
| 327 *scriptChecked = script; | 347 *scriptChecked = script; |
| 328 return family; | 348 return family; |
| 329 } | 349 } |
| 330 | 350 |
| 331 } // namespace WebCore | 351 } // namespace WebCore |
| OLD | NEW |