| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2006, 2007 Apple Computer, Inc. | 2 * Copyright (C) 2006, 2007 Apple Computer, Inc. |
| 3 * Copyright (c) 2006, 2007, 2008, 2009, 2012 Google Inc. All rights reserved. | 3 * Copyright (c) 2006, 2007, 2008, 2009, 2012 Google Inc. All rights reserved. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions are | 6 * modification, are permitted provided that the following conditions are |
| 7 * met: | 7 * met: |
| 8 * | 8 * |
| 9 * * Redistributions of source code must retain the above copyright | 9 * * Redistributions of source code must retain the above copyright |
| 10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 { | 63 { |
| 64 SkPaint paint; | 64 SkPaint paint; |
| 65 fontData->setupPaint(&paint); | 65 fontData->setupPaint(&paint); |
| 66 paint.setTextEncoding(SkPaint::kUTF32_TextEncoding); | 66 paint.setTextEncoding(SkPaint::kUTF32_TextEncoding); |
| 67 | 67 |
| 68 uint16_t glyph; | 68 uint16_t glyph; |
| 69 paint.textToGlyphs(&character, sizeof(character), &glyph); | 69 paint.textToGlyphs(&character, sizeof(character), &glyph); |
| 70 return glyph; | 70 return glyph; |
| 71 } | 71 } |
| 72 | 72 |
| 73 // Minimum size, in pixels, at which anti alias is enabled for certain |
| 74 // scripts. Only applies to the Direct Write backend for now. |
| 75 static unsigned minSizeForAntiAlias(UScriptCode script) |
| 76 { |
| 77 switch (script) { |
| 78 case USCRIPT_TRADITIONAL_HAN: |
| 79 return 24; |
| 80 case USCRIPT_SIMPLIFIED_HAN: |
| 81 case USCRIPT_HIRAGANA: |
| 82 case USCRIPT_KATAKANA: |
| 83 case USCRIPT_KATAKANA_OR_HIRAGANA: |
| 84 case USCRIPT_HANGUL: |
| 85 case USCRIPT_BENGALI: |
| 86 return 16; |
| 87 case USCRIPT_THAI: |
| 88 case USCRIPT_HEBREW: |
| 89 case USCRIPT_ARABIC: |
| 90 case USCRIPT_DEVANAGARI: |
| 91 case USCRIPT_GURMUKHI: |
| 92 case USCRIPT_GUJARATI: |
| 93 case USCRIPT_TAMIL: |
| 94 case USCRIPT_TELUGU: |
| 95 case USCRIPT_KANNADA: |
| 96 case USCRIPT_GEORGIAN: |
| 97 case USCRIPT_ARMENIAN: |
| 98 case USCRIPT_THAANA: |
| 99 case USCRIPT_CANADIAN_ABORIGINAL: |
| 100 case USCRIPT_CHEROKEE: |
| 101 case USCRIPT_MONGOLIAN: |
| 102 default: |
| 103 return 0; |
| 104 } |
| 105 } |
| 106 |
| 107 static bool fontRequiresFullHinting(const AtomicString& familyName) |
| 108 { |
| 109 DEFINE_STATIC_LOCAL(AtomicString, courierNew, ("Courier New", AtomicString::
ConstructFromLiteral)); |
| 110 if (equalIgnoringCase(familyName, courierNew)) |
| 111 return true; |
| 112 |
| 113 return false; |
| 114 } |
| 115 |
| 73 // Given the desired base font, this will create a SimpleFontData for a specific | 116 // Given the desired base font, this will create a SimpleFontData for a specific |
| 74 // font that can be used to render the given range of characters. | 117 // font that can be used to render the given range of characters. |
| 75 PassRefPtr<SimpleFontData> FontCache::platformFallbackForCharacter(const FontDes
cription& fontDescription, UChar32 character, const SimpleFontData*) | 118 PassRefPtr<SimpleFontData> FontCache::platformFallbackForCharacter(const FontDes
cription& fontDescription, UChar32 character, const SimpleFontData*) |
| 76 { | 119 { |
| 77 // FIXME: Consider passing fontDescription.dominantScript() | 120 // FIXME: Consider passing fontDescription.dominantScript() |
| 78 // to GetFallbackFamily here. | 121 // to GetFallbackFamily here. |
| 79 UScriptCode script; | 122 UScriptCode script; |
| 80 const wchar_t* family = getFallbackFamily(character, | 123 const wchar_t* family = getFallbackFamily(character, |
| 81 fontDescription.genericFamily(), | 124 fontDescription.genericFamily(), |
| 82 &script); | 125 &script); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 for (i = 0; (!data || !fontContainsCharacter(data, family, character)) && i
< numFonts; ++i) { | 185 for (i = 0; (!data || !fontContainsCharacter(data, family, character)) && i
< numFonts; ++i) { |
| 143 family = panUniFonts[i]; | 186 family = panUniFonts[i]; |
| 144 data = getFontPlatformData(fontDescription, AtomicString(family, wcslen(
family))); | 187 data = getFontPlatformData(fontDescription, AtomicString(family, wcslen(
family))); |
| 145 } | 188 } |
| 146 | 189 |
| 147 // When i-th font (0-base) in |panUniFonts| contains a character and | 190 // When i-th font (0-base) in |panUniFonts| contains a character and |
| 148 // we get out of the loop, |i| will be |i + 1|. That is, if only the | 191 // we get out of the loop, |i| will be |i + 1|. That is, if only the |
| 149 // last font in the array covers the character, |i| will be numFonts. | 192 // last font in the array covers the character, |i| will be numFonts. |
| 150 // So, we have to use '<=" rather than '<' to see if we found a font | 193 // So, we have to use '<=" rather than '<' to see if we found a font |
| 151 // covering the character. | 194 // covering the character. |
| 152 if (i <= numFonts) | 195 if (i <= numFonts) { |
| 196 if (s_useDirectWrite) |
| 197 data->setMinSizeForAntiAlias(minSizeForAntiAlias(script)); |
| 153 return fontDataFromFontPlatformData(data, DoNotRetain); | 198 return fontDataFromFontPlatformData(data, DoNotRetain); |
| 199 } |
| 154 | 200 |
| 155 return nullptr; | 201 return nullptr; |
| 156 } | 202 } |
| 157 | 203 |
| 158 static inline bool equalIgnoringCase(const AtomicString& a, const SkString& b) | 204 static inline bool equalIgnoringCase(const AtomicString& a, const SkString& b) |
| 159 { | 205 { |
| 160 return equalIgnoringCase(a, AtomicString::fromUTF8(b.c_str())); | 206 return equalIgnoringCase(a, AtomicString::fromUTF8(b.c_str())); |
| 161 } | 207 } |
| 162 | 208 |
| 163 static bool typefacesMatchesFamily(const SkTypeface* tf, const AtomicString& fam
ily) | 209 static bool typefacesMatchesFamily(const SkTypeface* tf, const AtomicString& fam
ily) |
| (...skipping 16 matching lines...) Expand all Loading... |
| 180 if (!matchesRequestedFamily) { | 226 if (!matchesRequestedFamily) { |
| 181 SkString familyName; | 227 SkString familyName; |
| 182 tf->getFamilyName(&familyName); | 228 tf->getFamilyName(&familyName); |
| 183 if (equalIgnoringCase(family, familyName)) | 229 if (equalIgnoringCase(family, familyName)) |
| 184 matchesRequestedFamily = true; | 230 matchesRequestedFamily = true; |
| 185 } | 231 } |
| 186 | 232 |
| 187 return matchesRequestedFamily; | 233 return matchesRequestedFamily; |
| 188 } | 234 } |
| 189 | 235 |
| 190 // Minimum size, in pixels, at which anti alias is enabled for certain | |
| 191 // scripts. Only applies to the Direct Write backend for now. | |
| 192 static unsigned minSizeForAntiAlias(UScriptCode script) | |
| 193 { | |
| 194 switch (script) { | |
| 195 case USCRIPT_TRADITIONAL_HAN: | |
| 196 return 24; | |
| 197 case USCRIPT_SIMPLIFIED_HAN: | |
| 198 case USCRIPT_HIRAGANA: | |
| 199 case USCRIPT_KATAKANA: | |
| 200 case USCRIPT_KATAKANA_OR_HIRAGANA: | |
| 201 case USCRIPT_HANGUL: | |
| 202 case USCRIPT_BENGALI: | |
| 203 return 16; | |
| 204 case USCRIPT_THAI: | |
| 205 case USCRIPT_HEBREW: | |
| 206 case USCRIPT_ARABIC: | |
| 207 case USCRIPT_DEVANAGARI: | |
| 208 case USCRIPT_GURMUKHI: | |
| 209 case USCRIPT_GUJARATI: | |
| 210 case USCRIPT_TAMIL: | |
| 211 case USCRIPT_TELUGU: | |
| 212 case USCRIPT_KANNADA: | |
| 213 case USCRIPT_GEORGIAN: | |
| 214 case USCRIPT_ARMENIAN: | |
| 215 case USCRIPT_THAANA: | |
| 216 case USCRIPT_CANADIAN_ABORIGINAL: | |
| 217 case USCRIPT_CHEROKEE: | |
| 218 case USCRIPT_MONGOLIAN: | |
| 219 default: | |
| 220 return 0; | |
| 221 } | |
| 222 } | |
| 223 | |
| 224 static bool fontRequiresFullHinting(const AtomicString& familyName) | |
| 225 { | |
| 226 DEFINE_STATIC_LOCAL(AtomicString, courierNew, ("Courier New", AtomicString::
ConstructFromLiteral)); | |
| 227 if (equalIgnoringCase(familyName, courierNew)) | |
| 228 return true; | |
| 229 | |
| 230 return false; | |
| 231 } | |
| 232 | |
| 233 FontPlatformData* FontCache::createFontPlatformData(const FontDescription& fontD
escription, const AtomicString& family, float fontSize) | 236 FontPlatformData* FontCache::createFontPlatformData(const FontDescription& fontD
escription, const AtomicString& family, float fontSize) |
| 234 { | 237 { |
| 235 CString name; | 238 CString name; |
| 236 RefPtr<SkTypeface> tf = createTypeface(fontDescription, family, name); | 239 RefPtr<SkTypeface> tf = createTypeface(fontDescription, family, name); |
| 237 if (!tf) | 240 if (!tf) |
| 238 return 0; | 241 return 0; |
| 239 | 242 |
| 240 // Windows will always give us a valid pointer here, even if the face name | 243 // Windows will always give us a valid pointer here, even if the face name |
| 241 // is non-existent. We have to double-check and see if the family name was | 244 // is non-existent. We have to double-check and see if the family name was |
| 242 // really used. | 245 // really used. |
| (...skipping 17 matching lines...) Expand all Loading... |
| 260 result->setMinSizeForAntiAlias( | 263 result->setMinSizeForAntiAlias( |
| 261 minSizeForAntiAlias(fontDescription.script())); | 264 minSizeForAntiAlias(fontDescription.script())); |
| 262 if (fontRequiresFullHinting(family)) | 265 if (fontRequiresFullHinting(family)) |
| 263 result->setHinting(SkPaint::kFull_Hinting); | 266 result->setHinting(SkPaint::kFull_Hinting); |
| 264 } | 267 } |
| 265 | 268 |
| 266 return result; | 269 return result; |
| 267 } | 270 } |
| 268 | 271 |
| 269 } | 272 } |
| OLD | NEW |