| 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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 public: | 43 public: |
| 44 SkTypeface_Android(int index, | 44 SkTypeface_Android(int index, |
| 45 const SkFontStyle& style, | 45 const SkFontStyle& style, |
| 46 bool isFixedPitch, | 46 bool isFixedPitch, |
| 47 const SkString& familyName) | 47 const SkString& familyName) |
| 48 : INHERITED(style, SkTypefaceCache::NewFontID(), isFixedPitch) | 48 : INHERITED(style, SkTypefaceCache::NewFontID(), isFixedPitch) |
| 49 , fIndex(index) | 49 , fIndex(index) |
| 50 , fFamilyName(familyName) { } | 50 , fFamilyName(familyName) { } |
| 51 | 51 |
| 52 protected: | 52 protected: |
| 53 virtual void onGetFamilyName(SkString* familyName) const SK_OVERRIDE { | 53 void onGetFamilyName(SkString* familyName) const SK_OVERRIDE { |
| 54 *familyName = fFamilyName; | 54 *familyName = fFamilyName; |
| 55 } | 55 } |
| 56 | 56 |
| 57 int fIndex; | 57 int fIndex; |
| 58 SkString fFamilyName; | 58 SkString fFamilyName; |
| 59 | 59 |
| 60 private: | 60 private: |
| 61 typedef SkTypeface_FreeType INHERITED; | 61 typedef SkTypeface_FreeType INHERITED; |
| 62 }; | 62 }; |
| 63 | 63 |
| (...skipping 13 matching lines...) Expand all 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 virtual SkStream* onOpenStream(int* ttcIndex) const SK_OVERRIDE { | 87 SkStream* 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 }; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 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 virtual 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 SkAutoTUnref<SkStream> fStream; |
| 125 | 125 |
| 126 typedef SkTypeface_Android INHERITED; | 126 typedef SkTypeface_Android INHERITED; |
| 127 }; | 127 }; |
| 128 | 128 |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 familyName = *cannonicalFamilyName; | 184 familyName = *cannonicalFamilyName; |
| 185 } | 185 } |
| 186 | 186 |
| 187 fStyles.push_back().reset(SkNEW_ARGS(SkTypeface_AndroidSystem, | 187 fStyles.push_back().reset(SkNEW_ARGS(SkTypeface_AndroidSystem, |
| 188 (pathName, ttcIndex, | 188 (pathName, ttcIndex, |
| 189 style, isFixedWidth, familyNam
e, | 189 style, isFixedWidth, familyNam
e, |
| 190 lang, variant))); | 190 lang, variant))); |
| 191 } | 191 } |
| 192 } | 192 } |
| 193 | 193 |
| 194 virtual int count() SK_OVERRIDE { | 194 int count() SK_OVERRIDE { |
| 195 return fStyles.count(); | 195 return fStyles.count(); |
| 196 } | 196 } |
| 197 virtual void getStyle(int index, SkFontStyle* style, SkString* name) SK_OVER
RIDE { | 197 void getStyle(int index, SkFontStyle* style, SkString* name) SK_OVERRIDE { |
| 198 if (index < 0 || fStyles.count() <= index) { | 198 if (index < 0 || fStyles.count() <= index) { |
| 199 return; | 199 return; |
| 200 } | 200 } |
| 201 if (style) { | 201 if (style) { |
| 202 *style = this->style(index); | 202 *style = this->style(index); |
| 203 } | 203 } |
| 204 if (name) { | 204 if (name) { |
| 205 name->reset(); | 205 name->reset(); |
| 206 } | 206 } |
| 207 } | 207 } |
| 208 virtual SkTypeface_AndroidSystem* createTypeface(int index) SK_OVERRIDE { | 208 SkTypeface_AndroidSystem* createTypeface(int index) SK_OVERRIDE { |
| 209 if (index < 0 || fStyles.count() <= index) { | 209 if (index < 0 || fStyles.count() <= index) { |
| 210 return NULL; | 210 return NULL; |
| 211 } | 211 } |
| 212 return SkRef(fStyles[index].get()); | 212 return SkRef(fStyles[index].get()); |
| 213 } | 213 } |
| 214 | 214 |
| 215 /** Find the typeface in this style set that most closely matches the given
pattern. | 215 /** Find the typeface in this style set that most closely matches the given
pattern. |
| 216 * TODO: consider replacing with SkStyleSet_Indirect::matchStyle(); | 216 * TODO: consider replacing with SkStyleSet_Indirect::matchStyle(); |
| 217 * this simpler version using match_score() passes all our tests. | 217 * this simpler version using match_score() passes all our tests. |
| 218 */ | 218 */ |
| 219 virtual SkTypeface_AndroidSystem* matchStyle(const SkFontStyle& pattern) SK_
OVERRIDE { | 219 SkTypeface_AndroidSystem* matchStyle(const SkFontStyle& pattern) SK_OVERRIDE
{ |
| 220 if (0 == fStyles.count()) { | 220 if (0 == fStyles.count()) { |
| 221 return NULL; | 221 return NULL; |
| 222 } | 222 } |
| 223 SkTypeface_AndroidSystem* closest = fStyles[0]; | 223 SkTypeface_AndroidSystem* closest = fStyles[0]; |
| 224 int minScore = std::numeric_limits<int>::max(); | 224 int minScore = std::numeric_limits<int>::max(); |
| 225 for (int i = 0; i < fStyles.count(); ++i) { | 225 for (int i = 0; i < fStyles.count(); ++i) { |
| 226 SkFontStyle style = this->style(i); | 226 SkFontStyle style = this->style(i); |
| 227 int score = match_score(pattern, style); | 227 int score = match_score(pattern, style); |
| 228 if (score < minScore) { | 228 if (score < minScore) { |
| 229 closest = fStyles[i]; | 229 closest = fStyles[i]; |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 277 SkTDArray<FontFamily*> fontFamilies; | 277 SkTDArray<FontFamily*> fontFamilies; |
| 278 SkFontConfigParser::GetTestFontFamilies(fontFamilies, mainConfigFile, fa
llbackConfigFile); | 278 SkFontConfigParser::GetTestFontFamilies(fontFamilies, mainConfigFile, fa
llbackConfigFile); |
| 279 this->buildNameToFamilyMap(fontFamilies, basePath); | 279 this->buildNameToFamilyMap(fontFamilies, basePath); |
| 280 this->findDefaultFont(); | 280 this->findDefaultFont(); |
| 281 } | 281 } |
| 282 | 282 |
| 283 protected: | 283 protected: |
| 284 /** Returns not how many families we have, but how many unique names | 284 /** Returns not how many families we have, but how many unique names |
| 285 * exist among the families. | 285 * exist among the families. |
| 286 */ | 286 */ |
| 287 virtual int onCountFamilies() const SK_OVERRIDE { | 287 int onCountFamilies() const SK_OVERRIDE { |
| 288 return fNameToFamilyMap.count(); | 288 return fNameToFamilyMap.count(); |
| 289 } | 289 } |
| 290 | 290 |
| 291 virtual void onGetFamilyName(int index, SkString* familyName) const SK_OVERR
IDE { | 291 void onGetFamilyName(int index, SkString* familyName) const SK_OVERRIDE { |
| 292 if (index < 0 || fNameToFamilyMap.count() <= index) { | 292 if (index < 0 || fNameToFamilyMap.count() <= index) { |
| 293 familyName->reset(); | 293 familyName->reset(); |
| 294 return; | 294 return; |
| 295 } | 295 } |
| 296 familyName->set(fNameToFamilyMap[index].name); | 296 familyName->set(fNameToFamilyMap[index].name); |
| 297 } | 297 } |
| 298 | 298 |
| 299 virtual SkFontStyleSet* onCreateStyleSet(int index) const SK_OVERRIDE { | 299 SkFontStyleSet* onCreateStyleSet(int index) const SK_OVERRIDE { |
| 300 if (index < 0 || fNameToFamilyMap.count() <= index) { | 300 if (index < 0 || fNameToFamilyMap.count() <= index) { |
| 301 return NULL; | 301 return NULL; |
| 302 } | 302 } |
| 303 return SkRef(fNameToFamilyMap[index].styleSet); | 303 return SkRef(fNameToFamilyMap[index].styleSet); |
| 304 } | 304 } |
| 305 | 305 |
| 306 virtual SkFontStyleSet* onMatchFamily(const char familyName[]) const SK_OVER
RIDE { | 306 SkFontStyleSet* onMatchFamily(const char familyName[]) const SK_OVERRIDE { |
| 307 if (!familyName) { | 307 if (!familyName) { |
| 308 return NULL; | 308 return NULL; |
| 309 } | 309 } |
| 310 SkAutoAsciiToLC tolc(familyName); | 310 SkAutoAsciiToLC tolc(familyName); |
| 311 for (int i = 0; i < fNameToFamilyMap.count(); ++i) { | 311 for (int i = 0; i < fNameToFamilyMap.count(); ++i) { |
| 312 if (fNameToFamilyMap[i].name.equals(tolc.lc())) { | 312 if (fNameToFamilyMap[i].name.equals(tolc.lc())) { |
| 313 return SkRef(fNameToFamilyMap[i].styleSet); | 313 return SkRef(fNameToFamilyMap[i].styleSet); |
| 314 } | 314 } |
| 315 } | 315 } |
| 316 // TODO: eventually we should not need to name fallback families. | 316 // TODO: eventually we should not need to name fallback families. |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 401 find_family_style_character(fFallbackNameToFamilyMap, | 401 find_family_style_character(fFallbackNameToFamilyMap, |
| 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 virtual SkTypeface* onCreateFromData(SkData* data, int ttcIndex) const SK_OV
ERRIDE { | 411 SkTypeface* onCreateFromData(SkData* data, int ttcIndex) const SK_OVERRIDE { |
| 412 SkAutoTUnref<SkStream> stream(new SkMemoryStream(data)); | 412 SkAutoTUnref<SkStream> stream(new SkMemoryStream(data)); |
| 413 return this->createFromStream(stream, ttcIndex); | 413 return this->createFromStream(stream, ttcIndex); |
| 414 } | 414 } |
| 415 | 415 |
| 416 virtual SkTypeface* onCreateFromFile(const char path[], int ttcIndex) const
SK_OVERRIDE { | 416 SkTypeface* onCreateFromFile(const char path[], int ttcIndex) const SK_OVERR
IDE { |
| 417 SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(path)); | 417 SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(path)); |
| 418 return stream.get() ? this->createFromStream(stream, ttcIndex) : NULL; | 418 return stream.get() ? this->createFromStream(stream, ttcIndex) : NULL; |
| 419 } | 419 } |
| 420 | 420 |
| 421 virtual SkTypeface* onCreateFromStream(SkStream* stream, int ttcIndex) const
SK_OVERRIDE { | 421 SkTypeface* onCreateFromStream(SkStream* stream, int ttcIndex) const SK_OVER
RIDE { |
| 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, (stream, ttcIndex, | 428 return SkNEW_ARGS(SkTypeface_AndroidStream, (stream, ttcIndex, |
| 429 style, isFixedPitch, name))
; | 429 style, isFixedPitch, name))
; |
| 430 } | 430 } |
| 431 | 431 |
| (...skipping 110 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 |