| 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 char* lang, SkString*
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 char* 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); |
| 513 |
| 514 // if it is not one of the accepted variants then move to the next famil
y |
| 515 int32_t acceptedVariants = SkPaintOptionsAndroid::kDefault_Variant | |
| 516 SkPaintOptionsAndroid::kElegant_Variant; |
| 517 if (!(fFontFamilies[familyRecID].fPaintOptions.getFontVariant() & accept
edVariants)) { |
| 518 continue; |
| 519 } |
| 520 |
| 511 FontRecID fontRecID = find_best_style(fFontFamilies[familyRecID], SkType
face::kNormal); | 521 FontRecID fontRecID = find_best_style(fFontFamilies[familyRecID], SkType
face::kNormal); |
| 512 SkTypeface* face = this->getTypefaceForFontRec(fontRecID); | 522 SkTypeface* face = this->getTypefaceForFontRec(fontRecID); |
| 513 | 523 |
| 514 SkPaint paint; | 524 SkPaint paint; |
| 515 paint.setTypeface(face); | 525 paint.setTypeface(face); |
| 516 paint.setTextEncoding(SkPaint::kUTF32_TextEncoding); | 526 paint.setTextEncoding(SkPaint::kUTF32_TextEncoding); |
| 517 | 527 |
| 518 uint16_t glyphID; | 528 uint16_t glyphID; |
| 519 paint.textToGlyphs(&uni, sizeof(uni), &glyphID); | 529 paint.textToGlyphs(&uni, sizeof(uni), &glyphID); |
| 520 if (glyphID != 0) { | 530 if (glyphID != 0) { |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 655 "lang=%s, variant=%d, nextFallbackIndex[%d,%d] => nextLogicalTyp
eface=%d", | 665 "lang=%s, variant=%d, nextFallbackIndex[%d,%d] => nextLogicalTyp
eface=%d", |
| 656 currFontID, origFontID, currFontRecID, opts.getLanguage().getTag
().c_str(), | 666 currFontID, origFontID, currFontRecID, opts.getLanguage().getTag
().c_str(), |
| 657 variant, nextFallbackFontIndex, currentFallbackList->getAt(nextF
allbackFontIndex), | 667 variant, nextFallbackFontIndex, currentFallbackList->getAt(nextF
allbackFontIndex), |
| 658 (nextLogicalTypeface) ? nextLogicalTypeface->uniqueID() : 0)); | 668 (nextLogicalTypeface) ? nextLogicalTypeface->uniqueID() : 0)); |
| 659 return SkSafeRef(nextLogicalTypeface); | 669 return SkSafeRef(nextLogicalTypeface); |
| 660 } | 670 } |
| 661 | 671 |
| 662 /////////////////////////////////////////////////////////////////////////////// | 672 /////////////////////////////////////////////////////////////////////////////// |
| 663 | 673 |
| 664 bool SkGetFallbackFamilyNameForChar(SkUnichar uni, SkString* name) { | 674 bool SkGetFallbackFamilyNameForChar(SkUnichar uni, SkString* name) { |
| 675 SkString locale = SkFontConfigParser::GetLocale(); |
| 665 SkFontConfigInterfaceAndroid* fontConfig = getSingletonInterface(); | 676 SkFontConfigInterfaceAndroid* fontConfig = getSingletonInterface(); |
| 666 return fontConfig->getFallbackFamilyNameForChar(uni, name); | 677 return fontConfig->getFallbackFamilyNameForChar(uni, locale.c_str(), name); |
| 678 } |
| 679 |
| 680 bool SkGetFallbackFamilyNameForChar(SkUnichar uni, const char* lang, SkString* n
ame) { |
| 681 SkFontConfigInterfaceAndroid* fontConfig = getSingletonInterface(); |
| 682 return fontConfig->getFallbackFamilyNameForChar(uni, lang, name); |
| 667 } | 683 } |
| 668 | 684 |
| 669 void SkUseTestFontConfigFile(const char* mainconf, const char* fallbackconf, | 685 void SkUseTestFontConfigFile(const char* mainconf, const char* fallbackconf, |
| 670 const char* fontsdir) { | 686 const char* fontsdir) { |
| 671 gTestMainConfigFile = mainconf; | 687 gTestMainConfigFile = mainconf; |
| 672 gTestFallbackConfigFile = fallbackconf; | 688 gTestFallbackConfigFile = fallbackconf; |
| 673 gTestFontFilePrefix = fontsdir; | 689 gTestFontFilePrefix = fontsdir; |
| 674 SkASSERT(gTestMainConfigFile); | 690 SkASSERT(gTestMainConfigFile); |
| 675 SkASSERT(gTestFallbackConfigFile); | 691 SkASSERT(gTestFallbackConfigFile); |
| 676 SkASSERT(gTestFontFilePrefix); | 692 SkASSERT(gTestFontFilePrefix); |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 834 return SkCreateTypefaceForScriptNG(getHBScriptFromHBScriptOld(script), style
, fontVariant); | 850 return SkCreateTypefaceForScriptNG(getHBScriptFromHBScriptOld(script), style
, fontVariant); |
| 835 } | 851 } |
| 836 | 852 |
| 837 #endif | 853 #endif |
| 838 | 854 |
| 839 /////////////////////////////////////////////////////////////////////////////// | 855 /////////////////////////////////////////////////////////////////////////////// |
| 840 | 856 |
| 841 SkFontMgr* SkFontMgr::Factory() { | 857 SkFontMgr* SkFontMgr::Factory() { |
| 842 return NULL; | 858 return NULL; |
| 843 } | 859 } |
| OLD | NEW |