OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SkTypes.h" | 8 #include "SkTypes.h" |
9 | 9 |
10 #include "SkData.h" | 10 #include "SkData.h" |
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
357 for (int i = 0; i < fFontStyleSets.count(); ++i) { | 357 for (int i = 0; i < fFontStyleSets.count(); ++i) { |
358 for (int j = 0; j < fFontStyleSets[i]->fStyles.count(); ++j) { | 358 for (int j = 0; j < fFontStyleSets[i]->fStyles.count(); ++j) { |
359 if (fFontStyleSets[i]->fStyles[j] == typeface) { | 359 if (fFontStyleSets[i]->fStyles[j] == typeface) { |
360 return fFontStyleSets[i]->matchStyle(style); | 360 return fFontStyleSets[i]->matchStyle(style); |
361 } | 361 } |
362 } | 362 } |
363 } | 363 } |
364 return nullptr; | 364 return nullptr; |
365 } | 365 } |
366 | 366 |
367 static SkTypeface_AndroidSystem* find_family_style_character( | 367 static sk_sp<SkTypeface_AndroidSystem> find_family_style_character( |
368 const SkTDArray<NameToFamily>& fallbackNameToFamilyMap, | 368 const SkTDArray<NameToFamily>& fallbackNameToFamilyMap, |
369 const SkFontStyle& style, bool elegant, | 369 const SkFontStyle& style, bool elegant, |
370 const SkString& langTag, SkUnichar character) | 370 const SkString& langTag, SkUnichar character) |
371 { | 371 { |
372 for (int i = 0; i < fallbackNameToFamilyMap.count(); ++i) { | 372 for (int i = 0; i < fallbackNameToFamilyMap.count(); ++i) { |
373 SkFontStyleSet_Android* family = fallbackNameToFamilyMap[i].styleSet
; | 373 SkFontStyleSet_Android* family = fallbackNameToFamilyMap[i].styleSet
; |
374 SkAutoTUnref<SkTypeface_AndroidSystem> face(family->matchStyle(style
)); | 374 sk_sp<SkTypeface_AndroidSystem> face(family->matchStyle(style)); |
375 | 375 |
376 if (!langTag.isEmpty() && !face->fLang.getTag().startsWith(langTag.c
_str())) { | 376 if (!langTag.isEmpty() && !face->fLang.getTag().startsWith(langTag.c
_str())) { |
377 continue; | 377 continue; |
378 } | 378 } |
379 | 379 |
380 if (SkToBool(face->fVariantStyle & kElegant_FontVariant) != elegant)
{ | 380 if (SkToBool(face->fVariantStyle & kElegant_FontVariant) != elegant)
{ |
381 continue; | 381 continue; |
382 } | 382 } |
383 | 383 |
384 SkPaint paint; | 384 SkPaint paint; |
385 paint.setTypeface(face); | 385 paint.setTypeface(face); |
386 paint.setTextEncoding(SkPaint::kUTF32_TextEncoding); | 386 paint.setTextEncoding(SkPaint::kUTF32_TextEncoding); |
387 | 387 |
388 uint16_t glyphID; | 388 uint16_t glyphID; |
389 paint.textToGlyphs(&character, sizeof(character), &glyphID); | 389 paint.textToGlyphs(&character, sizeof(character), &glyphID); |
390 if (glyphID != 0) { | 390 if (glyphID != 0) { |
391 return face.release(); | 391 return face; |
392 } | 392 } |
393 } | 393 } |
394 return nullptr; | 394 return nullptr; |
395 } | 395 } |
396 | 396 |
397 virtual SkTypeface* onMatchFamilyStyleCharacter(const char familyName[], | 397 virtual SkTypeface* onMatchFamilyStyleCharacter(const char familyName[], |
398 const SkFontStyle& style, | 398 const SkFontStyle& style, |
399 const char* bcp47[], | 399 const char* bcp47[], |
400 int bcp47Count, | 400 int bcp47Count, |
401 SkUnichar character) const o
verride | 401 SkUnichar character) const o
verride |
402 { | 402 { |
403 // The variant 'elegant' is 'not squashed', 'compact' is 'stays in ascen
t/descent'. | 403 // The variant 'elegant' is 'not squashed', 'compact' is 'stays in ascen
t/descent'. |
404 // The variant 'default' means 'compact and elegant'. | 404 // The variant 'default' means 'compact and elegant'. |
405 // As a result, it is not possible to know the variant context from the
font alone. | 405 // As a result, it is not possible to know the variant context from the
font alone. |
406 // TODO: add 'is_elegant' and 'is_compact' bits to 'style' request. | 406 // TODO: add 'is_elegant' and 'is_compact' bits to 'style' request. |
407 | 407 |
408 // The first time match anything elegant, second time anything not elega
nt. | 408 // The first time match anything elegant, second time anything not elega
nt. |
409 for (int elegant = 2; elegant --> 0;) { | 409 for (int elegant = 2; elegant --> 0;) { |
410 for (int bcp47Index = bcp47Count; bcp47Index --> 0;) { | 410 for (int bcp47Index = bcp47Count; bcp47Index --> 0;) { |
411 SkLanguage lang(bcp47[bcp47Index]); | 411 SkLanguage lang(bcp47[bcp47Index]); |
412 while (!lang.getTag().isEmpty()) { | 412 while (!lang.getTag().isEmpty()) { |
413 SkTypeface_AndroidSystem* matchingTypeface = | 413 sk_sp<SkTypeface_AndroidSystem> matchingTypeface = |
414 find_family_style_character(fFallbackNameToFamilyMap, | 414 find_family_style_character(fFallbackNameToFamilyMap, |
415 style, SkToBool(elegant), | 415 style, SkToBool(elegant), |
416 lang.getTag(), character); | 416 lang.getTag(), character); |
417 if (matchingTypeface) { | 417 if (matchingTypeface) { |
418 return matchingTypeface; | 418 return matchingTypeface.release(); |
419 } | 419 } |
420 | 420 |
421 lang = lang.getParent(); | 421 lang = lang.getParent(); |
422 } | 422 } |
423 } | 423 } |
424 SkTypeface_AndroidSystem* matchingTypeface = | 424 sk_sp<SkTypeface_AndroidSystem> matchingTypeface = |
425 find_family_style_character(fFallbackNameToFamilyMap, | 425 find_family_style_character(fFallbackNameToFamilyMap, |
426 style, SkToBool(elegant), | 426 style, SkToBool(elegant), |
427 SkString(), character); | 427 SkString(), character); |
428 if (matchingTypeface) { | 428 if (matchingTypeface) { |
429 return matchingTypeface; | 429 return matchingTypeface.release(); |
430 } | 430 } |
431 } | 431 } |
432 return nullptr; | 432 return nullptr; |
433 } | 433 } |
434 | 434 |
435 SkTypeface* onCreateFromData(SkData* data, int ttcIndex) const override { | 435 SkTypeface* onCreateFromData(SkData* data, int ttcIndex) const override { |
436 return this->createFromStream(new SkMemoryStream(data), ttcIndex); | 436 return this->createFromStream(new SkMemoryStream(data), ttcIndex); |
437 } | 437 } |
438 | 438 |
439 SkTypeface* onCreateFromFile(const char path[], int ttcIndex) const override
{ | 439 SkTypeface* onCreateFromFile(const char path[], int ttcIndex) const override
{ |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
578 SkASSERT(custom->fSystemFontUse < SK_ARRAY_COUNT(gSystemFontUseStrings))
; | 578 SkASSERT(custom->fSystemFontUse < SK_ARRAY_COUNT(gSystemFontUseStrings))
; |
579 SkDEBUGF(("SystemFontUse: %s BasePath: %s Fonts: %s FallbackFonts: %s\n"
, | 579 SkDEBUGF(("SystemFontUse: %s BasePath: %s Fonts: %s FallbackFonts: %s\n"
, |
580 gSystemFontUseStrings[custom->fSystemFontUse], | 580 gSystemFontUseStrings[custom->fSystemFontUse], |
581 custom->fBasePath, | 581 custom->fBasePath, |
582 custom->fFontsXml, | 582 custom->fFontsXml, |
583 custom->fFallbackFontsXml)); | 583 custom->fFallbackFontsXml)); |
584 } | 584 } |
585 | 585 |
586 return new SkFontMgr_Android(custom); | 586 return new SkFontMgr_Android(custom); |
587 } | 587 } |
OLD | NEW |