| 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 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 // new APIs | 88 // new APIs |
| 89 virtual SkDataTable* getFamilyNames() SK_OVERRIDE; | 89 virtual SkDataTable* getFamilyNames() SK_OVERRIDE; |
| 90 virtual bool matchFamilySet(const char inFamilyName[], | 90 virtual bool matchFamilySet(const char inFamilyName[], |
| 91 SkString* outFamilyName, | 91 SkString* outFamilyName, |
| 92 SkTArray<FontIdentity>*) SK_OVERRIDE; | 92 SkTArray<FontIdentity>*) SK_OVERRIDE; |
| 93 | 93 |
| 94 /** | 94 /** |
| 95 * Get the family name of the font in the default fallback font list that | 95 * Get the family name of the font in the default fallback font list that |
| 96 * contains the specified chararacter. if no font is found, returns false. | 96 * contains the specified chararacter. if no font is found, returns false. |
| 97 */ | 97 */ |
| 98 bool getFallbackFamilyNameForChar(SkUnichar uni, SkString* name); | 98 bool getFallbackFamilyNameForChar(SkUnichar uni, const SkString& lang, SkStr
ing* name); |
| 99 /** | 99 /** |
| 100 * | 100 * |
| 101 */ | 101 */ |
| 102 SkTypeface* getTypefaceForChar(SkUnichar uni, SkTypeface::Style style, | 102 SkTypeface* getTypefaceForChar(SkUnichar uni, SkTypeface::Style style, |
| 103 SkPaintOptionsAndroid::FontVariant fontVarian
t); | 103 SkPaintOptionsAndroid::FontVariant fontVarian
t); |
| 104 SkTypeface* nextLogicalTypeface(SkFontID currFontID, SkFontID origFontID, | 104 SkTypeface* nextLogicalTypeface(SkFontID currFontID, SkFontID origFontID, |
| 105 const SkPaintOptionsAndroid& options); | 105 const SkPaintOptionsAndroid& options); |
| 106 | 106 |
| 107 private: | 107 private: |
| 108 void addFallbackFamily(FamilyRecID fontRecID); | 108 void addFallbackFamily(FamilyRecID fontRecID); |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 fontRec.fIsValid = find_name_and_attributes(stream.get(), &name, | 239 fontRec.fIsValid = find_name_and_attributes(stream.get(), &name, |
| 240 &fontRec.fStyle, &is
FixedWidth); | 240 &fontRec.fStyle, &is
FixedWidth); |
| 241 } else { | 241 } else { |
| 242 if (!family->fIsFallbackFont) { | 242 if (!family->fIsFallbackFont) { |
| 243 SkDebugf("---- failed to open <%s> as a font\n", filename.c_
str()); | 243 SkDebugf("---- failed to open <%s> as a font\n", filename.c_
str()); |
| 244 } | 244 } |
| 245 } | 245 } |
| 246 | 246 |
| 247 if (fontRec.fIsValid) { | 247 if (fontRec.fIsValid) { |
| 248 DEBUG_FONT(("---- SystemFonts[%d][%d] fallback=%d file=%s", | 248 DEBUG_FONT(("---- SystemFonts[%d][%d] fallback=%d file=%s", |
| 249 i, fFonts.count() - 1, fontRec.fIsFallbackFont, filen
ame.c_str())); | 249 i, fFonts.count() - 1, family->fIsFallbackFont, filen
ame.c_str())); |
| 250 } else { | 250 } else { |
| 251 DEBUG_FONT(("---- SystemFonts[%d][%d] fallback=%d file=%s (INVAL
ID)", | 251 DEBUG_FONT(("---- SystemFonts[%d][%d] fallback=%d file=%s (INVAL
ID)", |
| 252 i, fFonts.count() - 1, fontRec.fIsFallbackFont, filen
ame.c_str())); | 252 i, fFonts.count() - 1, family->fIsFallbackFont, filen
ame.c_str())); |
| 253 continue; | 253 continue; |
| 254 } | 254 } |
| 255 | 255 |
| 256 // create a familyRec now that we know that at least one font in | 256 // create a familyRec now that we know that at least one font in |
| 257 // the family is valid | 257 // the family is valid |
| 258 if (familyRec == NULL) { | 258 if (familyRec == NULL) { |
| 259 familyRec = &fFontFamilies.push_back(); | 259 familyRec = &fFontFamilies.push_back(); |
| 260 familyRecID = fFontFamilies.count() - 1; | 260 familyRecID = fFontFamilies.count() - 1; |
| 261 fontRec.fFamilyRecID = familyRecID; | 261 fontRec.fFamilyRecID = familyRecID; |
| 262 | 262 |
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 497 face = SkTypeface::CreateFromName(familyName, fontRec.fStyle); | 497 face = SkTypeface::CreateFromName(familyName, fontRec.fStyle); |
| 498 } | 498 } |
| 499 | 499 |
| 500 // store the result for subsequent lookups | 500 // store the result for subsequent lookups |
| 501 fontRec.fTypeface = face; | 501 fontRec.fTypeface = face; |
| 502 } | 502 } |
| 503 SkASSERT(face); | 503 SkASSERT(face); |
| 504 return face; | 504 return face; |
| 505 } | 505 } |
| 506 | 506 |
| 507 bool SkFontConfigInterfaceAndroid::getFallbackFamilyNameForChar(SkUnichar uni, S
kString* name) { | 507 bool SkFontConfigInterfaceAndroid::getFallbackFamilyNameForChar(SkUnichar uni, |
| 508 FallbackFontList* fallbackFontList = this->getCurrentLocaleFallbackFontList(
); | 508 const SkString&
lang, |
| 509 SkString* name)
{ |
| 510 FallbackFontList* fallbackFontList = this->findFallbackFontList(lang); |
| 509 for (int i = 0; i < fallbackFontList->count(); i++) { | 511 for (int i = 0; i < fallbackFontList->count(); i++) { |
| 510 FamilyRecID familyRecID = fallbackFontList->getAt(i); | 512 FamilyRecID familyRecID = fallbackFontList->getAt(i); |
| 511 FontRecID fontRecID = find_best_style(fFontFamilies[familyRecID], SkType
face::kNormal); | 513 FontRecID fontRecID = find_best_style(fFontFamilies[familyRecID], SkType
face::kNormal); |
| 512 SkTypeface* face = this->getTypefaceForFontRec(fontRecID); | 514 SkTypeface* face = this->getTypefaceForFontRec(fontRecID); |
| 513 | 515 |
| 514 SkPaint paint; | 516 SkPaint paint; |
| 515 paint.setTypeface(face); | 517 paint.setTypeface(face); |
| 516 paint.setTextEncoding(SkPaint::kUTF32_TextEncoding); | 518 paint.setTextEncoding(SkPaint::kUTF32_TextEncoding); |
| 517 | 519 |
| 518 uint16_t glyphID; | 520 uint16_t glyphID; |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 655 "lang=%s, variant=%d, nextFallbackIndex[%d,%d] => nextLogicalTyp
eface=%d", | 657 "lang=%s, variant=%d, nextFallbackIndex[%d,%d] => nextLogicalTyp
eface=%d", |
| 656 currFontID, origFontID, currFontRecID, opts.getLanguage().getTag
().c_str(), | 658 currFontID, origFontID, currFontRecID, opts.getLanguage().getTag
().c_str(), |
| 657 variant, nextFallbackFontIndex, currentFallbackList->getAt(nextF
allbackFontIndex), | 659 variant, nextFallbackFontIndex, currentFallbackList->getAt(nextF
allbackFontIndex), |
| 658 (nextLogicalTypeface) ? nextLogicalTypeface->uniqueID() : 0)); | 660 (nextLogicalTypeface) ? nextLogicalTypeface->uniqueID() : 0)); |
| 659 return SkSafeRef(nextLogicalTypeface); | 661 return SkSafeRef(nextLogicalTypeface); |
| 660 } | 662 } |
| 661 | 663 |
| 662 /////////////////////////////////////////////////////////////////////////////// | 664 /////////////////////////////////////////////////////////////////////////////// |
| 663 | 665 |
| 664 bool SkGetFallbackFamilyNameForChar(SkUnichar uni, SkString* name) { | 666 bool SkGetFallbackFamilyNameForChar(SkUnichar uni, SkString* name) { |
| 667 SkString locale = SkFontConfigParser::GetLocale(); |
| 665 SkFontConfigInterfaceAndroid* fontConfig = getSingletonInterface(); | 668 SkFontConfigInterfaceAndroid* fontConfig = getSingletonInterface(); |
| 666 return fontConfig->getFallbackFamilyNameForChar(uni, name); | 669 return fontConfig->getFallbackFamilyNameForChar(uni, locale, name); |
| 670 } |
| 671 |
| 672 bool SkGetFallbackFamilyNameForChar(SkUnichar uni, const SkString& lang, SkStrin
g* name) { |
| 673 SkFontConfigInterfaceAndroid* fontConfig = getSingletonInterface(); |
| 674 return fontConfig->getFallbackFamilyNameForChar(uni, lang, name); |
| 667 } | 675 } |
| 668 | 676 |
| 669 void SkUseTestFontConfigFile(const char* mainconf, const char* fallbackconf, | 677 void SkUseTestFontConfigFile(const char* mainconf, const char* fallbackconf, |
| 670 const char* fontsdir) { | 678 const char* fontsdir) { |
| 671 gTestMainConfigFile = mainconf; | 679 gTestMainConfigFile = mainconf; |
| 672 gTestFallbackConfigFile = fallbackconf; | 680 gTestFallbackConfigFile = fallbackconf; |
| 673 gTestFontFilePrefix = fontsdir; | 681 gTestFontFilePrefix = fontsdir; |
| 674 SkASSERT(gTestMainConfigFile); | 682 SkASSERT(gTestMainConfigFile); |
| 675 SkASSERT(gTestFallbackConfigFile); | 683 SkASSERT(gTestFallbackConfigFile); |
| 676 SkASSERT(gTestFontFilePrefix); | 684 SkASSERT(gTestFontFilePrefix); |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 834 return SkCreateTypefaceForScriptNG(getHBScriptFromHBScriptOld(script), style
, fontVariant); | 842 return SkCreateTypefaceForScriptNG(getHBScriptFromHBScriptOld(script), style
, fontVariant); |
| 835 } | 843 } |
| 836 | 844 |
| 837 #endif | 845 #endif |
| 838 | 846 |
| 839 /////////////////////////////////////////////////////////////////////////////// | 847 /////////////////////////////////////////////////////////////////////////////// |
| 840 | 848 |
| 841 SkFontMgr* SkFontMgr::Factory() { | 849 SkFontMgr* SkFontMgr::Factory() { |
| 842 return NULL; | 850 return NULL; |
| 843 } | 851 } |
| OLD | NEW |