Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: src/ports/SkFontConfigInterface_android.cpp

Issue 24364008: Update PDF backend to support fallback fonts on Android. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: testing more fallbacks Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/pdf/SkPDFDevice.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 * contains the specified chararacter. if no font is found, returns false. 97 * contains the specified chararacter. if no font is found, returns false.
98 */ 98 */
99 bool getFallbackFamilyNameForChar(SkUnichar uni, const char* lang, SkString* name); 99 bool getFallbackFamilyNameForChar(SkUnichar uni, const char* lang, SkString* name);
100 /** 100 /**
101 * 101 *
102 */ 102 */
103 SkTypeface* getTypefaceForChar(SkUnichar uni, SkTypeface::Style style, 103 SkTypeface* getTypefaceForChar(SkUnichar uni, SkTypeface::Style style,
104 SkPaintOptionsAndroid::FontVariant fontVarian t); 104 SkPaintOptionsAndroid::FontVariant fontVarian t);
105 SkTypeface* nextLogicalTypeface(SkFontID currFontID, SkFontID origFontID, 105 SkTypeface* nextLogicalTypeface(SkFontID currFontID, SkFontID origFontID,
106 const SkPaintOptionsAndroid& options); 106 const SkPaintOptionsAndroid& options);
107 SkTypeface* getTypefaceForGlyphID(uint16_t glyphID, const SkTypeface* origTy peface,
108 const SkPaintOptionsAndroid& options,
109 int* lowerBounds, int* upperBounds);
107 110
108 private: 111 private:
109 void addFallbackFamily(FamilyRecID fontRecID); 112 void addFallbackFamily(FamilyRecID fontRecID);
110 SkTypeface* getTypefaceForFontRec(FontRecID fontRecID); 113 SkTypeface* getTypefaceForFontRec(FontRecID fontRecID);
111 FallbackFontList* getCurrentLocaleFallbackFontList(); 114 FallbackFontList* getCurrentLocaleFallbackFontList();
112 FallbackFontList* findFallbackFontList(const SkLanguage& lang, bool isOrigin al = true); 115 FallbackFontList* findFallbackFontList(const SkLanguage& lang, bool isOrigin al = true);
113 116
114 SkTArray<FontRec> fFonts; 117 SkTArray<FontRec> fFonts;
115 SkTArray<FamilyRec> fFontFamilies; 118 SkTArray<FamilyRec> fFontFamilies;
116 SkTDict<FamilyRecID> fFamilyNameDict; 119 SkTDict<FamilyRecID> fFamilyNameDict;
(...skipping 548 matching lines...) Expand 10 before | Expand all | Expand 10 after
665 } 668 }
666 669
667 DEBUG_FONT(("---- nextLogicalFont: currFontID=%d, origFontID=%d, currRecID=% d, " 670 DEBUG_FONT(("---- nextLogicalFont: currFontID=%d, origFontID=%d, currRecID=% d, "
668 "lang=%s, variant=%d, nextFallbackIndex[%d,%d] => nextLogicalTyp eface=%d", 671 "lang=%s, variant=%d, nextFallbackIndex[%d,%d] => nextLogicalTyp eface=%d",
669 currFontID, origFontID, currFontRecID, opts.getLanguage().getTag ().c_str(), 672 currFontID, origFontID, currFontRecID, opts.getLanguage().getTag ().c_str(),
670 variant, nextFallbackFontIndex, currentFallbackList->getAt(nextF allbackFontIndex), 673 variant, nextFallbackFontIndex, currentFallbackList->getAt(nextF allbackFontIndex),
671 (nextLogicalTypeface) ? nextLogicalTypeface->uniqueID() : 0)); 674 (nextLogicalTypeface) ? nextLogicalTypeface->uniqueID() : 0));
672 return SkSafeRef(nextLogicalTypeface); 675 return SkSafeRef(nextLogicalTypeface);
673 } 676 }
674 677
678 SkTypeface* SkFontConfigInterfaceAndroid::getTypefaceForGlyphID(uint16_t glyphID ,
679 const SkTypeface * origTypeface,
680 const SkPaintOpt ionsAndroid& opts,
681 int* lBounds, in t* uBounds) {
682 // If we aren't using fallbacks then we shouldn't be calling this
683 SkASSERT(opts.isUsingFontFallbacks());
684 SkASSERT(origTypeface);
685
686 SkTypeface* currentTypeface = NULL;
687 int lowerBounds = 0; //inclusive
688 int upperBounds = origTypeface->countGlyphs(); //exclusive
689
690 // check to see if the glyph is in the bounds of the origTypeface
691 if (glyphID < upperBounds) {
692 currentTypeface = const_cast<SkTypeface*>(origTypeface);
693 } else {
694 FallbackFontList* currentFallbackList = findFallbackFontList(opts.getLan guage());
695 SkASSERT(currentFallbackList);
696
697 // If an object is set to prefer "kDefault_Variant" it means they have n o preference
698 // In this case, we set the value to "kCompact_Variant"
699 SkPaintOptionsAndroid::FontVariant variant = opts.getFontVariant();
700 if (variant == SkPaintOptionsAndroid::kDefault_Variant) {
701 variant = SkPaintOptionsAndroid::kCompact_Variant;
702 }
703
704 int32_t acceptedVariants = SkPaintOptionsAndroid::kDefault_Variant | var iant;
705 SkTypeface::Style origStyle = origTypeface->style();
706
707 for (int x = 0; x < currentFallbackList->count(); ++x) {
708 const FamilyRecID familyRecID = currentFallbackList->getAt(x);
709 const SkPaintOptionsAndroid& familyOptions = fFontFamilies[familyRec ID].fPaintOptions;
710 if ((familyOptions.getFontVariant() & acceptedVariants) != 0) {
711 FontRecID matchedFont = find_best_style(fFontFamilies[familyRecI D], origStyle);
712 currentTypeface = this->getTypefaceForFontRec(matchedFont);
713 lowerBounds = upperBounds;
714 upperBounds += currentTypeface->countGlyphs();
715 if (glyphID < upperBounds) {
716 break;
717 }
718 }
719 }
720 }
721
722 if (NULL != currentTypeface) {
723 if (lBounds) {
724 *lBounds = lowerBounds;
725 }
726 if (uBounds) {
727 *uBounds = upperBounds;
728 }
729 }
730 return currentTypeface;
731 }
732
675 /////////////////////////////////////////////////////////////////////////////// 733 ///////////////////////////////////////////////////////////////////////////////
676 734
677 bool SkGetFallbackFamilyNameForChar(SkUnichar uni, SkString* name) { 735 bool SkGetFallbackFamilyNameForChar(SkUnichar uni, SkString* name) {
678 SkString locale = SkFontConfigParser::GetLocale(); 736 SkString locale = SkFontConfigParser::GetLocale();
679 SkFontConfigInterfaceAndroid* fontConfig = getSingletonInterface(); 737 SkFontConfigInterfaceAndroid* fontConfig = getSingletonInterface();
680 return fontConfig->getFallbackFamilyNameForChar(uni, locale.c_str(), name); 738 return fontConfig->getFallbackFamilyNameForChar(uni, locale.c_str(), name);
681 } 739 }
682 740
683 bool SkGetFallbackFamilyNameForChar(SkUnichar uni, const char* lang, SkString* n ame) { 741 bool SkGetFallbackFamilyNameForChar(SkUnichar uni, const char* lang, SkString* n ame) {
684 SkFontConfigInterfaceAndroid* fontConfig = getSingletonInterface(); 742 SkFontConfigInterfaceAndroid* fontConfig = getSingletonInterface();
(...skipping 12 matching lines...) Expand all
697 gTestMainConfigFile, gTestFallbackConfigFile, gTestFontFilePrefix) ); 755 gTestMainConfigFile, gTestFallbackConfigFile, gTestFontFilePrefix) );
698 } 756 }
699 757
700 SkTypeface* SkAndroidNextLogicalTypeface(SkFontID currFontID, SkFontID origFontI D, 758 SkTypeface* SkAndroidNextLogicalTypeface(SkFontID currFontID, SkFontID origFontI D,
701 const SkPaintOptionsAndroid& options) { 759 const SkPaintOptionsAndroid& options) {
702 SkFontConfigInterfaceAndroid* fontConfig = getSingletonInterface(); 760 SkFontConfigInterfaceAndroid* fontConfig = getSingletonInterface();
703 return fontConfig->nextLogicalTypeface(currFontID, origFontID, options); 761 return fontConfig->nextLogicalTypeface(currFontID, origFontID, options);
704 762
705 } 763 }
706 764
765 SkTypeface* SkGetTypefaceForGlyphID(uint16_t glyphID, const SkTypeface* origType face,
766 const SkPaintOptionsAndroid& options,
767 int* lowerBounds, int* upperBounds) {
768 SkFontConfigInterfaceAndroid* fontConfig = getSingletonInterface();
769 return fontConfig->getTypefaceForGlyphID(glyphID, origTypeface, options,
770 lowerBounds, upperBounds);
771 }
772
707 /////////////////////////////////////////////////////////////////////////////// 773 ///////////////////////////////////////////////////////////////////////////////
708 774
709 #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK 775 #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
710 776
711 struct HB_UnicodeMapping { 777 struct HB_UnicodeMapping {
712 // TODO: when the WebView no longer needs harfbuzz_old, remove 778 // TODO: when the WebView no longer needs harfbuzz_old, remove
713 HB_Script script_old; 779 HB_Script script_old;
714 hb_script_t script; 780 hb_script_t script;
715 const SkUnichar unicode; 781 const SkUnichar unicode;
716 }; 782 };
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
853 return SkCreateTypefaceForScriptNG(getHBScriptFromHBScriptOld(script), style , fontVariant); 919 return SkCreateTypefaceForScriptNG(getHBScriptFromHBScriptOld(script), style , fontVariant);
854 } 920 }
855 921
856 #endif 922 #endif
857 923
858 /////////////////////////////////////////////////////////////////////////////// 924 ///////////////////////////////////////////////////////////////////////////////
859 925
860 SkFontMgr* SkFontMgr::Factory() { 926 SkFontMgr* SkFontMgr::Factory() {
861 return NULL; 927 return NULL;
862 } 928 }
OLDNEW
« no previous file with comments | « src/pdf/SkPDFDevice.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698