| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "SkFontConfigParser_android.h" | 8 #include "SkFontConfigParser_android.h" |
| 9 #include "SkFontDescriptor.h" | 9 #include "SkFontDescriptor.h" |
| 10 #include "SkFontHost_FreeType_common.h" | 10 #include "SkFontHost_FreeType_common.h" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 #endif | 35 #endif |
| 36 | 36 |
| 37 // For test only. | 37 // For test only. |
| 38 static const char* gTestMainConfigFile = NULL; | 38 static const char* gTestMainConfigFile = NULL; |
| 39 static const char* gTestFallbackConfigFile = NULL; | 39 static const char* gTestFallbackConfigFile = NULL; |
| 40 static const char* gTestFontFilePrefix = NULL; | 40 static const char* gTestFontFilePrefix = NULL; |
| 41 | 41 |
| 42 class SkTypeface_Android : public SkTypeface_FreeType { | 42 class SkTypeface_Android : public SkTypeface_FreeType { |
| 43 public: | 43 public: |
| 44 SkTypeface_Android(int index, | 44 SkTypeface_Android(int index, |
| 45 Style style, | 45 const SkFontStyle& style, |
| 46 bool isFixedPitch, | 46 bool isFixedPitch, |
| 47 const SkString familyName) | 47 const SkString familyName) |
| 48 : INHERITED(style, SkTypefaceCache::NewFontID(), isFixedPitch) | 48 : INHERITED(style, SkTypefaceCache::NewFontID(), isFixedPitch) |
| 49 , fIndex(index) | 49 , fIndex(index) |
| 50 , fFamilyName(familyName) { } | 50 , fFamilyName(familyName) { } |
| 51 | 51 |
| 52 protected: | 52 protected: |
| 53 virtual void onGetFamilyName(SkString* familyName) const SK_OVERRIDE { | 53 virtual void onGetFamilyName(SkString* familyName) const SK_OVERRIDE { |
| 54 *familyName = fFamilyName; | 54 *familyName = fFamilyName; |
| 55 } | 55 } |
| 56 | 56 |
| 57 int fIndex; | 57 int fIndex; |
| 58 SkString fFamilyName; | 58 SkString fFamilyName; |
| 59 | 59 |
| 60 private: | 60 private: |
| 61 typedef SkTypeface_FreeType INHERITED; | 61 typedef SkTypeface_FreeType INHERITED; |
| 62 }; | 62 }; |
| 63 | 63 |
| 64 class SkTypeface_AndroidSystem : public SkTypeface_Android { | 64 class SkTypeface_AndroidSystem : public SkTypeface_Android { |
| 65 public: | 65 public: |
| 66 SkTypeface_AndroidSystem(const SkString pathName, | 66 SkTypeface_AndroidSystem(const SkString pathName, |
| 67 int index, | 67 int index, |
| 68 Style style, | 68 const SkFontStyle& style, |
| 69 bool isFixedPitch, | 69 bool isFixedPitch, |
| 70 const SkString familyName, | 70 const SkString familyName, |
| 71 const SkLanguage& lang, | 71 const SkLanguage& lang, |
| 72 FontVariant variantStyle) | 72 FontVariant variantStyle) |
| 73 : INHERITED(index, style, isFixedPitch, familyName) | 73 : INHERITED(index, style, isFixedPitch, familyName) |
| 74 , fPathName(pathName) | 74 , fPathName(pathName) |
| 75 , fLang(lang) | 75 , fLang(lang) |
| 76 , fVariantStyle(variantStyle) { } | 76 , fVariantStyle(variantStyle) { } |
| 77 | 77 |
| 78 virtual void onGetFontDescriptor(SkFontDescriptor* desc, | 78 virtual void onGetFontDescriptor(SkFontDescriptor* desc, |
| (...skipping 14 matching lines...) Expand all Loading... |
| 93 const SkLanguage fLang; | 93 const SkLanguage fLang; |
| 94 const FontVariant fVariantStyle; | 94 const FontVariant fVariantStyle; |
| 95 | 95 |
| 96 typedef SkTypeface_Android INHERITED; | 96 typedef SkTypeface_Android INHERITED; |
| 97 }; | 97 }; |
| 98 | 98 |
| 99 class SkTypeface_AndroidStream : public SkTypeface_Android { | 99 class SkTypeface_AndroidStream : public SkTypeface_Android { |
| 100 public: | 100 public: |
| 101 SkTypeface_AndroidStream(SkStream* stream, | 101 SkTypeface_AndroidStream(SkStream* stream, |
| 102 int index, | 102 int index, |
| 103 Style style, | 103 const SkFontStyle& style, |
| 104 bool isFixedPitch, | 104 bool isFixedPitch, |
| 105 const SkString familyName) | 105 const SkString familyName) |
| 106 : INHERITED(index, style, isFixedPitch, familyName) | 106 : INHERITED(index, style, isFixedPitch, familyName) |
| 107 , fStream(SkRef(stream)) { } | 107 , fStream(SkRef(stream)) { } |
| 108 | 108 |
| 109 virtual void onGetFontDescriptor(SkFontDescriptor* desc, | 109 virtual void onGetFontDescriptor(SkFontDescriptor* desc, |
| 110 bool* serialize) const SK_OVERRIDE { | 110 bool* serialize) const SK_OVERRIDE { |
| 111 SkASSERT(desc); | 111 SkASSERT(desc); |
| 112 SkASSERT(serialize); | 112 SkASSERT(serialize); |
| 113 desc->setFamilyName(fFamilyName.c_str()); | 113 desc->setFamilyName(fFamilyName.c_str()); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 get_path_for_sys_fonts(basePath, fontFile.fFileName, &pathName); | 151 get_path_for_sys_fonts(basePath, fontFile.fFileName, &pathName); |
| 152 | 152 |
| 153 SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(pathName.c_str()
)); | 153 SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(pathName.c_str()
)); |
| 154 if (!stream.get()) { | 154 if (!stream.get()) { |
| 155 DEBUG_FONT(("---- SystemFonts[%d] file=%s (NOT EXIST)", i, pathN
ame.c_str())); | 155 DEBUG_FONT(("---- SystemFonts[%d] file=%s (NOT EXIST)", i, pathN
ame.c_str())); |
| 156 continue; | 156 continue; |
| 157 } | 157 } |
| 158 | 158 |
| 159 const int ttcIndex = fontFile.fIndex; | 159 const int ttcIndex = fontFile.fIndex; |
| 160 SkString familyName; | 160 SkString familyName; |
| 161 SkTypeface::Style style; | 161 SkFontStyle style; |
| 162 bool isFixedWidth; | 162 bool isFixedWidth; |
| 163 if (!SkTypeface_FreeType::ScanFont(stream.get(), ttcIndex, | 163 if (!SkTypeface_FreeType::ScanFont(stream.get(), ttcIndex, |
| 164 &familyName, &style, &isFixedWidt
h)) { | 164 &familyName, &style, &isFixedWidt
h)) { |
| 165 DEBUG_FONT(("---- SystemFonts[%d] file=%s (INVALID)", i, pathNam
e.c_str())); | 165 DEBUG_FONT(("---- SystemFonts[%d] file=%s (INVALID)", i, pathNam
e.c_str())); |
| 166 continue; | 166 continue; |
| 167 } | 167 } |
| 168 | 168 |
| 169 const SkLanguage& lang = family.fLanguage; | 169 const SkLanguage& lang = family.fLanguage; |
| 170 uint32_t variant = family.fVariant; | 170 uint32_t variant = family.fVariant; |
| 171 if (kDefault_FontVariant == variant) { | 171 if (kDefault_FontVariant == variant) { |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 397 return this->createFromStream(stream, ttcIndex); | 397 return this->createFromStream(stream, ttcIndex); |
| 398 } | 398 } |
| 399 | 399 |
| 400 virtual SkTypeface* onCreateFromFile(const char path[], int ttcIndex) const
SK_OVERRIDE { | 400 virtual SkTypeface* onCreateFromFile(const char path[], int ttcIndex) const
SK_OVERRIDE { |
| 401 SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(path)); | 401 SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(path)); |
| 402 return stream.get() ? this->createFromStream(stream, ttcIndex) : NULL; | 402 return stream.get() ? this->createFromStream(stream, ttcIndex) : NULL; |
| 403 } | 403 } |
| 404 | 404 |
| 405 virtual SkTypeface* onCreateFromStream(SkStream* stream, int ttcIndex) const
SK_OVERRIDE { | 405 virtual SkTypeface* onCreateFromStream(SkStream* stream, int ttcIndex) const
SK_OVERRIDE { |
| 406 bool isFixedPitch; | 406 bool isFixedPitch; |
| 407 SkTypeface::Style style; | 407 SkFontStyle style; |
| 408 SkString name; | 408 SkString name; |
| 409 if (!SkTypeface_FreeType::ScanFont(stream, ttcIndex, &name, &style, &isF
ixedPitch)) { | 409 if (!SkTypeface_FreeType::ScanFont(stream, ttcIndex, &name, &style, &isF
ixedPitch)) { |
| 410 return NULL; | 410 return NULL; |
| 411 } | 411 } |
| 412 return SkNEW_ARGS(SkTypeface_AndroidStream, (stream, ttcIndex, | 412 return SkNEW_ARGS(SkTypeface_AndroidStream, (stream, ttcIndex, |
| 413 style, isFixedPitch, name))
; | 413 style, isFixedPitch, name))
; |
| 414 } | 414 } |
| 415 | 415 |
| 416 | 416 |
| 417 virtual SkTypeface* onLegacyCreateTypeface(const char familyName[], | 417 virtual SkTypeface* onLegacyCreateTypeface(const char familyName[], |
| 418 unsigned styleBits) const SK_OVER
RIDE { | 418 unsigned styleBits) const SK_OVER
RIDE { |
| 419 SkTypeface::Style oldStyle = (SkTypeface::Style)styleBits; | 419 SkFontStyle style = SkFontStyle(styleBits); |
| 420 SkFontStyle style = SkFontStyle(oldStyle & SkTypeface::kBold | |
| 421 ? SkFontStyle::kBold_Weight | |
| 422 : SkFontStyle::kNormal_Weight, | |
| 423 SkFontStyle::kNormal_Width, | |
| 424 oldStyle & SkTypeface::kItalic | |
| 425 ? SkFontStyle::kItalic_Slant | |
| 426 : SkFontStyle::kUpright_Slant); | |
| 427 | 420 |
| 428 if (familyName) { | 421 if (familyName) { |
| 429 // On Android, we must return NULL when we can't find the requested | 422 // On Android, we must return NULL when we can't find the requested |
| 430 // named typeface so that the system/app can provide their own recov
ery | 423 // named typeface so that the system/app can provide their own recov
ery |
| 431 // mechanism. On other platforms we'd provide a typeface from the | 424 // mechanism. On other platforms we'd provide a typeface from the |
| 432 // default family instead. | 425 // default family instead. |
| 433 return this->onMatchFamilyStyle(familyName, style); | 426 return this->onMatchFamilyStyle(familyName, style); |
| 434 } | 427 } |
| 435 return fDefaultFamily->matchStyle(style); | 428 return fDefaultFamily->matchStyle(style); |
| 436 } | 429 } |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 530 SkDEBUGF(("Use Test Config File Main %s, Fallback %s, Font Dir %s", | 523 SkDEBUGF(("Use Test Config File Main %s, Fallback %s, Font Dir %s", |
| 531 gTestMainConfigFile, gTestFallbackConfigFile, gTestFontFilePrefix)
); | 524 gTestMainConfigFile, gTestFallbackConfigFile, gTestFontFilePrefix)
); |
| 532 } | 525 } |
| 533 | 526 |
| 534 void SkGetTestFontConfiguration(const char** mainconf, const char** fallbackconf
, | 527 void SkGetTestFontConfiguration(const char** mainconf, const char** fallbackconf
, |
| 535 const char** fontsdir) { | 528 const char** fontsdir) { |
| 536 *mainconf = gTestMainConfigFile; | 529 *mainconf = gTestMainConfigFile; |
| 537 *fallbackconf = gTestFallbackConfigFile; | 530 *fallbackconf = gTestFallbackConfigFile; |
| 538 *fontsdir = gTestFontFilePrefix; | 531 *fontsdir = gTestFontFilePrefix; |
| 539 } | 532 } |
| OLD | NEW |