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 756 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
767 | 767 |
768 } | 768 } |
769 | 769 |
770 SkTypeface* SkGetTypefaceForGlyphID(uint16_t glyphID, const SkTypeface* origType
face, | 770 SkTypeface* SkGetTypefaceForGlyphID(uint16_t glyphID, const SkTypeface* origType
face, |
771 const SkPaintOptionsAndroid& options, | 771 const SkPaintOptionsAndroid& options, |
772 int* lowerBounds, int* upperBounds) { | 772 int* lowerBounds, int* upperBounds) { |
773 SkFontConfigInterfaceAndroid* fontConfig = getSingletonInterface(); | 773 SkFontConfigInterfaceAndroid* fontConfig = getSingletonInterface(); |
774 return fontConfig->getTypefaceForGlyphID(glyphID, origTypeface, options, | 774 return fontConfig->getTypefaceForGlyphID(glyphID, origTypeface, options, |
775 lowerBounds, upperBounds); | 775 lowerBounds, upperBounds); |
776 } | 776 } |
777 | |
778 /////////////////////////////////////////////////////////////////////////////// | |
779 | |
780 #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK | |
781 | |
782 struct HB_UnicodeMapping { | |
783 hb_script_t script; | |
784 const SkUnichar unicode; | |
785 }; | |
786 | |
787 /* | |
788 * The following scripts are not complex fonts and we do not expect them to be p
arsed by this table | |
789 * HB_SCRIPT_COMMON, | |
790 * HB_SCRIPT_GREEK, | |
791 * HB_SCRIPT_CYRILLIC, | |
792 * HB_SCRIPT_HANGUL | |
793 * HB_SCRIPT_INHERITED | |
794 */ | |
795 | |
796 /* Harfbuzz (old) is missing a number of scripts in its table. For these, | |
797 * we include a value which can never happen. We won't get complex script | |
798 * shaping in these cases, but the library wouldn't know how to shape | |
799 * them anyway. */ | |
800 #define HB_Script_Unknown HB_ScriptCount | |
801 | |
802 static HB_UnicodeMapping HB_UnicodeMappingArray[] = { | |
803 {HB_SCRIPT_ARMENIAN, 0x0531}, | |
804 {HB_SCRIPT_HEBREW, 0x0591}, | |
805 {HB_SCRIPT_ARABIC, 0x0600}, | |
806 {HB_SCRIPT_SYRIAC, 0x0710}, | |
807 {HB_SCRIPT_THAANA, 0x0780}, | |
808 {HB_SCRIPT_NKO, 0x07C0}, | |
809 {HB_SCRIPT_DEVANAGARI, 0x0901}, | |
810 {HB_SCRIPT_BENGALI, 0x0981}, | |
811 {HB_SCRIPT_GURMUKHI, 0x0A10}, | |
812 {HB_SCRIPT_GUJARATI, 0x0A90}, | |
813 {HB_SCRIPT_ORIYA, 0x0B10}, | |
814 {HB_SCRIPT_TAMIL, 0x0B82}, | |
815 {HB_SCRIPT_TELUGU, 0x0C10}, | |
816 {HB_SCRIPT_KANNADA, 0x0C90}, | |
817 {HB_SCRIPT_MALAYALAM, 0x0D10}, | |
818 {HB_SCRIPT_SINHALA, 0x0D90}, | |
819 {HB_SCRIPT_THAI, 0x0E01}, | |
820 {HB_SCRIPT_LAO, 0x0E81}, | |
821 {HB_SCRIPT_TIBETAN, 0x0F00}, | |
822 {HB_SCRIPT_MYANMAR, 0x1000}, | |
823 {HB_SCRIPT_GEORGIAN, 0x10A0}, | |
824 {HB_SCRIPT_ETHIOPIC, 0x1200}, | |
825 {HB_SCRIPT_CHEROKEE, 0x13A0}, | |
826 {HB_SCRIPT_OGHAM, 0x1680}, | |
827 {HB_SCRIPT_RUNIC, 0x16A0}, | |
828 {HB_SCRIPT_KHMER, 0x1780}, | |
829 {HB_SCRIPT_TAI_LE, 0x1950}, | |
830 {HB_SCRIPT_NEW_TAI_LUE, 0x1980}, | |
831 {HB_SCRIPT_TAI_THAM, 0x1A20}, | |
832 {HB_SCRIPT_CHAM, 0xAA00}, | |
833 }; | |
834 | |
835 // returns 0 for "Not Found" | |
836 static SkUnichar getUnicodeFromHBScript(hb_script_t script) { | |
837 SkUnichar unichar = 0; | |
838 int numSupportedFonts = sizeof(HB_UnicodeMappingArray) / sizeof(HB_UnicodeMa
pping); | |
839 for (int i = 0; i < numSupportedFonts; i++) { | |
840 if (script == HB_UnicodeMappingArray[i].script) { | |
841 unichar = HB_UnicodeMappingArray[i].unicode; | |
842 break; | |
843 } | |
844 } | |
845 return unichar; | |
846 } | |
847 | |
848 struct TypefaceLookupStruct { | |
849 hb_script_t script; | |
850 SkTypeface::Style style; | |
851 SkPaintOptionsAndroid::FontVariant fontVariant; | |
852 SkTypeface* typeface; | |
853 }; | |
854 | |
855 SK_DECLARE_STATIC_MUTEX(gTypefaceTableMutex); // This is the mutex for gTypefac
eTable | |
856 static SkTDArray<TypefaceLookupStruct> gTypefaceTable; // This is protected by
gTypefaceTableMutex | |
857 | |
858 static int typefaceLookupCompare(const TypefaceLookupStruct& first, | |
859 const TypefaceLookupStruct& second) { | |
860 if (first.script != second.script) { | |
861 return (first.script > second.script) ? 1 : -1; | |
862 } | |
863 if (first.style != second.style) { | |
864 return (first.style > second.style) ? 1 : -1; | |
865 } | |
866 if (first.fontVariant != second.fontVariant) { | |
867 return (first.fontVariant > second.fontVariant) ? 1 : -1; | |
868 } | |
869 return 0; | |
870 } | |
871 | |
872 SkTypeface* SkCreateTypefaceForScript(hb_script_t script, SkTypeface::Style styl
e, | |
873 SkPaintOptionsAndroid::FontVariant fontVar
iant) { | |
874 SkAutoMutexAcquire ac(gTypefaceTableMutex); | |
875 | |
876 TypefaceLookupStruct key; | |
877 key.script = script; | |
878 key.style = style; | |
879 key.fontVariant = fontVariant; | |
880 | |
881 int index = SkTSearch<TypefaceLookupStruct>( | |
882 (const TypefaceLookupStruct*) gTypefaceTable.begin(), | |
883 gTypefaceTable.count(), key, sizeof(TypefaceLookupStruct), | |
884 typefaceLookupCompare); | |
885 | |
886 SkTypeface* retTypeface = NULL; | |
887 if (index >= 0) { | |
888 retTypeface = gTypefaceTable[index].typeface; | |
889 } | |
890 else { | |
891 SkUnichar unichar = getUnicodeFromHBScript(script); | |
892 if (!unichar) { | |
893 return NULL; | |
894 } | |
895 | |
896 SkFontConfigInterfaceAndroid* fontConfig = getSingletonInterface(); | |
897 retTypeface = fontConfig->getTypefaceForChar(unichar, style, fontVariant
); | |
898 | |
899 // add to the lookup table | |
900 key.typeface = retTypeface; | |
901 *gTypefaceTable.insert(~index) = key; | |
902 } | |
903 | |
904 // we ref(), the caller is expected to unref when they are done | |
905 return SkSafeRef(retTypeface); | |
906 } | |
907 | |
908 #endif | |
909 | |
OLD | NEW |