OLD | NEW |
1 /***************************************************************************/ | 1 /***************************************************************************/ |
2 /* */ | 2 /* */ |
3 /* cffparse.c */ | 3 /* cffparse.c */ |
4 /* */ | 4 /* */ |
5 /* CFF token stream parser (body) */ | 5 /* CFF token stream parser (body) */ |
6 /* */ | 6 /* */ |
7 /* Copyright 1996-2004, 2007-2014 by */ | 7 /* Copyright 1996-2015 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 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 | 122 |
123 | 123 |
124 /* read a real */ | 124 /* read a real */ |
125 static FT_Fixed | 125 static FT_Fixed |
126 cff_parse_real( FT_Byte* start, | 126 cff_parse_real( FT_Byte* start, |
127 FT_Byte* limit, | 127 FT_Byte* limit, |
128 FT_Long power_ten, | 128 FT_Long power_ten, |
129 FT_Long* scaling ) | 129 FT_Long* scaling ) |
130 { | 130 { |
131 FT_Byte* p = start; | 131 FT_Byte* p = start; |
132 FT_UInt nib; | 132 FT_Int nib; |
133 FT_UInt phase; | 133 FT_UInt phase; |
134 | 134 |
135 FT_Long result, number, exponent; | 135 FT_Long result, number, exponent; |
136 FT_Int sign = 0, exponent_sign = 0, have_overflow = 0; | 136 FT_Int sign = 0, exponent_sign = 0, have_overflow = 0; |
137 FT_Long exponent_add, integer_length, fraction_length; | 137 FT_Long exponent_add, integer_length, fraction_length; |
138 | 138 |
139 | 139 |
140 if ( scaling ) | 140 if ( scaling ) |
141 *scaling = 0; | 141 *scaling = 0; |
142 | 142 |
(...skipping 16 matching lines...) Expand all Loading... |
159 if ( phase ) | 159 if ( phase ) |
160 { | 160 { |
161 p++; | 161 p++; |
162 | 162 |
163 /* Make sure we don't read past the end. */ | 163 /* Make sure we don't read past the end. */ |
164 if ( p >= limit ) | 164 if ( p >= limit ) |
165 goto Bad; | 165 goto Bad; |
166 } | 166 } |
167 | 167 |
168 /* Get the nibble. */ | 168 /* Get the nibble. */ |
169 nib = ( p[0] >> phase ) & 0xF; | 169 nib = (FT_Int)( p[0] >> phase ) & 0xF; |
170 phase = 4 - phase; | 170 phase = 4 - phase; |
171 | 171 |
172 if ( nib == 0xE ) | 172 if ( nib == 0xE ) |
173 sign = 1; | 173 sign = 1; |
174 else if ( nib > 9 ) | 174 else if ( nib > 9 ) |
175 break; | 175 break; |
176 else | 176 else |
177 { | 177 { |
178 /* Increase exponent if we can't add the digit. */ | 178 /* Increase exponent if we can't add the digit. */ |
179 if ( number >= 0xCCCCCCCL ) | 179 if ( number >= 0xCCCCCCCL ) |
180 exponent_add++; | 180 exponent_add++; |
181 /* Skip leading zeros. */ | 181 /* Skip leading zeros. */ |
182 else if ( nib || number ) | 182 else if ( nib || number ) |
183 { | 183 { |
184 integer_length++; | 184 integer_length++; |
185 number = number * 10 + nib; | 185 number = number * 10 + nib; |
186 } | 186 } |
187 } | 187 } |
188 } | 188 } |
189 | 189 |
190 /* Read fraction part, if any. */ | 190 /* Read fraction part, if any. */ |
191 if ( nib == 0xa ) | 191 if ( nib == 0xA ) |
192 for (;;) | 192 for (;;) |
193 { | 193 { |
194 /* If we entered this iteration with phase == 4, we need */ | 194 /* If we entered this iteration with phase == 4, we need */ |
195 /* to read a new byte. */ | 195 /* to read a new byte. */ |
196 if ( phase ) | 196 if ( phase ) |
197 { | 197 { |
198 p++; | 198 p++; |
199 | 199 |
200 /* Make sure we don't read past the end. */ | 200 /* Make sure we don't read past the end. */ |
201 if ( p >= limit ) | 201 if ( p >= limit ) |
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
552 | 552 |
553 goto Exit; | 553 goto Exit; |
554 } | 554 } |
555 | 555 |
556 matrix->yx = cff_parse_fixed_scaled( data++, scaling ); | 556 matrix->yx = cff_parse_fixed_scaled( data++, scaling ); |
557 matrix->xy = cff_parse_fixed_scaled( data++, scaling ); | 557 matrix->xy = cff_parse_fixed_scaled( data++, scaling ); |
558 matrix->yy = cff_parse_fixed_scaled( data++, scaling ); | 558 matrix->yy = cff_parse_fixed_scaled( data++, scaling ); |
559 offset->x = cff_parse_fixed_scaled( data++, scaling ); | 559 offset->x = cff_parse_fixed_scaled( data++, scaling ); |
560 offset->y = cff_parse_fixed_scaled( data, scaling ); | 560 offset->y = cff_parse_fixed_scaled( data, scaling ); |
561 | 561 |
562 *upm = power_tens[scaling]; | 562 *upm = (FT_ULong)power_tens[scaling]; |
563 | 563 |
564 FT_TRACE4(( " [%f %f %f %f %f %f]\n", | 564 FT_TRACE4(( " [%f %f %f %f %f %f]\n", |
565 (double)matrix->xx / *upm / 65536, | 565 (double)matrix->xx / *upm / 65536, |
566 (double)matrix->xy / *upm / 65536, | 566 (double)matrix->xy / *upm / 65536, |
567 (double)matrix->yx / *upm / 65536, | 567 (double)matrix->yx / *upm / 65536, |
568 (double)matrix->yy / *upm / 65536, | 568 (double)matrix->yy / *upm / 65536, |
569 (double)offset->x / *upm / 65536, | 569 (double)offset->x / *upm / 65536, |
570 (double)offset->y / *upm / 65536 )); | 570 (double)offset->y / *upm / 65536 )); |
571 } | 571 } |
572 | 572 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
610 { | 610 { |
611 CFF_FontRecDict dict = (CFF_FontRecDict)parser->object; | 611 CFF_FontRecDict dict = (CFF_FontRecDict)parser->object; |
612 FT_Byte** data = parser->stack; | 612 FT_Byte** data = parser->stack; |
613 FT_Error error; | 613 FT_Error error; |
614 | 614 |
615 | 615 |
616 error = FT_ERR( Stack_Underflow ); | 616 error = FT_ERR( Stack_Underflow ); |
617 | 617 |
618 if ( parser->top >= parser->stack + 2 ) | 618 if ( parser->top >= parser->stack + 2 ) |
619 { | 619 { |
620 dict->private_size = cff_parse_num( data++ ); | 620 FT_Long tmp; |
621 dict->private_offset = cff_parse_num( data ); | 621 |
| 622 |
| 623 tmp = cff_parse_num( data++ ); |
| 624 if ( tmp < 0 ) |
| 625 { |
| 626 FT_ERROR(( "cff_parse_private_dict: Invalid dictionary size\n" )); |
| 627 error = FT_THROW( Invalid_File_Format ); |
| 628 goto Fail; |
| 629 } |
| 630 dict->private_size = (FT_ULong)tmp; |
| 631 |
| 632 tmp = cff_parse_num( data ); |
| 633 if ( tmp < 0 ) |
| 634 { |
| 635 FT_ERROR(( "cff_parse_private_dict: Invalid dictionary offset\n" )); |
| 636 error = FT_THROW( Invalid_File_Format ); |
| 637 goto Fail; |
| 638 } |
| 639 dict->private_offset = (FT_ULong)tmp; |
| 640 |
622 FT_TRACE4(( " %lu %lu\n", | 641 FT_TRACE4(( " %lu %lu\n", |
623 dict->private_size, dict->private_offset )); | 642 dict->private_size, dict->private_offset )); |
624 | 643 |
625 error = FT_Err_Ok; | 644 error = FT_Err_Ok; |
626 } | 645 } |
627 | 646 |
| 647 Fail: |
628 return error; | 648 return error; |
629 } | 649 } |
630 | 650 |
631 | 651 |
632 static FT_Error | 652 static FT_Error |
633 cff_parse_cid_ros( CFF_Parser parser ) | 653 cff_parse_cid_ros( CFF_Parser parser ) |
634 { | 654 { |
635 CFF_FontRecDict dict = (CFF_FontRecDict)parser->object; | 655 CFF_FontRecDict dict = (CFF_FontRecDict)parser->object; |
636 FT_Byte** data = parser->stack; | 656 FT_Byte** data = parser->stack; |
637 FT_Error error; | 657 FT_Error error; |
(...skipping 526 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1164 error = FT_THROW( Invalid_Argument ); | 1184 error = FT_THROW( Invalid_Argument ); |
1165 goto Exit; | 1185 goto Exit; |
1166 | 1186 |
1167 Syntax_Error: | 1187 Syntax_Error: |
1168 error = FT_THROW( Invalid_Argument ); | 1188 error = FT_THROW( Invalid_Argument ); |
1169 goto Exit; | 1189 goto Exit; |
1170 } | 1190 } |
1171 | 1191 |
1172 | 1192 |
1173 /* END */ | 1193 /* END */ |
OLD | NEW |