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 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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); |
135 } | 135 } |
136 full->append(name); | 136 full->append(name); |
137 } | 137 } |
138 | 138 |
139 class SkFontStyleSet_Android : public SkFontStyleSet { | 139 class SkFontStyleSet_Android : public SkFontStyleSet { |
140 public: | 140 public: |
141 explicit SkFontStyleSet_Android(const FontFamily& family, const char* basePa
th, | 141 explicit SkFontStyleSet_Android(const FontFamily& family, const char* basePa
th) { |
142 const SkTypeface_FreeType::Scanner& scanner) | |
143 { | |
144 const SkString* cannonicalFamilyName = NULL; | 142 const SkString* cannonicalFamilyName = NULL; |
145 if (family.fNames.count() > 0) { | 143 if (family.fNames.count() > 0) { |
146 cannonicalFamilyName = &family.fNames[0]; | 144 cannonicalFamilyName = &family.fNames[0]; |
147 } | 145 } |
148 // TODO? make this lazy | 146 // TODO? make this lazy |
149 for (int i = 0; i < family.fFonts.count(); ++i) { | 147 for (int i = 0; i < family.fFonts.count(); ++i) { |
150 const FontFileInfo& fontFile = family.fFonts[i]; | 148 const FontFileInfo& fontFile = family.fFonts[i]; |
151 | 149 |
152 SkString pathName; | 150 SkString pathName; |
153 get_path_for_sys_fonts(basePath, fontFile.fFileName, &pathName); | 151 get_path_for_sys_fonts(basePath, fontFile.fFileName, &pathName); |
154 | 152 |
155 SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(pathName.c_str()
)); | 153 SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(pathName.c_str()
)); |
156 if (!stream.get()) { | 154 if (!stream.get()) { |
157 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())); |
158 continue; | 156 continue; |
159 } | 157 } |
160 | 158 |
161 const int ttcIndex = fontFile.fIndex; | 159 const int ttcIndex = fontFile.fIndex; |
162 SkString familyName; | 160 SkString familyName; |
163 SkFontStyle style; | 161 SkFontStyle style; |
164 bool isFixedWidth; | 162 bool isFixedWidth; |
165 if (!scanner.scanFont(stream.get(), ttcIndex, &familyName, &style, &
isFixedWidth)) { | 163 if (!SkTypeface_FreeType::ScanFont(stream.get(), ttcIndex, |
| 164 &familyName, &style, &isFixedWidt
h)) { |
166 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())); |
167 continue; | 166 continue; |
168 } | 167 } |
169 | 168 |
170 const SkLanguage& lang = family.fLanguage; | 169 const SkLanguage& lang = family.fLanguage; |
171 uint32_t variant = family.fVariant; | 170 uint32_t variant = family.fVariant; |
172 if (kDefault_FontVariant == variant) { | 171 if (kDefault_FontVariant == variant) { |
173 variant = kCompact_FontVariant | kElegant_FontVariant; | 172 variant = kCompact_FontVariant | kElegant_FontVariant; |
174 } | 173 } |
175 | 174 |
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
429 | 428 |
430 virtual SkTypeface* onCreateFromFile(const char path[], int ttcIndex) const
SK_OVERRIDE { | 429 virtual SkTypeface* onCreateFromFile(const char path[], int ttcIndex) const
SK_OVERRIDE { |
431 SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(path)); | 430 SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(path)); |
432 return stream.get() ? this->createFromStream(stream, ttcIndex) : NULL; | 431 return stream.get() ? this->createFromStream(stream, ttcIndex) : NULL; |
433 } | 432 } |
434 | 433 |
435 virtual SkTypeface* onCreateFromStream(SkStream* stream, int ttcIndex) const
SK_OVERRIDE { | 434 virtual SkTypeface* onCreateFromStream(SkStream* stream, int ttcIndex) const
SK_OVERRIDE { |
436 bool isFixedPitch; | 435 bool isFixedPitch; |
437 SkFontStyle style; | 436 SkFontStyle style; |
438 SkString name; | 437 SkString name; |
439 if (!fScanner.scanFont(stream, ttcIndex, &name, &style, &isFixedPitch))
{ | 438 if (!SkTypeface_FreeType::ScanFont(stream, ttcIndex, &name, &style, &isF
ixedPitch)) { |
440 return NULL; | 439 return NULL; |
441 } | 440 } |
442 return SkNEW_ARGS(SkTypeface_AndroidStream, (stream, ttcIndex, | 441 return SkNEW_ARGS(SkTypeface_AndroidStream, (stream, ttcIndex, |
443 style, isFixedPitch, name))
; | 442 style, isFixedPitch, name))
; |
444 } | 443 } |
445 | 444 |
446 | 445 |
447 virtual SkTypeface* onLegacyCreateTypeface(const char familyName[], | 446 virtual SkTypeface* onLegacyCreateTypeface(const char familyName[], |
448 unsigned styleBits) const SK_OVER
RIDE { | 447 unsigned styleBits) const SK_OVER
RIDE { |
449 SkFontStyle style = SkFontStyle(styleBits); | 448 SkFontStyle style = SkFontStyle(styleBits); |
450 | 449 |
451 if (familyName) { | 450 if (familyName) { |
452 // On Android, we must return NULL when we can't find the requested | 451 // On Android, we must return NULL when we can't find the requested |
453 // named typeface so that the system/app can provide their own recov
ery | 452 // named typeface so that the system/app can provide their own recov
ery |
454 // mechanism. On other platforms we'd provide a typeface from the | 453 // mechanism. On other platforms we'd provide a typeface from the |
455 // default family instead. | 454 // default family instead. |
456 return this->onMatchFamilyStyle(familyName, style); | 455 return this->onMatchFamilyStyle(familyName, style); |
457 } | 456 } |
458 return fDefaultFamily->matchStyle(style); | 457 return fDefaultFamily->matchStyle(style); |
459 } | 458 } |
460 | 459 |
461 | 460 |
462 private: | 461 private: |
463 | 462 |
464 SkTypeface_FreeType::Scanner fScanner; | |
465 | |
466 SkTArray<SkAutoTUnref<SkFontStyleSet_Android>, true> fFontStyleSets; | 463 SkTArray<SkAutoTUnref<SkFontStyleSet_Android>, true> fFontStyleSets; |
467 SkFontStyleSet* fDefaultFamily; | 464 SkFontStyleSet* fDefaultFamily; |
468 SkTypeface* fDefaultTypeface; | 465 SkTypeface* fDefaultTypeface; |
469 | 466 |
470 SkTDArray<NameToFamily> fNameToFamilyMap; | 467 SkTDArray<NameToFamily> fNameToFamilyMap; |
471 SkTDArray<NameToFamily> fFallbackNameToFamilyMap; | 468 SkTDArray<NameToFamily> fFallbackNameToFamilyMap; |
472 | 469 |
473 void buildNameToFamilyMap(SkTDArray<FontFamily*> families, const char* baseP
ath) { | 470 void buildNameToFamilyMap(SkTDArray<FontFamily*> families, const char* baseP
ath) { |
474 for (int i = 0; i < families.count(); i++) { | 471 for (int i = 0; i < families.count(); i++) { |
475 FontFamily& family = *families[i]; | 472 FontFamily& family = *families[i]; |
476 | 473 |
477 SkTDArray<NameToFamily>* nameToFamily = &fNameToFamilyMap; | 474 SkTDArray<NameToFamily>* nameToFamily = &fNameToFamilyMap; |
478 if (family.fIsFallbackFont) { | 475 if (family.fIsFallbackFont) { |
479 nameToFamily = &fFallbackNameToFamilyMap; | 476 nameToFamily = &fFallbackNameToFamilyMap; |
480 | 477 |
481 if (0 == family.fNames.count()) { | 478 if (0 == family.fNames.count()) { |
482 SkString& fallbackName = family.fNames.push_back(); | 479 SkString& fallbackName = family.fNames.push_back(); |
483 fallbackName.printf("%.2x##fallback", i); | 480 fallbackName.printf("%.2x##fallback", i); |
484 } | 481 } |
485 } | 482 } |
486 | 483 |
487 SkFontStyleSet_Android* newSet = | 484 SkFontStyleSet_Android* newSet = SkNEW_ARGS(SkFontStyleSet_Android,
(family, basePath)); |
488 SkNEW_ARGS(SkFontStyleSet_Android, (family, basePath, fScanner))
; | |
489 if (0 == newSet->count()) { | 485 if (0 == newSet->count()) { |
490 SkDELETE(newSet); | 486 SkDELETE(newSet); |
491 continue; | 487 continue; |
492 } | 488 } |
493 fFontStyleSets.push_back().reset(newSet); | 489 fFontStyleSets.push_back().reset(newSet); |
494 | 490 |
495 for (int j = 0; j < family.fNames.count(); j++) { | 491 for (int j = 0; j < family.fNames.count(); j++) { |
496 NameToFamily* nextEntry = nameToFamily->append(); | 492 NameToFamily* nextEntry = nameToFamily->append(); |
497 SkNEW_PLACEMENT_ARGS(&nextEntry->name, SkString, (family.fNames[
j])); | 493 SkNEW_PLACEMENT_ARGS(&nextEntry->name, SkString, (family.fNames[
j])); |
498 nextEntry->styleSet = newSet; | 494 nextEntry->styleSet = newSet; |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
556 SkDEBUGF(("Use Test Config File Main %s, Fallback %s, Font Dir %s", | 552 SkDEBUGF(("Use Test Config File Main %s, Fallback %s, Font Dir %s", |
557 gTestMainConfigFile, gTestFallbackConfigFile, gTestFontFilePrefix)
); | 553 gTestMainConfigFile, gTestFallbackConfigFile, gTestFontFilePrefix)
); |
558 } | 554 } |
559 | 555 |
560 void SkGetTestFontConfiguration(const char** mainconf, const char** fallbackconf
, | 556 void SkGetTestFontConfiguration(const char** mainconf, const char** fallbackconf
, |
561 const char** fontsdir) { | 557 const char** fontsdir) { |
562 *mainconf = gTestMainConfigFile; | 558 *mainconf = gTestMainConfigFile; |
563 *fallbackconf = gTestFallbackConfigFile; | 559 *fallbackconf = gTestFallbackConfigFile; |
564 *fontsdir = gTestFontFilePrefix; | 560 *fontsdir = gTestFontFilePrefix; |
565 } | 561 } |
OLD | NEW |