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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 #define INVALID_FONT_REC_ID -1 | 48 #define INVALID_FONT_REC_ID -1 |
49 | 49 |
50 typedef int32_t FamilyRecID; | 50 typedef int32_t FamilyRecID; |
51 #define INVALID_FAMILY_REC_ID -1 | 51 #define INVALID_FAMILY_REC_ID -1 |
52 | 52 |
53 // used to record our notion of the pre-existing fonts | 53 // used to record our notion of the pre-existing fonts |
54 struct FontRec { | 54 struct FontRec { |
55 SkRefPtr<SkTypeface> fTypeface; | 55 SkRefPtr<SkTypeface> fTypeface; |
56 SkString fFileName; | 56 SkString fFileName; |
57 SkTypeface::Style fStyle; | 57 SkTypeface::Style fStyle; |
58 SkPaintOptionsAndroid fPaintOptions; | |
59 bool fIsFallbackFont; | |
60 bool fIsValid; | 58 bool fIsValid; |
61 FamilyRecID fFamilyRecID; | 59 FamilyRecID fFamilyRecID; |
62 }; | 60 }; |
63 | 61 |
64 struct FamilyRec { | 62 struct FamilyRec { |
65 FamilyRec() { | 63 FamilyRec() { |
66 memset(fFontRecID, INVALID_FONT_REC_ID, sizeof(fFontRecID)); | 64 memset(fFontRecID, INVALID_FONT_REC_ID, sizeof(fFontRecID)); |
67 } | 65 } |
68 | 66 |
69 static const int FONT_STYLE_COUNT = 4; | 67 static const int FONT_STYLE_COUNT = 4; |
70 FontRecID fFontRecID[FONT_STYLE_COUNT]; | 68 FontRecID fFontRecID[FONT_STYLE_COUNT]; |
| 69 bool fIsFallbackFont; |
| 70 SkPaintOptionsAndroid fPaintOptions; |
71 }; | 71 }; |
72 | 72 |
73 | 73 |
74 typedef SkTDArray<FontRecID> FallbackFontList; | 74 typedef SkTDArray<FamilyRecID> FallbackFontList; |
75 | 75 |
76 class SkFontConfigInterfaceAndroid : public SkFontConfigInterface { | 76 class SkFontConfigInterfaceAndroid : public SkFontConfigInterface { |
77 public: | 77 public: |
78 SkFontConfigInterfaceAndroid(SkTDArray<FontFamily*>& fontFamilies); | 78 SkFontConfigInterfaceAndroid(SkTDArray<FontFamily*>& fontFamilies); |
79 virtual ~SkFontConfigInterfaceAndroid(); | 79 virtual ~SkFontConfigInterfaceAndroid(); |
80 | 80 |
81 virtual bool matchFamilyName(const char familyName[], | 81 virtual bool matchFamilyName(const char familyName[], |
82 SkTypeface::Style requested, | 82 SkTypeface::Style requested, |
83 FontIdentity* outFontIdentifier, | 83 FontIdentity* outFontIdentifier, |
84 SkString* outFamilyName, | 84 SkString* outFamilyName, |
(...skipping 13 matching lines...) Expand all Loading... |
98 bool getFallbackFamilyNameForChar(SkUnichar uni, SkString* name); | 98 bool getFallbackFamilyNameForChar(SkUnichar uni, SkString* name); |
99 /** | 99 /** |
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 addFallbackFamily(FamilyRecID fontRecID); |
109 SkTypeface* getTypefaceForFontRec(FontRecID fontRecID); | 109 SkTypeface* getTypefaceForFontRec(FontRecID fontRecID); |
110 FallbackFontList* getCurrentLocaleFallbackFontList(); | 110 FallbackFontList* getCurrentLocaleFallbackFontList(); |
111 FallbackFontList* findFallbackFontList(const SkLanguage& lang, bool isOrigin
al = true); | 111 FallbackFontList* findFallbackFontList(const SkLanguage& lang, bool isOrigin
al = true); |
112 | 112 |
113 SkTArray<FontRec> fFonts; | 113 SkTArray<FontRec> fFonts; |
114 SkTArray<FamilyRec> fFontFamilies; | 114 SkTArray<FamilyRec> fFontFamilies; |
115 SkTDict<FamilyRecID> fFamilyNameDict; | 115 SkTDict<FamilyRecID> fFamilyNameDict; |
116 FamilyRecID fDefaultFamilyRecID; | 116 FamilyRecID fDefaultFamilyRecID; |
117 | 117 |
118 // (SkLanguage)<->(fallback chain index) translation | 118 // (SkLanguage)<->(fallback chain index) translation |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 | 220 |
221 if (has_font(fFonts, filename)) { | 221 if (has_font(fFonts, filename)) { |
222 SkDebugf("---- system font and fallback font files specify a dup
licate " | 222 SkDebugf("---- system font and fallback font files specify a dup
licate " |
223 "font %s, skipping the second occurrence", filename.c_st
r()); | 223 "font %s, skipping the second occurrence", filename.c_st
r()); |
224 continue; | 224 continue; |
225 } | 225 } |
226 | 226 |
227 FontRec& fontRec = fFonts.push_back(); | 227 FontRec& fontRec = fFonts.push_back(); |
228 fontRec.fFileName = filename; | 228 fontRec.fFileName = filename; |
229 fontRec.fStyle = SkTypeface::kNormal; | 229 fontRec.fStyle = SkTypeface::kNormal; |
230 fontRec.fPaintOptions = family->fFontFiles[j]->fPaintOptions; | |
231 fontRec.fIsFallbackFont = family->fIsFallbackFont; | |
232 fontRec.fIsValid = false; | 230 fontRec.fIsValid = false; |
233 fontRec.fFamilyRecID = familyRecID; | 231 fontRec.fFamilyRecID = familyRecID; |
234 | 232 |
235 const FontRecID fontRecID = fFonts.count() - 1; | 233 const FontRecID fontRecID = fFonts.count() - 1; |
236 | 234 |
237 SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(filename.c_str()
)); | 235 SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(filename.c_str()
)); |
238 if (stream.get() != NULL) { | 236 if (stream.get() != NULL) { |
239 bool isFixedWidth; | 237 bool isFixedWidth; |
240 SkString name; | 238 SkString name; |
241 fontRec.fIsValid = find_name_and_attributes(stream.get(), &name, | 239 fontRec.fIsValid = find_name_and_attributes(stream.get(), &name, |
242 &fontRec.fStyle, &is
FixedWidth); | 240 &fontRec.fStyle, &is
FixedWidth); |
243 } else { | 241 } else { |
244 if (!fontRec.fIsFallbackFont) { | 242 if (!family->fIsFallbackFont) { |
245 SkDebugf("---- failed to open <%s> as a font\n", filename.c_
str()); | 243 SkDebugf("---- failed to open <%s> as a font\n", filename.c_
str()); |
246 } | 244 } |
247 } | 245 } |
248 | 246 |
249 if (fontRec.fIsValid) { | 247 if (fontRec.fIsValid) { |
250 DEBUG_FONT(("---- SystemFonts[%d][%d] fallback=%d file=%s", | 248 DEBUG_FONT(("---- SystemFonts[%d][%d] fallback=%d file=%s", |
251 i, fFonts.count() - 1, fontRec.fIsFallbackFont, filen
ame.c_str())); | 249 i, fFonts.count() - 1, fontRec.fIsFallbackFont, filen
ame.c_str())); |
252 } else { | 250 } else { |
253 DEBUG_FONT(("---- SystemFonts[%d][%d] fallback=%d file=%s (INVAL
ID)", | 251 DEBUG_FONT(("---- SystemFonts[%d][%d] fallback=%d file=%s (INVAL
ID)", |
254 i, fFonts.count() - 1, fontRec.fIsFallbackFont, filen
ame.c_str())); | 252 i, fFonts.count() - 1, fontRec.fIsFallbackFont, filen
ame.c_str())); |
255 continue; | 253 continue; |
256 } | 254 } |
257 | 255 |
258 // create a familyRec now that we know that at least one font in | 256 // create a familyRec now that we know that at least one font in |
259 // the family is valid | 257 // the family is valid |
260 if (familyRec == NULL) { | 258 if (familyRec == NULL) { |
261 familyRec = &fFontFamilies.push_back(); | 259 familyRec = &fFontFamilies.push_back(); |
262 familyRecID = fFontFamilies.count() - 1; | 260 familyRecID = fFontFamilies.count() - 1; |
263 fontRec.fFamilyRecID = familyRecID; | 261 fontRec.fFamilyRecID = familyRecID; |
| 262 |
| 263 familyRec->fIsFallbackFont = family->fIsFallbackFont; |
| 264 familyRec->fPaintOptions = family->fFontFiles[j]->fPaintOptions; |
| 265 |
| 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) { |
| 271 SkDebugf("Every font file within a family must have identical" |
| 272 "language and variant attributes"); |
| 273 sk_throw(); |
264 } | 274 } |
265 | 275 |
266 // add this font to the current familyRec | 276 // add this font to the current familyRec |
267 if (INVALID_FONT_REC_ID != familyRec->fFontRecID[fontRec.fStyle]) { | 277 if (INVALID_FONT_REC_ID != familyRec->fFontRecID[fontRec.fStyle]) { |
268 DEBUG_FONT(("Overwriting familyRec for style[%d] old,new:(%d,%d)
", | 278 DEBUG_FONT(("Overwriting familyRec for style[%d] old,new:(%d,%d)
", |
269 fontRec.fStyle, familyRec->fFontRecID[fontRec.fStyle
], | 279 fontRec.fStyle, familyRec->fFontRecID[fontRec.fStyle
], |
270 fontRecID)); | 280 fontRecID)); |
271 } | 281 } |
272 familyRec->fFontRecID[fontRec.fStyle] = fontRecID; | 282 familyRec->fFontRecID[fontRec.fStyle] = fontRecID; |
273 | 283 |
274 // if this is a fallback font then add it to the appropriate fallbac
k chains | |
275 if (fontRec.fIsFallbackFont) { | |
276 addFallbackFont(fontRecID); | |
277 } | |
278 | |
279 // add the fallback file name to the name dictionary. This is neede
d | 284 // add the fallback file name to the name dictionary. This is neede
d |
280 // by getFallbackFamilyNameForChar() so that fallback families can b
e | 285 // by getFallbackFamilyNameForChar() so that fallback families can b
e |
281 // requested by the filenames of the fonts they contain. | 286 // requested by the filenames of the fonts they contain. |
282 if (family->fIsFallbackFont && familyRec) { | 287 if (familyRec && familyRec->fIsFallbackFont) { |
283 insert_into_name_dict(fFamilyNameDict, fontRec.fFileName.c_str()
, familyRecID); | 288 insert_into_name_dict(fFamilyNameDict, fontRec.fFileName.c_str()
, familyRecID); |
284 } | 289 } |
285 } | 290 } |
286 | 291 |
287 // add the names that map to this family to the dictionary for easy look
up | 292 // add the names that map to this family to the dictionary for easy look
up |
288 if (familyRec && !family->fIsFallbackFont) { | 293 if (familyRec && !familyRec->fIsFallbackFont) { |
289 SkTDArray<const char*> names = family->fNames; | 294 SkTDArray<const char*> names = family->fNames; |
290 if (names.isEmpty()) { | 295 if (names.isEmpty()) { |
291 SkDEBUGFAIL("ERROR: non-fallback font with no name"); | 296 SkDEBUGFAIL("ERROR: non-fallback font with no name"); |
292 continue; | 297 continue; |
293 } | 298 } |
294 | 299 |
295 for (int i = 0; i < names.count(); i++) { | 300 for (int i = 0; i < names.count(); i++) { |
296 insert_into_name_dict(fFamilyNameDict, names[i], familyRecID); | 301 insert_into_name_dict(fFamilyNameDict, names[i], familyRecID); |
297 } | 302 } |
298 } | 303 } |
299 | 304 |
300 } | 305 } |
301 | 306 |
302 DEBUG_FONT(("---- We have %d system fonts", fFonts.count())); | 307 DEBUG_FONT(("---- We have %d system fonts", fFonts.count())); |
303 | 308 |
304 if (fFontFamilies.count() > 0) { | 309 if (fFontFamilies.count() > 0) { |
305 fDefaultFamilyRecID = 0; | 310 fDefaultFamilyRecID = 0; |
306 } | 311 } |
307 | 312 |
308 // scans the default fallback font chain, adding every entry to every other | 313 // scans the default fallback font chain, adding every entry to every other |
309 // fallback font chain to which it does not belong. this results in every | 314 // fallback font chain to which it does not belong. this results in every |
310 // language-specific fallback font chain having all of its fallback fonts at | 315 // language-specific fallback font chain having all of its fallback fonts at |
311 // the front of the chain, and everything else at the end. | 316 // the front of the chain, and everything else at the end. |
312 FallbackFontList* fallbackList; | 317 FallbackFontList* fallbackList; |
313 SkTDict<FallbackFontList*>::Iter iter(fFallbackFontDict); | 318 SkTDict<FallbackFontList*>::Iter iter(fFallbackFontDict); |
314 const char* fallbackLang = iter.next(&fallbackList); | 319 const char* fallbackLang = iter.next(&fallbackList); |
315 while(fallbackLang != NULL) { | 320 while(fallbackLang != NULL) { |
316 for (int i = 0; i < fDefaultFallbackList.count(); i++) { | 321 for (int i = 0; i < fDefaultFallbackList.count(); i++) { |
317 FontRecID fontRecID = fDefaultFallbackList[i]; | 322 FamilyRecID familyRecID = fDefaultFallbackList[i]; |
318 const SkString& fontLang = fFonts[fontRecID].fPaintOptions.getLangua
ge().getTag(); | 323 const SkString& fontLang = fFontFamilies[familyRecID].fPaintOptions.
getLanguage().getTag(); |
319 if (strcmp(fallbackLang, fontLang.c_str()) != 0) { | 324 if (strcmp(fallbackLang, fontLang.c_str()) != 0) { |
320 fallbackList->push(fontRecID); | 325 fallbackList->push(familyRecID); |
321 } | 326 } |
322 } | 327 } |
323 // move to the next fallback list in the dictionary | 328 // move to the next fallback list in the dictionary |
324 fallbackLang = iter.next(&fallbackList); | 329 fallbackLang = iter.next(&fallbackList); |
325 } | 330 } |
326 } | 331 } |
327 | 332 |
328 SkFontConfigInterfaceAndroid::~SkFontConfigInterfaceAndroid() { | 333 SkFontConfigInterfaceAndroid::~SkFontConfigInterfaceAndroid() { |
329 // iterate through and cleanup fFallbackFontDict | 334 // iterate through and cleanup fFallbackFontDict |
330 SkTDict<FallbackFontList*>::Iter iter(fFallbackFontDict); | 335 SkTDict<FallbackFontList*>::Iter iter(fFallbackFontDict); |
331 FallbackFontList* fallbackList; | 336 FallbackFontList* fallbackList; |
332 while(iter.next(&fallbackList) != NULL) { | 337 while(iter.next(&fallbackList) != NULL) { |
333 SkDELETE(fallbackList); | 338 SkDELETE(fallbackList); |
334 } | 339 } |
335 } | 340 } |
336 | 341 |
337 void SkFontConfigInterfaceAndroid::addFallbackFont(FontRecID fontRecID) { | 342 void SkFontConfigInterfaceAndroid::addFallbackFamily(FamilyRecID familyRecID) { |
338 SkASSERT(fontRecID < fFonts.count()); | 343 SkASSERT(familyRecID < fFontFamilies.count()); |
339 const FontRec& fontRec = fFonts[fontRecID]; | 344 const FamilyRec& familyRec = fFontFamilies[familyRecID]; |
340 SkASSERT(fontRec.fIsFallbackFont); | 345 SkASSERT(familyRec.fIsFallbackFont); |
341 | 346 |
342 // add to the default fallback list | 347 // add to the default fallback list |
343 fDefaultFallbackList.push(fontRecID); | 348 fDefaultFallbackList.push(familyRecID); |
344 | 349 |
345 // stop here if it is the default language tag | 350 // stop here if it is the default language tag |
346 const SkString& languageTag = fontRec.fPaintOptions.getLanguage().getTag(); | 351 const SkString& languageTag = familyRec.fPaintOptions.getLanguage().getTag()
; |
347 if (languageTag.isEmpty()) { | 352 if (languageTag.isEmpty()) { |
348 return; | 353 return; |
349 } | 354 } |
350 | 355 |
351 // add to the appropriate language's custom fallback list | 356 // add to the appropriate language's custom fallback list |
352 FallbackFontList* customList = NULL; | 357 FallbackFontList* customList = NULL; |
353 if (!fFallbackFontDict.find(languageTag.c_str(), &customList)) { | 358 if (!fFallbackFontDict.find(languageTag.c_str(), &customList)) { |
354 DEBUG_FONT(("---- Created fallback list for \"%s\"", languageTag.c_str(
))); | 359 DEBUG_FONT(("---- Created fallback list for \"%s\"", languageTag.c_str(
))); |
355 customList = SkNEW(FallbackFontList); | 360 customList = SkNEW(FallbackFontList); |
356 fFallbackFontDict.set(languageTag.c_str(), customList); | 361 fFallbackFontDict.set(languageTag.c_str(), customList); |
357 } | 362 } |
358 SkASSERT(customList != NULL); | 363 SkASSERT(customList != NULL); |
359 customList->push(fontRecID); | 364 customList->push(familyRecID); |
360 } | 365 } |
361 | 366 |
362 | 367 |
363 static FontRecID find_best_style(const FamilyRec& family, SkTypeface::Style styl
e) { | 368 static FontRecID find_best_style(const FamilyRec& family, SkTypeface::Style styl
e) { |
364 | 369 |
365 const FontRecID* fontRecIDs = family.fFontRecID; | 370 const FontRecID* fontRecIDs = family.fFontRecID; |
366 | 371 |
367 if (fontRecIDs[style] != INVALID_FONT_REC_ID) { // exact match | 372 if (fontRecIDs[style] != INVALID_FONT_REC_ID) { // exact match |
368 return fontRecIDs[style]; | 373 return fontRecIDs[style]; |
369 } | 374 } |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
495 // store the result for subsequent lookups | 500 // store the result for subsequent lookups |
496 fontRec.fTypeface = face; | 501 fontRec.fTypeface = face; |
497 } | 502 } |
498 SkASSERT(face); | 503 SkASSERT(face); |
499 return face; | 504 return face; |
500 } | 505 } |
501 | 506 |
502 bool SkFontConfigInterfaceAndroid::getFallbackFamilyNameForChar(SkUnichar uni, S
kString* name) { | 507 bool SkFontConfigInterfaceAndroid::getFallbackFamilyNameForChar(SkUnichar uni, S
kString* name) { |
503 FallbackFontList* fallbackFontList = this->getCurrentLocaleFallbackFontList(
); | 508 FallbackFontList* fallbackFontList = this->getCurrentLocaleFallbackFontList(
); |
504 for (int i = 0; i < fallbackFontList->count(); i++) { | 509 for (int i = 0; i < fallbackFontList->count(); i++) { |
505 FontRecID fontRecID = fallbackFontList->getAt(i); | 510 FamilyRecID familyRecID = fallbackFontList->getAt(i); |
| 511 FontRecID fontRecID = find_best_style(fFontFamilies[familyRecID], SkType
face::kNormal); |
506 SkTypeface* face = this->getTypefaceForFontRec(fontRecID); | 512 SkTypeface* face = this->getTypefaceForFontRec(fontRecID); |
507 | 513 |
508 SkPaint paint; | 514 SkPaint paint; |
509 paint.setTypeface(face); | 515 paint.setTypeface(face); |
510 paint.setTextEncoding(SkPaint::kUTF32_TextEncoding); | 516 paint.setTextEncoding(SkPaint::kUTF32_TextEncoding); |
511 | 517 |
512 uint16_t glyphID; | 518 uint16_t glyphID; |
513 paint.textToGlyphs(&uni, sizeof(uni), &glyphID); | 519 paint.textToGlyphs(&uni, sizeof(uni), &glyphID); |
514 if (glyphID != 0) { | 520 if (glyphID != 0) { |
515 name->set(fFonts[fontRecID].fFileName); | 521 name->set(fFonts[fontRecID].fFileName); |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
586 // as WebKit to customize their font selection. In any case, clients can use | 592 // as WebKit to customize their font selection. In any case, clients can use |
587 // GetFallbackFamilyNameForChar() to get the fallback font for individual | 593 // GetFallbackFamilyNameForChar() to get the fallback font for individual |
588 // characters. | 594 // characters. |
589 if (!opts.isUsingFontFallbacks()) { | 595 if (!opts.isUsingFontFallbacks()) { |
590 return NULL; | 596 return NULL; |
591 } | 597 } |
592 | 598 |
593 FallbackFontList* currentFallbackList = findFallbackFontList(opts.getLanguag
e()); | 599 FallbackFontList* currentFallbackList = findFallbackFontList(opts.getLanguag
e()); |
594 SkASSERT(currentFallbackList); | 600 SkASSERT(currentFallbackList); |
595 | 601 |
| 602 SkTypeface::Style origStyle = SkTypeface::kNormal; |
| 603 const SkTypeface* origTypeface = SkTypefaceCache::FindByID(origFontID); |
| 604 if (NULL != origTypeface) { |
| 605 origStyle = origTypeface->style(); |
| 606 } |
| 607 |
596 // we must convert currTypeface into a FontRecID | 608 // we must convert currTypeface into a FontRecID |
597 FontRecID currFontRecID = INVALID_FONT_REC_ID; | 609 FontRecID currFontRecID = INVALID_FONT_REC_ID; |
598 const SkTypeface* currTypeface = SkTypefaceCache::FindByID(currFontID); | 610 const SkTypeface* currTypeface = SkTypefaceCache::FindByID(currFontID); |
599 // non-system fonts are not in the font cache so if we are asked to fallback | 611 // non-system fonts are not in the font cache so if we are asked to fallback |
600 // for a non-system font we will start at the front of the chain. | 612 // for a non-system font we will start at the front of the chain. |
601 if (NULL != currTypeface && currFontID != origFontID) { | 613 if (NULL != currTypeface && currFontID != origFontID) { |
602 currFontRecID = ((FontConfigTypeface*)currTypeface)->getIdentity().fID; | 614 currFontRecID = ((FontConfigTypeface*)currTypeface)->getIdentity().fID; |
603 SkASSERT(INVALID_FONT_REC_ID != currFontRecID); | 615 SkASSERT(INVALID_FONT_REC_ID != currFontRecID); |
604 } | 616 } |
605 | 617 |
| 618 FamilyRecID currFamilyRecID = INVALID_FAMILY_REC_ID; |
| 619 if (INVALID_FONT_REC_ID != currFontRecID) { |
| 620 currFamilyRecID = fFonts[currFontRecID].fFamilyRecID; |
| 621 } |
| 622 |
606 // lookup the index next font in the chain | 623 // lookup the index next font in the chain |
607 int currFallbackFontIndex = currentFallbackList->find(currFontRecID); | 624 int currFallbackFontIndex = currentFallbackList->find(currFamilyRecID); |
608 // We add 1 to the returned index for 2 reasons: (1) if find succeeds it mov
es | 625 // We add 1 to the returned index for 2 reasons: (1) if find succeeds it mov
es |
609 // our index to the next entry in the list; (2) if find() fails it returns | 626 // our index to the next entry in the list; (2) if find() fails it returns |
610 // -1 and incrementing it will set our starting index to 0 (the head of the
list) | 627 // -1 and incrementing it will set our starting index to 0 (the head of the
list) |
611 int nextFallbackFontIndex = currFallbackFontIndex + 1; | 628 int nextFallbackFontIndex = currFallbackFontIndex + 1; |
612 | 629 |
613 if(nextFallbackFontIndex >= currentFallbackList->count()) { | 630 if(nextFallbackFontIndex >= currentFallbackList->count()) { |
614 return NULL; | 631 return NULL; |
615 } | 632 } |
616 | 633 |
617 // If a rec object is set to prefer "kDefault_Variant" it means they have no
preference | 634 // If a rec object is set to prefer "kDefault_Variant" it means they have no
preference |
618 // In this case, we set the value to "kCompact_Variant" | 635 // In this case, we set the value to "kCompact_Variant" |
619 SkPaintOptionsAndroid::FontVariant variant = opts.getFontVariant(); | 636 SkPaintOptionsAndroid::FontVariant variant = opts.getFontVariant(); |
620 if (variant == SkPaintOptionsAndroid::kDefault_Variant) { | 637 if (variant == SkPaintOptionsAndroid::kDefault_Variant) { |
621 variant = SkPaintOptionsAndroid::kCompact_Variant; | 638 variant = SkPaintOptionsAndroid::kCompact_Variant; |
622 } | 639 } |
623 | 640 |
624 int32_t acceptedVariants = SkPaintOptionsAndroid::kDefault_Variant | variant
; | 641 int32_t acceptedVariants = SkPaintOptionsAndroid::kDefault_Variant | variant
; |
625 | 642 |
626 SkTypeface* nextLogicalTypeface = 0; | 643 SkTypeface* nextLogicalTypeface = 0; |
627 while (nextFallbackFontIndex < currentFallbackList->count()) { | 644 while (nextFallbackFontIndex < currentFallbackList->count()) { |
628 FontRecID fontRecID = currentFallbackList->getAt(nextFallbackFontIndex); | 645 FamilyRecID familyRecID = currentFallbackList->getAt(nextFallbackFontInd
ex); |
629 if ((fFonts[fontRecID].fPaintOptions.getFontVariant() & acceptedVariants
) != 0) { | 646 if ((fFontFamilies[familyRecID].fPaintOptions.getFontVariant() & accepte
dVariants) != 0) { |
630 nextLogicalTypeface = this->getTypefaceForFontRec(fontRecID); | 647 FontRecID matchedFont = find_best_style(fFontFamilies[familyRecID],
origStyle); |
| 648 nextLogicalTypeface = this->getTypefaceForFontRec(matchedFont); |
631 break; | 649 break; |
632 } | 650 } |
633 nextFallbackFontIndex++; | 651 nextFallbackFontIndex++; |
634 } | 652 } |
635 | 653 |
636 DEBUG_FONT(("---- nextLogicalFont: currFontID=%d, origFontID=%d, currRecID=%
d, " | 654 DEBUG_FONT(("---- nextLogicalFont: currFontID=%d, origFontID=%d, currRecID=%
d, " |
637 "lang=%s, variant=%d, nextFallbackIndex[%d,%d] => nextLogicalTyp
eface=%d", | 655 "lang=%s, variant=%d, nextFallbackIndex[%d,%d] => nextLogicalTyp
eface=%d", |
638 currFontID, origFontID, currFontRecID, opts.getLanguage().getTag
().c_str(), | 656 currFontID, origFontID, currFontRecID, opts.getLanguage().getTag
().c_str(), |
639 variant, nextFallbackFontIndex, currentFallbackList->getAt(nextF
allbackFontIndex), | 657 variant, nextFallbackFontIndex, currentFallbackList->getAt(nextF
allbackFontIndex), |
640 (nextLogicalTypeface) ? nextLogicalTypeface->uniqueID() : 0)); | 658 (nextLogicalTypeface) ? nextLogicalTypeface->uniqueID() : 0)); |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
816 return SkCreateTypefaceForScriptNG(getHBScriptFromHBScriptOld(script), style
, fontVariant); | 834 return SkCreateTypefaceForScriptNG(getHBScriptFromHBScriptOld(script), style
, fontVariant); |
817 } | 835 } |
818 | 836 |
819 #endif | 837 #endif |
820 | 838 |
821 /////////////////////////////////////////////////////////////////////////////// | 839 /////////////////////////////////////////////////////////////////////////////// |
822 | 840 |
823 SkFontMgr* SkFontMgr::Factory() { | 841 SkFontMgr* SkFontMgr::Factory() { |
824 return NULL; | 842 return NULL; |
825 } | 843 } |
OLD | NEW |