| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2013 The Android Open Source Project | 3 * Copyright 2013 The Android Open Source Project |
| 4 * | 4 * |
| 5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 #include "SkFontConfigInterface.h" | 9 #include "SkFontConfigInterface.h" |
| 10 #include "SkTypeface_android.h" | 10 #include "SkTypeface_android.h" |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 */ | 103 */ |
| 104 SkTypeface* nextLogicalTypeface(SkFontID currFontID, SkFontID origFontID, | 104 SkTypeface* nextLogicalTypeface(SkFontID currFontID, SkFontID origFontID, |
| 105 const SkPaintOptionsAndroid& options); | 105 const SkPaintOptionsAndroid& options); |
| 106 SkTypeface* getTypefaceForGlyphID(uint16_t glyphID, const SkTypeface* origTy
peface, | 106 SkTypeface* getTypefaceForGlyphID(uint16_t glyphID, const SkTypeface* origTy
peface, |
| 107 const SkPaintOptionsAndroid& options, | 107 const SkPaintOptionsAndroid& options, |
| 108 int* lowerBounds, int* upperBounds); | 108 int* lowerBounds, int* upperBounds); |
| 109 | 109 |
| 110 private: | 110 private: |
| 111 void addFallbackFamily(FamilyRecID fontRecID); | 111 void addFallbackFamily(FamilyRecID fontRecID); |
| 112 SkTypeface* getTypefaceForFontRec(FontRecID fontRecID); | 112 SkTypeface* getTypefaceForFontRec(FontRecID fontRecID); |
| 113 FallbackFontList* getCurrentLocaleFallbackFontList(); | |
| 114 FallbackFontList* findFallbackFontList(const SkLanguage& lang, bool isOrigin
al = true); | 113 FallbackFontList* findFallbackFontList(const SkLanguage& lang, bool isOrigin
al = true); |
| 115 | 114 |
| 116 SkTArray<FontRec, true> fFonts; | 115 SkTArray<FontRec, true> fFonts; |
| 117 SkTArray<FamilyRec, true> fFontFamilies; | 116 SkTArray<FamilyRec, true> fFontFamilies; |
| 118 SkTDict<FamilyRecID> fFamilyNameDict; | 117 SkTDict<FamilyRecID> fFamilyNameDict; |
| 119 FamilyRecID fDefaultFamilyRecID; | 118 FamilyRecID fDefaultFamilyRecID; |
| 120 | 119 |
| 121 // (SkLanguage)<->(fallback chain index) translation | 120 // (SkLanguage)<->(fallback chain index) translation |
| 122 SkTDict<FallbackFontList*> fFallbackFontDict; | 121 SkTDict<FallbackFontList*> fFallbackFontDict; |
| 123 SkTDict<FallbackFontList*> fFallbackFontAliasDict; | 122 SkTDict<FallbackFontList*> fFallbackFontAliasDict; |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 // defer initializing the familyRec until we can be sure that at least | 211 // defer initializing the familyRec until we can be sure that at least |
| 213 // one of it's children contains a valid font file | 212 // one of it's children contains a valid font file |
| 214 FamilyRec* familyRec = NULL; | 213 FamilyRec* familyRec = NULL; |
| 215 FamilyRecID familyRecID = INVALID_FAMILY_REC_ID; | 214 FamilyRecID familyRecID = INVALID_FAMILY_REC_ID; |
| 216 | 215 |
| 217 for (int j = 0; j < family->fFontFiles.count(); ++j) { | 216 for (int j = 0; j < family->fFontFiles.count(); ++j) { |
| 218 SkString filename; | 217 SkString filename; |
| 219 get_path_for_sys_fonts(&filename, family->fFontFiles[j].fFileName); | 218 get_path_for_sys_fonts(&filename, family->fFontFiles[j].fFileName); |
| 220 | 219 |
| 221 if (has_font(fFonts, filename)) { | 220 if (has_font(fFonts, filename)) { |
| 222 SkDebugf("---- system font and fallback font files specify a dup
licate " | 221 DEBUG_FONT(("---- system font and fallback font files specify a
duplicate " |
| 223 "font %s, skipping the second occurrence", filename.c_st
r()); | 222 "font %s, skipping the second occurrence", filename.c_st
r())); |
| 224 continue; | |
| 225 } | 223 } |
| 226 | 224 |
| 227 FontRec& fontRec = fFonts.push_back(); | 225 FontRec& fontRec = fFonts.push_back(); |
| 228 fontRec.fFileName = filename; | 226 fontRec.fFileName = filename; |
| 229 fontRec.fStyle = SkTypeface::kNormal; | 227 fontRec.fStyle = SkTypeface::kNormal; |
| 230 fontRec.fIsValid = false; | 228 fontRec.fIsValid = false; |
| 231 fontRec.fFamilyRecID = familyRecID; | 229 fontRec.fFamilyRecID = familyRecID; |
| 232 | 230 |
| 233 const FontRecID fontRecID = fFonts.count() - 1; | 231 const FontRecID fontRecID = fFonts.count() - 1; |
| 234 | 232 |
| (...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 503 // store the result for subsequent lookups | 501 // store the result for subsequent lookups |
| 504 fontRec.fTypeface.reset(face); | 502 fontRec.fTypeface.reset(face); |
| 505 } | 503 } |
| 506 SkASSERT(face); | 504 SkASSERT(face); |
| 507 return face; | 505 return face; |
| 508 } | 506 } |
| 509 | 507 |
| 510 bool SkFontConfigInterfaceAndroid::getFallbackFamilyNameForChar(SkUnichar uni, | 508 bool SkFontConfigInterfaceAndroid::getFallbackFamilyNameForChar(SkUnichar uni, |
| 511 const char* lang
, | 509 const char* lang
, |
| 512 SkString* name)
{ | 510 SkString* name)
{ |
| 513 FallbackFontList* fallbackFontList = NULL; | 511 const SkString locale(lang); |
| 514 const SkString langTag(lang); | 512 if (NULL == fLocaleFallbackFontList || locale != fCachedLocale) { |
| 515 if (langTag.isEmpty()) { | 513 fCachedLocale = locale; |
| 516 fallbackFontList = this->getCurrentLocaleFallbackFontList(); | 514 fLocaleFallbackFontList = this->findFallbackFontList(locale); |
| 517 } else { | |
| 518 fallbackFontList = this->findFallbackFontList(langTag); | |
| 519 } | 515 } |
| 516 FallbackFontList* fallbackFontList = fLocaleFallbackFontList; |
| 520 | 517 |
| 521 for (int i = 0; i < fallbackFontList->count(); i++) { | 518 for (int i = 0; i < fallbackFontList->count(); i++) { |
| 522 FamilyRecID familyRecID = fallbackFontList->getAt(i); | 519 FamilyRecID familyRecID = fallbackFontList->getAt(i); |
| 523 | 520 |
| 524 // if it is not one of the accepted variants then move to the next famil
y | 521 // if it is not one of the accepted variants then move to the next famil
y |
| 525 int32_t acceptedVariants = SkPaintOptionsAndroid::kDefault_Variant | | 522 int32_t acceptedVariants = SkPaintOptionsAndroid::kDefault_Variant | |
| 526 SkPaintOptionsAndroid::kElegant_Variant; | 523 SkPaintOptionsAndroid::kElegant_Variant; |
| 527 if (!(fFontFamilies[familyRecID].fPaintOptions.getFontVariant() & accept
edVariants)) { | 524 if (!(fFontFamilies[familyRecID].fPaintOptions.getFontVariant() & accept
edVariants)) { |
| 528 continue; | 525 continue; |
| 529 } | 526 } |
| 530 | 527 |
| 531 FontRecID fontRecID = find_best_style(fFontFamilies[familyRecID], SkType
face::kNormal); | 528 FontRecID fontRecID = find_best_style(fFontFamilies[familyRecID], SkType
face::kNormal); |
| 532 SkTypeface* face = this->getTypefaceForFontRec(fontRecID); | 529 SkTypeface* face = this->getTypefaceForFontRec(fontRecID); |
| 533 | 530 |
| 534 SkPaint paint; | 531 SkPaint paint; |
| 535 paint.setTypeface(face); | 532 paint.setTypeface(face); |
| 536 paint.setTextEncoding(SkPaint::kUTF32_TextEncoding); | 533 paint.setTextEncoding(SkPaint::kUTF32_TextEncoding); |
| 537 | 534 |
| 538 uint16_t glyphID; | 535 uint16_t glyphID; |
| 539 paint.textToGlyphs(&uni, sizeof(uni), &glyphID); | 536 paint.textToGlyphs(&uni, sizeof(uni), &glyphID); |
| 540 if (glyphID != 0) { | 537 if (glyphID != 0) { |
| 541 name->set(fFontFamilies[familyRecID].fFallbackName); | 538 name->set(fFontFamilies[familyRecID].fFallbackName); |
| 542 return true; | 539 return true; |
| 543 } | 540 } |
| 544 } | 541 } |
| 545 return false; | 542 return false; |
| 546 } | 543 } |
| 547 | 544 |
| 548 FallbackFontList* SkFontConfigInterfaceAndroid::getCurrentLocaleFallbackFontList
() { | |
| 549 SkString locale = SkFontConfigParser::GetLocale(); | |
| 550 if (NULL == fLocaleFallbackFontList || locale != fCachedLocale) { | |
| 551 fCachedLocale = locale; | |
| 552 fLocaleFallbackFontList = this->findFallbackFontList(locale); | |
| 553 } | |
| 554 return fLocaleFallbackFontList; | |
| 555 } | |
| 556 | |
| 557 FallbackFontList* SkFontConfigInterfaceAndroid::findFallbackFontList(const SkLan
guage& lang, | 545 FallbackFontList* SkFontConfigInterfaceAndroid::findFallbackFontList(const SkLan
guage& lang, |
| 558 bool isOrig
inal) { | 546 bool isOrig
inal) { |
| 559 const SkString& langTag = lang.getTag(); | 547 const SkString& langTag = lang.getTag(); |
| 560 if (langTag.isEmpty()) { | 548 if (langTag.isEmpty()) { |
| 561 return &fDefaultFallbackList; | 549 return &fDefaultFallbackList; |
| 562 } | 550 } |
| 563 | 551 |
| 564 FallbackFontList* fallbackFontList; | 552 FallbackFontList* fallbackFontList; |
| 565 if (fFallbackFontDict.find(langTag.c_str(), langTag.size(), &fallbackFontLis
t) || | 553 if (fFallbackFontDict.find(langTag.c_str(), langTag.size(), &fallbackFontLis
t) || |
| 566 fFallbackFontAliasDict.find(langTag.c_str(), langTag.size(), &fallbackFo
ntList)) { | 554 fFallbackFontAliasDict.find(langTag.c_str(), langTag.size(), &fallbackFo
ntList)) { |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 734 | 722 |
| 735 } | 723 } |
| 736 | 724 |
| 737 SkTypeface* SkGetTypefaceForGlyphID(uint16_t glyphID, const SkTypeface* origType
face, | 725 SkTypeface* SkGetTypefaceForGlyphID(uint16_t glyphID, const SkTypeface* origType
face, |
| 738 const SkPaintOptionsAndroid& options, | 726 const SkPaintOptionsAndroid& options, |
| 739 int* lowerBounds, int* upperBounds) { | 727 int* lowerBounds, int* upperBounds) { |
| 740 SkFontConfigInterfaceAndroid* fontConfig = getSingletonInterface(); | 728 SkFontConfigInterfaceAndroid* fontConfig = getSingletonInterface(); |
| 741 return fontConfig->getTypefaceForGlyphID(glyphID, origTypeface, options, | 729 return fontConfig->getTypefaceForGlyphID(glyphID, origTypeface, options, |
| 742 lowerBounds, upperBounds); | 730 lowerBounds, upperBounds); |
| 743 } | 731 } |
| OLD | NEW |