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 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 addFallbackFont(FontRecID fontRecID); | 108 void addFallbackFont(FontRecID fontRecID); |
109 SkTypeface* getTypefaceForFontRec(FontRecID fontRecID); | 109 SkTypeface* getTypefaceForFontRec(FontRecID fontRecID); |
110 FallbackFontList* getCurrentLocaleFallbackFontList(); | |
110 FallbackFontList* findFallbackFontList(const SkLanguage& lang, bool isOrigin al = true); | 111 FallbackFontList* findFallbackFontList(const SkLanguage& lang, bool isOrigin al = true); |
111 | 112 |
112 SkTArray<FontRec> fFonts; | 113 SkTArray<FontRec> fFonts; |
113 SkTArray<FamilyRec> fFontFamilies; | 114 SkTArray<FamilyRec> fFontFamilies; |
114 SkTDict<FamilyRecID> fFamilyNameDict; | 115 SkTDict<FamilyRecID> fFamilyNameDict; |
115 FamilyRecID fDefaultFamilyRecID; | 116 FamilyRecID fDefaultFamilyRecID; |
116 | 117 |
117 // (SkLanguage)<->(fallback chain index) translation | 118 // (SkLanguage)<->(fallback chain index) translation |
118 SkTDict<FallbackFontList*> fFallbackFontDict; | 119 SkTDict<FallbackFontList*> fFallbackFontDict; |
119 SkTDict<FallbackFontList*> fFallbackFontAliasDict; | 120 SkTDict<FallbackFontList*> fFallbackFontAliasDict; |
120 FallbackFontList fDefaultFallbackList; | 121 FallbackFontList fDefaultFallbackList; |
122 | |
123 // fallback info for current locale | |
124 SkMutex fLocaleMutex; | |
125 SkString fCachedLocale; | |
126 FallbackFontList* fLocaleFallbackFontList; | |
121 }; | 127 }; |
122 | 128 |
123 /////////////////////////////////////////////////////////////////////////////// | 129 /////////////////////////////////////////////////////////////////////////////// |
124 | 130 |
125 static SkFontConfigInterfaceAndroid* getSingletonInterface() { | 131 static SkFontConfigInterfaceAndroid* getSingletonInterface() { |
126 SK_DECLARE_STATIC_MUTEX(gMutex); | 132 SK_DECLARE_STATIC_MUTEX(gMutex); |
127 static SkFontConfigInterfaceAndroid* gFontConfigInterface; | 133 static SkFontConfigInterfaceAndroid* gFontConfigInterface; |
128 | 134 |
129 SkAutoMutexAcquire ac(gMutex); | 135 SkAutoMutexAcquire ac(gMutex); |
130 if (NULL == gFontConfigInterface) { | 136 if (NULL == gFontConfigInterface) { |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
186 SkTypeface::Style* style, bool* isFixedWidth); | 192 SkTypeface::Style* style, bool* isFixedWidth); |
187 | 193 |
188 /////////////////////////////////////////////////////////////////////////////// | 194 /////////////////////////////////////////////////////////////////////////////// |
189 | 195 |
190 SkFontConfigInterfaceAndroid::SkFontConfigInterfaceAndroid(SkTDArray<FontFamily* >& fontFamilies) : | 196 SkFontConfigInterfaceAndroid::SkFontConfigInterfaceAndroid(SkTDArray<FontFamily* >& fontFamilies) : |
191 fFonts(fontFamilies.count()), | 197 fFonts(fontFamilies.count()), |
192 fFontFamilies(fontFamilies.count() / FamilyRec::FONT_STYLE_COUNT), | 198 fFontFamilies(fontFamilies.count() / FamilyRec::FONT_STYLE_COUNT), |
193 fFamilyNameDict(1024), | 199 fFamilyNameDict(1024), |
194 fDefaultFamilyRecID(INVALID_FAMILY_REC_ID), | 200 fDefaultFamilyRecID(INVALID_FAMILY_REC_ID), |
195 fFallbackFontDict(128), | 201 fFallbackFontDict(128), |
196 fFallbackFontAliasDict(128) { | 202 fFallbackFontAliasDict(128), |
203 fLocaleFallbackFontList(NULL) { | |
197 | 204 |
198 for (int i = 0; i < fontFamilies.count(); ++i) { | 205 for (int i = 0; i < fontFamilies.count(); ++i) { |
199 FontFamily* family = fontFamilies[i]; | 206 FontFamily* family = fontFamilies[i]; |
200 | 207 |
201 // defer initializing the familyRec until we can be sure that at least | 208 // defer initializing the familyRec until we can be sure that at least |
202 // one of it's children contains a valid font file | 209 // one of it's children contains a valid font file |
203 FamilyRec* familyRec = NULL; | 210 FamilyRec* familyRec = NULL; |
204 FamilyRecID familyRecID = INVALID_FAMILY_REC_ID; | 211 FamilyRecID familyRecID = INVALID_FAMILY_REC_ID; |
205 | 212 |
206 for (int j = 0; j < family->fFontFiles.count(); ++j) { | 213 for (int j = 0; j < family->fFontFiles.count(); ++j) { |
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
482 } | 489 } |
483 | 490 |
484 // store the result for subsequent lookups | 491 // store the result for subsequent lookups |
485 fontRec.fTypeface = face; | 492 fontRec.fTypeface = face; |
486 } | 493 } |
487 SkASSERT(face); | 494 SkASSERT(face); |
488 return face; | 495 return face; |
489 } | 496 } |
490 | 497 |
491 bool SkFontConfigInterfaceAndroid::getFallbackFamilyNameForChar(SkUnichar uni, S kString* name) { | 498 bool SkFontConfigInterfaceAndroid::getFallbackFamilyNameForChar(SkUnichar uni, S kString* name) { |
492 for (int i = 0; i < fDefaultFallbackList.count(); i++) { | 499 FallbackFontList* fallbackFontList = this->getCurrentLocaleFallbackFontList( ); |
493 FontRecID fontRecID = fDefaultFallbackList[i]; | 500 for (int i = 0; i < fallbackFontList->count(); i++) { |
501 FontRecID fontRecID = fallbackFontList->getAt(i); | |
494 SkTypeface* face = this->getTypefaceForFontRec(fontRecID); | 502 SkTypeface* face = this->getTypefaceForFontRec(fontRecID); |
495 | 503 |
496 SkPaint paint; | 504 SkPaint paint; |
497 paint.setTypeface(face); | 505 paint.setTypeface(face); |
498 paint.setTextEncoding(SkPaint::kUTF32_TextEncoding); | 506 paint.setTextEncoding(SkPaint::kUTF32_TextEncoding); |
499 | 507 |
500 uint16_t glyphID; | 508 uint16_t glyphID; |
501 paint.textToGlyphs(&uni, sizeof(uni), &glyphID); | 509 paint.textToGlyphs(&uni, sizeof(uni), &glyphID); |
502 if (glyphID != 0) { | 510 if (glyphID != 0) { |
503 name->set(fFonts[fontRecID].fFileName); | 511 name->set(fFonts[fontRecID].fFileName); |
(...skipping 22 matching lines...) Expand all Loading... | |
526 SkGlyphCache* cache = autoCache.getCache(); | 534 SkGlyphCache* cache = autoCache.getCache(); |
527 | 535 |
528 SkScalerContext* ctx = cache->getScalerContext(); | 536 SkScalerContext* ctx = cache->getScalerContext(); |
529 if (ctx) { | 537 if (ctx) { |
530 SkFontID fontID = ctx->findTypefaceIdForChar(uni); | 538 SkFontID fontID = ctx->findTypefaceIdForChar(uni); |
531 return SkTypefaceCache::FindByID(fontID); | 539 return SkTypefaceCache::FindByID(fontID); |
532 } | 540 } |
533 return NULL; | 541 return NULL; |
534 } | 542 } |
535 | 543 |
544 FallbackFontList* SkFontConfigInterfaceAndroid::getCurrentLocaleFallbackFontList () { | |
545 SkAutoMutexAcquire mutex(&fLocaleMutex); | |
546 | |
547 SkString locale = SkFontConfigParser::GetLocale(); | |
548 if (NULL == fLocaleFallbackFontList || locale != fCachedLocale) { | |
549 fCachedLocale = locale; | |
550 fLocaleFallbackFontList = this->findFallbackFontList(locale); | |
reed1
2013/06/25 16:28:45
Does this leak the old fontlist?
djsollen
2013/06/25 16:38:20
The short answer is no. The fallbackfontlist is p
reed1
2013/06/25 16:48:24
In line 550 we assign into fLocalFallbackFontList.
| |
551 } | |
552 | |
553 return fLocaleFallbackFontList; | |
reed1
2013/06/25 16:28:45
the caller can manipulate this object outside of t
djsollen
2013/06/25 16:38:20
removed the mutex in the next patch set.
On 2013/
| |
554 } | |
555 | |
536 FallbackFontList* SkFontConfigInterfaceAndroid::findFallbackFontList(const SkLan guage& lang, | 556 FallbackFontList* SkFontConfigInterfaceAndroid::findFallbackFontList(const SkLan guage& lang, |
537 bool isOrig inal) { | 557 bool isOrig inal) { |
538 const SkString& langTag = lang.getTag(); | 558 const SkString& langTag = lang.getTag(); |
539 if (langTag.isEmpty()) { | 559 if (langTag.isEmpty()) { |
540 return &fDefaultFallbackList; | 560 return &fDefaultFallbackList; |
541 } | 561 } |
542 | 562 |
543 FallbackFontList* fallbackFontList; | 563 FallbackFontList* fallbackFontList; |
544 if (fFallbackFontDict.find(langTag.c_str(), langTag.size(), &fallbackFontLis t) || | 564 if (fFallbackFontDict.find(langTag.c_str(), langTag.size(), &fallbackFontLis t) || |
545 fFallbackFontAliasDict.find(langTag.c_str(), langTag.size(), &fallbackFo ntList)) { | 565 fFallbackFontAliasDict.find(langTag.c_str(), langTag.size(), &fallbackFo ntList)) { |
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
795 return SkCreateTypefaceForScriptNG(getHBScriptFromHBScriptOld(script), style , fontVariant); | 815 return SkCreateTypefaceForScriptNG(getHBScriptFromHBScriptOld(script), style , fontVariant); |
796 } | 816 } |
797 | 817 |
798 #endif | 818 #endif |
799 | 819 |
800 /////////////////////////////////////////////////////////////////////////////// | 820 /////////////////////////////////////////////////////////////////////////////// |
801 | 821 |
802 SkFontMgr* SkFontMgr::Factory() { | 822 SkFontMgr* SkFontMgr::Factory() { |
803 return NULL; | 823 return NULL; |
804 } | 824 } |
OLD | NEW |