Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (c) 2011 Google Inc. All rights reserved. | 2 * Copyright (c) 2011 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 17 matching lines...) Expand all Loading... | |
| 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 "config.h" | 31 #include "config.h" |
| 32 #include "platform/fonts/FontCache.h" | 32 #include "platform/fonts/FontCache.h" |
| 33 | 33 |
| 34 | 34 |
| 35 #include "platform/fonts/SimpleFontData.h" | 35 #include "platform/fonts/SimpleFontData.h" |
| 36 #include "platform/fonts/FontDescription.h" | 36 #include "platform/fonts/FontDescription.h" |
| 37 #include "platform/fonts/FontFaceCreationParams.h" | 37 #include "platform/fonts/FontFaceCreationParams.h" |
| 38 | 38 #include "third_party/skia/include/core/SkTypeface.h" |
| 39 #include "SkTypeface_android.h" | 39 #include "third_party/skia/include/ports/SkFontMgr.h" |
| 40 | 40 |
| 41 namespace blink { | 41 namespace blink { |
| 42 | 42 |
| 43 static AtomicString getFamilyNameForCharacter(UChar32 c, UScriptCode script) | 43 static AtomicString getFamilyNameForCharacter(UChar32 c, UScriptCode script) |
| 44 { | 44 { |
| 45 // This is a hack to use the preferred font for CJK scripts. | 45 // This is a hack to use the preferred font for CJK scripts. |
| 46 // FIXME: Use new Skia API once Android system supports per-family and per-s cript fallback fonts. | 46 // FIXME: Use new Skia API once Android system supports per-family and per-s cript fallback fonts. |
| 47 const char* locale; | 47 const char* locale; |
| 48 switch (script) { | 48 switch (script) { |
| 49 case USCRIPT_SIMPLIFIED_HAN: | 49 case USCRIPT_SIMPLIFIED_HAN: |
| 50 locale = "zh-CN"; | 50 locale = "zh-CN"; |
| 51 break; | 51 break; |
| 52 case USCRIPT_TRADITIONAL_HAN: | 52 case USCRIPT_TRADITIONAL_HAN: |
| 53 locale = "zh-TW"; | 53 locale = "zh-TW"; |
| 54 break; | 54 break; |
| 55 case USCRIPT_KATAKANA_OR_HIRAGANA: | 55 case USCRIPT_KATAKANA_OR_HIRAGANA: |
| 56 locale = "ja"; | 56 locale = "ja"; |
| 57 break; | 57 break; |
| 58 case USCRIPT_HANGUL: | 58 case USCRIPT_HANGUL: |
| 59 locale = "ko"; | 59 locale = "ko"; |
| 60 break; | 60 break; |
| 61 default: | 61 default: |
| 62 locale = 0; | 62 locale = 0; |
| 63 break; | 63 break; |
| 64 } | 64 } |
| 65 | 65 |
| 66 SkString skiaFamilyName; | 66 RefPtr<SkFontMgr> fm = adoptRef(SkFontMgr::RefDefault()); |
| 67 if (!SkGetFallbackFamilyNameForChar(c, locale, &skiaFamilyName) || skiaFamil yName.isEmpty()) | 67 RefPtr<SkTypeface> typeface = adoptRef(fm->matchFamilyStyleCharacter(0, SkFo ntStyle(), locale, c)); |
| 68 if (!typeface) | |
| 68 return emptyAtom; | 69 return emptyAtom; |
| 69 | 70 |
| 71 SkString skiaFamilyName; | |
| 72 typeface->getFamilyName(&skiaFamilyName); | |
| 70 return skiaFamilyName.c_str(); | 73 return skiaFamilyName.c_str(); |
|
f(malita)
2014/08/07 17:41:07
Unrelated nit: for the sake of the next person loo
bungeman-skia
2014/08/07 17:48:06
OMG, yes. This is what it was doing, so I'm leavin
| |
| 71 } | 74 } |
| 72 | 75 |
| 73 PassRefPtr<SimpleFontData> FontCache::fallbackFontForCharacter(const FontDescrip tion& fontDescription, UChar32 c, const SimpleFontData*) | 76 PassRefPtr<SimpleFontData> FontCache::fallbackFontForCharacter(const FontDescrip tion& fontDescription, UChar32 c, const SimpleFontData*) |
| 74 { | 77 { |
| 75 AtomicString familyName = getFamilyNameForCharacter(c, fontDescription.scrip t()); | 78 AtomicString familyName = getFamilyNameForCharacter(c, fontDescription.scrip t()); |
| 76 if (familyName.isEmpty()) | 79 if (familyName.isEmpty()) |
| 77 return getLastResortFallbackFont(fontDescription, DoNotRetain); | 80 return getLastResortFallbackFont(fontDescription, DoNotRetain); |
| 78 return fontDataFromFontPlatformData(getFontPlatformData(fontDescription, Fon tFaceCreationParams(familyName)), DoNotRetain); | 81 return fontDataFromFontPlatformData(getFontPlatformData(fontDescription, Fon tFaceCreationParams(familyName)), DoNotRetain); |
| 79 } | 82 } |
| 80 | 83 |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 95 break; | 98 break; |
| 96 default: | 99 default: |
| 97 // For other scripts, use the default generic family mapping logic. | 100 // For other scripts, use the default generic family mapping logic. |
| 98 return familyName; | 101 return familyName; |
| 99 } | 102 } |
| 100 | 103 |
| 101 return getFamilyNameForCharacter(examplerChar, script); | 104 return getFamilyNameForCharacter(examplerChar, script); |
| 102 } | 105 } |
| 103 | 106 |
| 104 } // namespace blink | 107 } // namespace blink |
| OLD | NEW |