1 /***************************************************************************/ |
1 /**************************************************************************** |
2 /* */ |
2 * |
3 /* sfdriver.c */ |
3 * sfdriver.c |
4 /* */ |
4 * |
5 /* High-level SFNT driver interface (body). */ |
5 * High-level SFNT driver interface (body). |
6 /* */ |
6 * |
7 /* Copyright 1996-2018 by */ |
7 * Copyright (C) 1996-2019 by |
8 /* David Turner, Robert Wilhelm, and Werner Lemberg. */ |
8 * David Turner, Robert Wilhelm, and Werner Lemberg. |
9 /* */ |
9 * |
10 /* This file is part of the FreeType project, and may only be used, */ |
10 * This file is part of the FreeType project, and may only be used, |
11 /* modified, and distributed under the terms of the FreeType project */ |
11 * modified, and distributed under the terms of the FreeType project |
12 /* license, LICENSE.TXT. By continuing to use, modify, or distribute */ |
12 * license, LICENSE.TXT. By continuing to use, modify, or distribute |
13 /* this file you indicate that you have read the license and */ |
13 * this file you indicate that you have read the license and |
14 /* understand and accept it fully. */ |
14 * understand and accept it fully. |
15 /* */ |
15 * |
16 /***************************************************************************/ |
16 */ |
17 |
17 |
18 |
18 |
19 #include <ft2build.h> |
19 #include <ft2build.h> |
20 #include FT_INTERNAL_DEBUG_H |
20 #include FT_INTERNAL_DEBUG_H |
21 #include FT_INTERNAL_SFNT_H |
21 #include FT_INTERNAL_SFNT_H |
489 if ( FT_ALLOC( result, entry->stringLength / 2 + 1 ) ) |
491 if ( FT_ALLOC( result, entry->stringLength / 2 + 1 ) ) |
490 return NULL; |
492 return NULL; |
491 |
493 |
492 if ( FT_STREAM_SEEK( entry->stringOffset ) || |
494 if ( FT_STREAM_SEEK( entry->stringOffset ) || |
493 FT_FRAME_ENTER( entry->stringLength ) ) |
495 FT_FRAME_ENTER( entry->stringLength ) ) |
494 { |
496 goto get_win_string_error; |
495 FT_FREE( result ); |
|
496 entry->stringLength = 0; |
|
497 entry->stringOffset = 0; |
|
498 FT_FREE( entry->string ); |
|
499 |
|
500 return NULL; |
|
501 } |
|
502 |
497 |
503 r = (FT_String*)result; |
498 r = (FT_String*)result; |
504 p = (FT_Char*)stream->cursor; |
499 p = (FT_Char*)stream->cursor; |
505 |
500 |
506 for ( len = entry->stringLength / 2; len > 0; len--, p += 2 ) |
501 for ( len = entry->stringLength / 2; len > 0; len--, p += 2 ) |
507 { |
502 { |
508 if ( p[0] == 0 ) |
503 if ( p[0] == 0 && char_type( p[1] ) ) |
|
504 *r++ = p[1]; |
|
505 else |
509 { |
506 { |
510 if ( char_type( p[1] ) ) |
507 if ( report_invalid_characters ) |
511 *r++ = p[1]; |
508 FT_TRACE0(( "get_win_string:" |
512 else |
509 " Character 0x%X invalid in PS name string\n", |
513 { |
510 ((unsigned)p[0])*256 + (unsigned)p[1] )); |
514 if ( report_invalid_characters ) |
511 break; |
515 { |
|
516 FT_TRACE0(( "get_win_string:" |
|
517 " Character `%c' (0x%X) invalid in PS name string\n", |
|
518 p[1], p[1] )); |
|
519 /* it's not the job of FreeType to correct PS names... */ |
|
520 *r++ = p[1]; |
|
521 } |
|
522 } |
|
523 } |
512 } |
524 } |
513 } |
525 *r = '\0'; |
514 if ( !len ) |
|
515 *r = '\0'; |
526 |
516 |
527 FT_FRAME_EXIT(); |
517 FT_FRAME_EXIT(); |
528 |
518 |
529 return result; |
519 if ( !len ) |
|
520 return result; |
|
521 |
|
522 get_win_string_error: |
|
523 FT_FREE( result ); |
|
524 |
|
525 entry->stringLength = 0; |
|
526 entry->stringOffset = 0; |
|
527 FT_FREE( entry->string ); |
|
528 |
|
529 return NULL; |
530 } |
530 } |
531 |
531 |
532 |
532 |
533 static char* |
533 static char* |
534 get_apple_string( FT_Memory memory, |
534 get_apple_string( FT_Memory memory, |
826 result = get_win_string( face->root.memory, |
827 result = get_win_string( face->root.memory, |
827 face->name_table.stream, |
828 face->name_table.stream, |
828 face->name_table.names + win, |
829 face->name_table.names + win, |
829 sfnt_is_alphanumeric, |
830 sfnt_is_alphanumeric, |
830 0 ); |
831 0 ); |
831 else |
832 if ( !result && apple != -1 ) |
832 result = get_apple_string( face->root.memory, |
833 result = get_apple_string( face->root.memory, |
833 face->name_table.stream, |
834 face->name_table.stream, |
834 face->name_table.names + apple, |
835 face->name_table.names + apple, |
835 sfnt_is_alphanumeric, |
836 sfnt_is_alphanumeric, |
836 0 ); |
837 0 ); |
|
838 |
|
839 if ( !result ) |
|
840 { |
|
841 FT_TRACE0(( "sfnt_get_var_ps_name:" |
|
842 " No valid PS name prefix for font instances found\n" )); |
|
843 return NULL; |
|
844 } |
837 |
845 |
838 len = ft_strlen( result ); |
846 len = ft_strlen( result ); |
839 |
847 |
840 /* sanitize if necessary; we reserve space for 36 bytes (a 128bit */ |
848 /* sanitize if necessary; we reserve space for 36 bytes (a 128bit */ |
841 /* checksum as a hex number, preceded by `-' and followed by three */ |
849 /* checksum as a hex number, preceded by `-' and followed by three */ |
1130 |
1138 |
1131 #endif /* TT_CONFIG_OPTION_BDF */ |
1139 #endif /* TT_CONFIG_OPTION_BDF */ |
1132 |
1140 |
1133 |
1141 |
1134 /* |
1142 /* |
1135 * SERVICE LIST |
1143 * SERVICE LIST |
1136 */ |
1144 */ |
1137 |
1145 |
1138 #if defined TT_CONFIG_OPTION_POSTSCRIPT_NAMES && defined TT_CONFIG_OPTION_BDF |
1146 #if defined TT_CONFIG_OPTION_POSTSCRIPT_NAMES && defined TT_CONFIG_OPTION_BDF |
1139 FT_DEFINE_SERVICEDESCREC5( |
1147 FT_DEFINE_SERVICEDESCREC5( |
1140 sfnt_services, |
1148 sfnt_services, |
1141 |
1149 |
1142 FT_SERVICE_ID_SFNT_TABLE, &SFNT_SERVICE_SFNT_TABLE_GET, |
1150 FT_SERVICE_ID_SFNT_TABLE, &sfnt_service_sfnt_table, |
1143 FT_SERVICE_ID_POSTSCRIPT_FONT_NAME, &SFNT_SERVICE_PS_NAME_GET, |
1151 FT_SERVICE_ID_POSTSCRIPT_FONT_NAME, &sfnt_service_ps_name, |
1144 FT_SERVICE_ID_GLYPH_DICT, &SFNT_SERVICE_GLYPH_DICT_GET, |
1152 FT_SERVICE_ID_GLYPH_DICT, &sfnt_service_glyph_dict, |
1145 FT_SERVICE_ID_BDF, &SFNT_SERVICE_BDF_GET, |
1153 FT_SERVICE_ID_BDF, &sfnt_service_bdf, |
1146 FT_SERVICE_ID_TT_CMAP, &TT_SERVICE_CMAP_INFO_GET ) |
1154 FT_SERVICE_ID_TT_CMAP, &tt_service_get_cmap_info ) |
1147 #elif defined TT_CONFIG_OPTION_POSTSCRIPT_NAMES |
1155 #elif defined TT_CONFIG_OPTION_POSTSCRIPT_NAMES |
1148 FT_DEFINE_SERVICEDESCREC4( |
1156 FT_DEFINE_SERVICEDESCREC4( |
1149 sfnt_services, |
1157 sfnt_services, |
1150 |
1158 |
1151 FT_SERVICE_ID_SFNT_TABLE, &SFNT_SERVICE_SFNT_TABLE_GET, |
1159 FT_SERVICE_ID_SFNT_TABLE, &sfnt_service_sfnt_table, |
1152 FT_SERVICE_ID_POSTSCRIPT_FONT_NAME, &SFNT_SERVICE_PS_NAME_GET, |
1160 FT_SERVICE_ID_POSTSCRIPT_FONT_NAME, &sfnt_service_ps_name, |
1153 FT_SERVICE_ID_GLYPH_DICT, &SFNT_SERVICE_GLYPH_DICT_GET, |
1161 FT_SERVICE_ID_GLYPH_DICT, &sfnt_service_glyph_dict, |
1154 FT_SERVICE_ID_TT_CMAP, &TT_SERVICE_CMAP_INFO_GET ) |
1162 FT_SERVICE_ID_TT_CMAP, &tt_service_get_cmap_info ) |
1155 #elif defined TT_CONFIG_OPTION_BDF |
1163 #elif defined TT_CONFIG_OPTION_BDF |
1156 FT_DEFINE_SERVICEDESCREC4( |
1164 FT_DEFINE_SERVICEDESCREC4( |
1157 sfnt_services, |
1165 sfnt_services, |
1158 |
1166 |
1159 FT_SERVICE_ID_SFNT_TABLE, &SFNT_SERVICE_SFNT_TABLE_GET, |
1167 FT_SERVICE_ID_SFNT_TABLE, &sfnt_service_sfnt_table, |
1160 FT_SERVICE_ID_POSTSCRIPT_FONT_NAME, &SFNT_SERVICE_PS_NAME_GET, |
1168 FT_SERVICE_ID_POSTSCRIPT_FONT_NAME, &sfnt_service_ps_name, |
1161 FT_SERVICE_ID_BDF, &SFNT_SERVICE_BDF_GET, |
1169 FT_SERVICE_ID_BDF, &sfnt_service_bdf, |
1162 FT_SERVICE_ID_TT_CMAP, &TT_SERVICE_CMAP_INFO_GET ) |
1170 FT_SERVICE_ID_TT_CMAP, &tt_service_get_cmap_info ) |
1163 #else |
1171 #else |
1164 FT_DEFINE_SERVICEDESCREC3( |
1172 FT_DEFINE_SERVICEDESCREC3( |
1165 sfnt_services, |
1173 sfnt_services, |
1166 |
1174 |
1167 FT_SERVICE_ID_SFNT_TABLE, &SFNT_SERVICE_SFNT_TABLE_GET, |
1175 FT_SERVICE_ID_SFNT_TABLE, &sfnt_service_sfnt_table, |
1168 FT_SERVICE_ID_POSTSCRIPT_FONT_NAME, &SFNT_SERVICE_PS_NAME_GET, |
1176 FT_SERVICE_ID_POSTSCRIPT_FONT_NAME, &sfnt_service_ps_name, |
1169 FT_SERVICE_ID_TT_CMAP, &TT_SERVICE_CMAP_INFO_GET ) |
1177 FT_SERVICE_ID_TT_CMAP, &tt_service_get_cmap_info ) |
1170 #endif |
1178 #endif |
1171 |
1179 |
1172 |
1180 |
1173 FT_CALLBACK_DEF( FT_Module_Interface ) |
1181 FT_CALLBACK_DEF( FT_Module_Interface ) |
1174 sfnt_get_interface( FT_Module module, |
1182 sfnt_get_interface( FT_Module module, |
1175 const char* module_interface ) |
1183 const char* module_interface ) |
1176 { |
1184 { |
1177 /* SFNT_SERVICES_GET dereferences `library' in PIC mode */ |
|
1178 #ifdef FT_CONFIG_OPTION_PIC |
|
1179 FT_Library library; |
|
1180 |
|
1181 |
|
1182 if ( !module ) |
|
1183 return NULL; |
|
1184 library = module->library; |
|
1185 if ( !library ) |
|
1186 return NULL; |
|
1187 #else |
|
1188 FT_UNUSED( module ); |
1185 FT_UNUSED( module ); |
1189 #endif |
1186 |
1190 |
1187 return ft_service_list_lookup( sfnt_services, module_interface ); |
1191 return ft_service_list_lookup( SFNT_SERVICES_GET, module_interface ); |
|
1192 } |
1188 } |
1193 |
1189 |
1194 |
1190 |
1195 #ifdef TT_CONFIG_OPTION_EMBEDDED_BITMAPS |
1191 #ifdef TT_CONFIG_OPTION_EMBEDDED_BITMAPS |
1196 #define PUT_EMBEDDED_BITMAPS( a ) a |
1192 #define PUT_EMBEDDED_BITMAPS( a ) a |
1197 #else |
1193 #else |
1198 #define PUT_EMBEDDED_BITMAPS( a ) NULL |
1194 #define PUT_EMBEDDED_BITMAPS( a ) NULL |
|
1195 #endif |
|
1196 |
|
1197 #ifdef TT_CONFIG_OPTION_COLOR_LAYERS |
|
1198 #define PUT_COLOR_LAYERS( a ) a |
|
1199 #else |
|
1200 #define PUT_COLOR_LAYERS( a ) NULL |
1199 #endif |
1201 #endif |
1200 |
1202 |
1201 #ifdef TT_CONFIG_OPTION_POSTSCRIPT_NAMES |
1203 #ifdef TT_CONFIG_OPTION_POSTSCRIPT_NAMES |
1202 #define PUT_PS_NAMES( a ) a |
1204 #define PUT_PS_NAMES( a ) a |
1203 #else |
1205 #else |
1254 /* TT_Load_Table_Func load_eblc */ |
1256 /* TT_Load_Table_Func load_eblc */ |
1255 PUT_EMBEDDED_BITMAPS( tt_face_free_sbit ), |
1257 PUT_EMBEDDED_BITMAPS( tt_face_free_sbit ), |
1256 /* TT_Free_Table_Func free_eblc */ |
1258 /* TT_Free_Table_Func free_eblc */ |
1257 |
1259 |
1258 PUT_EMBEDDED_BITMAPS( tt_face_set_sbit_strike ), |
1260 PUT_EMBEDDED_BITMAPS( tt_face_set_sbit_strike ), |
1259 /* TT_Set_SBit_Strike_Func set_sbit_strike */ |
1261 /* TT_Set_SBit_Strike_Func set_sbit_strike */ |
1260 PUT_EMBEDDED_BITMAPS( tt_face_load_strike_metrics ), |
1262 PUT_EMBEDDED_BITMAPS( tt_face_load_strike_metrics ), |
1261 /* TT_Load_Strike_Metrics_Func load_strike_metrics */ |
1263 /* TT_Load_Strike_Metrics_Func load_strike_metrics */ |
|
1264 |
|
1265 PUT_COLOR_LAYERS( tt_face_load_cpal ), |
|
1266 /* TT_Load_Table_Func load_cpal */ |
|
1267 PUT_COLOR_LAYERS( tt_face_load_colr ), |
|
1268 /* TT_Load_Table_Func load_colr */ |
|
1269 PUT_COLOR_LAYERS( tt_face_free_cpal ), |
|
1270 /* TT_Free_Table_Func free_cpal */ |
|
1271 PUT_COLOR_LAYERS( tt_face_free_colr ), |
|
1272 /* TT_Free_Table_Func free_colr */ |
|
1273 PUT_COLOR_LAYERS( tt_face_palette_set ), |
|
1274 /* TT_Set_Palette_Func set_palette */ |
|
1275 PUT_COLOR_LAYERS( tt_face_get_colr_layer ), |
|
1276 /* TT_Get_Colr_Layer_Func get_colr_layer */ |
|
1277 PUT_COLOR_LAYERS( tt_face_colr_blend_layer ), |
|
1278 /* TT_Blend_Colr_Func colr_blend */ |
1262 |
1279 |
1263 tt_face_get_metrics, /* TT_Get_Metrics_Func get_metrics */ |
1280 tt_face_get_metrics, /* TT_Get_Metrics_Func get_metrics */ |
1264 |
1281 |
1265 tt_face_get_name, /* TT_Get_Name_Func get_name */ |
1282 tt_face_get_name, /* TT_Get_Name_Func get_name */ |
1266 sfnt_get_name_id /* TT_Get_Name_ID_Func get_name_id */ |
1283 sfnt_get_name_id /* TT_Get_Name_ID_Func get_name_id */ |