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

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

Issue 24288002: Use different unique identifier for a fallback family. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: mtkleins comments Created 7 years, 3 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 | no next file » | 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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 }; 60 };
61 61
62 struct FamilyRec { 62 struct FamilyRec {
63 FamilyRec() { 63 FamilyRec() {
64 memset(fFontRecID, INVALID_FONT_REC_ID, sizeof(fFontRecID)); 64 memset(fFontRecID, INVALID_FONT_REC_ID, sizeof(fFontRecID));
65 } 65 }
66 66
67 static const int FONT_STYLE_COUNT = 4; 67 static const int FONT_STYLE_COUNT = 4;
68 FontRecID fFontRecID[FONT_STYLE_COUNT]; 68 FontRecID fFontRecID[FONT_STYLE_COUNT];
69 bool fIsFallbackFont; 69 bool fIsFallbackFont;
70 SkString fFallbackName;
70 SkPaintOptionsAndroid fPaintOptions; 71 SkPaintOptionsAndroid fPaintOptions;
71 }; 72 };
72 73
73 74
74 typedef SkTDArray<FamilyRecID> FallbackFontList; 75 typedef SkTDArray<FamilyRecID> FallbackFontList;
75 76
76 class SkFontConfigInterfaceAndroid : public SkFontConfigInterface { 77 class SkFontConfigInterfaceAndroid : public SkFontConfigInterface {
77 public: 78 public:
78 SkFontConfigInterfaceAndroid(SkTDArray<FontFamily*>& fontFamilies); 79 SkFontConfigInterfaceAndroid(SkTDArray<FontFamily*>& fontFamilies);
79 virtual ~SkFontConfigInterfaceAndroid(); 80 virtual ~SkFontConfigInterfaceAndroid();
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 // create a familyRec now that we know that at least one font in 257 // create a familyRec now that we know that at least one font in
257 // the family is valid 258 // the family is valid
258 if (familyRec == NULL) { 259 if (familyRec == NULL) {
259 familyRec = &fFontFamilies.push_back(); 260 familyRec = &fFontFamilies.push_back();
260 familyRecID = fFontFamilies.count() - 1; 261 familyRecID = fFontFamilies.count() - 1;
261 fontRec.fFamilyRecID = familyRecID; 262 fontRec.fFamilyRecID = familyRecID;
262 263
263 familyRec->fIsFallbackFont = family->fIsFallbackFont; 264 familyRec->fIsFallbackFont = family->fIsFallbackFont;
264 familyRec->fPaintOptions = family->fFontFiles[j]->fPaintOptions; 265 familyRec->fPaintOptions = family->fFontFiles[j]->fPaintOptions;
265 266
266 // if this is a fallback font then add it to the appropriate fal lback chains
267 if (familyRec->fIsFallbackFont) {
268 addFallbackFamily(familyRecID);
269 }
270 } else if (familyRec->fPaintOptions != family->fFontFiles[j]->fPaint Options) { 267 } else if (familyRec->fPaintOptions != family->fFontFiles[j]->fPaint Options) {
271 SkDebugf("Every font file within a family must have identical" 268 SkDebugf("Every font file within a family must have identical"
272 "language and variant attributes"); 269 "language and variant attributes");
273 sk_throw(); 270 sk_throw();
274 } 271 }
275 272
276 // add this font to the current familyRec 273 // add this font to the current familyRec
277 if (INVALID_FONT_REC_ID != familyRec->fFontRecID[fontRec.fStyle]) { 274 if (INVALID_FONT_REC_ID != familyRec->fFontRecID[fontRec.fStyle]) {
278 DEBUG_FONT(("Overwriting familyRec for style[%d] old,new:(%d,%d) ", 275 DEBUG_FONT(("Overwriting familyRec for style[%d] old,new:(%d,%d) ",
279 fontRec.fStyle, familyRec->fFontRecID[fontRec.fStyle ], 276 fontRec.fStyle, familyRec->fFontRecID[fontRec.fStyle ],
280 fontRecID)); 277 fontRecID));
281 } 278 }
282 familyRec->fFontRecID[fontRec.fStyle] = fontRecID; 279 familyRec->fFontRecID[fontRec.fStyle] = fontRecID;
280 }
283 281
284 // add the fallback file name to the name dictionary. This is neede d 282 if (familyRec) {
285 // by getFallbackFamilyNameForChar() so that fallback families can b e 283 if (familyRec->fIsFallbackFont) {
286 // requested by the filenames of the fonts they contain. 284 // add the font to the appropriate fallback chains and also inse rt a
287 if (familyRec && familyRec->fIsFallbackFont) { 285 // unique name into the familyNameDict for internal usage
288 insert_into_name_dict(fFamilyNameDict, fontRec.fFileName.c_str() , familyRecID); 286 addFallbackFamily(familyRecID);
287 } else {
288 // add the names that map to this family to the dictionary for e asy lookup
289 const SkTDArray<const char*>& names = family->fNames;
290 if (names.isEmpty()) {
291 SkDEBUGFAIL("ERROR: non-fallback font with no name");
292 continue;
293 }
294
295 for (int i = 0; i < names.count(); i++) {
296 insert_into_name_dict(fFamilyNameDict, names[i], familyRecID );
297 }
289 } 298 }
290 } 299 }
291
292 // add the names that map to this family to the dictionary for easy look up
293 if (familyRec && !familyRec->fIsFallbackFont) {
294 SkTDArray<const char*> names = family->fNames;
295 if (names.isEmpty()) {
296 SkDEBUGFAIL("ERROR: non-fallback font with no name");
297 continue;
298 }
299
300 for (int i = 0; i < names.count(); i++) {
301 insert_into_name_dict(fFamilyNameDict, names[i], familyRecID);
302 }
303 }
304
305 } 300 }
306 301
307 DEBUG_FONT(("---- We have %d system fonts", fFonts.count())); 302 DEBUG_FONT(("---- We have %d system fonts", fFonts.count()));
308 303
309 if (fFontFamilies.count() > 0) { 304 if (fFontFamilies.count() > 0) {
310 fDefaultFamilyRecID = 0; 305 fDefaultFamilyRecID = 0;
311 } 306 }
312 307
313 // scans the default fallback font chain, adding every entry to every other 308 // scans the default fallback font chain, adding every entry to every other
314 // fallback font chain to which it does not belong. this results in every 309 // fallback font chain to which it does not belong. this results in every
(...skipping 19 matching lines...) Expand all
334 // iterate through and cleanup fFallbackFontDict 329 // iterate through and cleanup fFallbackFontDict
335 SkTDict<FallbackFontList*>::Iter iter(fFallbackFontDict); 330 SkTDict<FallbackFontList*>::Iter iter(fFallbackFontDict);
336 FallbackFontList* fallbackList; 331 FallbackFontList* fallbackList;
337 while(iter.next(&fallbackList) != NULL) { 332 while(iter.next(&fallbackList) != NULL) {
338 SkDELETE(fallbackList); 333 SkDELETE(fallbackList);
339 } 334 }
340 } 335 }
341 336
342 void SkFontConfigInterfaceAndroid::addFallbackFamily(FamilyRecID familyRecID) { 337 void SkFontConfigInterfaceAndroid::addFallbackFamily(FamilyRecID familyRecID) {
343 SkASSERT(familyRecID < fFontFamilies.count()); 338 SkASSERT(familyRecID < fFontFamilies.count());
344 const FamilyRec& familyRec = fFontFamilies[familyRecID]; 339 FamilyRec& familyRec = fFontFamilies[familyRecID];
345 SkASSERT(familyRec.fIsFallbackFont); 340 SkASSERT(familyRec.fIsFallbackFont);
346 341
342 // add the fallback family to the name dictionary. This is
343 // needed by getFallbackFamilyNameForChar() so that fallback
344 // families can be identified by a unique name. The unique
345 // identifier that we've chosen is the familyID in hex (e.g. '0F##fallback') .
346 familyRec.fFallbackName.printf("%.2x##fallback", familyRecID);
347 insert_into_name_dict(fFamilyNameDict, familyRec.fFallbackName.c_str(), fami lyRecID);
348
347 // add to the default fallback list 349 // add to the default fallback list
348 fDefaultFallbackList.push(familyRecID); 350 fDefaultFallbackList.push(familyRecID);
349 351
350 // stop here if it is the default language tag 352 // stop here if it is the default language tag
351 const SkString& languageTag = familyRec.fPaintOptions.getLanguage().getTag() ; 353 const SkString& languageTag = familyRec.fPaintOptions.getLanguage().getTag() ;
352 if (languageTag.isEmpty()) { 354 if (languageTag.isEmpty()) {
353 return; 355 return;
354 } 356 }
355 357
356 // add to the appropriate language's custom fallback list 358 // add to the appropriate language's custom fallback list
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
522 FontRecID fontRecID = find_best_style(fFontFamilies[familyRecID], SkType face::kNormal); 524 FontRecID fontRecID = find_best_style(fFontFamilies[familyRecID], SkType face::kNormal);
523 SkTypeface* face = this->getTypefaceForFontRec(fontRecID); 525 SkTypeface* face = this->getTypefaceForFontRec(fontRecID);
524 526
525 SkPaint paint; 527 SkPaint paint;
526 paint.setTypeface(face); 528 paint.setTypeface(face);
527 paint.setTextEncoding(SkPaint::kUTF32_TextEncoding); 529 paint.setTextEncoding(SkPaint::kUTF32_TextEncoding);
528 530
529 uint16_t glyphID; 531 uint16_t glyphID;
530 paint.textToGlyphs(&uni, sizeof(uni), &glyphID); 532 paint.textToGlyphs(&uni, sizeof(uni), &glyphID);
531 if (glyphID != 0) { 533 if (glyphID != 0) {
532 name->set(fFonts[fontRecID].fFileName); 534 name->set(fFontFamilies[familyRecID].fFallbackName);
533 return true; 535 return true;
534 } 536 }
535 } 537 }
536 return false; 538 return false;
537 } 539 }
538 540
539 SkTypeface* SkFontConfigInterfaceAndroid::getTypefaceForChar(SkUnichar uni, 541 SkTypeface* SkFontConfigInterfaceAndroid::getTypefaceForChar(SkUnichar uni,
540 SkTypeface::Style s tyle, 542 SkTypeface::Style s tyle,
541 SkPaintOptionsAndro id::FontVariant fontVariant) { 543 SkPaintOptionsAndro id::FontVariant fontVariant) {
542 FontRecID fontRecID = find_best_style(fFontFamilies[fDefaultFamilyRecID], st yle); 544 FontRecID fontRecID = find_best_style(fFontFamilies[fDefaultFamilyRecID], st yle);
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after
851 return SkCreateTypefaceForScriptNG(getHBScriptFromHBScriptOld(script), style , fontVariant); 853 return SkCreateTypefaceForScriptNG(getHBScriptFromHBScriptOld(script), style , fontVariant);
852 } 854 }
853 855
854 #endif 856 #endif
855 857
856 /////////////////////////////////////////////////////////////////////////////// 858 ///////////////////////////////////////////////////////////////////////////////
857 859
858 SkFontMgr* SkFontMgr::Factory() { 860 SkFontMgr* SkFontMgr::Factory() {
859 return NULL; 861 return NULL;
860 } 862 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698