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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 Loading... | |
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 this is a fallback font then add it to the appropriate fallbac k chains |
286 // requested by the filenames of the fonts they contain. | 284 if (familyRec->fIsFallbackFont) { |
287 if (familyRec && familyRec->fIsFallbackFont) { | 285 addFallbackFamily(familyRecID); |
mtklein
2013/09/20 18:53:38
Can you add a note here that this calls insert_int
| |
288 insert_into_name_dict(fFamilyNameDict, fontRec.fFileName.c_str() , familyRecID); | 286 } else { |
287 // add the names that map to this family to the dictionary for e asy lookup | |
288 const SkTDArray<const char*>& names = family->fNames; | |
289 if (names.isEmpty()) { | |
290 SkDEBUGFAIL("ERROR: non-fallback font with no name"); | |
291 continue; | |
292 } | |
293 | |
294 for (int i = 0; i < names.count(); i++) { | |
295 insert_into_name_dict(fFamilyNameDict, names[i], familyRecID ); | |
296 } | |
289 } | 297 } |
290 } | 298 } |
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 } | 299 } |
306 | 300 |
307 DEBUG_FONT(("---- We have %d system fonts", fFonts.count())); | 301 DEBUG_FONT(("---- We have %d system fonts", fFonts.count())); |
308 | 302 |
309 if (fFontFamilies.count() > 0) { | 303 if (fFontFamilies.count() > 0) { |
310 fDefaultFamilyRecID = 0; | 304 fDefaultFamilyRecID = 0; |
311 } | 305 } |
312 | 306 |
313 // scans the default fallback font chain, adding every entry to every other | 307 // 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 | 308 // fallback font chain to which it does not belong. this results in every |
(...skipping 19 matching lines...) Expand all Loading... | |
334 // iterate through and cleanup fFallbackFontDict | 328 // iterate through and cleanup fFallbackFontDict |
335 SkTDict<FallbackFontList*>::Iter iter(fFallbackFontDict); | 329 SkTDict<FallbackFontList*>::Iter iter(fFallbackFontDict); |
336 FallbackFontList* fallbackList; | 330 FallbackFontList* fallbackList; |
337 while(iter.next(&fallbackList) != NULL) { | 331 while(iter.next(&fallbackList) != NULL) { |
338 SkDELETE(fallbackList); | 332 SkDELETE(fallbackList); |
339 } | 333 } |
340 } | 334 } |
341 | 335 |
342 void SkFontConfigInterfaceAndroid::addFallbackFamily(FamilyRecID familyRecID) { | 336 void SkFontConfigInterfaceAndroid::addFallbackFamily(FamilyRecID familyRecID) { |
343 SkASSERT(familyRecID < fFontFamilies.count()); | 337 SkASSERT(familyRecID < fFontFamilies.count()); |
344 const FamilyRec& familyRec = fFontFamilies[familyRecID]; | 338 FamilyRec& familyRec = fFontFamilies[familyRecID]; |
345 SkASSERT(familyRec.fIsFallbackFont); | 339 SkASSERT(familyRec.fIsFallbackFont); |
346 | 340 |
341 // add the fallback family to the name dictionary. This is | |
342 // needed by getFallbackFamilyNameForChar() so that fallback | |
343 // families can be identified by a unique name. The unique | |
344 // identifier that we've chosen is the familyID in hex. | |
mtklein
2013/09/20 18:53:38
Can you add an e.g. here? I was wondering what ex
| |
345 familyRec.fFallbackName.printf("%.2x##fallback", familyRecID); | |
346 insert_into_name_dict(fFamilyNameDict, familyRec.fFallbackName.c_str(), fami lyRecID); | |
347 | |
347 // add to the default fallback list | 348 // add to the default fallback list |
348 fDefaultFallbackList.push(familyRecID); | 349 fDefaultFallbackList.push(familyRecID); |
349 | 350 |
350 // stop here if it is the default language tag | 351 // stop here if it is the default language tag |
351 const SkString& languageTag = familyRec.fPaintOptions.getLanguage().getTag() ; | 352 const SkString& languageTag = familyRec.fPaintOptions.getLanguage().getTag() ; |
352 if (languageTag.isEmpty()) { | 353 if (languageTag.isEmpty()) { |
353 return; | 354 return; |
354 } | 355 } |
355 | 356 |
356 // add to the appropriate language's custom fallback list | 357 // add to the appropriate language's custom fallback list |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
522 FontRecID fontRecID = find_best_style(fFontFamilies[familyRecID], SkType face::kNormal); | 523 FontRecID fontRecID = find_best_style(fFontFamilies[familyRecID], SkType face::kNormal); |
523 SkTypeface* face = this->getTypefaceForFontRec(fontRecID); | 524 SkTypeface* face = this->getTypefaceForFontRec(fontRecID); |
524 | 525 |
525 SkPaint paint; | 526 SkPaint paint; |
526 paint.setTypeface(face); | 527 paint.setTypeface(face); |
527 paint.setTextEncoding(SkPaint::kUTF32_TextEncoding); | 528 paint.setTextEncoding(SkPaint::kUTF32_TextEncoding); |
528 | 529 |
529 uint16_t glyphID; | 530 uint16_t glyphID; |
530 paint.textToGlyphs(&uni, sizeof(uni), &glyphID); | 531 paint.textToGlyphs(&uni, sizeof(uni), &glyphID); |
531 if (glyphID != 0) { | 532 if (glyphID != 0) { |
532 name->set(fFonts[fontRecID].fFileName); | 533 name->set(fFontFamilies[familyRecID].fFallbackName); |
533 return true; | 534 return true; |
534 } | 535 } |
535 } | 536 } |
536 return false; | 537 return false; |
537 } | 538 } |
538 | 539 |
539 SkTypeface* SkFontConfigInterfaceAndroid::getTypefaceForChar(SkUnichar uni, | 540 SkTypeface* SkFontConfigInterfaceAndroid::getTypefaceForChar(SkUnichar uni, |
540 SkTypeface::Style s tyle, | 541 SkTypeface::Style s tyle, |
541 SkPaintOptionsAndro id::FontVariant fontVariant) { | 542 SkPaintOptionsAndro id::FontVariant fontVariant) { |
542 FontRecID fontRecID = find_best_style(fFontFamilies[fDefaultFamilyRecID], st yle); | 543 FontRecID fontRecID = find_best_style(fFontFamilies[fDefaultFamilyRecID], st yle); |
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
851 return SkCreateTypefaceForScriptNG(getHBScriptFromHBScriptOld(script), style , fontVariant); | 852 return SkCreateTypefaceForScriptNG(getHBScriptFromHBScriptOld(script), style , fontVariant); |
852 } | 853 } |
853 | 854 |
854 #endif | 855 #endif |
855 | 856 |
856 /////////////////////////////////////////////////////////////////////////////// | 857 /////////////////////////////////////////////////////////////////////////////// |
857 | 858 |
858 SkFontMgr* SkFontMgr::Factory() { | 859 SkFontMgr* SkFontMgr::Factory() { |
859 return NULL; | 860 return NULL; |
860 } | 861 } |
OLD | NEW |