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); |
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 if (familyRec && !familyRec->fIsFallbackFont) { | |
Xianzhu
2013/09/19 19:07:25
This condition can be removed.
| |
289 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], familyR ecID); | |
297 } | |
298 } | |
289 } | 299 } |
290 } | 300 } |
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 } | 301 } |
306 | 302 |
307 DEBUG_FONT(("---- We have %d system fonts", fFonts.count())); | 303 DEBUG_FONT(("---- We have %d system fonts", fFonts.count())); |
308 | 304 |
309 if (fFontFamilies.count() > 0) { | 305 if (fFontFamilies.count() > 0) { |
310 fDefaultFamilyRecID = 0; | 306 fDefaultFamilyRecID = 0; |
311 } | 307 } |
312 | 308 |
313 // scans the default fallback font chain, adding every entry to every other | 309 // 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 | 310 // 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 | 330 // iterate through and cleanup fFallbackFontDict |
335 SkTDict<FallbackFontList*>::Iter iter(fFallbackFontDict); | 331 SkTDict<FallbackFontList*>::Iter iter(fFallbackFontDict); |
336 FallbackFontList* fallbackList; | 332 FallbackFontList* fallbackList; |
337 while(iter.next(&fallbackList) != NULL) { | 333 while(iter.next(&fallbackList) != NULL) { |
338 SkDELETE(fallbackList); | 334 SkDELETE(fallbackList); |
339 } | 335 } |
340 } | 336 } |
341 | 337 |
342 void SkFontConfigInterfaceAndroid::addFallbackFamily(FamilyRecID familyRecID) { | 338 void SkFontConfigInterfaceAndroid::addFallbackFamily(FamilyRecID familyRecID) { |
343 SkASSERT(familyRecID < fFontFamilies.count()); | 339 SkASSERT(familyRecID < fFontFamilies.count()); |
344 const FamilyRec& familyRec = fFontFamilies[familyRecID]; | 340 FamilyRec& familyRec = fFontFamilies[familyRecID]; |
345 SkASSERT(familyRec.fIsFallbackFont); | 341 SkASSERT(familyRec.fIsFallbackFont); |
346 | 342 |
343 // add the fallback family to the name dictionary. This is | |
344 // needed by getFallbackFamilyNameForChar() so that fallback | |
345 // families can be identified by a unique name. The unique | |
346 // identifier that we've chosen is the familyID in hex. | |
347 familyRec.fFallbackName.printf("%.2x##fallback", familyRecID); | |
348 insert_into_name_dict(fFamilyNameDict, familyRec.fFallbackName.c_str(), fami lyRecID); | |
349 | |
347 // add to the default fallback list | 350 // add to the default fallback list |
348 fDefaultFallbackList.push(familyRecID); | 351 fDefaultFallbackList.push(familyRecID); |
349 | 352 |
350 // stop here if it is the default language tag | 353 // stop here if it is the default language tag |
351 const SkString& languageTag = familyRec.fPaintOptions.getLanguage().getTag() ; | 354 const SkString& languageTag = familyRec.fPaintOptions.getLanguage().getTag() ; |
352 if (languageTag.isEmpty()) { | 355 if (languageTag.isEmpty()) { |
353 return; | 356 return; |
354 } | 357 } |
355 | 358 |
356 // add to the appropriate language's custom fallback list | 359 // 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); | 525 FontRecID fontRecID = find_best_style(fFontFamilies[familyRecID], SkType face::kNormal); |
523 SkTypeface* face = this->getTypefaceForFontRec(fontRecID); | 526 SkTypeface* face = this->getTypefaceForFontRec(fontRecID); |
524 | 527 |
525 SkPaint paint; | 528 SkPaint paint; |
526 paint.setTypeface(face); | 529 paint.setTypeface(face); |
527 paint.setTextEncoding(SkPaint::kUTF32_TextEncoding); | 530 paint.setTextEncoding(SkPaint::kUTF32_TextEncoding); |
528 | 531 |
529 uint16_t glyphID; | 532 uint16_t glyphID; |
530 paint.textToGlyphs(&uni, sizeof(uni), &glyphID); | 533 paint.textToGlyphs(&uni, sizeof(uni), &glyphID); |
531 if (glyphID != 0) { | 534 if (glyphID != 0) { |
532 name->set(fFonts[fontRecID].fFileName); | 535 name->set(fFontFamilies[familyRecID].fFallbackName); |
533 return true; | 536 return true; |
534 } | 537 } |
535 } | 538 } |
536 return false; | 539 return false; |
537 } | 540 } |
538 | 541 |
539 SkTypeface* SkFontConfigInterfaceAndroid::getTypefaceForChar(SkUnichar uni, | 542 SkTypeface* SkFontConfigInterfaceAndroid::getTypefaceForChar(SkUnichar uni, |
540 SkTypeface::Style s tyle, | 543 SkTypeface::Style s tyle, |
541 SkPaintOptionsAndro id::FontVariant fontVariant) { | 544 SkPaintOptionsAndro id::FontVariant fontVariant) { |
542 FontRecID fontRecID = find_best_style(fFontFamilies[fDefaultFamilyRecID], st yle); | 545 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); | 854 return SkCreateTypefaceForScriptNG(getHBScriptFromHBScriptOld(script), style , fontVariant); |
852 } | 855 } |
853 | 856 |
854 #endif | 857 #endif |
855 | 858 |
856 /////////////////////////////////////////////////////////////////////////////// | 859 /////////////////////////////////////////////////////////////////////////////// |
857 | 860 |
858 SkFontMgr* SkFontMgr::Factory() { | 861 SkFontMgr* SkFontMgr::Factory() { |
859 return NULL; | 862 return NULL; |
860 } | 863 } |
OLD | NEW |