| 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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 | 77 |
| 78 virtual void onGetFontDescriptor(SkFontDescriptor* desc, | 78 virtual void onGetFontDescriptor(SkFontDescriptor* desc, |
| 79 bool* serialize) const SK_OVERRIDE { | 79 bool* serialize) const SK_OVERRIDE { |
| 80 SkASSERT(desc); | 80 SkASSERT(desc); |
| 81 SkASSERT(serialize); | 81 SkASSERT(serialize); |
| 82 desc->setFamilyName(fFamilyName.c_str()); | 82 desc->setFamilyName(fFamilyName.c_str()); |
| 83 desc->setFontFileName(fPathName.c_str()); | 83 desc->setFontFileName(fPathName.c_str()); |
| 84 desc->setFontIndex(fIndex); | 84 desc->setFontIndex(fIndex); |
| 85 *serialize = false; | 85 *serialize = false; |
| 86 } | 86 } |
| 87 SkStream* onOpenStream(int* ttcIndex) const SK_OVERRIDE { | 87 SkStreamAsset* onOpenStream(int* ttcIndex) const SK_OVERRIDE { |
| 88 *ttcIndex = fIndex; | 88 *ttcIndex = fIndex; |
| 89 return SkStream::NewFromFile(fPathName.c_str()); | 89 return SkStream::NewFromFile(fPathName.c_str()); |
| 90 } | 90 } |
| 91 | 91 |
| 92 const SkString fPathName; | 92 const SkString fPathName; |
| 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(SkStreamAsset* stream, |
| 102 int index, | 102 int index, |
| 103 const SkFontStyle& 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(stream) { } | 107 , fStream(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()); |
| 114 desc->setFontFileName(NULL); | 114 desc->setFontFileName(NULL); |
| 115 *serialize = true; | 115 *serialize = true; |
| 116 } | 116 } |
| 117 | 117 |
| 118 SkStream* onOpenStream(int* ttcIndex) const SK_OVERRIDE { | 118 SkStreamAsset* onOpenStream(int* ttcIndex) const SK_OVERRIDE { |
| 119 *ttcIndex = fIndex; | 119 *ttcIndex = fIndex; |
| 120 return fStream->duplicate(); | 120 return fStream->duplicate(); |
| 121 } | 121 } |
| 122 | 122 |
| 123 private: | 123 private: |
| 124 SkAutoTDelete<SkStream> fStream; | 124 SkAutoTDelete<SkStreamAsset> fStream; |
| 125 | 125 |
| 126 typedef SkTypeface_Android INHERITED; | 126 typedef SkTypeface_Android INHERITED; |
| 127 }; | 127 }; |
| 128 | 128 |
| 129 void get_path_for_sys_fonts(const char* basePath, const SkString& name, SkString
* full) { | 129 void get_path_for_sys_fonts(const char* basePath, const SkString& name, SkString
* full) { |
| 130 if (basePath) { | 130 if (basePath) { |
| 131 full->set(basePath); | 131 full->set(basePath); |
| 132 } else { | 132 } else { |
| 133 full->set(getenv("ANDROID_ROOT")); | 133 full->set(getenv("ANDROID_ROOT")); |
| 134 full->append(SK_FONT_FILE_PREFIX); | 134 full->append(SK_FONT_FILE_PREFIX); |
| (...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 406 } | 406 } |
| 407 } | 407 } |
| 408 return NULL; | 408 return NULL; |
| 409 } | 409 } |
| 410 | 410 |
| 411 SkTypeface* onCreateFromData(SkData* data, int ttcIndex) const SK_OVERRIDE { | 411 SkTypeface* onCreateFromData(SkData* data, int ttcIndex) const SK_OVERRIDE { |
| 412 return this->createFromStream(new SkMemoryStream(data), ttcIndex); | 412 return this->createFromStream(new SkMemoryStream(data), ttcIndex); |
| 413 } | 413 } |
| 414 | 414 |
| 415 SkTypeface* onCreateFromFile(const char path[], int ttcIndex) const SK_OVERR
IDE { | 415 SkTypeface* onCreateFromFile(const char path[], int ttcIndex) const SK_OVERR
IDE { |
| 416 SkAutoTDelete<SkStream> stream(SkStream::NewFromFile(path)); | 416 SkAutoTDelete<SkStreamAsset> stream(SkStream::NewFromFile(path)); |
| 417 return stream.get() ? this->createFromStream(stream.detach(), ttcIndex)
: NULL; | 417 return stream.get() ? this->createFromStream(stream.detach(), ttcIndex)
: NULL; |
| 418 } | 418 } |
| 419 | 419 |
| 420 SkTypeface* onCreateFromStream(SkStream* stream, int ttcIndex) const SK_OVER
RIDE { | 420 SkTypeface* onCreateFromStream(SkStreamAsset* bareStream, int ttcIndex) cons
t SK_OVERRIDE { |
| 421 SkAutoTDelete<SkStream> streamDeleter(stream); | 421 SkAutoTDelete<SkStreamAsset> stream(bareStream); |
| 422 bool isFixedPitch; | 422 bool isFixedPitch; |
| 423 SkFontStyle style; | 423 SkFontStyle style; |
| 424 SkString name; | 424 SkString name; |
| 425 if (!fScanner.scanFont(stream, ttcIndex, &name, &style, &isFixedPitch))
{ | 425 if (!fScanner.scanFont(stream, ttcIndex, &name, &style, &isFixedPitch))
{ |
| 426 return NULL; | 426 return NULL; |
| 427 } | 427 } |
| 428 return SkNEW_ARGS(SkTypeface_AndroidStream, (streamDeleter.detach(), ttc
Index, | 428 return SkNEW_ARGS(SkTypeface_AndroidStream, (stream.detach(), ttcIndex, |
| 429 style, isFixedPitch, name))
; | 429 style, isFixedPitch, name))
; |
| 430 } | 430 } |
| 431 | 431 |
| 432 | 432 |
| 433 virtual SkTypeface* onLegacyCreateTypeface(const char familyName[], | 433 virtual SkTypeface* onLegacyCreateTypeface(const char familyName[], |
| 434 unsigned styleBits) const SK_OVER
RIDE { | 434 unsigned styleBits) const SK_OVER
RIDE { |
| 435 SkFontStyle style = SkFontStyle(styleBits); | 435 SkFontStyle style = SkFontStyle(styleBits); |
| 436 | 436 |
| 437 if (familyName) { | 437 if (familyName) { |
| 438 // On Android, we must return NULL when we can't find the requested | 438 // On Android, we must return NULL when we can't find the requested |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 542 SkDEBUGF(("Use Test Config File Main %s, Fallback %s, Font Dir %s", | 542 SkDEBUGF(("Use Test Config File Main %s, Fallback %s, Font Dir %s", |
| 543 gTestMainConfigFile, gTestFallbackConfigFile, gTestFontFilePrefix)
); | 543 gTestMainConfigFile, gTestFallbackConfigFile, gTestFontFilePrefix)
); |
| 544 } | 544 } |
| 545 | 545 |
| 546 void SkGetTestFontConfiguration(const char** mainconf, const char** fallbackconf
, | 546 void SkGetTestFontConfiguration(const char** mainconf, const char** fallbackconf
, |
| 547 const char** fontsdir) { | 547 const char** fontsdir) { |
| 548 *mainconf = gTestMainConfigFile; | 548 *mainconf = gTestMainConfigFile; |
| 549 *fallbackconf = gTestFallbackConfigFile; | 549 *fallbackconf = gTestFallbackConfigFile; |
| 550 *fontsdir = gTestFontFilePrefix; | 550 *fontsdir = gTestFontFilePrefix; |
| 551 } | 551 } |
| OLD | NEW |