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 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 * contains the specified chararacter. if no font is found, returns false. | 96 * contains the specified chararacter. if no font is found, returns false. |
97 */ | 97 */ |
98 bool getFallbackFamilyNameForChar(SkUnichar uni, const char* lang, SkString*
name); | 98 bool getFallbackFamilyNameForChar(SkUnichar uni, const char* lang, 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 SkTypeface* getTypefaceForGlyphID(uint16_t glyphID, const SkTypeface* origTy
peface, |
| 107 const SkPaintOptionsAndroid& options, |
| 108 int* lowerBounds, int* upperBounds); |
106 | 109 |
107 private: | 110 private: |
108 void addFallbackFamily(FamilyRecID fontRecID); | 111 void addFallbackFamily(FamilyRecID fontRecID); |
109 SkTypeface* getTypefaceForFontRec(FontRecID fontRecID); | 112 SkTypeface* getTypefaceForFontRec(FontRecID fontRecID); |
110 FallbackFontList* getCurrentLocaleFallbackFontList(); | 113 FallbackFontList* getCurrentLocaleFallbackFontList(); |
111 FallbackFontList* findFallbackFontList(const SkLanguage& lang, bool isOrigin
al = true); | 114 FallbackFontList* findFallbackFontList(const SkLanguage& lang, bool isOrigin
al = true); |
112 | 115 |
113 SkTArray<FontRec> fFonts; | 116 SkTArray<FontRec> fFonts; |
114 SkTArray<FamilyRec> fFontFamilies; | 117 SkTArray<FamilyRec> fFontFamilies; |
115 SkTDict<FamilyRecID> fFamilyNameDict; | 118 SkTDict<FamilyRecID> fFamilyNameDict; |
(...skipping 547 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
663 } | 666 } |
664 | 667 |
665 DEBUG_FONT(("---- nextLogicalFont: currFontID=%d, origFontID=%d, currRecID=%
d, " | 668 DEBUG_FONT(("---- nextLogicalFont: currFontID=%d, origFontID=%d, currRecID=%
d, " |
666 "lang=%s, variant=%d, nextFallbackIndex[%d,%d] => nextLogicalTyp
eface=%d", | 669 "lang=%s, variant=%d, nextFallbackIndex[%d,%d] => nextLogicalTyp
eface=%d", |
667 currFontID, origFontID, currFontRecID, opts.getLanguage().getTag
().c_str(), | 670 currFontID, origFontID, currFontRecID, opts.getLanguage().getTag
().c_str(), |
668 variant, nextFallbackFontIndex, currentFallbackList->getAt(nextF
allbackFontIndex), | 671 variant, nextFallbackFontIndex, currentFallbackList->getAt(nextF
allbackFontIndex), |
669 (nextLogicalTypeface) ? nextLogicalTypeface->uniqueID() : 0)); | 672 (nextLogicalTypeface) ? nextLogicalTypeface->uniqueID() : 0)); |
670 return SkSafeRef(nextLogicalTypeface); | 673 return SkSafeRef(nextLogicalTypeface); |
671 } | 674 } |
672 | 675 |
| 676 SkTypeface* SkFontConfigInterfaceAndroid::getTypefaceForGlyphID(uint16_t glyphID
, |
| 677 const SkTypeface
* origTypeface, |
| 678 const SkPaintOpt
ionsAndroid& opts, |
| 679 int* lBounds, in
t* uBounds) { |
| 680 // Skia does not support font fallback by default. This enables clients such |
| 681 // as WebKit to customize their font selection. In any case, clients can use |
| 682 // GetFallbackFamilyNameForChar() to get the fallback font for individual |
| 683 // characters. |
| 684 if (!opts.isUsingFontFallbacks()) { |
| 685 return NULL; |
| 686 } |
| 687 |
| 688 SkTypeface* currentTypeface = NULL; |
| 689 int lowerBounds = 0; //inclusive |
| 690 int upperBounds = origTypeface->countGlyphs(); //exclusive |
| 691 |
| 692 // check to see if the glyph is in the bounds of the origTypeface |
| 693 if (glyphID < upperBounds) { |
| 694 currentTypeface = const_cast<SkTypeface*>(origTypeface); |
| 695 } else { |
| 696 FallbackFontList* currentFallbackList = findFallbackFontList(opts.getLan
guage()); |
| 697 SkASSERT(currentFallbackList); |
| 698 |
| 699 // If an object is set to prefer "kDefault_Variant" it means they have n
o preference |
| 700 // In this case, we set the value to "kCompact_Variant" |
| 701 SkPaintOptionsAndroid::FontVariant variant = opts.getFontVariant(); |
| 702 if (variant == SkPaintOptionsAndroid::kDefault_Variant) { |
| 703 variant = SkPaintOptionsAndroid::kCompact_Variant; |
| 704 } |
| 705 |
| 706 int32_t acceptedVariants = SkPaintOptionsAndroid::kDefault_Variant | var
iant; |
| 707 SkTypeface::Style origStyle = origTypeface->style(); |
| 708 |
| 709 for (int x = 0; x < currentFallbackList->count(); ++x) { |
| 710 FamilyRecID familyRecID = currentFallbackList->getAt(x); |
| 711 if ((fFontFamilies[familyRecID].fPaintOptions.getFontVariant() & acc
eptedVariants) != 0) { |
| 712 FontRecID matchedFont = find_best_style(fFontFamilies[familyRecI
D], origStyle); |
| 713 currentTypeface = this->getTypefaceForFontRec(matchedFont); |
| 714 lowerBounds = upperBounds; |
| 715 upperBounds += currentTypeface->countGlyphs(); |
| 716 if (glyphID < upperBounds) { |
| 717 break; |
| 718 } |
| 719 } |
| 720 } |
| 721 } |
| 722 |
| 723 if (currentTypeface) { |
| 724 if (lBounds) { |
| 725 *lBounds = lowerBounds; |
| 726 } |
| 727 if (uBounds) { |
| 728 *uBounds = upperBounds; |
| 729 } |
| 730 } |
| 731 return SkSafeRef(currentTypeface); |
| 732 } |
| 733 |
673 /////////////////////////////////////////////////////////////////////////////// | 734 /////////////////////////////////////////////////////////////////////////////// |
674 | 735 |
675 bool SkGetFallbackFamilyNameForChar(SkUnichar uni, SkString* name) { | 736 bool SkGetFallbackFamilyNameForChar(SkUnichar uni, SkString* name) { |
676 SkString locale = SkFontConfigParser::GetLocale(); | 737 SkString locale = SkFontConfigParser::GetLocale(); |
677 SkFontConfigInterfaceAndroid* fontConfig = getSingletonInterface(); | 738 SkFontConfigInterfaceAndroid* fontConfig = getSingletonInterface(); |
678 return fontConfig->getFallbackFamilyNameForChar(uni, locale.c_str(), name); | 739 return fontConfig->getFallbackFamilyNameForChar(uni, locale.c_str(), name); |
679 } | 740 } |
680 | 741 |
681 bool SkGetFallbackFamilyNameForChar(SkUnichar uni, const char* lang, SkString* n
ame) { | 742 bool SkGetFallbackFamilyNameForChar(SkUnichar uni, const char* lang, SkString* n
ame) { |
682 SkFontConfigInterfaceAndroid* fontConfig = getSingletonInterface(); | 743 SkFontConfigInterfaceAndroid* fontConfig = getSingletonInterface(); |
(...skipping 12 matching lines...) Expand all Loading... |
695 gTestMainConfigFile, gTestFallbackConfigFile, gTestFontFilePrefix)
); | 756 gTestMainConfigFile, gTestFallbackConfigFile, gTestFontFilePrefix)
); |
696 } | 757 } |
697 | 758 |
698 SkTypeface* SkAndroidNextLogicalTypeface(SkFontID currFontID, SkFontID origFontI
D, | 759 SkTypeface* SkAndroidNextLogicalTypeface(SkFontID currFontID, SkFontID origFontI
D, |
699 const SkPaintOptionsAndroid& options) { | 760 const SkPaintOptionsAndroid& options) { |
700 SkFontConfigInterfaceAndroid* fontConfig = getSingletonInterface(); | 761 SkFontConfigInterfaceAndroid* fontConfig = getSingletonInterface(); |
701 return fontConfig->nextLogicalTypeface(currFontID, origFontID, options); | 762 return fontConfig->nextLogicalTypeface(currFontID, origFontID, options); |
702 | 763 |
703 } | 764 } |
704 | 765 |
| 766 SkTypeface* SkGetTypefaceForGlyphID(uint16_t glyphID, const SkTypeface* origType
face, |
| 767 const SkPaintOptionsAndroid& options, |
| 768 int* lowerBounds, int* upperBounds) { |
| 769 SkFontConfigInterfaceAndroid* fontConfig = getSingletonInterface(); |
| 770 return fontConfig->getTypefaceForGlyphID(glyphID, origTypeface, options, |
| 771 lowerBounds, upperBounds); |
| 772 } |
| 773 |
705 /////////////////////////////////////////////////////////////////////////////// | 774 /////////////////////////////////////////////////////////////////////////////// |
706 | 775 |
707 #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK | 776 #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK |
708 | 777 |
709 struct HB_UnicodeMapping { | 778 struct HB_UnicodeMapping { |
710 // TODO: when the WebView no longer needs harfbuzz_old, remove | 779 // TODO: when the WebView no longer needs harfbuzz_old, remove |
711 HB_Script script_old; | 780 HB_Script script_old; |
712 hb_script_t script; | 781 hb_script_t script; |
713 const SkUnichar unicode; | 782 const SkUnichar unicode; |
714 }; | 783 }; |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
851 return SkCreateTypefaceForScriptNG(getHBScriptFromHBScriptOld(script), style
, fontVariant); | 920 return SkCreateTypefaceForScriptNG(getHBScriptFromHBScriptOld(script), style
, fontVariant); |
852 } | 921 } |
853 | 922 |
854 #endif | 923 #endif |
855 | 924 |
856 /////////////////////////////////////////////////////////////////////////////// | 925 /////////////////////////////////////////////////////////////////////////////// |
857 | 926 |
858 SkFontMgr* SkFontMgr::Factory() { | 927 SkFontMgr* SkFontMgr::Factory() { |
859 return NULL; | 928 return NULL; |
860 } | 929 } |
OLD | NEW |