| 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 564 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 575 const char* famName = get_name(match, FC_FAMILY); | 575 const char* famName = get_name(match, FC_FAMILY); |
| 576 if (famName && !find_name(names, famName)) { | 576 if (famName && !find_name(names, famName)) { |
| 577 *names.append() = famName; | 577 *names.append() = famName; |
| 578 *sizes.append() = strlen(famName) + 1; | 578 *sizes.append() = strlen(famName) + 1; |
| 579 } | 579 } |
| 580 } | 580 } |
| 581 | 581 |
| 582 return SkDataTable::NewCopyArrays((const void*const*)names.begin(), | 582 return SkDataTable::NewCopyArrays((const void*const*)names.begin(), |
| 583 sizes.begin(), names.count()); | 583 sizes.begin(), names.count()); |
| 584 } | 584 } |
| 585 | |
| 586 bool SkFontConfigInterfaceDirect::matchFamilySet(const char inFamilyName[], | |
| 587 SkString* outFamilyName, | |
| 588 SkTArray<FontIdentity>* ids) { | |
| 589 SkAutoMutexAcquire ac(mutex_); | |
| 590 | |
| 591 #if 0 | |
| 592 SkString familyStr(familyName ? familyName : ""); | |
| 593 if (familyStr.size() > kMaxFontFamilyLength) { | |
| 594 return false; | |
| 595 } | |
| 596 | |
| 597 SkAutoMutexAcquire ac(mutex_); | |
| 598 | |
| 599 FcPattern* pattern = FcPatternCreate(); | |
| 600 | |
| 601 if (familyName) { | |
| 602 FcPatternAddString(pattern, FC_FAMILY, (FcChar8*)familyName); | |
| 603 } | |
| 604 FcPatternAddBool(pattern, FC_SCALABLE, FcTrue); | |
| 605 | |
| 606 FcConfigSubstitute(nullptr, pattern, FcMatchPattern); | |
| 607 FcDefaultSubstitute(pattern); | |
| 608 | |
| 609 // Font matching: | |
| 610 // CSS often specifies a fallback list of families: | |
| 611 // font-family: a, b, c, serif; | |
| 612 // However, fontconfig will always do its best to find *a* font when asked | |
| 613 // for something so we need a way to tell if the match which it has found is | |
| 614 // "good enough" for us. Otherwise, we can return nullptr which gets piped u
p | |
| 615 // and lets WebKit know to try the next CSS family name. However, fontconfig | |
| 616 // configs allow substitutions (mapping "Arial -> Helvetica" etc) and we | |
| 617 // wish to support that. | |
| 618 // | |
| 619 // Thus, if a specific family is requested we set @family_requested. Then we | |
| 620 // record two strings: the family name after config processing and the | |
| 621 // family name after resolving. If the two are equal, it's a good match. | |
| 622 // | |
| 623 // So consider the case where a user has mapped Arial to Helvetica in their | |
| 624 // config. | |
| 625 // requested family: "Arial" | |
| 626 // post_config_family: "Helvetica" | |
| 627 // post_match_family: "Helvetica" | |
| 628 // -> good match | |
| 629 // | |
| 630 // and for a missing font: | |
| 631 // requested family: "Monaco" | |
| 632 // post_config_family: "Monaco" | |
| 633 // post_match_family: "Times New Roman" | |
| 634 // -> BAD match | |
| 635 // | |
| 636 // However, we special-case fallback fonts; see IsFallbackFontAllowed(). | |
| 637 | |
| 638 const char* post_config_family = get_name(pattern, FC_FAMILY); | |
| 639 | |
| 640 FcResult result; | |
| 641 FcFontSet* font_set = FcFontSort(0, pattern, 0, 0, &result); | |
| 642 if (!font_set) { | |
| 643 FcPatternDestroy(pattern); | |
| 644 return false; | |
| 645 } | |
| 646 | |
| 647 FcPattern* match = this->MatchFont(font_set, post_config_family, familyStr); | |
| 648 if (!match) { | |
| 649 FcPatternDestroy(pattern); | |
| 650 FcFontSetDestroy(font_set); | |
| 651 return false; | |
| 652 } | |
| 653 | |
| 654 FcPatternDestroy(pattern); | |
| 655 | |
| 656 // From here out we just extract our results from 'match' | |
| 657 | |
| 658 if (FcPatternGetString(match, FC_FAMILY, 0, &post_config_family) != FcResult
Match) { | |
| 659 FcFontSetDestroy(font_set); | |
| 660 return false; | |
| 661 } | |
| 662 | |
| 663 FcChar8* c_filename; | |
| 664 if (FcPatternGetString(match, FC_FILE, 0, &c_filename) != FcResultMatch) { | |
| 665 FcFontSetDestroy(font_set); | |
| 666 return false; | |
| 667 } | |
| 668 | |
| 669 int face_index; | |
| 670 if (FcPatternGetInteger(match, FC_INDEX, 0, &face_index) != FcResultMatch) { | |
| 671 FcFontSetDestroy(font_set); | |
| 672 return false; | |
| 673 } | |
| 674 | |
| 675 FcFontSetDestroy(font_set); | |
| 676 | |
| 677 if (outIdentity) { | |
| 678 outIdentity->fTTCIndex = face_index; | |
| 679 outIdentity->fString.set((const char*)c_filename); | |
| 680 } | |
| 681 if (outFamilyName) { | |
| 682 outFamilyName->set((const char*)post_config_family); | |
| 683 } | |
| 684 if (outStyle) { | |
| 685 *outStyle = GetFontStyle(match); | |
| 686 } | |
| 687 return true; | |
| 688 | |
| 689 //////////////////// | |
| 690 | |
| 691 int count; | |
| 692 FcPattern** match = this->MatchFont(font_set, post_config_family, &count
); | |
| 693 if (!match) { | |
| 694 FcPatternDestroy(pattern); | |
| 695 FcFontSetDestroy(font_set); | |
| 696 return nullptr; | |
| 697 } | |
| 698 | |
| 699 FcPatternDestroy(pattern); | |
| 700 | |
| 701 SkTDArray<FcPattern*> trimmedMatches; | |
| 702 for (int i = 0; i < count; ++i) { | |
| 703 const char* justName = find_just_name(get_name(match[i], FC_FILE)); | |
| 704 if (!is_lower(*justName)) { | |
| 705 *trimmedMatches.append() = match[i]; | |
| 706 } | |
| 707 } | |
| 708 | |
| 709 SkFontStyleSet_FC* sset = new SkFontStyleSet_FC
(trimmedMatches.begin(),
trimmedMatches.count()); | |
| 710 #endif | |
| 711 return false; | |
| 712 } | |
| OLD | NEW |