OLD | NEW |
1 /***************************************************************************/ | 1 /***************************************************************************/ |
2 /* */ | 2 /* */ |
3 /* cffload.c */ | 3 /* cffload.c */ |
4 /* */ | 4 /* */ |
5 /* OpenType and CFF data/program tables loader (body). */ | 5 /* OpenType and CFF data/program tables loader (body). */ |
6 /* */ | 6 /* */ |
7 /* Copyright 1996-2011 by */ | 7 /* Copyright 1996-2013 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 |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 FT_ULong size; | 243 FT_ULong size; |
244 | 244 |
245 | 245 |
246 /* there is at least one element; read the offset size, */ | 246 /* there is at least one element; read the offset size, */ |
247 /* then access the offset table to compute the index's total size */ | 247 /* then access the offset table to compute the index's total size */ |
248 if ( FT_READ_BYTE( offsize ) ) | 248 if ( FT_READ_BYTE( offsize ) ) |
249 goto Exit; | 249 goto Exit; |
250 | 250 |
251 if ( offsize < 1 || offsize > 4 ) | 251 if ( offsize < 1 || offsize > 4 ) |
252 { | 252 { |
253 error = CFF_Err_Invalid_Table; | 253 error = FT_THROW( Invalid_Table ); |
254 goto Exit; | 254 goto Exit; |
255 } | 255 } |
256 | 256 |
257 idx->count = count; | 257 idx->count = count; |
258 idx->off_size = offsize; | 258 idx->off_size = offsize; |
259 size = (FT_ULong)( count + 1 ) * offsize; | 259 size = (FT_ULong)( count + 1 ) * offsize; |
260 | 260 |
261 idx->data_offset = idx->start + 3 + size; | 261 idx->data_offset = idx->start + 3 + size; |
262 | 262 |
263 if ( FT_STREAM_SKIP( size - offsize ) ) | 263 if ( FT_STREAM_SKIP( size - offsize ) ) |
264 goto Exit; | 264 goto Exit; |
265 | 265 |
266 size = cff_index_read_offset( idx, &error ); | 266 size = cff_index_read_offset( idx, &error ); |
267 if ( error ) | 267 if ( error ) |
268 goto Exit; | 268 goto Exit; |
269 | 269 |
270 if ( size == 0 ) | 270 if ( size == 0 ) |
271 { | 271 { |
272 error = CFF_Err_Invalid_Table; | 272 error = FT_THROW( Invalid_Table ); |
273 goto Exit; | 273 goto Exit; |
274 } | 274 } |
275 | 275 |
276 idx->data_size = --size; | 276 idx->data_size = --size; |
277 | 277 |
278 if ( load ) | 278 if ( load ) |
279 { | 279 { |
280 /* load the data */ | 280 /* load the data */ |
281 if ( FT_FRAME_EXTRACT( size, idx->bytes ) ) | 281 if ( FT_FRAME_EXTRACT( size, idx->bytes ) ) |
282 goto Exit; | 282 goto Exit; |
(...skipping 28 matching lines...) Expand all Loading... |
311 | 311 |
312 FT_FREE( idx->offsets ); | 312 FT_FREE( idx->offsets ); |
313 FT_MEM_ZERO( idx, sizeof ( *idx ) ); | 313 FT_MEM_ZERO( idx, sizeof ( *idx ) ); |
314 } | 314 } |
315 } | 315 } |
316 | 316 |
317 | 317 |
318 static FT_Error | 318 static FT_Error |
319 cff_index_load_offsets( CFF_Index idx ) | 319 cff_index_load_offsets( CFF_Index idx ) |
320 { | 320 { |
321 FT_Error error = CFF_Err_Ok; | 321 FT_Error error = FT_Err_Ok; |
322 FT_Stream stream = idx->stream; | 322 FT_Stream stream = idx->stream; |
323 FT_Memory memory = stream->memory; | 323 FT_Memory memory = stream->memory; |
324 | 324 |
325 | 325 |
326 if ( idx->count > 0 && idx->offsets == NULL ) | 326 if ( idx->count > 0 && idx->offsets == NULL ) |
327 { | 327 { |
328 FT_Byte offsize = idx->off_size; | 328 FT_Byte offsize = idx->off_size; |
329 FT_ULong data_size; | 329 FT_ULong data_size; |
330 FT_Byte* p; | 330 FT_Byte* p; |
331 FT_Byte* p_end; | 331 FT_Byte* p_end; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
377 | 377 |
378 | 378 |
379 /* Allocate a table containing pointers to an index's elements. */ | 379 /* Allocate a table containing pointers to an index's elements. */ |
380 /* The `pool' argument makes this function convert the index */ | 380 /* The `pool' argument makes this function convert the index */ |
381 /* entries to C-style strings (this is, NULL-terminated). */ | 381 /* entries to C-style strings (this is, NULL-terminated). */ |
382 static FT_Error | 382 static FT_Error |
383 cff_index_get_pointers( CFF_Index idx, | 383 cff_index_get_pointers( CFF_Index idx, |
384 FT_Byte*** table, | 384 FT_Byte*** table, |
385 FT_Byte** pool ) | 385 FT_Byte** pool ) |
386 { | 386 { |
387 FT_Error error = CFF_Err_Ok; | 387 FT_Error error = FT_Err_Ok; |
388 FT_Memory memory = idx->stream->memory; | 388 FT_Memory memory = idx->stream->memory; |
389 FT_Byte** t = NULL; | 389 |
| 390 FT_Byte** t = NULL; |
390 FT_Byte* new_bytes = NULL; | 391 FT_Byte* new_bytes = NULL; |
391 | 392 |
392 | 393 |
393 *table = NULL; | 394 *table = NULL; |
394 | 395 |
395 if ( idx->offsets == NULL ) | 396 if ( idx->offsets == NULL ) |
396 { | 397 { |
397 error = cff_index_load_offsets( idx ); | 398 error = cff_index_load_offsets( idx ); |
398 if ( error ) | 399 if ( error ) |
399 goto Exit; | 400 goto Exit; |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
464 return error; | 465 return error; |
465 } | 466 } |
466 | 467 |
467 | 468 |
468 FT_LOCAL_DEF( FT_Error ) | 469 FT_LOCAL_DEF( FT_Error ) |
469 cff_index_access_element( CFF_Index idx, | 470 cff_index_access_element( CFF_Index idx, |
470 FT_UInt element, | 471 FT_UInt element, |
471 FT_Byte** pbytes, | 472 FT_Byte** pbytes, |
472 FT_ULong* pbyte_len ) | 473 FT_ULong* pbyte_len ) |
473 { | 474 { |
474 FT_Error error = CFF_Err_Ok; | 475 FT_Error error = FT_Err_Ok; |
475 | 476 |
476 | 477 |
477 if ( idx && idx->count > element ) | 478 if ( idx && idx->count > element ) |
478 { | 479 { |
479 /* compute start and end offsets */ | 480 /* compute start and end offsets */ |
480 FT_Stream stream = idx->stream; | 481 FT_Stream stream = idx->stream; |
481 FT_ULong off1, off2 = 0; | 482 FT_ULong off1, off2 = 0; |
482 | 483 |
483 | 484 |
484 /* load offsets from file or the offset table */ | 485 /* load offsets from file or the offset table */ |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
549 } | 550 } |
550 } | 551 } |
551 else | 552 else |
552 { | 553 { |
553 /* empty index element */ | 554 /* empty index element */ |
554 *pbytes = 0; | 555 *pbytes = 0; |
555 *pbyte_len = 0; | 556 *pbyte_len = 0; |
556 } | 557 } |
557 } | 558 } |
558 else | 559 else |
559 error = CFF_Err_Invalid_Argument; | 560 error = FT_THROW( Invalid_Argument ); |
560 | 561 |
561 Exit: | 562 Exit: |
562 return error; | 563 return error; |
563 } | 564 } |
564 | 565 |
565 | 566 |
566 FT_LOCAL_DEF( void ) | 567 FT_LOCAL_DEF( void ) |
567 cff_index_forget_element( CFF_Index idx, | 568 cff_index_forget_element( CFF_Index idx, |
568 FT_Byte** pbytes ) | 569 FT_Byte** pbytes ) |
569 { | 570 { |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
689 goto Exit; | 690 goto Exit; |
690 | 691 |
691 fdselect->data_size = num_ranges * 3 + 2; | 692 fdselect->data_size = num_ranges * 3 + 2; |
692 | 693 |
693 Load_Data: | 694 Load_Data: |
694 if ( FT_FRAME_EXTRACT( fdselect->data_size, fdselect->data ) ) | 695 if ( FT_FRAME_EXTRACT( fdselect->data_size, fdselect->data ) ) |
695 goto Exit; | 696 goto Exit; |
696 break; | 697 break; |
697 | 698 |
698 default: /* hmm... that's wrong */ | 699 default: /* hmm... that's wrong */ |
699 error = CFF_Err_Invalid_File_Format; | 700 error = FT_THROW( Invalid_File_Format ); |
700 } | 701 } |
701 | 702 |
702 Exit: | 703 Exit: |
703 return error; | 704 return error; |
704 } | 705 } |
705 | 706 |
706 | 707 |
707 FT_LOCAL_DEF( FT_Byte ) | 708 FT_LOCAL_DEF( FT_Byte ) |
708 cff_fd_select_get( CFF_FDSelect fdselect, | 709 cff_fd_select_get( CFF_FDSelect fdselect, |
709 FT_UInt glyph_index ) | 710 FT_UInt glyph_index ) |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
773 /*** CFF font support ***/ | 774 /*** CFF font support ***/ |
774 /*** ***/ | 775 /*** ***/ |
775 /*************************************************************************/ | 776 /*************************************************************************/ |
776 /*************************************************************************/ | 777 /*************************************************************************/ |
777 | 778 |
778 static FT_Error | 779 static FT_Error |
779 cff_charset_compute_cids( CFF_Charset charset, | 780 cff_charset_compute_cids( CFF_Charset charset, |
780 FT_UInt num_glyphs, | 781 FT_UInt num_glyphs, |
781 FT_Memory memory ) | 782 FT_Memory memory ) |
782 { | 783 { |
783 FT_Error error = CFF_Err_Ok; | 784 FT_Error error = FT_Err_Ok; |
784 FT_UInt i; | 785 FT_UInt i; |
785 FT_Long j; | 786 FT_Long j; |
786 FT_UShort max_cid = 0; | 787 FT_UShort max_cid = 0; |
787 | 788 |
788 | 789 |
789 if ( charset->max_cid > 0 ) | 790 if ( charset->max_cid > 0 ) |
790 goto Exit; | 791 goto Exit; |
791 | 792 |
792 for ( i = 0; i < num_glyphs; i++ ) | 793 for ( i = 0; i < num_glyphs; i++ ) |
793 { | 794 { |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
852 | 853 |
853 static FT_Error | 854 static FT_Error |
854 cff_charset_load( CFF_Charset charset, | 855 cff_charset_load( CFF_Charset charset, |
855 FT_UInt num_glyphs, | 856 FT_UInt num_glyphs, |
856 FT_Stream stream, | 857 FT_Stream stream, |
857 FT_ULong base_offset, | 858 FT_ULong base_offset, |
858 FT_ULong offset, | 859 FT_ULong offset, |
859 FT_Bool invert ) | 860 FT_Bool invert ) |
860 { | 861 { |
861 FT_Memory memory = stream->memory; | 862 FT_Memory memory = stream->memory; |
862 FT_Error error = CFF_Err_Ok; | 863 FT_Error error = FT_Err_Ok; |
863 FT_UShort glyph_sid; | 864 FT_UShort glyph_sid; |
864 | 865 |
865 | 866 |
866 /* If the the offset is greater than 2, we have to parse the */ | 867 /* If the the offset is greater than 2, we have to parse the */ |
867 /* charset table. */ | 868 /* charset table. */ |
868 if ( offset > 2 ) | 869 if ( offset > 2 ) |
869 { | 870 { |
870 FT_UInt j; | 871 FT_UInt j; |
871 | 872 |
872 | 873 |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
936 | 937 |
937 /* Fill in the range of sids -- `nleft + 1' glyphs. */ | 938 /* Fill in the range of sids -- `nleft + 1' glyphs. */ |
938 for ( i = 0; j < num_glyphs && i <= nleft; i++, j++, glyph_sid++ ) | 939 for ( i = 0; j < num_glyphs && i <= nleft; i++, j++, glyph_sid++ ) |
939 charset->sids[j] = glyph_sid; | 940 charset->sids[j] = glyph_sid; |
940 } | 941 } |
941 } | 942 } |
942 break; | 943 break; |
943 | 944 |
944 default: | 945 default: |
945 FT_ERROR(( "cff_charset_load: invalid table format\n" )); | 946 FT_ERROR(( "cff_charset_load: invalid table format\n" )); |
946 error = CFF_Err_Invalid_File_Format; | 947 error = FT_THROW( Invalid_File_Format ); |
947 goto Exit; | 948 goto Exit; |
948 } | 949 } |
949 } | 950 } |
950 else | 951 else |
951 { | 952 { |
952 /* Parse default tables corresponding to offset == 0, 1, or 2. */ | 953 /* Parse default tables corresponding to offset == 0, 1, or 2. */ |
953 /* CFF specification intimates the following: */ | 954 /* CFF specification intimates the following: */ |
954 /* */ | 955 /* */ |
955 /* In order to use a predefined charset, the following must be */ | 956 /* In order to use a predefined charset, the following must be */ |
956 /* true: The charset constructed for the glyphs in the font's */ | 957 /* true: The charset constructed for the glyphs in the font's */ |
957 /* charstrings dictionary must match the predefined charset in */ | 958 /* charstrings dictionary must match the predefined charset in */ |
958 /* the first num_glyphs. */ | 959 /* the first num_glyphs. */ |
959 | 960 |
960 charset->offset = offset; /* record charset type */ | 961 charset->offset = offset; /* record charset type */ |
961 | 962 |
962 switch ( (FT_UInt)offset ) | 963 switch ( (FT_UInt)offset ) |
963 { | 964 { |
964 case 0: | 965 case 0: |
965 if ( num_glyphs > 229 ) | 966 if ( num_glyphs > 229 ) |
966 { | 967 { |
967 FT_ERROR(( "cff_charset_load: implicit charset larger than\n" | 968 FT_ERROR(( "cff_charset_load: implicit charset larger than\n" |
968 "predefined charset (Adobe ISO-Latin)\n" )); | 969 "predefined charset (Adobe ISO-Latin)\n" )); |
969 error = CFF_Err_Invalid_File_Format; | 970 error = FT_THROW( Invalid_File_Format ); |
970 goto Exit; | 971 goto Exit; |
971 } | 972 } |
972 | 973 |
973 /* Allocate memory for sids. */ | 974 /* Allocate memory for sids. */ |
974 if ( FT_NEW_ARRAY( charset->sids, num_glyphs ) ) | 975 if ( FT_NEW_ARRAY( charset->sids, num_glyphs ) ) |
975 goto Exit; | 976 goto Exit; |
976 | 977 |
977 /* Copy the predefined charset into the allocated memory. */ | 978 /* Copy the predefined charset into the allocated memory. */ |
978 FT_ARRAY_COPY( charset->sids, cff_isoadobe_charset, num_glyphs ); | 979 FT_ARRAY_COPY( charset->sids, cff_isoadobe_charset, num_glyphs ); |
979 | 980 |
980 break; | 981 break; |
981 | 982 |
982 case 1: | 983 case 1: |
983 if ( num_glyphs > 166 ) | 984 if ( num_glyphs > 166 ) |
984 { | 985 { |
985 FT_ERROR(( "cff_charset_load: implicit charset larger than\n" | 986 FT_ERROR(( "cff_charset_load: implicit charset larger than\n" |
986 "predefined charset (Adobe Expert)\n" )); | 987 "predefined charset (Adobe Expert)\n" )); |
987 error = CFF_Err_Invalid_File_Format; | 988 error = FT_THROW( Invalid_File_Format ); |
988 goto Exit; | 989 goto Exit; |
989 } | 990 } |
990 | 991 |
991 /* Allocate memory for sids. */ | 992 /* Allocate memory for sids. */ |
992 if ( FT_NEW_ARRAY( charset->sids, num_glyphs ) ) | 993 if ( FT_NEW_ARRAY( charset->sids, num_glyphs ) ) |
993 goto Exit; | 994 goto Exit; |
994 | 995 |
995 /* Copy the predefined charset into the allocated memory. */ | 996 /* Copy the predefined charset into the allocated memory. */ |
996 FT_ARRAY_COPY( charset->sids, cff_expert_charset, num_glyphs ); | 997 FT_ARRAY_COPY( charset->sids, cff_expert_charset, num_glyphs ); |
997 | 998 |
998 break; | 999 break; |
999 | 1000 |
1000 case 2: | 1001 case 2: |
1001 if ( num_glyphs > 87 ) | 1002 if ( num_glyphs > 87 ) |
1002 { | 1003 { |
1003 FT_ERROR(( "cff_charset_load: implicit charset larger than\n" | 1004 FT_ERROR(( "cff_charset_load: implicit charset larger than\n" |
1004 "predefined charset (Adobe Expert Subset)\n" )); | 1005 "predefined charset (Adobe Expert Subset)\n" )); |
1005 error = CFF_Err_Invalid_File_Format; | 1006 error = FT_THROW( Invalid_File_Format ); |
1006 goto Exit; | 1007 goto Exit; |
1007 } | 1008 } |
1008 | 1009 |
1009 /* Allocate memory for sids. */ | 1010 /* Allocate memory for sids. */ |
1010 if ( FT_NEW_ARRAY( charset->sids, num_glyphs ) ) | 1011 if ( FT_NEW_ARRAY( charset->sids, num_glyphs ) ) |
1011 goto Exit; | 1012 goto Exit; |
1012 | 1013 |
1013 /* Copy the predefined charset into the allocated memory. */ | 1014 /* Copy the predefined charset into the allocated memory. */ |
1014 FT_ARRAY_COPY( charset->sids, cff_expertsubset_charset, num_glyphs ); | 1015 FT_ARRAY_COPY( charset->sids, cff_expertsubset_charset, num_glyphs ); |
1015 | 1016 |
1016 break; | 1017 break; |
1017 | 1018 |
1018 default: | 1019 default: |
1019 error = CFF_Err_Invalid_File_Format; | 1020 error = FT_THROW( Invalid_File_Format ); |
1020 goto Exit; | 1021 goto Exit; |
1021 } | 1022 } |
1022 } | 1023 } |
1023 | 1024 |
1024 /* we have to invert the `sids' array for subsetted CID-keyed fonts */ | 1025 /* we have to invert the `sids' array for subsetted CID-keyed fonts */ |
1025 if ( invert ) | 1026 if ( invert ) |
1026 error = cff_charset_compute_cids( charset, num_glyphs, memory ); | 1027 error = cff_charset_compute_cids( charset, num_glyphs, memory ); |
1027 | 1028 |
1028 Exit: | 1029 Exit: |
1029 /* Clean up if there was an error. */ | 1030 /* Clean up if there was an error. */ |
(...skipping 20 matching lines...) Expand all Loading... |
1050 | 1051 |
1051 | 1052 |
1052 static FT_Error | 1053 static FT_Error |
1053 cff_encoding_load( CFF_Encoding encoding, | 1054 cff_encoding_load( CFF_Encoding encoding, |
1054 CFF_Charset charset, | 1055 CFF_Charset charset, |
1055 FT_UInt num_glyphs, | 1056 FT_UInt num_glyphs, |
1056 FT_Stream stream, | 1057 FT_Stream stream, |
1057 FT_ULong base_offset, | 1058 FT_ULong base_offset, |
1058 FT_ULong offset ) | 1059 FT_ULong offset ) |
1059 { | 1060 { |
1060 FT_Error error = CFF_Err_Ok; | 1061 FT_Error error = FT_Err_Ok; |
1061 FT_UInt count; | 1062 FT_UInt count; |
1062 FT_UInt j; | 1063 FT_UInt j; |
1063 FT_UShort glyph_sid; | 1064 FT_UShort glyph_sid; |
1064 FT_UInt glyph_code; | 1065 FT_UInt glyph_code; |
1065 | 1066 |
1066 | 1067 |
1067 /* Check for charset->sids. If we do not have this, we fail. */ | 1068 /* Check for charset->sids. If we do not have this, we fail. */ |
1068 if ( !charset->sids ) | 1069 if ( !charset->sids ) |
1069 { | 1070 { |
1070 error = CFF_Err_Invalid_File_Format; | 1071 error = FT_THROW( Invalid_File_Format ); |
1071 goto Exit; | 1072 goto Exit; |
1072 } | 1073 } |
1073 | 1074 |
1074 /* Zero out the code to gid/sid mappings. */ | 1075 /* Zero out the code to gid/sid mappings. */ |
1075 for ( j = 0; j < 256; j++ ) | 1076 for ( j = 0; j < 256; j++ ) |
1076 { | 1077 { |
1077 encoding->sids [j] = 0; | 1078 encoding->sids [j] = 0; |
1078 encoding->codes[j] = 0; | 1079 encoding->codes[j] = 0; |
1079 } | 1080 } |
1080 | 1081 |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1180 } | 1181 } |
1181 | 1182 |
1182 /* simple check; one never knows what can be found in a font */ | 1183 /* simple check; one never knows what can be found in a font */ |
1183 if ( encoding->count > 256 ) | 1184 if ( encoding->count > 256 ) |
1184 encoding->count = 256; | 1185 encoding->count = 256; |
1185 } | 1186 } |
1186 break; | 1187 break; |
1187 | 1188 |
1188 default: | 1189 default: |
1189 FT_ERROR(( "cff_encoding_load: invalid table format\n" )); | 1190 FT_ERROR(( "cff_encoding_load: invalid table format\n" )); |
1190 error = CFF_Err_Invalid_File_Format; | 1191 error = FT_THROW( Invalid_File_Format ); |
1191 goto Exit; | 1192 goto Exit; |
1192 } | 1193 } |
1193 | 1194 |
1194 /* Parse supplemental encodings, if any. */ | 1195 /* Parse supplemental encodings, if any. */ |
1195 if ( encoding->format & 0x80 ) | 1196 if ( encoding->format & 0x80 ) |
1196 { | 1197 { |
1197 FT_UInt gindex; | 1198 FT_UInt gindex; |
1198 | 1199 |
1199 | 1200 |
1200 /* count supplements */ | 1201 /* count supplements */ |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1273 else | 1274 else |
1274 { | 1275 { |
1275 encoding->codes[j] = 0; | 1276 encoding->codes[j] = 0; |
1276 encoding->sids [j] = 0; | 1277 encoding->sids [j] = 0; |
1277 } | 1278 } |
1278 } | 1279 } |
1279 break; | 1280 break; |
1280 | 1281 |
1281 default: | 1282 default: |
1282 FT_ERROR(( "cff_encoding_load: invalid table format\n" )); | 1283 FT_ERROR(( "cff_encoding_load: invalid table format\n" )); |
1283 error = CFF_Err_Invalid_File_Format; | 1284 error = FT_THROW( Invalid_File_Format ); |
1284 goto Exit; | 1285 goto Exit; |
1285 } | 1286 } |
1286 } | 1287 } |
1287 | 1288 |
1288 Exit: | 1289 Exit: |
1289 | 1290 |
1290 /* Clean up if there was an error. */ | 1291 /* Clean up if there was an error. */ |
1291 return error; | 1292 return error; |
1292 } | 1293 } |
1293 | 1294 |
(...skipping 12 matching lines...) Expand all Loading... |
1306 FT_ULong dict_len; | 1307 FT_ULong dict_len; |
1307 CFF_FontRecDict top = &font->font_dict; | 1308 CFF_FontRecDict top = &font->font_dict; |
1308 CFF_Private priv = &font->private_dict; | 1309 CFF_Private priv = &font->private_dict; |
1309 | 1310 |
1310 | 1311 |
1311 cff_parser_init( &parser, CFF_CODE_TOPDICT, &font->font_dict, library ); | 1312 cff_parser_init( &parser, CFF_CODE_TOPDICT, &font->font_dict, library ); |
1312 | 1313 |
1313 /* set defaults */ | 1314 /* set defaults */ |
1314 FT_MEM_ZERO( top, sizeof ( *top ) ); | 1315 FT_MEM_ZERO( top, sizeof ( *top ) ); |
1315 | 1316 |
1316 top->underline_position = -100L << 16; | 1317 top->underline_position = -( 100L << 16 ); |
1317 top->underline_thickness = 50L << 16; | 1318 top->underline_thickness = 50L << 16; |
1318 top->charstring_type = 2; | 1319 top->charstring_type = 2; |
1319 top->font_matrix.xx = 0x10000L; | 1320 top->font_matrix.xx = 0x10000L; |
1320 top->font_matrix.yy = 0x10000L; | 1321 top->font_matrix.yy = 0x10000L; |
1321 top->cid_count = 8720; | 1322 top->cid_count = 8720; |
1322 | 1323 |
1323 /* we use the implementation specific SID value 0xFFFF to indicate */ | 1324 /* we use the implementation specific SID value 0xFFFF to indicate */ |
1324 /* missing entries */ | 1325 /* missing entries */ |
1325 top->version = 0xFFFFU; | 1326 top->version = 0xFFFFU; |
1326 top->notice = 0xFFFFU; | 1327 top->notice = 0xFFFFU; |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1432 FT_FRAME_BYTE( header_size ), | 1433 FT_FRAME_BYTE( header_size ), |
1433 FT_FRAME_BYTE( absolute_offsize ), | 1434 FT_FRAME_BYTE( absolute_offsize ), |
1434 FT_FRAME_END | 1435 FT_FRAME_END |
1435 }; | 1436 }; |
1436 | 1437 |
1437 FT_Error error; | 1438 FT_Error error; |
1438 FT_Memory memory = stream->memory; | 1439 FT_Memory memory = stream->memory; |
1439 FT_ULong base_offset; | 1440 FT_ULong base_offset; |
1440 CFF_FontRecDict dict; | 1441 CFF_FontRecDict dict; |
1441 CFF_IndexRec string_index; | 1442 CFF_IndexRec string_index; |
| 1443 FT_Int subfont_index; |
1442 | 1444 |
1443 | 1445 |
1444 FT_ZERO( font ); | 1446 FT_ZERO( font ); |
1445 FT_ZERO( &string_index ); | 1447 FT_ZERO( &string_index ); |
1446 | 1448 |
1447 font->stream = stream; | 1449 font->stream = stream; |
1448 font->memory = memory; | 1450 font->memory = memory; |
1449 dict = &font->top_font.font_dict; | 1451 dict = &font->top_font.font_dict; |
1450 base_offset = FT_STREAM_POS(); | 1452 base_offset = FT_STREAM_POS(); |
1451 | 1453 |
1452 /* read CFF font header */ | 1454 /* read CFF font header */ |
1453 if ( FT_STREAM_READ_FIELDS( cff_header_fields, font ) ) | 1455 if ( FT_STREAM_READ_FIELDS( cff_header_fields, font ) ) |
1454 goto Exit; | 1456 goto Exit; |
1455 | 1457 |
1456 /* check format */ | 1458 /* check format */ |
1457 if ( font->version_major != 1 || | 1459 if ( font->version_major != 1 || |
1458 font->header_size < 4 || | 1460 font->header_size < 4 || |
1459 font->absolute_offsize > 4 ) | 1461 font->absolute_offsize > 4 ) |
1460 { | 1462 { |
1461 FT_TRACE2(( " not a CFF font header\n" )); | 1463 FT_TRACE2(( " not a CFF font header\n" )); |
1462 error = CFF_Err_Unknown_File_Format; | 1464 error = FT_THROW( Unknown_File_Format ); |
1463 goto Exit; | 1465 goto Exit; |
1464 } | 1466 } |
1465 | 1467 |
1466 /* skip the rest of the header */ | 1468 /* skip the rest of the header */ |
1467 if ( FT_STREAM_SKIP( font->header_size - 4 ) ) | 1469 if ( FT_STREAM_SKIP( font->header_size - 4 ) ) |
1468 goto Exit; | 1470 goto Exit; |
1469 | 1471 |
1470 /* read the name, top dict, string and global subrs index */ | 1472 /* read the name, top dict, string and global subrs index */ |
1471 if ( FT_SET_ERROR( cff_index_init( &font->name_index, | 1473 if ( FT_SET_ERROR( cff_index_init( &font->name_index, |
1472 stream, 0 ) ) || | 1474 stream, 0 ) ) || |
1473 FT_SET_ERROR( cff_index_init( &font->font_dict_index, | 1475 FT_SET_ERROR( cff_index_init( &font->font_dict_index, |
1474 stream, 0 ) ) || | 1476 stream, 0 ) ) || |
1475 FT_SET_ERROR( cff_index_init( &string_index, | 1477 FT_SET_ERROR( cff_index_init( &string_index, |
1476 stream, 1 ) ) || | 1478 stream, 1 ) ) || |
1477 FT_SET_ERROR( cff_index_init( &font->global_subrs_index, | 1479 FT_SET_ERROR( cff_index_init( &font->global_subrs_index, |
1478 stream, 1 ) ) || | 1480 stream, 1 ) ) || |
1479 FT_SET_ERROR( cff_index_get_pointers( &string_index, | 1481 FT_SET_ERROR( cff_index_get_pointers( &string_index, |
1480 &font->strings, | 1482 &font->strings, |
1481 &font->string_pool ) ) ) | 1483 &font->string_pool ) ) ) |
1482 goto Exit; | 1484 goto Exit; |
1483 | 1485 |
1484 font->num_strings = string_index.count; | 1486 font->num_strings = string_index.count; |
1485 | 1487 |
1486 /* well, we don't really forget the `disabled' fonts... */ | 1488 if ( pure_cff ) |
1487 font->num_faces = font->name_index.count; | |
1488 if ( face_index >= (FT_Int)font->num_faces ) | |
1489 { | 1489 { |
1490 FT_ERROR(( "cff_font_load: incorrect face index = %d\n", | 1490 /* well, we don't really forget the `disabled' fonts... */ |
1491 face_index )); | 1491 subfont_index = face_index; |
1492 error = CFF_Err_Invalid_Argument; | 1492 |
| 1493 if ( subfont_index >= (FT_Int)font->name_index.count ) |
| 1494 { |
| 1495 FT_ERROR(( "cff_font_load:" |
| 1496 " invalid subfont index for pure CFF font (%d)\n", |
| 1497 subfont_index )); |
| 1498 error = FT_THROW( Invalid_Argument ); |
| 1499 goto Exit; |
| 1500 } |
| 1501 |
| 1502 font->num_faces = font->name_index.count; |
| 1503 } |
| 1504 else |
| 1505 { |
| 1506 subfont_index = 0; |
| 1507 |
| 1508 if ( font->name_index.count > 1 ) |
| 1509 { |
| 1510 FT_ERROR(( "cff_font_load:" |
| 1511 " invalid CFF font with multiple subfonts\n" |
| 1512 " " |
| 1513 " in SFNT wrapper\n" )); |
| 1514 error = FT_THROW( Invalid_File_Format ); |
| 1515 goto Exit; |
| 1516 } |
1493 } | 1517 } |
1494 | 1518 |
1495 /* in case of a font format check, simply exit now */ | 1519 /* in case of a font format check, simply exit now */ |
1496 if ( face_index < 0 ) | 1520 if ( face_index < 0 ) |
1497 goto Exit; | 1521 goto Exit; |
1498 | 1522 |
1499 /* now, parse the top-level font dictionary */ | 1523 /* now, parse the top-level font dictionary */ |
1500 FT_TRACE4(( "parsing top-level\n" )); | 1524 FT_TRACE4(( "parsing top-level\n" )); |
1501 error = cff_subfont_load( &font->top_font, | 1525 error = cff_subfont_load( &font->top_font, |
1502 &font->font_dict_index, | 1526 &font->font_dict_index, |
1503 face_index, | 1527 subfont_index, |
1504 stream, | 1528 stream, |
1505 base_offset, | 1529 base_offset, |
1506 library ); | 1530 library ); |
1507 if ( error ) | 1531 if ( error ) |
1508 goto Exit; | 1532 goto Exit; |
1509 | 1533 |
1510 if ( FT_STREAM_SEEK( base_offset + dict->charstrings_offset ) ) | 1534 if ( FT_STREAM_SEEK( base_offset + dict->charstrings_offset ) ) |
1511 goto Exit; | 1535 goto Exit; |
1512 | 1536 |
1513 error = cff_index_init( &font->charstrings_index, stream, 0 ); | 1537 error = cff_index_init( &font->charstrings_index, stream, 0 ); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1569 if ( error ) | 1593 if ( error ) |
1570 goto Exit; | 1594 goto Exit; |
1571 } | 1595 } |
1572 else | 1596 else |
1573 font->num_subfonts = 0; | 1597 font->num_subfonts = 0; |
1574 | 1598 |
1575 /* read the charstrings index now */ | 1599 /* read the charstrings index now */ |
1576 if ( dict->charstrings_offset == 0 ) | 1600 if ( dict->charstrings_offset == 0 ) |
1577 { | 1601 { |
1578 FT_ERROR(( "cff_font_load: no charstrings offset\n" )); | 1602 FT_ERROR(( "cff_font_load: no charstrings offset\n" )); |
1579 error = CFF_Err_Invalid_File_Format; | 1603 error = FT_THROW( Invalid_File_Format ); |
1580 goto Exit; | 1604 goto Exit; |
1581 } | 1605 } |
1582 | 1606 |
1583 font->num_glyphs = font->charstrings_index.count; | 1607 font->num_glyphs = font->charstrings_index.count; |
1584 | 1608 |
1585 error = cff_index_get_pointers( &font->global_subrs_index, | 1609 error = cff_index_get_pointers( &font->global_subrs_index, |
1586 &font->global_subrs, NULL ); | 1610 &font->global_subrs, NULL ); |
1587 | 1611 |
1588 if ( error ) | 1612 if ( error ) |
1589 goto Exit; | 1613 goto Exit; |
(...skipping 18 matching lines...) Expand all Loading... |
1608 stream, | 1632 stream, |
1609 base_offset, | 1633 base_offset, |
1610 dict->encoding_offset ); | 1634 dict->encoding_offset ); |
1611 if ( error ) | 1635 if ( error ) |
1612 goto Exit; | 1636 goto Exit; |
1613 } | 1637 } |
1614 } | 1638 } |
1615 | 1639 |
1616 /* get the font name (/CIDFontName for CID-keyed fonts, */ | 1640 /* get the font name (/CIDFontName for CID-keyed fonts, */ |
1617 /* /FontName otherwise) */ | 1641 /* /FontName otherwise) */ |
1618 font->font_name = cff_index_get_name( font, face_index ); | 1642 font->font_name = cff_index_get_name( font, subfont_index ); |
1619 | 1643 |
1620 Exit: | 1644 Exit: |
1621 cff_index_done( &string_index ); | 1645 cff_index_done( &string_index ); |
1622 | 1646 |
1623 return error; | 1647 return error; |
1624 } | 1648 } |
1625 | 1649 |
1626 | 1650 |
1627 FT_LOCAL_DEF( void ) | 1651 FT_LOCAL_DEF( void ) |
1628 cff_font_done( CFF_Font font ) | 1652 cff_font_done( CFF_Font font ) |
(...skipping 24 matching lines...) Expand all Loading... |
1653 cff_subfont_done( memory, &font->top_font ); | 1677 cff_subfont_done( memory, &font->top_font ); |
1654 | 1678 |
1655 CFF_Done_FD_Select( &font->fd_select, font->stream ); | 1679 CFF_Done_FD_Select( &font->fd_select, font->stream ); |
1656 | 1680 |
1657 FT_FREE( font->font_info ); | 1681 FT_FREE( font->font_info ); |
1658 | 1682 |
1659 FT_FREE( font->font_name ); | 1683 FT_FREE( font->font_name ); |
1660 FT_FREE( font->global_subrs ); | 1684 FT_FREE( font->global_subrs ); |
1661 FT_FREE( font->strings ); | 1685 FT_FREE( font->strings ); |
1662 FT_FREE( font->string_pool ); | 1686 FT_FREE( font->string_pool ); |
| 1687 |
| 1688 if ( font->cf2_instance.finalizer ) |
| 1689 { |
| 1690 font->cf2_instance.finalizer( font->cf2_instance.data ); |
| 1691 FT_FREE( font->cf2_instance.data ); |
| 1692 } |
1663 } | 1693 } |
1664 | 1694 |
1665 | 1695 |
1666 /* END */ | 1696 /* END */ |
OLD | NEW |