skia cmap その2
skia cmap その2
1094 /*************************************************************************/ 1095 /* */ 1096 /* <Function> */ 1097 /* open_face */ 1098 /* */ 1099 /* <Description> */ 1100 /* This function does some work for FT_Open_Face(). */ 1101 /* */ 1102 static FT_Error 1103 open_face( FT_Driver driver, 1104 FT_Stream stream, 1105 FT_Long face_index, 1106 FT_Int num_params, 1107 FT_Parameter* params, 1108 FT_Face *aface ) 1109 { 1110 FT_Memory memory; 1111 FT_Driver_Class clazz; 1112 FT_Face face = 0; 1113 FT_Error error, error2; 1114 FT_Face_Internal internal = NULL; 1115 1116 1117 clazz = driver->clazz; 1118 memory = driver->root.memory; 1119 1120 /* allocate the face object and perform basic initialization */ 1121 if ( FT_ALLOC( face, clazz->face_object_size ) ) 1122 goto Fail; 1123 1124 if ( FT_NEW( internal ) ) 1125 goto Fail; 1126 1127 face->internal = internal; 1128 1129 face->driver = driver; 1130 face->memory = memory; 1131 face->stream = stream; 1132 1133 #ifdef FT_CONFIG_OPTION_INCREMENTAL 1134 { 1135 int i; 1136 1137 1138 face->internal->incremental_interface = 0; 1139 for ( i = 0; i < num_params && !face->internal->incremental_interface; 1140 i++ ) 1141 if ( params[i].tag == FT_PARAM_TAG_INCREMENTAL ) 1142 face->internal->incremental_interface = 1143 (FT_Incremental_Interface)params[i].data; 1144 } 1145 #endif 1146 1147 if ( clazz->init_face ) 1148 error = clazz->init_face( stream, 1149 face, 1150 (FT_Int)face_index, 1151 num_params, 1152 params ); 1153 if ( error ) 1154 goto Fail; 1155 1156 /* select Unicode charmap by default */ 1157 error2 = find_unicode_charmap( face ); <================================================= 1158 1159 /* if no Unicode charmap can be found, FT_Err_Invalid_CharMap_Handle */ 1160 /* is returned. */ 1161 1162 /* no error should happen, but we want to play safe */ 1163 if ( error2 && error2 != FT_Err_Invalid_CharMap_Handle ) 1164 { 1165 error = error2; 1166 goto Fail; 1167 } 1168 1169 *aface = face; 1170 1171 Fail: 1172 if ( error ) 1173 { 1174 destroy_charmaps( face, memory ); 1175 if ( clazz->done_face ) 1176 clazz->done_face( face ); 1177 FT_FREE( internal ); 1178 FT_FREE( face ); 1179 *aface = 0; 1180 } 1181 1182 return error; 1183 } ||< ></blockquote>< ><blockquote cite="http://tools.oesf.biz/android-4.4.2_r1.0/xref/external/chromium_org/third_party/freetype/src/base/ftobjs.c#2991" title="Cross Reference: /external/chromium_org/third_party/freetype/src/base/ftobjs.c">< >|cpp| 2972 FT_EXPORT_DEF( FT_Error ) 2973 FT_Select_Charmap( FT_Face face, 2974 FT_Encoding encoding ) 2975 { 2976 FT_CharMap* cur; 2977 FT_CharMap* limit; 2978 2979 2980 if ( !face ) 2981 return FT_Err_Invalid_Face_Handle; 2982 2983 if ( encoding == FT_ENCODING_NONE ) 2984 return FT_Err_Invalid_Argument; 2985 2986 /* FT_ENCODING_UNICODE is special. We try to find the `best' Unicode */ 2987 /* charmap available, i.e., one with UCS-4 characters, if possible. */ 2988 /* */ 2989 /* This is done by find_unicode_charmap() above, to share code. */ 2990 if ( encoding == FT_ENCODING_UNICODE ) 2991 return find_unicode_charmap( face ); <================================================== 2992 2993 cur = face->charmaps; 2994 if ( !cur ) 2995 return FT_Err_Invalid_CharMap_Handle; 2996 2997 limit = cur + face->num_charmaps; 2998 2999 for ( ; cur < limit; cur++ ) 3000 { 3001 if ( cur[0]->encoding == encoding ) 3002 { 3003 #ifdef FT_MAX_CHARMAP_CACHEABLE 3004 if ( cur - face->charmaps > FT_MAX_CHARMAP_CACHEABLE ) 3005 { 3006 FT_ERROR(( "FT_Select_Charmap: requested charmap is found (%d), " 3007 "but in too late position to cache\n", 3008 cur - face->charmaps )); 3009 continue; 3010 } 3011 #endif 3012 face->charmap = cur[0]; 3013 return 0; 3014 } 3015 } 3016 3017 return FT_Err_Invalid_Argument; 3018 }
UCS4を探してなかったらUCS2を探す
936 /*************************************************************************/ 937 /* */ 938 /* <Function> */ 939 /* find_unicode_charmap */ 940 /* */ 941 /* <Description> */ 942 /* This function finds a Unicode charmap, if there is one. */ 943 /* And if there is more than one, it tries to favour the more */ 944 /* extensive one, i.e., one that supports UCS-4 against those which */ 945 /* are limited to the BMP (said UCS-2 encoding.) */ 946 /* */ 947 /* This function is called from open_face() (just below), and also */ 948 /* from FT_Select_Charmap( ..., FT_ENCODING_UNICODE ). */ 949 /* */ 950 static FT_Error 951 find_unicode_charmap( FT_Face face ) 952 { 953 FT_CharMap* first; 954 FT_CharMap* cur; 955 956 957 /* caller should have already checked that `face' is valid */ 958 FT_ASSERT( face ); 959 960 first = face->charmaps; 961 962 if ( !first ) 963 return FT_Err_Invalid_CharMap_Handle; 964 965 /* 966 * The original TrueType specification(s) only specified charmap 967 * formats that are capable of mapping 8 or 16 bit character codes to 968 * glyph indices. 969 * 970 * However, recent updates to the Apple and OpenType specifications 971 * introduced new formats that are capable of mapping 32-bit character 972 * codes as well. And these are already used on some fonts, mainly to 973 * map non-BMP Asian ideographs as defined in Unicode. 974 * 975 * For compatibility purposes, these fonts generally come with 976 * *several* Unicode charmaps: 977 * 978 * - One of them in the "old" 16-bit format, that cannot access 979 * all glyphs in the font. 980 * 981 * - Another one in the "new" 32-bit format, that can access all 982 * the glyphs. 983 * 984 * This function has been written to always favor a 32-bit charmap 985 * when found. Otherwise, a 16-bit one is returned when found. 986 */ 987 988 /* Since the `interesting' table, with IDs (3,10), is normally the */ 989 /* last one, we loop backwards. This loses with type1 fonts with */ 990 /* non-BMP characters (<.0001%), this wins with .ttf with non-BMP */ 991 /* chars (.01% ?), and this is the same about 99.99% of the time! */ 992 993 cur = first + face->num_charmaps; /* points after the last one */ 994 995 for ( ; --cur >= first; ) 996 { 997 if ( cur[0]->encoding == FT_ENCODING_UNICODE ) 998 { 999 /* XXX If some new encodings to represent UCS-4 are added, */ 1000 /* they should be added here. */ 1001 if ( ( cur[0]->platform_id == TT_PLATFORM_MICROSOFT && 1002 cur[0]->encoding_id == TT_MS_ID_UCS_4 ) || 1003 ( cur[0]->platform_id == TT_PLATFORM_APPLE_UNICODE && 1004 cur[0]->encoding_id == TT_APPLE_ID_UNICODE_32 ) ) 1005 { 1006 #ifdef FT_MAX_CHARMAP_CACHEABLE 1007 if ( cur - first > FT_MAX_CHARMAP_CACHEABLE ) 1008 { 1009 FT_ERROR(( "find_unicode_charmap: UCS-4 cmap is found " 1010 "at too late position (%d)\n", cur - first )); 1011 continue; 1012 } 1013 #endif 1014 face->charmap = cur[0]; 1015 return FT_Err_Ok; 1016 } 1017 } 1018 } 1019 1020 /* We do not have any UCS-4 charmap. */ 1021 /* Do the loop again and search for UCS-2 charmaps. */ 1022 cur = first + face->num_charmaps; 1023 1024 for ( ; --cur >= first; ) 1025 { 1026 if ( cur[0]->encoding == FT_ENCODING_UNICODE ) 1027 { 1028 #ifdef FT_MAX_CHARMAP_CACHEABLE 1029 if ( cur - first > FT_MAX_CHARMAP_CACHEABLE ) 1030 { 1031 FT_ERROR(( "find_unicode_charmap: UCS-2 cmap is found " 1032 "at too late position (%d)\n", cur - first )); 1033 continue; 1034 } 1035 #endif 1036 face->charmap = cur[0]; 1037 return FT_Err_Ok; 1038 } 1039 } 1040 1041 return FT_Err_Invalid_CharMap_Handle; 1042 }