Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8)

Side by Side Diff: src/ports/SkFontMgr_android.cpp

Issue 672723002: Extend SkFontMgr_Custom to cover ttc, otf, pfb. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Keep FT_Stream alive, protect library with mutex. Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/ports/SkFontHost_linux.cpp ('k') | src/ports/SkFontMgr_fontconfig.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 {
142 const SkString* cannonicalFamilyName = NULL; 144 const SkString* cannonicalFamilyName = NULL;
143 if (family.fNames.count() > 0) { 145 if (family.fNames.count() > 0) {
144 cannonicalFamilyName = &family.fNames[0]; 146 cannonicalFamilyName = &family.fNames[0];
145 } 147 }
146 // TODO? make this lazy 148 // TODO? make this lazy
147 for (int i = 0; i < family.fFonts.count(); ++i) { 149 for (int i = 0; i < family.fFonts.count(); ++i) {
148 const FontFileInfo& fontFile = family.fFonts[i]; 150 const FontFileInfo& fontFile = family.fFonts[i];
149 151
150 SkString pathName; 152 SkString pathName;
151 get_path_for_sys_fonts(basePath, fontFile.fFileName, &pathName); 153 get_path_for_sys_fonts(basePath, fontFile.fFileName, &pathName);
152 154
153 SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(pathName.c_str() )); 155 SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(pathName.c_str() ));
154 if (!stream.get()) { 156 if (!stream.get()) {
155 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()));
156 continue; 158 continue;
157 } 159 }
158 160
159 const int ttcIndex = fontFile.fIndex; 161 const int ttcIndex = fontFile.fIndex;
160 SkString familyName; 162 SkString familyName;
161 SkFontStyle style; 163 SkFontStyle style;
162 bool isFixedWidth; 164 bool isFixedWidth;
163 if (!SkTypeface_FreeType::ScanFont(stream.get(), ttcIndex, 165 if (!scanner.scanFont(stream.get(), ttcIndex, &familyName, &style, & isFixedWidth)) {
164 &familyName, &style, &isFixedWidt h)) {
165 DEBUG_FONT(("---- SystemFonts[%d] file=%s (INVALID)", i, pathNam e.c_str())); 166 DEBUG_FONT(("---- SystemFonts[%d] file=%s (INVALID)", i, pathNam e.c_str()));
166 continue; 167 continue;
167 } 168 }
168 169
169 const SkLanguage& lang = family.fLanguage; 170 const SkLanguage& lang = family.fLanguage;
170 uint32_t variant = family.fVariant; 171 uint32_t variant = family.fVariant;
171 if (kDefault_FontVariant == variant) { 172 if (kDefault_FontVariant == variant) {
172 variant = kCompact_FontVariant | kElegant_FontVariant; 173 variant = kCompact_FontVariant | kElegant_FontVariant;
173 } 174 }
174 175
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
428 429
429 virtual SkTypeface* onCreateFromFile(const char path[], int ttcIndex) const SK_OVERRIDE { 430 virtual SkTypeface* onCreateFromFile(const char path[], int ttcIndex) const SK_OVERRIDE {
430 SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(path)); 431 SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(path));
431 return stream.get() ? this->createFromStream(stream, ttcIndex) : NULL; 432 return stream.get() ? this->createFromStream(stream, ttcIndex) : NULL;
432 } 433 }
433 434
434 virtual SkTypeface* onCreateFromStream(SkStream* stream, int ttcIndex) const SK_OVERRIDE { 435 virtual SkTypeface* onCreateFromStream(SkStream* stream, int ttcIndex) const SK_OVERRIDE {
435 bool isFixedPitch; 436 bool isFixedPitch;
436 SkFontStyle style; 437 SkFontStyle style;
437 SkString name; 438 SkString name;
438 if (!SkTypeface_FreeType::ScanFont(stream, ttcIndex, &name, &style, &isF ixedPitch)) { 439 if (!fScanner.scanFont(stream, ttcIndex, &name, &style, &isFixedPitch)) {
439 return NULL; 440 return NULL;
440 } 441 }
441 return SkNEW_ARGS(SkTypeface_AndroidStream, (stream, ttcIndex, 442 return SkNEW_ARGS(SkTypeface_AndroidStream, (stream, ttcIndex,
442 style, isFixedPitch, name)) ; 443 style, isFixedPitch, name)) ;
443 } 444 }
444 445
445 446
446 virtual SkTypeface* onLegacyCreateTypeface(const char familyName[], 447 virtual SkTypeface* onLegacyCreateTypeface(const char familyName[],
447 unsigned styleBits) const SK_OVER RIDE { 448 unsigned styleBits) const SK_OVER RIDE {
448 SkFontStyle style = SkFontStyle(styleBits); 449 SkFontStyle style = SkFontStyle(styleBits);
449 450
450 if (familyName) { 451 if (familyName) {
451 // On Android, we must return NULL when we can't find the requested 452 // On Android, we must return NULL when we can't find the requested
452 // named typeface so that the system/app can provide their own recov ery 453 // named typeface so that the system/app can provide their own recov ery
453 // mechanism. On other platforms we'd provide a typeface from the 454 // mechanism. On other platforms we'd provide a typeface from the
454 // default family instead. 455 // default family instead.
455 return this->onMatchFamilyStyle(familyName, style); 456 return this->onMatchFamilyStyle(familyName, style);
456 } 457 }
457 return fDefaultFamily->matchStyle(style); 458 return fDefaultFamily->matchStyle(style);
458 } 459 }
459 460
460 461
461 private: 462 private:
462 463
464 SkTypeface_FreeType::Scanner fScanner;
465
463 SkTArray<SkAutoTUnref<SkFontStyleSet_Android>, true> fFontStyleSets; 466 SkTArray<SkAutoTUnref<SkFontStyleSet_Android>, true> fFontStyleSets;
464 SkFontStyleSet* fDefaultFamily; 467 SkFontStyleSet* fDefaultFamily;
465 SkTypeface* fDefaultTypeface; 468 SkTypeface* fDefaultTypeface;
466 469
467 SkTDArray<NameToFamily> fNameToFamilyMap; 470 SkTDArray<NameToFamily> fNameToFamilyMap;
468 SkTDArray<NameToFamily> fFallbackNameToFamilyMap; 471 SkTDArray<NameToFamily> fFallbackNameToFamilyMap;
469 472
470 void buildNameToFamilyMap(SkTDArray<FontFamily*> families, const char* baseP ath) { 473 void buildNameToFamilyMap(SkTDArray<FontFamily*> families, const char* baseP ath) {
471 for (int i = 0; i < families.count(); i++) { 474 for (int i = 0; i < families.count(); i++) {
472 FontFamily& family = *families[i]; 475 FontFamily& family = *families[i];
473 476
474 SkTDArray<NameToFamily>* nameToFamily = &fNameToFamilyMap; 477 SkTDArray<NameToFamily>* nameToFamily = &fNameToFamilyMap;
475 if (family.fIsFallbackFont) { 478 if (family.fIsFallbackFont) {
476 nameToFamily = &fFallbackNameToFamilyMap; 479 nameToFamily = &fFallbackNameToFamilyMap;
477 480
478 if (0 == family.fNames.count()) { 481 if (0 == family.fNames.count()) {
479 SkString& fallbackName = family.fNames.push_back(); 482 SkString& fallbackName = family.fNames.push_back();
480 fallbackName.printf("%.2x##fallback", i); 483 fallbackName.printf("%.2x##fallback", i);
481 } 484 }
482 } 485 }
483 486
484 SkFontStyleSet_Android* newSet = SkNEW_ARGS(SkFontStyleSet_Android, (family, basePath)); 487 SkFontStyleSet_Android* newSet =
488 SkNEW_ARGS(SkFontStyleSet_Android, (family, basePath, fScanner)) ;
485 if (0 == newSet->count()) { 489 if (0 == newSet->count()) {
486 SkDELETE(newSet); 490 SkDELETE(newSet);
487 continue; 491 continue;
488 } 492 }
489 fFontStyleSets.push_back().reset(newSet); 493 fFontStyleSets.push_back().reset(newSet);
490 494
491 for (int j = 0; j < family.fNames.count(); j++) { 495 for (int j = 0; j < family.fNames.count(); j++) {
492 NameToFamily* nextEntry = nameToFamily->append(); 496 NameToFamily* nextEntry = nameToFamily->append();
493 SkNEW_PLACEMENT_ARGS(&nextEntry->name, SkString, (family.fNames[ j])); 497 SkNEW_PLACEMENT_ARGS(&nextEntry->name, SkString, (family.fNames[ j]));
494 nextEntry->styleSet = newSet; 498 nextEntry->styleSet = newSet;
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
552 SkDEBUGF(("Use Test Config File Main %s, Fallback %s, Font Dir %s", 556 SkDEBUGF(("Use Test Config File Main %s, Fallback %s, Font Dir %s",
553 gTestMainConfigFile, gTestFallbackConfigFile, gTestFontFilePrefix) ); 557 gTestMainConfigFile, gTestFallbackConfigFile, gTestFontFilePrefix) );
554 } 558 }
555 559
556 void SkGetTestFontConfiguration(const char** mainconf, const char** fallbackconf , 560 void SkGetTestFontConfiguration(const char** mainconf, const char** fallbackconf ,
557 const char** fontsdir) { 561 const char** fontsdir) {
558 *mainconf = gTestMainConfigFile; 562 *mainconf = gTestMainConfigFile;
559 *fallbackconf = gTestFallbackConfigFile; 563 *fallbackconf = gTestFallbackConfigFile;
560 *fontsdir = gTestFontFilePrefix; 564 *fontsdir = gTestFontFilePrefix;
561 } 565 }
OLDNEW
« no previous file with comments | « src/ports/SkFontHost_linux.cpp ('k') | src/ports/SkFontMgr_fontconfig.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698