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

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

Issue 451093002: Use test config in SkFontMgr_android. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Move logic out to factory. Created 6 years, 4 months 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/SkFontConfigInterface_android.cpp ('k') | no next file » | 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"
11 #include "SkFontMgr.h" 11 #include "SkFontMgr.h"
12 #include "SkFontStyle.h" 12 #include "SkFontStyle.h"
13 #include "SkStream.h" 13 #include "SkStream.h"
14 #include "SkTDArray.h" 14 #include "SkTDArray.h"
15 #include "SkTSearch.h" 15 #include "SkTSearch.h"
16 #include "SkTypeface.h" 16 #include "SkTypeface.h"
17 #include "SkTypeface_android.h"
17 #include "SkTypefaceCache.h" 18 #include "SkTypefaceCache.h"
18 19
19 #include <limits> 20 #include <limits>
20 #include <stdlib.h> 21 #include <stdlib.h>
21 22
22 #ifndef SK_FONT_FILE_PREFIX 23 #ifndef SK_FONT_FILE_PREFIX
23 # define SK_FONT_FILE_PREFIX "/fonts/" 24 # define SK_FONT_FILE_PREFIX "/fonts/"
24 #endif 25 #endif
25 26
26 #ifndef SK_DEBUG_FONTS 27 #ifndef SK_DEBUG_FONTS
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 *ttcIndex = fIndex; 111 *ttcIndex = fIndex;
111 return fStream->duplicate(); 112 return fStream->duplicate();
112 } 113 }
113 114
114 private: 115 private:
115 SkAutoTUnref<SkStream> fStream; 116 SkAutoTUnref<SkStream> fStream;
116 117
117 typedef SkTypeface_Android INHERITED; 118 typedef SkTypeface_Android INHERITED;
118 }; 119 };
119 120
120 void get_path_for_sys_fonts(SkString* full, const SkString& name) { 121 void get_path_for_sys_fonts(const char* basePath, const SkString& name, SkString * full) {
121 full->set(getenv("ANDROID_ROOT")); 122 if (basePath) {
122 full->append(SK_FONT_FILE_PREFIX); 123 full->set(basePath);
124 } else {
125 full->set(getenv("ANDROID_ROOT"));
126 full->append(SK_FONT_FILE_PREFIX);
127 }
123 full->append(name); 128 full->append(name);
124 } 129 }
125 130
126 class SkFontStyleSet_Android : public SkFontStyleSet { 131 class SkFontStyleSet_Android : public SkFontStyleSet {
127 public: 132 public:
128 explicit SkFontStyleSet_Android(const FontFamily& family) { 133 explicit SkFontStyleSet_Android(const FontFamily& family, const char* basePa th) {
129 const SkString* cannonicalFamilyName = NULL; 134 const SkString* cannonicalFamilyName = NULL;
130 if (family.fNames.count() > 0) { 135 if (family.fNames.count() > 0) {
131 cannonicalFamilyName = &family.fNames[0]; 136 cannonicalFamilyName = &family.fNames[0];
132 } 137 }
133 // TODO? make this lazy 138 // TODO? make this lazy
134 for (int i = 0; i < family.fFontFiles.count(); ++i) { 139 for (int i = 0; i < family.fFontFiles.count(); ++i) {
135 const FontFileInfo& fontFile = family.fFontFiles[i]; 140 const FontFileInfo& fontFile = family.fFontFiles[i];
136 141
137 SkString pathName; 142 SkString pathName;
138 get_path_for_sys_fonts(&pathName, fontFile.fFileName); 143 get_path_for_sys_fonts(basePath, fontFile.fFileName, &pathName);
139 144
140 SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(pathName.c_str() )); 145 SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(pathName.c_str() ));
141 if (!stream.get()) { 146 if (!stream.get()) {
142 DEBUG_FONT(("---- SystemFonts[%d] file=%s (NOT EXIST)", i, pathN ame.c_str())); 147 DEBUG_FONT(("---- SystemFonts[%d] file=%s (NOT EXIST)", i, pathN ame.c_str()));
143 continue; 148 continue;
144 } 149 }
145 150
146 const int ttcIndex = fontFile.fIndex; 151 const int ttcIndex = fontFile.fIndex;
147 SkString familyName; 152 SkString familyName;
148 SkTypeface::Style style; 153 SkTypeface::Style style;
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 struct NameToFamily { 258 struct NameToFamily {
254 SkString name; 259 SkString name;
255 SkFontStyleSet_Android* styleSet; 260 SkFontStyleSet_Android* styleSet;
256 }; 261 };
257 262
258 class SkFontMgr_Android : public SkFontMgr { 263 class SkFontMgr_Android : public SkFontMgr {
259 public: 264 public:
260 SkFontMgr_Android() { 265 SkFontMgr_Android() {
261 SkTDArray<FontFamily*> fontFamilies; 266 SkTDArray<FontFamily*> fontFamilies;
262 SkFontConfigParser::GetFontFamilies(fontFamilies); 267 SkFontConfigParser::GetFontFamilies(fontFamilies);
263 this->buildNameToFamilyMap(fontFamilies); 268 this->buildNameToFamilyMap(fontFamilies, NULL);
269 this->findDefaultFont();
270 }
271 SkFontMgr_Android(const char* mainConfigFile, const char* fallbackConfigFile ,
272 const char* basePath)
273 {
274 SkTDArray<FontFamily*> fontFamilies;
275 SkFontConfigParser::GetTestFontFamilies(fontFamilies, mainConfigFile, fa llbackConfigFile);
276 this->buildNameToFamilyMap(fontFamilies, basePath);
264 this->findDefaultFont(); 277 this->findDefaultFont();
265 } 278 }
266 279
267 protected: 280 protected:
268 /** Returns not how many families we have, but how many unique names 281 /** Returns not how many families we have, but how many unique names
269 * exist among the families. 282 * exist among the families.
270 */ 283 */
271 virtual int onCountFamilies() const SK_OVERRIDE { 284 virtual int onCountFamilies() const SK_OVERRIDE {
272 return fNameToFamilyMap.count(); 285 return fNameToFamilyMap.count();
273 } 286 }
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
418 431
419 private: 432 private:
420 433
421 SkTArray<SkAutoTUnref<SkFontStyleSet_Android>, true> fFontStyleSets; 434 SkTArray<SkAutoTUnref<SkFontStyleSet_Android>, true> fFontStyleSets;
422 SkFontStyleSet* fDefaultFamily; 435 SkFontStyleSet* fDefaultFamily;
423 SkTypeface* fDefaultTypeface; 436 SkTypeface* fDefaultTypeface;
424 437
425 SkTDArray<NameToFamily> fNameToFamilyMap; 438 SkTDArray<NameToFamily> fNameToFamilyMap;
426 SkTDArray<NameToFamily> fFallbackNameToFamilyMap; 439 SkTDArray<NameToFamily> fFallbackNameToFamilyMap;
427 440
428 void buildNameToFamilyMap(SkTDArray<FontFamily*> families) { 441 void buildNameToFamilyMap(SkTDArray<FontFamily*> families, const char* baseP ath) {
429 for (int i = 0; i < families.count(); i++) { 442 for (int i = 0; i < families.count(); i++) {
430 FontFamily& family = *families[i]; 443 FontFamily& family = *families[i];
431 444
432 SkTDArray<NameToFamily>* nameToFamily = &fNameToFamilyMap; 445 SkTDArray<NameToFamily>* nameToFamily = &fNameToFamilyMap;
433 if (family.fIsFallbackFont) { 446 if (family.fIsFallbackFont) {
434 nameToFamily = &fFallbackNameToFamilyMap; 447 nameToFamily = &fFallbackNameToFamilyMap;
435 448
436 if (0 == family.fNames.count()) { 449 if (0 == family.fNames.count()) {
437 SkString& fallbackName = family.fNames.push_back(); 450 SkString& fallbackName = family.fNames.push_back();
438 fallbackName.printf("%.2x##fallback", i); 451 fallbackName.printf("%.2x##fallback", i);
439 } 452 }
440 } 453 }
441 454
442 SkFontStyleSet_Android* newSet = SkNEW_ARGS(SkFontStyleSet_Android, (family)); 455 SkFontStyleSet_Android* newSet = SkNEW_ARGS(SkFontStyleSet_Android, (family, basePath));
443 if (0 == newSet->count()) { 456 if (0 == newSet->count()) {
444 SkDELETE(newSet); 457 SkDELETE(newSet);
445 continue; 458 continue;
446 } 459 }
447 fFontStyleSets.push_back().reset(newSet); 460 fFontStyleSets.push_back().reset(newSet);
448 461
449 for (int j = 0; j < family.fNames.count(); j++) { 462 for (int j = 0; j < family.fNames.count(); j++) {
450 NameToFamily* nextEntry = nameToFamily->append(); 463 NameToFamily* nextEntry = nameToFamily->append();
451 SkNEW_PLACEMENT_ARGS(&nextEntry->name, SkString, (family.fNames[ j])); 464 SkNEW_PLACEMENT_ARGS(&nextEntry->name, SkString, (family.fNames[ j]));
452 nextEntry->styleSet = newSet; 465 nextEntry->styleSet = newSet;
(...skipping 25 matching lines...) Expand all
478 SkASSERT(fDefaultFamily); 491 SkASSERT(fDefaultFamily);
479 SkASSERT(fDefaultTypeface); 492 SkASSERT(fDefaultTypeface);
480 } 493 }
481 494
482 typedef SkFontMgr INHERITED; 495 typedef SkFontMgr INHERITED;
483 }; 496 };
484 497
485 /////////////////////////////////////////////////////////////////////////////// 498 ///////////////////////////////////////////////////////////////////////////////
486 499
487 SkFontMgr* SkFontMgr::Factory() { 500 SkFontMgr* SkFontMgr::Factory() {
501 // The call to SkGetTestFontConfiguration is so that Chromium can override t he environment.
502 // TODO: these globals need to be removed, in favor of a constructor / separ ate Factory
503 // which can be used instead.
504 const char* mainConfigFile;
505 const char* fallbackConfigFile;
506 const char* basePath;
507 SkGetTestFontConfiguration(&mainConfigFile, &fallbackConfigFile, &basePath);
508 if (mainConfigFile) {
509 SkNEW_ARGS(SkFontMgr_Android, (mainConfigFile, fallbackConfigFile, baseP ath));
bungeman-skia 2014/08/11 17:45:23 Need to return here.
510 }
511
488 return SkNEW(SkFontMgr_Android); 512 return SkNEW(SkFontMgr_Android);
489 } 513 }
OLDNEW
« no previous file with comments | « src/ports/SkFontConfigInterface_android.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698