| 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 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 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(SkRef(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 SkStream* 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 SkAutoTUnref<SkStream> fStream; | 124 SkAutoTDelete<SkStream> 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 10 matching lines...) Expand all Loading... |
| 145 if (family.fNames.count() > 0) { | 145 if (family.fNames.count() > 0) { |
| 146 cannonicalFamilyName = &family.fNames[0]; | 146 cannonicalFamilyName = &family.fNames[0]; |
| 147 } | 147 } |
| 148 // TODO? make this lazy | 148 // TODO? make this lazy |
| 149 for (int i = 0; i < family.fFonts.count(); ++i) { | 149 for (int i = 0; i < family.fFonts.count(); ++i) { |
| 150 const FontFileInfo& fontFile = family.fFonts[i]; | 150 const FontFileInfo& fontFile = family.fFonts[i]; |
| 151 | 151 |
| 152 SkString pathName; | 152 SkString pathName; |
| 153 get_path_for_sys_fonts(basePath, fontFile.fFileName, &pathName); | 153 get_path_for_sys_fonts(basePath, fontFile.fFileName, &pathName); |
| 154 | 154 |
| 155 SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(pathName.c_str()
)); | 155 SkAutoTDelete<SkStream> stream(SkStream::NewFromFile(pathName.c_str(
))); |
| 156 if (!stream.get()) { | 156 if (!stream.get()) { |
| 157 DEBUG_FONT(("---- SystemFonts[%d] file=%s (NOT EXIST)", i, pathN
ame.c_str())); | 157 DEBUG_FONT(("---- SystemFonts[%d] file=%s (NOT EXIST)", i, pathN
ame.c_str())); |
| 158 continue; | 158 continue; |
| 159 } | 159 } |
| 160 | 160 |
| 161 const int ttcIndex = fontFile.fIndex; | 161 const int ttcIndex = fontFile.fIndex; |
| 162 SkString familyName; | 162 SkString familyName; |
| 163 SkFontStyle style; | 163 SkFontStyle style; |
| 164 bool isFixedWidth; | 164 bool isFixedWidth; |
| 165 if (!scanner.scanFont(stream.get(), ttcIndex, &familyName, &style, &
isFixedWidth)) { | 165 if (!scanner.scanFont(stream.get(), ttcIndex, &familyName, &style, &
isFixedWidth)) { |
| (...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 402 style, SkToBool(elegant), | 402 style, SkToBool(elegant), |
| 403 SkString(), character); | 403 SkString(), character); |
| 404 if (matchingTypeface) { | 404 if (matchingTypeface) { |
| 405 return matchingTypeface; | 405 return matchingTypeface; |
| 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 SkAutoTUnref<SkStream> stream(new SkMemoryStream(data)); | 412 return this->createFromStream(new SkMemoryStream(data), ttcIndex); |
| 413 return this->createFromStream(stream, ttcIndex); | |
| 414 } | 413 } |
| 415 | 414 |
| 416 SkTypeface* onCreateFromFile(const char path[], int ttcIndex) const SK_OVERR
IDE { | 415 SkTypeface* onCreateFromFile(const char path[], int ttcIndex) const SK_OVERR
IDE { |
| 417 SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(path)); | 416 SkAutoTDelete<SkStream> stream(SkStream::NewFromFile(path)); |
| 418 return stream.get() ? this->createFromStream(stream, ttcIndex) : NULL; | 417 return stream.get() ? this->createFromStream(stream.detach(), ttcIndex)
: NULL; |
| 419 } | 418 } |
| 420 | 419 |
| 421 SkTypeface* onCreateFromStream(SkStream* stream, int ttcIndex) const SK_OVER
RIDE { | 420 SkTypeface* onCreateFromStream(SkStream* stream, int ttcIndex) const SK_OVER
RIDE { |
| 422 bool isFixedPitch; | 421 bool isFixedPitch; |
| 423 SkFontStyle style; | 422 SkFontStyle style; |
| 424 SkString name; | 423 SkString name; |
| 425 if (!fScanner.scanFont(stream, ttcIndex, &name, &style, &isFixedPitch))
{ | 424 if (!fScanner.scanFont(stream, ttcIndex, &name, &style, &isFixedPitch))
{ |
| 425 SkDELETE(stream); |
| 426 return NULL; | 426 return NULL; |
| 427 } | 427 } |
| 428 return SkNEW_ARGS(SkTypeface_AndroidStream, (stream, ttcIndex, | 428 return SkNEW_ARGS(SkTypeface_AndroidStream, (stream, 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); |
| (...skipping 106 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 |