21 #include FT_INTERNAL_STREAM_H 22 #include FT_INTERNAL_DEBUG_H 35 #define FT_COMPONENT trace_cffparse 46 parser->top = parser->stack;
47 parser->object_code =
code;
91 val = ( v - 247 ) * 256 + p[0] + 108;
99 val = -( v - 251 ) * 256 - p[0] - 108;
113 static const FT_Long power_tens[] =
140 FT_Int sign = 0, exponent_sign = 0, have_overflow = 0;
141 FT_Long exponent_add, integer_length, fraction_length;
173 nib = ( p[0] >> phase ) & 0xF;
183 if ( number >= 0xCCCCCCCL )
186 else if ( nib || number )
189 number = number * 10 + nib;
210 nib = ( p[0] >> phase ) & 0xF;
216 if ( !nib && !number )
219 else if ( number < 0xCCCCCCCL && fraction_length < 9 )
222 number = number * 10 + nib;
249 nib = ( p[0] >> phase ) & 0xF;
255 if ( exponent > 1000 )
258 exponent = exponent * 10 + nib;
277 exponent += power_ten + exponent_add;
282 fraction_length += integer_length;
283 exponent += integer_length;
285 if ( fraction_length <= 5 )
287 if ( number > 0x7FFFL )
290 *scaling = exponent - fraction_length + 1;
296 FT_Long new_fraction_length, shift;
300 new_fraction_length =
FT_MIN( exponent, 5 );
301 shift = new_fraction_length - fraction_length;
305 exponent -= new_fraction_length;
306 number *= power_tens[shift];
307 if ( number > 0x7FFFL )
314 exponent -= fraction_length;
317 exponent -= fraction_length;
325 if ( ( number / power_tens[fraction_length - 5] ) > 0x7FFFL )
327 result =
FT_DivFix( number, power_tens[fraction_length - 4] );
328 *scaling = exponent - 4;
332 result =
FT_DivFix( number, power_tens[fraction_length - 5] );
333 *scaling = exponent - 5;
342 if ( integer_length > 5 )
344 if ( integer_length < -5 )
348 if ( integer_length < 0 )
350 number /= power_tens[-integer_length];
351 fraction_length += integer_length;
355 if ( fraction_length == 10 )
358 fraction_length -= 1;
362 if ( fraction_length > 0 )
364 if ( ( number / power_tens[fraction_length] ) > 0x7FFFL )
367 result =
FT_DivFix( number, power_tens[fraction_length] );
371 number *= power_tens[-fraction_length];
373 if ( number > 0x7FFFL )
387 result = 0x7FFFFFFFL;
407 return **d == 30 ? ( cff_parse_real( d[0], d[1], 0,
NULL ) >> 16 )
408 : cff_parse_integer( d[0], d[1] );
418 return cff_parse_real( d[0], d[1], scaling,
NULL );
421 FT_Long val = cff_parse_integer( d[0], d[1] );
425 val *= power_tens[scaling];
432 else if ( val < -0x7FFF )
451 return do_fixed( d, 0 );
458 cff_parse_fixed_scaled(
FT_Byte** d,
461 return do_fixed( d, scaling );
469 cff_parse_fixed_dynamic(
FT_Byte** d,
475 return cff_parse_real( d[0], d[1], 0, scaling );
482 number = cff_parse_integer( d[0], d[1] );
484 if ( number > 0x7FFFL )
486 for ( integer_length = 5; integer_length < 10; integer_length++ )
487 if ( number < power_tens[integer_length] )
490 if ( ( number / power_tens[integer_length - 5] ) > 0x7FFFL )
492 *scaling = integer_length - 4;
493 return FT_DivFix( number, power_tens[integer_length - 4] );
497 *scaling = integer_length - 5;
498 return FT_DivFix( number, power_tens[integer_length - 5] );
521 if ( parser->
top >= parser->
stack + 6 )
536 matrix->xx = cff_parse_fixed_dynamic(
data++, &scaling );
540 if ( scaling < 0 || scaling > 9 )
545 " strange scaling value for xx element (%d),\n" 547 " using default matrix\n", scaling ));
560 matrix->yx = cff_parse_fixed_scaled(
data++, scaling );
561 matrix->xy = cff_parse_fixed_scaled(
data++, scaling );
562 matrix->yy = cff_parse_fixed_scaled(
data++, scaling );
563 offset->x = cff_parse_fixed_scaled(
data++, scaling );
564 offset->y = cff_parse_fixed_scaled(
data, scaling );
566 *upm = power_tens[scaling];
569 (
double)
matrix->xx / *upm / 65536,
570 (
double)
matrix->xy / *upm / 65536,
571 (
double)
matrix->yx / *upm / 65536,
572 (
double)
matrix->yy / *upm / 65536,
573 (
double)
offset->x / *upm / 65536,
574 (
double)
offset->y / *upm / 65536 ));
593 if ( parser->
top >= parser->
stack + 4 )
622 if ( parser->
top >= parser->
stack + 2 )
646 if ( parser->
top >= parser->
stack + 3 )
651 FT_TRACE1((
"cff_parse_cid_ros: real supplement is rounded\n" ));
654 FT_TRACE1((
"cff_parse_cid_ros: negative supplement %d is found\n",
668 #define CFF_FIELD_NUM( code, name, id ) \ 669 CFF_FIELD( code, name, id, cff_kind_num ) 670 #define CFF_FIELD_FIXED( code, name, id ) \ 671 CFF_FIELD( code, name, id, cff_kind_fixed ) 672 #define CFF_FIELD_FIXED_1000( code, name, id ) \ 673 CFF_FIELD( code, name, id, cff_kind_fixed_thousand ) 674 #define CFF_FIELD_STRING( code, name, id ) \ 675 CFF_FIELD( code, name, id, cff_kind_string ) 676 #define CFF_FIELD_BOOL( code, name, id ) \ 677 CFF_FIELD( code, name, id, cff_kind_bool ) 679 #define CFFCODE_TOPDICT 0x1000 680 #define CFFCODE_PRIVATE 0x2000 683 #ifndef FT_CONFIG_OPTION_PIC 687 #undef CFF_FIELD_DELTA 690 #ifndef FT_DEBUG_LEVEL_TRACE 693 #define CFF_FIELD_CALLBACK( code, name, id ) \ 698 cff_parse_ ## name, \ 702 #define CFF_FIELD( code, name, id, kind ) \ 706 FT_FIELD_OFFSET( name ), \ 707 FT_FIELD_SIZE( name ), \ 711 #define CFF_FIELD_DELTA( code, name, max, id ) \ 715 FT_FIELD_OFFSET( name ), \ 716 FT_FIELD_SIZE_DELTA( name ), \ 719 FT_FIELD_OFFSET( num_ ## name ) \ 727 { 0, 0, 0, 0, 0, 0, 0 }
735 #define CFF_FIELD_CALLBACK( code, name, id ) \ 740 cff_parse_ ## name, \ 745 #define CFF_FIELD( code, name, id, kind ) \ 749 FT_FIELD_OFFSET( name ), \ 750 FT_FIELD_SIZE( name ), \ 755 #define CFF_FIELD_DELTA( code, name, max, id ) \ 759 FT_FIELD_OFFSET( name ), \ 760 FT_FIELD_SIZE_DELTA( name ), \ 763 FT_FIELD_OFFSET( num_ ## name ), \ 772 { 0, 0, 0, 0, 0, 0, 0, 0 }
795 FT_Create_Class_cff_field_handlers(
FT_Library library,
806 #define CFF_FIELD( code, name, id, kind ) i++; 807 #undef CFF_FIELD_DELTA 808 #define CFF_FIELD_DELTA( code, name, max, id ) i++; 809 #undef CFF_FIELD_CALLBACK 810 #define CFF_FIELD_CALLBACK( code, name, id ) i++; 822 #ifndef FT_DEBUG_LEVEL_TRACE 825 #undef CFF_FIELD_CALLBACK 826 #define CFF_FIELD_CALLBACK( code_, name_, id_ ) \ 827 clazz[i].kind = cff_kind_callback; \ 828 clazz[i].code = code_ | CFFCODE; \ 829 clazz[i].offset = 0; \ 831 clazz[i].reader = cff_parse_ ## name_; \ 832 clazz[i].array_max = 0; \ 833 clazz[i].count_offset = 0; \ 837 #define CFF_FIELD( code_, name_, id_, kind_ ) \ 838 clazz[i].kind = kind_; \ 839 clazz[i].code = code_ | CFFCODE; \ 840 clazz[i].offset = FT_FIELD_OFFSET( name_ ); \ 841 clazz[i].size = FT_FIELD_SIZE( name_ ); \ 842 clazz[i].reader = 0; \ 843 clazz[i].array_max = 0; \ 844 clazz[i].count_offset = 0; \ 847 #undef CFF_FIELD_DELTA 848 #define CFF_FIELD_DELTA( code_, name_, max_, id_ ) \ 849 clazz[i].kind = cff_kind_delta; \ 850 clazz[i].code = code_ | CFFCODE; \ 851 clazz[i].offset = FT_FIELD_OFFSET( name_ ); \ 852 clazz[i].size = FT_FIELD_SIZE_DELTA( name_ ); \ 853 clazz[i].reader = 0; \ 854 clazz[i].array_max = max_; \ 855 clazz[i].count_offset = FT_FIELD_OFFSET( num_ ## name_ ); \ 872 #undef CFF_FIELD_CALLBACK 873 #define CFF_FIELD_CALLBACK( code_, name_, id_ ) \ 874 clazz[i].kind = cff_kind_callback; \ 875 clazz[i].code = code_ | CFFCODE; \ 876 clazz[i].offset = 0; \ 878 clazz[i].reader = cff_parse_ ## name_; \ 879 clazz[i].array_max = 0; \ 880 clazz[i].count_offset = 0; \ 885 #define CFF_FIELD( code_, name_, id_, kind_ ) \ 886 clazz[i].kind = kind_; \ 887 clazz[i].code = code_ | CFFCODE; \ 888 clazz[i].offset = FT_FIELD_OFFSET( name_ ); \ 889 clazz[i].size = FT_FIELD_SIZE( name_ ); \ 890 clazz[i].reader = 0; \ 891 clazz[i].array_max = 0; \ 892 clazz[i].count_offset = 0; \ 896 #undef CFF_FIELD_DELTA 897 #define CFF_FIELD_DELTA( code_, name_, max_, id_ ) \ 898 clazz[i].kind = cff_kind_delta; \ 899 clazz[i].code = code_ | CFFCODE; \ 900 clazz[i].offset = FT_FIELD_OFFSET( name_ ); \ 901 clazz[i].size = FT_FIELD_SIZE_DELTA( name_ ); \ 902 clazz[i].reader = 0; \ 903 clazz[i].array_max = max_; \ 904 clazz[i].count_offset = FT_FIELD_OFFSET( num_ ## name_ ); \ 923 *output_class = clazz;
953 if ( v >= 27 && v != 31 )
1008 code = 0x100 |
p[0];
1028 goto Stack_Underflow;
1030 switch ( field->
kind )
1035 val = cff_parse_num( parser->
stack );
1039 val = cff_parse_fixed( parser->
stack );
1043 val = cff_parse_fixed_scaled( parser->
stack, 3 );
1046 switch ( field->
size )
1064 #ifdef FT_DEBUG_LEVEL_TRACE 1065 switch ( field->
kind )
1068 FT_TRACE4((
" %s\n", val ?
"true" :
"false" ));
1080 FT_TRACE4((
" %f\n", (
double)val / 65536 ));
1084 FT_TRACE4((
" %f\n", (
double)val / 65536 / 1000 ));
1110 while ( num_args > 0 )
1112 val += cff_parse_num(
data++ );
1113 switch ( field->
size )
#define FT_ALLOC(ptr, size)
FT_Byte * stack[CFF_MAX_STACK_DEPTH+1]
FT_DivFix(FT_Long a, FT_Long b)
#define FT_MEM_ZERO(dest, count)
GLdouble GLdouble GLdouble GLdouble q
cff_parser_init(CFF_Parser parser, FT_UInt code, void *object, FT_Library library)
return FT_THROW(Missing_Property)
struct CFF_FontRecDictRec_ * CFF_FontRecDict
#define FT_TRACE1(varformat)
#define FT_ASSERT(condition)
#define FT_TRACE4(varformat)
#define CFF_MAX_STACK_DEPTH
#define CFF_FIELD_HANDLERS_GET
GLsizei GLsizei GLenum GLenum const GLvoid * data
cff_parser_run(CFF_Parser parser, FT_Byte *start, FT_Byte *limit)
#define FT_DEBUG_LEVEL_TRACE
typedefFT_BEGIN_HEADER struct FT_MemoryRec_ * FT_Memory
if(!abbox) return FT_THROW(Invalid_Argument)