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-2011 by */ | 7 /* Copyright 1996-2004, 2007-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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 FT_Byte* p = start; | 58 FT_Byte* p = start; |
59 FT_Int v = *p++; | 59 FT_Int v = *p++; |
60 FT_Long val = 0; | 60 FT_Long val = 0; |
61 | 61 |
62 | 62 |
63 if ( v == 28 ) | 63 if ( v == 28 ) |
64 { | 64 { |
65 if ( p + 2 > limit ) | 65 if ( p + 2 > limit ) |
66 goto Bad; | 66 goto Bad; |
67 | 67 |
68 val = (FT_Short)( ( (FT_Int)p[0] << 8 ) | p[1] ); | 68 val = (FT_Short)( ( (FT_UShort)p[0] << 8 ) | p[1] ); |
69 p += 2; | 69 p += 2; |
70 } | 70 } |
71 else if ( v == 29 ) | 71 else if ( v == 29 ) |
72 { | 72 { |
73 if ( p + 4 > limit ) | 73 if ( p + 4 > limit ) |
74 goto Bad; | 74 goto Bad; |
75 | 75 |
76 val = ( (FT_Long)p[0] << 24 ) | | 76 val = (FT_Long)( ( (FT_ULong)p[0] << 24 ) | |
77 ( (FT_Long)p[1] << 16 ) | | 77 ( (FT_ULong)p[1] << 16 ) | |
78 ( (FT_Long)p[2] << 8 ) | | 78 ( (FT_ULong)p[2] << 8 ) | |
79 p[3]; | 79 (FT_ULong)p[3] ); |
80 p += 4; | 80 p += 4; |
81 } | 81 } |
82 else if ( v < 247 ) | 82 else if ( v < 247 ) |
83 { | 83 { |
84 val = v - 139; | 84 val = v - 139; |
85 } | 85 } |
86 else if ( v < 251 ) | 86 else if ( v < 251 ) |
87 { | 87 { |
88 if ( p + 1 > limit ) | 88 if ( p + 1 > limit ) |
89 goto Bad; | 89 goto Bad; |
90 | 90 |
91 val = ( v - 247 ) * 256 + p[0] + 108; | 91 val = ( v - 247 ) * 256 + p[0] + 108; |
92 p++; | 92 p++; |
93 } | 93 } |
94 else | 94 else |
95 { | 95 { |
96 if ( p + 1 > limit ) | 96 if ( p + 1 > limit ) |
97 goto Bad; | 97 goto Bad; |
98 | 98 |
99 val = -( v - 251 ) * 256 - p[0] - 108; | 99 val = -( v - 251 ) * 256 - p[0] - 108; |
100 p++; | 100 p++; |
101 } | 101 } |
102 | 102 |
103 Exit: | 103 Exit: |
104 return val; | 104 return val; |
105 | 105 |
106 Bad: | 106 Bad: |
107 val = 0; | 107 val = 0; |
| 108 FT_TRACE4(( "!!!END OF DATA:!!!" )); |
108 goto Exit; | 109 goto Exit; |
109 } | 110 } |
110 | 111 |
111 | 112 |
112 static const FT_Long power_tens[] = | 113 static const FT_Long power_tens[] = |
113 { | 114 { |
114 1L, | 115 1L, |
115 10L, | 116 10L, |
116 100L, | 117 100L, |
117 1000L, | 118 1000L, |
(...skipping 11 matching lines...) Expand all Loading... |
129 cff_parse_real( FT_Byte* start, | 130 cff_parse_real( FT_Byte* start, |
130 FT_Byte* limit, | 131 FT_Byte* limit, |
131 FT_Long power_ten, | 132 FT_Long power_ten, |
132 FT_Long* scaling ) | 133 FT_Long* scaling ) |
133 { | 134 { |
134 FT_Byte* p = start; | 135 FT_Byte* p = start; |
135 FT_UInt nib; | 136 FT_UInt nib; |
136 FT_UInt phase; | 137 FT_UInt phase; |
137 | 138 |
138 FT_Long result, number, exponent; | 139 FT_Long result, number, exponent; |
139 FT_Int sign = 0, exponent_sign = 0; | 140 FT_Int sign = 0, exponent_sign = 0, have_overflow = 0; |
140 FT_Long exponent_add, integer_length, fraction_length; | 141 FT_Long exponent_add, integer_length, fraction_length; |
141 | 142 |
142 | 143 |
143 if ( scaling ) | 144 if ( scaling ) |
144 *scaling = 0; | 145 *scaling = 0; |
145 | 146 |
146 result = 0; | 147 result = 0; |
147 | 148 |
148 number = 0; | 149 number = 0; |
149 exponent = 0; | 150 exponent = 0; |
150 | 151 |
151 exponent_add = 0; | 152 exponent_add = 0; |
152 integer_length = 0; | 153 integer_length = 0; |
153 fraction_length = 0; | 154 fraction_length = 0; |
154 | 155 |
155 /* First of all, read the integer part. */ | 156 /* First of all, read the integer part. */ |
156 phase = 4; | 157 phase = 4; |
157 | 158 |
158 for (;;) | 159 for (;;) |
159 { | 160 { |
160 /* If we entered this iteration with phase == 4, we need to */ | 161 /* If we entered this iteration with phase == 4, we need to */ |
161 /* read a new byte. This also skips past the initial 0x1E. */ | 162 /* read a new byte. This also skips past the initial 0x1E. */ |
162 if ( phase ) | 163 if ( phase ) |
163 { | 164 { |
164 p++; | 165 p++; |
165 | 166 |
166 /* Make sure we don't read past the end. */ | 167 /* Make sure we don't read past the end. */ |
167 if ( p >= limit ) | 168 if ( p >= limit ) |
168 goto Exit; | 169 goto Bad; |
169 } | 170 } |
170 | 171 |
171 /* Get the nibble. */ | 172 /* Get the nibble. */ |
172 nib = ( p[0] >> phase ) & 0xF; | 173 nib = ( p[0] >> phase ) & 0xF; |
173 phase = 4 - phase; | 174 phase = 4 - phase; |
174 | 175 |
175 if ( nib == 0xE ) | 176 if ( nib == 0xE ) |
176 sign = 1; | 177 sign = 1; |
177 else if ( nib > 9 ) | 178 else if ( nib > 9 ) |
178 break; | 179 break; |
(...skipping 16 matching lines...) Expand all Loading... |
195 for (;;) | 196 for (;;) |
196 { | 197 { |
197 /* If we entered this iteration with phase == 4, we need */ | 198 /* If we entered this iteration with phase == 4, we need */ |
198 /* to read a new byte. */ | 199 /* to read a new byte. */ |
199 if ( phase ) | 200 if ( phase ) |
200 { | 201 { |
201 p++; | 202 p++; |
202 | 203 |
203 /* Make sure we don't read past the end. */ | 204 /* Make sure we don't read past the end. */ |
204 if ( p >= limit ) | 205 if ( p >= limit ) |
205 goto Exit; | 206 goto Bad; |
206 } | 207 } |
207 | 208 |
208 /* Get the nibble. */ | 209 /* Get the nibble. */ |
209 nib = ( p[0] >> phase ) & 0xF; | 210 nib = ( p[0] >> phase ) & 0xF; |
210 phase = 4 - phase; | 211 phase = 4 - phase; |
211 if ( nib >= 10 ) | 212 if ( nib >= 10 ) |
212 break; | 213 break; |
213 | 214 |
214 /* Skip leading zeros if possible. */ | 215 /* Skip leading zeros if possible. */ |
215 if ( !nib && !number ) | 216 if ( !nib && !number ) |
(...skipping 18 matching lines...) Expand all Loading... |
234 for (;;) | 235 for (;;) |
235 { | 236 { |
236 /* If we entered this iteration with phase == 4, */ | 237 /* If we entered this iteration with phase == 4, */ |
237 /* we need to read a new byte. */ | 238 /* we need to read a new byte. */ |
238 if ( phase ) | 239 if ( phase ) |
239 { | 240 { |
240 p++; | 241 p++; |
241 | 242 |
242 /* Make sure we don't read past the end. */ | 243 /* Make sure we don't read past the end. */ |
243 if ( p >= limit ) | 244 if ( p >= limit ) |
244 goto Exit; | 245 goto Bad; |
245 } | 246 } |
246 | 247 |
247 /* Get the nibble. */ | 248 /* Get the nibble. */ |
248 nib = ( p[0] >> phase ) & 0xF; | 249 nib = ( p[0] >> phase ) & 0xF; |
249 phase = 4 - phase; | 250 phase = 4 - phase; |
250 if ( nib >= 10 ) | 251 if ( nib >= 10 ) |
251 break; | 252 break; |
252 | 253 |
253 exponent = exponent * 10 + nib; | |
254 | |
255 /* Arbitrarily limit exponent. */ | 254 /* Arbitrarily limit exponent. */ |
256 if ( exponent > 1000 ) | 255 if ( exponent > 1000 ) |
257 goto Exit; | 256 have_overflow = 1; |
| 257 else |
| 258 exponent = exponent * 10 + nib; |
258 } | 259 } |
259 | 260 |
260 if ( exponent_sign ) | 261 if ( exponent_sign ) |
261 exponent = -exponent; | 262 exponent = -exponent; |
262 } | 263 } |
263 | 264 |
| 265 if ( !number ) |
| 266 goto Exit; |
| 267 |
| 268 if ( have_overflow ) |
| 269 { |
| 270 if ( exponent_sign ) |
| 271 goto Underflow; |
| 272 else |
| 273 goto Overflow; |
| 274 } |
| 275 |
264 /* We don't check `power_ten' and `exponent_add'. */ | 276 /* We don't check `power_ten' and `exponent_add'. */ |
265 exponent += power_ten + exponent_add; | 277 exponent += power_ten + exponent_add; |
266 | 278 |
267 if ( scaling ) | 279 if ( scaling ) |
268 { | 280 { |
269 /* Only use `fraction_length'. */ | 281 /* Only use `fraction_length'. */ |
270 fraction_length += integer_length; | 282 fraction_length += integer_length; |
271 exponent += integer_length; | 283 exponent += integer_length; |
272 | 284 |
273 if ( fraction_length <= 5 ) | 285 if ( fraction_length <= 5 ) |
274 { | 286 { |
275 if ( number > 0x7FFFL ) | 287 if ( number > 0x7FFFL ) |
276 { | 288 { |
277 result = FT_DivFix( number, 10 ); | 289 result = FT_DivFix( number, 10 ); |
278 *scaling = exponent - fraction_length + 1; | 290 *scaling = exponent - fraction_length + 1; |
279 } | 291 } |
280 else | 292 else |
281 { | 293 { |
282 if ( exponent > 0 ) | 294 if ( exponent > 0 ) |
283 { | 295 { |
284 FT_Long new_fraction_length, shift; | 296 FT_Long new_fraction_length, shift; |
285 | 297 |
286 | 298 |
287 /* Make `scaling' as small as possible. */ | 299 /* Make `scaling' as small as possible. */ |
288 new_fraction_length = FT_MIN( exponent, 5 ); | 300 new_fraction_length = FT_MIN( exponent, 5 ); |
289 exponent -= new_fraction_length; | |
290 shift = new_fraction_length - fraction_length; | 301 shift = new_fraction_length - fraction_length; |
291 | 302 |
292 number *= power_tens[shift]; | 303 if ( shift > 0 ) |
293 if ( number > 0x7FFFL ) | |
294 { | 304 { |
295 number /= 10; | 305 exponent -= new_fraction_length; |
296 exponent += 1; | 306 number *= power_tens[shift]; |
| 307 if ( number > 0x7FFFL ) |
| 308 { |
| 309 number /= 10; |
| 310 exponent += 1; |
| 311 } |
297 } | 312 } |
| 313 else |
| 314 exponent -= fraction_length; |
298 } | 315 } |
299 else | 316 else |
300 exponent -= fraction_length; | 317 exponent -= fraction_length; |
301 | 318 |
302 result = number << 16; | 319 result = (FT_Long)( (FT_ULong)number << 16 ); |
303 *scaling = exponent; | 320 *scaling = exponent; |
304 } | 321 } |
305 } | 322 } |
306 else | 323 else |
307 { | 324 { |
308 if ( ( number / power_tens[fraction_length - 5] ) > 0x7FFFL ) | 325 if ( ( number / power_tens[fraction_length - 5] ) > 0x7FFFL ) |
309 { | 326 { |
310 result = FT_DivFix( number, power_tens[fraction_length - 4] ); | 327 result = FT_DivFix( number, power_tens[fraction_length - 4] ); |
311 *scaling = exponent - 4; | 328 *scaling = exponent - 4; |
312 } | 329 } |
313 else | 330 else |
314 { | 331 { |
315 result = FT_DivFix( number, power_tens[fraction_length - 5] ); | 332 result = FT_DivFix( number, power_tens[fraction_length - 5] ); |
316 *scaling = exponent - 5; | 333 *scaling = exponent - 5; |
317 } | 334 } |
318 } | 335 } |
319 } | 336 } |
320 else | 337 else |
321 { | 338 { |
322 integer_length += exponent; | 339 integer_length += exponent; |
323 fraction_length -= exponent; | 340 fraction_length -= exponent; |
324 | 341 |
325 /* Check for overflow and underflow. */ | 342 if ( integer_length > 5 ) |
326 if ( FT_ABS( integer_length ) > 5 ) | 343 goto Overflow; |
327 goto Exit; | 344 if ( integer_length < -5 ) |
| 345 goto Underflow; |
328 | 346 |
329 /* Remove non-significant digits. */ | 347 /* Remove non-significant digits. */ |
330 if ( integer_length < 0 ) | 348 if ( integer_length < 0 ) |
331 { | 349 { |
332 number /= power_tens[-integer_length]; | 350 number /= power_tens[-integer_length]; |
333 fraction_length += integer_length; | 351 fraction_length += integer_length; |
334 } | 352 } |
335 | 353 |
336 /* this can only happen if exponent was non-zero */ | 354 /* this can only happen if exponent was non-zero */ |
337 if ( fraction_length == 10 ) | 355 if ( fraction_length == 10 ) |
338 { | 356 { |
339 number /= 10; | 357 number /= 10; |
340 fraction_length -= 1; | 358 fraction_length -= 1; |
341 } | 359 } |
342 | 360 |
343 /* Convert into 16.16 format. */ | 361 /* Convert into 16.16 format. */ |
344 if ( fraction_length > 0 ) | 362 if ( fraction_length > 0 ) |
345 { | 363 { |
346 if ( ( number / power_tens[fraction_length] ) > 0x7FFFL ) | 364 if ( ( number / power_tens[fraction_length] ) > 0x7FFFL ) |
347 goto Exit; | 365 goto Exit; |
348 | 366 |
349 result = FT_DivFix( number, power_tens[fraction_length] ); | 367 result = FT_DivFix( number, power_tens[fraction_length] ); |
350 } | 368 } |
351 else | 369 else |
352 { | 370 { |
353 number *= power_tens[-fraction_length]; | 371 number *= power_tens[-fraction_length]; |
354 | 372 |
355 if ( number > 0x7FFFL ) | 373 if ( number > 0x7FFFL ) |
356 goto Exit; | 374 goto Overflow; |
357 | 375 |
358 result = number << 16; | 376 result = (FT_Long)( (FT_ULong)number << 16 ); |
359 } | 377 } |
360 } | 378 } |
361 | 379 |
| 380 Exit: |
362 if ( sign ) | 381 if ( sign ) |
363 result = -result; | 382 result = -result; |
364 | 383 |
365 Exit: | |
366 return result; | 384 return result; |
| 385 |
| 386 Overflow: |
| 387 result = 0x7FFFFFFFL; |
| 388 FT_TRACE4(( "!!!OVERFLOW:!!!" )); |
| 389 goto Exit; |
| 390 |
| 391 Underflow: |
| 392 result = 0; |
| 393 FT_TRACE4(( "!!!UNDERFLOW:!!!" )); |
| 394 goto Exit; |
| 395 |
| 396 Bad: |
| 397 result = 0; |
| 398 FT_TRACE4(( "!!!END OF DATA:!!!" )); |
| 399 goto Exit; |
367 } | 400 } |
368 | 401 |
369 | 402 |
370 /* read a number, either integer or real */ | 403 /* read a number, either integer or real */ |
371 static FT_Long | 404 static FT_Long |
372 cff_parse_num( FT_Byte** d ) | 405 cff_parse_num( FT_Byte** d ) |
373 { | 406 { |
374 return **d == 30 ? ( cff_parse_real( d[0], d[1], 0, NULL ) >> 16 ) | 407 return **d == 30 ? ( cff_parse_real( d[0], d[1], 0, NULL ) >> 16 ) |
375 : cff_parse_integer( d[0], d[1] ); | 408 : cff_parse_integer( d[0], d[1] ); |
376 } | 409 } |
377 | 410 |
378 | 411 |
379 /* read a floating point number, either integer or real */ | 412 /* read a floating point number, either integer or real */ |
380 static FT_Fixed | 413 static FT_Fixed |
| 414 do_fixed( FT_Byte** d, |
| 415 FT_Long scaling ) |
| 416 { |
| 417 if ( **d == 30 ) |
| 418 return cff_parse_real( d[0], d[1], scaling, NULL ); |
| 419 else |
| 420 { |
| 421 FT_Long val = cff_parse_integer( d[0], d[1] ); |
| 422 |
| 423 |
| 424 if ( scaling ) |
| 425 val *= power_tens[scaling]; |
| 426 |
| 427 if ( val > 0x7FFF ) |
| 428 { |
| 429 val = 0x7FFFFFFFL; |
| 430 goto Overflow; |
| 431 } |
| 432 else if ( val < -0x7FFF ) |
| 433 { |
| 434 val = -0x7FFFFFFFL; |
| 435 goto Overflow; |
| 436 } |
| 437 |
| 438 return (FT_Long)( (FT_ULong)val << 16 ); |
| 439 |
| 440 Overflow: |
| 441 FT_TRACE4(( "!!!OVERFLOW:!!!" )); |
| 442 return val; |
| 443 } |
| 444 } |
| 445 |
| 446 |
| 447 /* read a floating point number, either integer or real */ |
| 448 static FT_Fixed |
381 cff_parse_fixed( FT_Byte** d ) | 449 cff_parse_fixed( FT_Byte** d ) |
382 { | 450 { |
383 return **d == 30 ? cff_parse_real( d[0], d[1], 0, NULL ) | 451 return do_fixed( d, 0 ); |
384 : cff_parse_integer( d[0], d[1] ) << 16; | |
385 } | 452 } |
386 | 453 |
387 | 454 |
388 /* read a floating point number, either integer or real, */ | 455 /* read a floating point number, either integer or real, */ |
389 /* but return `10^scaling' times the number read in */ | 456 /* but return `10^scaling' times the number read in */ |
390 static FT_Fixed | 457 static FT_Fixed |
391 cff_parse_fixed_scaled( FT_Byte** d, | 458 cff_parse_fixed_scaled( FT_Byte** d, |
392 FT_Long scaling ) | 459 FT_Long scaling ) |
393 { | 460 { |
394 return **d == 30 ? cff_parse_real( d[0], d[1], scaling, NULL ) | 461 return do_fixed( d, scaling ); |
395 : ( cff_parse_integer( d[0], d[1] ) * | |
396 power_tens[scaling] ) << 16; | |
397 } | 462 } |
398 | 463 |
399 | 464 |
400 /* read a floating point number, either integer or real, */ | 465 /* read a floating point number, either integer or real, */ |
401 /* and return it as precise as possible -- `scaling' returns */ | 466 /* and return it as precise as possible -- `scaling' returns */ |
402 /* the scaling factor (as a power of 10) */ | 467 /* the scaling factor (as a power of 10) */ |
403 static FT_Fixed | 468 static FT_Fixed |
404 cff_parse_fixed_dynamic( FT_Byte** d, | 469 cff_parse_fixed_dynamic( FT_Byte** d, |
405 FT_Long* scaling ) | 470 FT_Long* scaling ) |
406 { | 471 { |
(...skipping 22 matching lines...) Expand all Loading... |
429 } | 494 } |
430 else | 495 else |
431 { | 496 { |
432 *scaling = integer_length - 5; | 497 *scaling = integer_length - 5; |
433 return FT_DivFix( number, power_tens[integer_length - 5] ); | 498 return FT_DivFix( number, power_tens[integer_length - 5] ); |
434 } | 499 } |
435 } | 500 } |
436 else | 501 else |
437 { | 502 { |
438 *scaling = 0; | 503 *scaling = 0; |
439 return number << 16; | 504 return (FT_Long)( (FT_ULong)number << 16 ); |
440 } | 505 } |
441 } | 506 } |
442 } | 507 } |
443 | 508 |
444 | 509 |
445 static FT_Error | 510 static FT_Error |
446 cff_parse_font_matrix( CFF_Parser parser ) | 511 cff_parse_font_matrix( CFF_Parser parser ) |
447 { | 512 { |
448 CFF_FontRecDict dict = (CFF_FontRecDict)parser->object; | 513 CFF_FontRecDict dict = (CFF_FontRecDict)parser->object; |
449 FT_Matrix* matrix = &dict->font_matrix; | 514 FT_Matrix* matrix = &dict->font_matrix; |
450 FT_Vector* offset = &dict->font_offset; | 515 FT_Vector* offset = &dict->font_offset; |
451 FT_ULong* upm = &dict->units_per_em; | 516 FT_ULong* upm = &dict->units_per_em; |
452 FT_Byte** data = parser->stack; | 517 FT_Byte** data = parser->stack; |
453 FT_Error error = CFF_Err_Stack_Underflow; | 518 FT_Error error = FT_ERR( Stack_Underflow ); |
454 | 519 |
455 | 520 |
456 if ( parser->top >= parser->stack + 6 ) | 521 if ( parser->top >= parser->stack + 6 ) |
457 { | 522 { |
458 FT_Long scaling; | 523 FT_Long scaling; |
459 | 524 |
460 | 525 |
461 error = CFF_Err_Ok; | 526 error = FT_Err_Ok; |
462 | 527 |
463 dict->has_font_matrix = TRUE; | 528 dict->has_font_matrix = TRUE; |
464 | 529 |
465 /* We expect a well-formed font matrix, this is, the matrix elements */ | 530 /* We expect a well-formed font matrix, this is, the matrix elements */ |
466 /* `xx' and `yy' are of approximately the same magnitude. To avoid */ | 531 /* `xx' and `yy' are of approximately the same magnitude. To avoid */ |
467 /* loss of precision, we use the magnitude of element `xx' to scale */ | 532 /* loss of precision, we use the magnitude of element `xx' to scale */ |
468 /* all other elements. The scaling factor is then contained in the */ | 533 /* all other elements. The scaling factor is then contained in the */ |
469 /* `units_per_em' value. */ | 534 /* `units_per_em' value. */ |
470 | 535 |
471 matrix->xx = cff_parse_fixed_dynamic( data++, &scaling ); | 536 matrix->xx = cff_parse_fixed_dynamic( data++, &scaling ); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
516 | 581 |
517 static FT_Error | 582 static FT_Error |
518 cff_parse_font_bbox( CFF_Parser parser ) | 583 cff_parse_font_bbox( CFF_Parser parser ) |
519 { | 584 { |
520 CFF_FontRecDict dict = (CFF_FontRecDict)parser->object; | 585 CFF_FontRecDict dict = (CFF_FontRecDict)parser->object; |
521 FT_BBox* bbox = &dict->font_bbox; | 586 FT_BBox* bbox = &dict->font_bbox; |
522 FT_Byte** data = parser->stack; | 587 FT_Byte** data = parser->stack; |
523 FT_Error error; | 588 FT_Error error; |
524 | 589 |
525 | 590 |
526 error = CFF_Err_Stack_Underflow; | 591 error = FT_ERR( Stack_Underflow ); |
527 | 592 |
528 if ( parser->top >= parser->stack + 4 ) | 593 if ( parser->top >= parser->stack + 4 ) |
529 { | 594 { |
530 bbox->xMin = FT_RoundFix( cff_parse_fixed( data++ ) ); | 595 bbox->xMin = FT_RoundFix( cff_parse_fixed( data++ ) ); |
531 bbox->yMin = FT_RoundFix( cff_parse_fixed( data++ ) ); | 596 bbox->yMin = FT_RoundFix( cff_parse_fixed( data++ ) ); |
532 bbox->xMax = FT_RoundFix( cff_parse_fixed( data++ ) ); | 597 bbox->xMax = FT_RoundFix( cff_parse_fixed( data++ ) ); |
533 bbox->yMax = FT_RoundFix( cff_parse_fixed( data ) ); | 598 bbox->yMax = FT_RoundFix( cff_parse_fixed( data ) ); |
534 error = CFF_Err_Ok; | 599 error = FT_Err_Ok; |
535 | 600 |
536 FT_TRACE4(( " [%d %d %d %d]\n", | 601 FT_TRACE4(( " [%d %d %d %d]\n", |
537 bbox->xMin / 65536, | 602 bbox->xMin / 65536, |
538 bbox->yMin / 65536, | 603 bbox->yMin / 65536, |
539 bbox->xMax / 65536, | 604 bbox->xMax / 65536, |
540 bbox->yMax / 65536 )); | 605 bbox->yMax / 65536 )); |
541 } | 606 } |
542 | 607 |
543 return error; | 608 return error; |
544 } | 609 } |
545 | 610 |
546 | 611 |
547 static FT_Error | 612 static FT_Error |
548 cff_parse_private_dict( CFF_Parser parser ) | 613 cff_parse_private_dict( CFF_Parser parser ) |
549 { | 614 { |
550 CFF_FontRecDict dict = (CFF_FontRecDict)parser->object; | 615 CFF_FontRecDict dict = (CFF_FontRecDict)parser->object; |
551 FT_Byte** data = parser->stack; | 616 FT_Byte** data = parser->stack; |
552 FT_Error error; | 617 FT_Error error; |
553 | 618 |
554 | 619 |
555 error = CFF_Err_Stack_Underflow; | 620 error = FT_ERR( Stack_Underflow ); |
556 | 621 |
557 if ( parser->top >= parser->stack + 2 ) | 622 if ( parser->top >= parser->stack + 2 ) |
558 { | 623 { |
559 dict->private_size = cff_parse_num( data++ ); | 624 dict->private_size = cff_parse_num( data++ ); |
560 dict->private_offset = cff_parse_num( data ); | 625 dict->private_offset = cff_parse_num( data ); |
561 FT_TRACE4(( " %lu %lu\n", | 626 FT_TRACE4(( " %lu %lu\n", |
562 dict->private_size, dict->private_offset )); | 627 dict->private_size, dict->private_offset )); |
563 | 628 |
564 error = CFF_Err_Ok; | 629 error = FT_Err_Ok; |
565 } | 630 } |
566 | 631 |
567 return error; | 632 return error; |
568 } | 633 } |
569 | 634 |
570 | 635 |
571 static FT_Error | 636 static FT_Error |
572 cff_parse_cid_ros( CFF_Parser parser ) | 637 cff_parse_cid_ros( CFF_Parser parser ) |
573 { | 638 { |
574 CFF_FontRecDict dict = (CFF_FontRecDict)parser->object; | 639 CFF_FontRecDict dict = (CFF_FontRecDict)parser->object; |
575 FT_Byte** data = parser->stack; | 640 FT_Byte** data = parser->stack; |
576 FT_Error error; | 641 FT_Error error; |
577 | 642 |
578 | 643 |
579 error = CFF_Err_Stack_Underflow; | 644 error = FT_ERR( Stack_Underflow ); |
580 | 645 |
581 if ( parser->top >= parser->stack + 3 ) | 646 if ( parser->top >= parser->stack + 3 ) |
582 { | 647 { |
583 dict->cid_registry = (FT_UInt)cff_parse_num( data++ ); | 648 dict->cid_registry = (FT_UInt)cff_parse_num( data++ ); |
584 dict->cid_ordering = (FT_UInt)cff_parse_num( data++ ); | 649 dict->cid_ordering = (FT_UInt)cff_parse_num( data++ ); |
585 if ( **data == 30 ) | 650 if ( **data == 30 ) |
586 FT_TRACE1(( "cff_parse_cid_ros: real supplement is rounded\n" )); | 651 FT_TRACE1(( "cff_parse_cid_ros: real supplement is rounded\n" )); |
587 dict->cid_supplement = cff_parse_num( data ); | 652 dict->cid_supplement = cff_parse_num( data ); |
588 if ( dict->cid_supplement < 0 ) | 653 if ( dict->cid_supplement < 0 ) |
589 FT_TRACE1(( "cff_parse_cid_ros: negative supplement %d is found\n", | 654 FT_TRACE1(( "cff_parse_cid_ros: negative supplement %d is found\n", |
590 dict->cid_supplement )); | 655 dict->cid_supplement )); |
591 error = CFF_Err_Ok; | 656 error = FT_Err_Ok; |
592 | 657 |
593 FT_TRACE4(( " %d %d %d\n", | 658 FT_TRACE4(( " %d %d %d\n", |
594 dict->cid_registry, | 659 dict->cid_registry, |
595 dict->cid_ordering, | 660 dict->cid_ordering, |
596 dict->cid_supplement )); | 661 dict->cid_supplement )); |
597 } | 662 } |
598 | 663 |
599 return error; | 664 return error; |
600 } | 665 } |
601 | 666 |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
723 | 788 |
724 if ( clazz ) | 789 if ( clazz ) |
725 FT_FREE( clazz ); | 790 FT_FREE( clazz ); |
726 } | 791 } |
727 | 792 |
728 | 793 |
729 FT_Error | 794 FT_Error |
730 FT_Create_Class_cff_field_handlers( FT_Library library, | 795 FT_Create_Class_cff_field_handlers( FT_Library library, |
731 CFF_Field_Handler** output_class ) | 796 CFF_Field_Handler** output_class ) |
732 { | 797 { |
733 CFF_Field_Handler* clazz; | 798 CFF_Field_Handler* clazz = NULL; |
734 FT_Error error; | 799 FT_Error error; |
735 FT_Memory memory = library->memory; | 800 FT_Memory memory = library->memory; |
736 | 801 |
737 int i = 0; | 802 int i = 0; |
738 | 803 |
739 | 804 |
740 #undef CFF_FIELD | 805 #undef CFF_FIELD |
741 #define CFF_FIELD( code, name, id, kind ) i++; | 806 #define CFF_FIELD( code, name, id, kind ) i++; |
742 #undef CFF_FIELD_DELTA | 807 #undef CFF_FIELD_DELTA |
743 #define CFF_FIELD_DELTA( code, name, max, id ) i++; | 808 #define CFF_FIELD_DELTA( code, name, max, id ) i++; |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
850 clazz[i].array_max = 0; | 915 clazz[i].array_max = 0; |
851 clazz[i].count_offset = 0; | 916 clazz[i].count_offset = 0; |
852 clazz[i].id = 0; | 917 clazz[i].id = 0; |
853 | 918 |
854 | 919 |
855 #endif /* FT_DEBUG_LEVEL_TRACE */ | 920 #endif /* FT_DEBUG_LEVEL_TRACE */ |
856 | 921 |
857 | 922 |
858 *output_class = clazz; | 923 *output_class = clazz; |
859 | 924 |
860 return CFF_Err_Ok; | 925 return FT_Err_Ok; |
861 } | 926 } |
862 | 927 |
863 | 928 |
864 #endif /* FT_CONFIG_OPTION_PIC */ | 929 #endif /* FT_CONFIG_OPTION_PIC */ |
865 | 930 |
866 | 931 |
867 FT_LOCAL_DEF( FT_Error ) | 932 FT_LOCAL_DEF( FT_Error ) |
868 cff_parser_run( CFF_Parser parser, | 933 cff_parser_run( CFF_Parser parser, |
869 FT_Byte* start, | 934 FT_Byte* start, |
870 FT_Byte* limit ) | 935 FT_Byte* limit ) |
871 { | 936 { |
872 FT_Byte* p = start; | 937 FT_Byte* p = start; |
873 FT_Error error = CFF_Err_Ok; | 938 FT_Error error = FT_Err_Ok; |
874 FT_Library library = parser->library; | 939 FT_Library library = parser->library; |
875 FT_UNUSED( library ); | 940 FT_UNUSED( library ); |
876 | 941 |
877 | 942 |
878 parser->top = parser->stack; | 943 parser->top = parser->stack; |
879 parser->start = start; | 944 parser->start = start; |
880 parser->limit = limit; | 945 parser->limit = limit; |
881 parser->cursor = start; | 946 parser->cursor = start; |
882 | 947 |
883 while ( p < limit ) | 948 while ( p < limit ) |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
937 { | 1002 { |
938 /* two byte operator */ | 1003 /* two byte operator */ |
939 p++; | 1004 p++; |
940 if ( p >= limit ) | 1005 if ( p >= limit ) |
941 goto Syntax_Error; | 1006 goto Syntax_Error; |
942 | 1007 |
943 code = 0x100 | p[0]; | 1008 code = 0x100 | p[0]; |
944 } | 1009 } |
945 code = code | parser->object_code; | 1010 code = code | parser->object_code; |
946 | 1011 |
947 for ( field = FT_CFF_FIELD_HANDLERS_GET; field->kind; field++ ) | 1012 for ( field = CFF_FIELD_HANDLERS_GET; field->kind; field++ ) |
948 { | 1013 { |
949 if ( field->code == (FT_Int)code ) | 1014 if ( field->code == (FT_Int)code ) |
950 { | 1015 { |
951 /* we found our field's handler; read it */ | 1016 /* we found our field's handler; read it */ |
952 FT_Long val; | 1017 FT_Long val; |
953 FT_Byte* q = (FT_Byte*)parser->object + field->offset; | 1018 FT_Byte* q = (FT_Byte*)parser->object + field->offset; |
954 | 1019 |
955 | 1020 |
956 #ifdef FT_DEBUG_LEVEL_TRACE | 1021 #ifdef FT_DEBUG_LEVEL_TRACE |
957 FT_TRACE4(( " %s", field->id )); | 1022 FT_TRACE4(( " %s", field->id )); |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1089 /* clear stack */ | 1154 /* clear stack */ |
1090 parser->top = parser->stack; | 1155 parser->top = parser->stack; |
1091 } | 1156 } |
1092 p++; | 1157 p++; |
1093 } | 1158 } |
1094 | 1159 |
1095 Exit: | 1160 Exit: |
1096 return error; | 1161 return error; |
1097 | 1162 |
1098 Stack_Overflow: | 1163 Stack_Overflow: |
1099 error = CFF_Err_Invalid_Argument; | 1164 error = FT_THROW( Invalid_Argument ); |
1100 goto Exit; | 1165 goto Exit; |
1101 | 1166 |
1102 Stack_Underflow: | 1167 Stack_Underflow: |
1103 error = CFF_Err_Invalid_Argument; | 1168 error = FT_THROW( Invalid_Argument ); |
1104 goto Exit; | 1169 goto Exit; |
1105 | 1170 |
1106 Syntax_Error: | 1171 Syntax_Error: |
1107 error = CFF_Err_Invalid_Argument; | 1172 error = FT_THROW( Invalid_Argument ); |
1108 goto Exit; | 1173 goto Exit; |
1109 } | 1174 } |
1110 | 1175 |
1111 | 1176 |
1112 /* END */ | 1177 /* END */ |
OLD | NEW |