Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(508)

Side by Side Diff: src/ports/SkFontConfigInterface_android.cpp

Issue 17691002: Ensure we use the current locale when looking up fallback fonts per character (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: remove mutex Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | src/ports/SkFontConfigParser_android.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 SkString fCachedLocale;
125 FallbackFontList* fLocaleFallbackFontList;
121 }; 126 };
122 127
123 /////////////////////////////////////////////////////////////////////////////// 128 ///////////////////////////////////////////////////////////////////////////////
124 129
125 static SkFontConfigInterfaceAndroid* getSingletonInterface() { 130 static SkFontConfigInterfaceAndroid* getSingletonInterface() {
126 SK_DECLARE_STATIC_MUTEX(gMutex); 131 SK_DECLARE_STATIC_MUTEX(gMutex);
127 static SkFontConfigInterfaceAndroid* gFontConfigInterface; 132 static SkFontConfigInterfaceAndroid* gFontConfigInterface;
128 133
129 SkAutoMutexAcquire ac(gMutex); 134 SkAutoMutexAcquire ac(gMutex);
130 if (NULL == gFontConfigInterface) { 135 if (NULL == gFontConfigInterface) {
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 SkTypeface::Style* style, bool* isFixedWidth); 191 SkTypeface::Style* style, bool* isFixedWidth);
187 192
188 /////////////////////////////////////////////////////////////////////////////// 193 ///////////////////////////////////////////////////////////////////////////////
189 194
190 SkFontConfigInterfaceAndroid::SkFontConfigInterfaceAndroid(SkTDArray<FontFamily* >& fontFamilies) : 195 SkFontConfigInterfaceAndroid::SkFontConfigInterfaceAndroid(SkTDArray<FontFamily* >& fontFamilies) :
191 fFonts(fontFamilies.count()), 196 fFonts(fontFamilies.count()),
192 fFontFamilies(fontFamilies.count() / FamilyRec::FONT_STYLE_COUNT), 197 fFontFamilies(fontFamilies.count() / FamilyRec::FONT_STYLE_COUNT),
193 fFamilyNameDict(1024), 198 fFamilyNameDict(1024),
194 fDefaultFamilyRecID(INVALID_FAMILY_REC_ID), 199 fDefaultFamilyRecID(INVALID_FAMILY_REC_ID),
195 fFallbackFontDict(128), 200 fFallbackFontDict(128),
196 fFallbackFontAliasDict(128) { 201 fFallbackFontAliasDict(128),
202 fLocaleFallbackFontList(NULL) {
197 203
198 for (int i = 0; i < fontFamilies.count(); ++i) { 204 for (int i = 0; i < fontFamilies.count(); ++i) {
199 FontFamily* family = fontFamilies[i]; 205 FontFamily* family = fontFamilies[i];
200 206
201 // defer initializing the familyRec until we can be sure that at least 207 // defer initializing the familyRec until we can be sure that at least
202 // one of it's children contains a valid font file 208 // one of it's children contains a valid font file
203 FamilyRec* familyRec = NULL; 209 FamilyRec* familyRec = NULL;
204 FamilyRecID familyRecID = INVALID_FAMILY_REC_ID; 210 FamilyRecID familyRecID = INVALID_FAMILY_REC_ID;
205 211
206 for (int j = 0; j < family->fFontFiles.count(); ++j) { 212 for (int j = 0; j < family->fFontFiles.count(); ++j) {
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after
482 } 488 }
483 489
484 // store the result for subsequent lookups 490 // store the result for subsequent lookups
485 fontRec.fTypeface = face; 491 fontRec.fTypeface = face;
486 } 492 }
487 SkASSERT(face); 493 SkASSERT(face);
488 return face; 494 return face;
489 } 495 }
490 496
491 bool SkFontConfigInterfaceAndroid::getFallbackFamilyNameForChar(SkUnichar uni, S kString* name) { 497 bool SkFontConfigInterfaceAndroid::getFallbackFamilyNameForChar(SkUnichar uni, S kString* name) {
492 for (int i = 0; i < fDefaultFallbackList.count(); i++) { 498 FallbackFontList* fallbackFontList = this->getCurrentLocaleFallbackFontList( );
493 FontRecID fontRecID = fDefaultFallbackList[i]; 499 for (int i = 0; i < fallbackFontList->count(); i++) {
500 FontRecID fontRecID = fallbackFontList->getAt(i);
494 SkTypeface* face = this->getTypefaceForFontRec(fontRecID); 501 SkTypeface* face = this->getTypefaceForFontRec(fontRecID);
495 502
496 SkPaint paint; 503 SkPaint paint;
497 paint.setTypeface(face); 504 paint.setTypeface(face);
498 paint.setTextEncoding(SkPaint::kUTF32_TextEncoding); 505 paint.setTextEncoding(SkPaint::kUTF32_TextEncoding);
499 506
500 uint16_t glyphID; 507 uint16_t glyphID;
501 paint.textToGlyphs(&uni, sizeof(uni), &glyphID); 508 paint.textToGlyphs(&uni, sizeof(uni), &glyphID);
502 if (glyphID != 0) { 509 if (glyphID != 0) {
503 name->set(fFonts[fontRecID].fFileName); 510 name->set(fFonts[fontRecID].fFileName);
(...skipping 22 matching lines...) Expand all
526 SkGlyphCache* cache = autoCache.getCache(); 533 SkGlyphCache* cache = autoCache.getCache();
527 534
528 SkScalerContext* ctx = cache->getScalerContext(); 535 SkScalerContext* ctx = cache->getScalerContext();
529 if (ctx) { 536 if (ctx) {
530 SkFontID fontID = ctx->findTypefaceIdForChar(uni); 537 SkFontID fontID = ctx->findTypefaceIdForChar(uni);
531 return SkTypefaceCache::FindByID(fontID); 538 return SkTypefaceCache::FindByID(fontID);
532 } 539 }
533 return NULL; 540 return NULL;
534 } 541 }
535 542
543 FallbackFontList* SkFontConfigInterfaceAndroid::getCurrentLocaleFallbackFontList () {
544 SkString locale = SkFontConfigParser::GetLocale();
545 if (NULL == fLocaleFallbackFontList || locale != fCachedLocale) {
546 fCachedLocale = locale;
547 fLocaleFallbackFontList = this->findFallbackFontList(locale);
548 }
549 return fLocaleFallbackFontList;
550 }
551
536 FallbackFontList* SkFontConfigInterfaceAndroid::findFallbackFontList(const SkLan guage& lang, 552 FallbackFontList* SkFontConfigInterfaceAndroid::findFallbackFontList(const SkLan guage& lang,
537 bool isOrig inal) { 553 bool isOrig inal) {
538 const SkString& langTag = lang.getTag(); 554 const SkString& langTag = lang.getTag();
539 if (langTag.isEmpty()) { 555 if (langTag.isEmpty()) {
540 return &fDefaultFallbackList; 556 return &fDefaultFallbackList;
541 } 557 }
542 558
543 FallbackFontList* fallbackFontList; 559 FallbackFontList* fallbackFontList;
544 if (fFallbackFontDict.find(langTag.c_str(), langTag.size(), &fallbackFontLis t) || 560 if (fFallbackFontDict.find(langTag.c_str(), langTag.size(), &fallbackFontLis t) ||
545 fFallbackFontAliasDict.find(langTag.c_str(), langTag.size(), &fallbackFo ntList)) { 561 fFallbackFontAliasDict.find(langTag.c_str(), langTag.size(), &fallbackFo ntList)) {
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
795 return SkCreateTypefaceForScriptNG(getHBScriptFromHBScriptOld(script), style , fontVariant); 811 return SkCreateTypefaceForScriptNG(getHBScriptFromHBScriptOld(script), style , fontVariant);
796 } 812 }
797 813
798 #endif 814 #endif
799 815
800 /////////////////////////////////////////////////////////////////////////////// 816 ///////////////////////////////////////////////////////////////////////////////
801 817
802 SkFontMgr* SkFontMgr::Factory() { 818 SkFontMgr* SkFontMgr::Factory() {
803 return NULL; 819 return NULL;
804 } 820 }
OLDNEW
« no previous file with comments | « no previous file | src/ports/SkFontConfigParser_android.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698