OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2009-2015 Google Inc. | 2 * Copyright 2009-2015 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 /* migrated from chrome/src/skia/ext/SkFontHost_fontconfig_direct.cpp */ | 8 /* migrated from chrome/src/skia/ext/SkFontHost_fontconfig_direct.cpp */ |
9 | 9 |
10 #include "SkBuffer.h" | 10 #include "SkBuffer.h" |
(...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
489 FcPatternAddInteger(pattern, FC_WEIGHT, weight); | 489 FcPatternAddInteger(pattern, FC_WEIGHT, weight); |
490 FcPatternAddInteger(pattern, FC_WIDTH , width); | 490 FcPatternAddInteger(pattern, FC_WIDTH , width); |
491 FcPatternAddInteger(pattern, FC_SLANT , slant); | 491 FcPatternAddInteger(pattern, FC_SLANT , slant); |
492 } | 492 } |
493 | 493 |
494 } // anonymous namespace | 494 } // anonymous namespace |
495 | 495 |
496 /////////////////////////////////////////////////////////////////////////////// | 496 /////////////////////////////////////////////////////////////////////////////// |
497 | 497 |
498 #define kMaxFontFamilyLength 2048 | 498 #define kMaxFontFamilyLength 2048 |
| 499 #ifdef SK_FONT_CONFIG_INTERFACE_ONLY_ALLOW_SFNT_FONTS |
| 500 const char* kFontFormatTrueType = "TrueType"; |
| 501 const char* kFontFormatCFF = "CFF"; |
| 502 #endif |
499 | 503 |
500 SkFontConfigInterfaceDirect::SkFontConfigInterfaceDirect() { | 504 SkFontConfigInterfaceDirect::SkFontConfigInterfaceDirect() { |
501 FCLocker lock; | 505 FCLocker lock; |
502 | 506 |
503 FcInit(); | 507 FcInit(); |
504 | 508 |
505 SkDEBUGCODE(fontconfiginterface_unittest();) | 509 SkDEBUGCODE(fontconfiginterface_unittest();) |
506 } | 510 } |
507 | 511 |
508 SkFontConfigInterfaceDirect::~SkFontConfigInterfaceDirect() { | 512 SkFontConfigInterfaceDirect::~SkFontConfigInterfaceDirect() { |
509 } | 513 } |
510 | 514 |
511 bool SkFontConfigInterfaceDirect::isAccessible(const char* filename) { | 515 bool SkFontConfigInterfaceDirect::isAccessible(const char* filename) { |
512 if (access(filename, R_OK) != 0) { | 516 if (access(filename, R_OK) != 0) { |
513 return false; | 517 return false; |
514 } | 518 } |
515 return true; | 519 return true; |
516 } | 520 } |
517 | 521 |
518 bool SkFontConfigInterfaceDirect::isValidPattern(FcPattern* pattern) { | 522 bool SkFontConfigInterfaceDirect::isValidPattern(FcPattern* pattern) { |
519 #ifdef SK_FONT_CONFIG_ONLY_ALLOW_SCALABLE_FONTS | 523 #ifdef SK_FONT_CONFIG_ONLY_ALLOW_SCALABLE_FONTS |
520 FcBool is_scalable; | 524 FcBool is_scalable; |
521 if (FcPatternGetBool(pattern, FC_SCALABLE, 0, &is_scalable) != FcResultMatch | 525 if (FcPatternGetBool(pattern, FC_SCALABLE, 0, &is_scalable) != FcResultMatch |
522 || !is_scalable) { | 526 || !is_scalable) { |
523 return false; | 527 return false; |
524 } | 528 } |
525 #endif | 529 #endif |
526 | 530 |
| 531 #ifdef SK_FONT_CONFIG_INTERFACE_ONLY_ALLOW_SFNT_FONTS |
| 532 const char* font_format = get_name(pattern, FC_FONTFORMAT); |
| 533 if (font_format |
| 534 && strcmp(font_format, kFontFormatTrueType) != 0 |
| 535 && strcmp(font_format, kFontFormatCFF) != 0) |
| 536 { |
| 537 return false; |
| 538 } |
| 539 #endif |
| 540 |
527 // fontconfig can also return fonts which are unreadable | 541 // fontconfig can also return fonts which are unreadable |
528 const char* c_filename = get_name(pattern, FC_FILE); | 542 const char* c_filename = get_name(pattern, FC_FILE); |
529 if (!c_filename) { | 543 if (!c_filename) { |
530 return false; | 544 return false; |
531 } | 545 } |
532 return this->isAccessible(c_filename); | 546 return this->isAccessible(c_filename); |
533 } | 547 } |
534 | 548 |
535 // Find matching font from |font_set| for the given font family. | 549 // Find matching font from |font_set| for the given font family. |
536 FcPattern* SkFontConfigInterfaceDirect::MatchFont(FcFontSet* font_set, | 550 FcPattern* SkFontConfigInterfaceDirect::MatchFont(FcFontSet* font_set, |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
586 | 600 |
587 FcPattern* pattern = FcPatternCreate(); | 601 FcPattern* pattern = FcPatternCreate(); |
588 | 602 |
589 if (familyName) { | 603 if (familyName) { |
590 FcPatternAddString(pattern, FC_FAMILY, (FcChar8*)familyName); | 604 FcPatternAddString(pattern, FC_FAMILY, (FcChar8*)familyName); |
591 } | 605 } |
592 fcpattern_from_skfontstyle(style, pattern); | 606 fcpattern_from_skfontstyle(style, pattern); |
593 | 607 |
594 FcPatternAddBool(pattern, FC_SCALABLE, FcTrue); | 608 FcPatternAddBool(pattern, FC_SCALABLE, FcTrue); |
595 | 609 |
| 610 #ifdef SK_FONT_CONFIG_INTERFACE_ONLY_ALLOW_SFNT_FONTS |
| 611 FcPatternAddString(pattern, FC_FONTFORMAT, reinterpret_cast<const FcChar8*>(
kFontFormatTrueType)); |
| 612 FcPatternAddString(pattern, FC_FONTFORMAT, reinterpret_cast<const FcChar8*>(
kFontFormatCFF)); |
| 613 #endif |
| 614 |
596 FcConfigSubstitute(nullptr, pattern, FcMatchPattern); | 615 FcConfigSubstitute(nullptr, pattern, FcMatchPattern); |
597 FcDefaultSubstitute(pattern); | 616 FcDefaultSubstitute(pattern); |
598 | 617 |
599 // Font matching: | 618 // Font matching: |
600 // CSS often specifies a fallback list of families: | 619 // CSS often specifies a fallback list of families: |
601 // font-family: a, b, c, serif; | 620 // font-family: a, b, c, serif; |
602 // However, fontconfig will always do its best to find *a* font when asked | 621 // However, fontconfig will always do its best to find *a* font when asked |
603 // for something so we need a way to tell if the match which it has found is | 622 // for something so we need a way to tell if the match which it has found is |
604 // "good enough" for us. Otherwise, we can return nullptr which gets piped u
p | 623 // "good enough" for us. Otherwise, we can return nullptr which gets piped u
p |
605 // and lets WebKit know to try the next CSS family name. However, fontconfig | 624 // and lets WebKit know to try the next CSS family name. However, fontconfig |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
726 const char* famName = get_name(match, FC_FAMILY); | 745 const char* famName = get_name(match, FC_FAMILY); |
727 if (famName && !find_name(names, famName)) { | 746 if (famName && !find_name(names, famName)) { |
728 *names.append() = famName; | 747 *names.append() = famName; |
729 *sizes.append() = strlen(famName) + 1; | 748 *sizes.append() = strlen(famName) + 1; |
730 } | 749 } |
731 } | 750 } |
732 | 751 |
733 return SkDataTable::MakeCopyArrays((const void*const*)names.begin(), | 752 return SkDataTable::MakeCopyArrays((const void*const*)names.begin(), |
734 sizes.begin(), names.count()); | 753 sizes.begin(), names.count()); |
735 } | 754 } |
OLD | NEW |