diff options
Diffstat (limited to 'src/psaux/t1decode.c')
-rw-r--r-- | src/psaux/t1decode.c | 165 |
1 files changed, 87 insertions, 78 deletions
diff --git a/src/psaux/t1decode.c b/src/psaux/t1decode.c index babf3ba..90874f0 100644 --- a/src/psaux/t1decode.c +++ b/src/psaux/t1decode.c @@ -4,8 +4,7 @@ /* */ /* PostScript Type 1 decoding routines (body). */ /* */ -/* Copyright 2000-2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 */ -/* 2010 by */ +/* Copyright 2000-2011 by */ /* David Turner, Robert Wilhelm, and Werner Lemberg. */ /* */ /* This file is part of the FreeType project, and may only be used, */ @@ -28,6 +27,8 @@ #include "psauxerr.h" +/* ensure proper sign extension */ +#define Fix2Int( f ) ( (FT_Int)(FT_Short)( (f) >> 16 ) ) /*************************************************************************/ /* */ @@ -373,15 +374,6 @@ #endif - /* we don't want to touch the source code -- use macro trick */ -#define start_point t1_builder_start_point -#define check_points t1_builder_check_points -#define add_point t1_builder_add_point -#define add_point1 t1_builder_add_point1 -#define add_contour t1_builder_add_contour -#define close_contour t1_builder_close_contour - - /* compute random seed from stack address of parameter */ seed = (FT_Fixed)( ( (FT_PtrDist)(char*)&seed ^ (FT_PtrDist)(char*)&decoder ^ @@ -405,7 +397,7 @@ FT_ASSERT( ( decoder->len_buildchar == 0 ) == ( decoder->buildchar == NULL ) ); - if ( decoder->len_buildchar > 0 ) + if ( decoder->buildchar && decoder->len_buildchar > 0 ) ft_memset( &decoder->buildchar[0], 0, sizeof( decoder->buildchar[0] ) * decoder->len_buildchar ); @@ -671,7 +663,7 @@ if ( large_int ) FT_TRACE4(( " %ld", value )); else - FT_TRACE4(( " %ld", (FT_Int32)( value >> 16 ) )); + FT_TRACE4(( " %ld", Fix2Int( value ) )); #endif *top++ = value; @@ -693,8 +685,8 @@ top -= 2; - subr_no = (FT_Int)( top[1] >> 16 ); - arg_cnt = (FT_Int)( top[0] >> 16 ); + subr_no = Fix2Int( top[1] ); + arg_cnt = Fix2Int( top[0] ); /***********************************************************/ /* */ @@ -733,14 +725,34 @@ switch ( subr_no ) { + case 0: /* end flex feature */ + if ( arg_cnt != 3 ) + goto Unexpected_OtherSubr; + + if ( decoder->flex_state == 0 || + decoder->num_flex_vectors != 7 ) + { + FT_ERROR(( "t1_decoder_parse_charstrings:" + " unexpected flex end\n" )); + goto Syntax_Error; + } + + /* the two `results' are popped by the following setcurrentpoint */ + top[0] = x; + top[1] = y; + known_othersubr_result_cnt = 2; + break; + case 1: /* start flex feature */ if ( arg_cnt != 0 ) goto Unexpected_OtherSubr; decoder->flex_state = 1; decoder->num_flex_vectors = 0; - if ( start_point( builder, x, y ) || - check_points( builder, 6 ) ) + if ( ( error = t1_builder_start_point( builder, x, y ) ) + != PSaux_Err_Ok || + ( error = t1_builder_check_points( builder, 6 ) ) + != PSaux_Err_Ok ) goto Fail; break; @@ -757,31 +769,13 @@ /* point without adding any point to the outline */ idx = decoder->num_flex_vectors++; if ( idx > 0 && idx < 7 ) - add_point( builder, - x, - y, - (FT_Byte)( idx == 3 || idx == 6 ) ); + t1_builder_add_point( builder, + x, + y, + (FT_Byte)( idx == 3 || idx == 6 ) ); } break; - case 0: /* end flex feature */ - if ( arg_cnt != 3 ) - goto Unexpected_OtherSubr; - - if ( decoder->flex_state == 0 || - decoder->num_flex_vectors != 7 ) - { - FT_ERROR(( "t1_decoder_parse_charstrings:" - " unexpected flex end\n" )); - goto Syntax_Error; - } - - /* the two `results' are popped by the following setcurrentpoint */ - top[0] = x; - top[1] = y; - known_othersubr_result_cnt = 2; - break; - case 3: /* change hints */ if ( arg_cnt != 1 ) goto Unexpected_OtherSubr; @@ -825,17 +819,18 @@ goto Syntax_Error; } - /* we want to compute: */ + /* We want to compute */ + /* */ + /* a0*w0 + a1*w1 + ... + ak*wk */ /* */ - /* a0*w0 + a1*w1 + ... + ak*wk */ + /* but we only have a0, a1-a0, a2-a0, ..., ak-a0. */ /* */ - /* but we only have the a0, a1-a0, a2-a0, .. ak-a0 */ - /* however, given that w0 + w1 + ... + wk == 1, we can */ - /* rewrite it easily as: */ + /* However, given that w0 + w1 + ... + wk == 1, we can */ + /* rewrite it easily as */ /* */ - /* a0 + (a1-a0)*w1 + (a2-a0)*w2 + .. + (ak-a0)*wk */ + /* a0 + (a1-a0)*w1 + (a2-a0)*w2 + ... + (ak-a0)*wk */ /* */ - /* where k == num_designs-1 */ + /* where k == num_designs-1. */ /* */ /* I guess that's why it's written in this `compact' */ /* form. */ @@ -869,7 +864,7 @@ if ( arg_cnt != 1 || blend == NULL ) goto Unexpected_OtherSubr; - idx = (FT_Int)( top[0] >> 16 ); + idx = Fix2Int( top[0] ); if ( idx < 0 || idx + blend->num_designs > decoder->len_buildchar ) @@ -937,7 +932,7 @@ if ( arg_cnt != 2 || blend == NULL ) goto Unexpected_OtherSubr; - idx = (FT_Int)( top[1] >> 16 ); + idx = Fix2Int( top[1] ); if ( idx < 0 || (FT_UInt) idx >= decoder->len_buildchar ) goto Unexpected_OtherSubr; @@ -958,7 +953,7 @@ if ( arg_cnt != 1 || blend == NULL ) goto Unexpected_OtherSubr; - idx = (FT_Int)( top[0] >> 16 ); + idx = Fix2Int( top[0] ); if ( idx < 0 || (FT_UInt) idx >= decoder->len_buildchar ) goto Unexpected_OtherSubr; @@ -1016,11 +1011,15 @@ break; default: - FT_ERROR(( "t1_decoder_parse_charstrings:" - " unknown othersubr [%d %d], wish me luck\n", - arg_cnt, subr_no )); - unknown_othersubr_result_cnt = arg_cnt; - break; + if ( arg_cnt >= 0 && subr_no >= 0 ) + { + FT_ERROR(( "t1_decoder_parse_charstrings:" + " unknown othersubr [%d %d], wish me luck\n", + arg_cnt, subr_no )); + unknown_othersubr_result_cnt = arg_cnt; + break; + } + /* fall through */ Unexpected_OtherSubr: FT_ERROR(( "t1_decoder_parse_charstrings:" @@ -1077,7 +1076,7 @@ case op_endchar: FT_TRACE4(( " endchar\n" )); - close_contour( builder ); + t1_builder_close_contour( builder ); /* close hints recording session */ if ( hinter ) @@ -1146,8 +1145,8 @@ top[0], top[1], top[2], - (FT_Int)( top[3] >> 16 ), - (FT_Int)( top[4] >> 16 ) ); + Fix2Int( top[3] ), + Fix2Int( top[4] ) ); case op_sbw: FT_TRACE4(( " sbw" )); @@ -1176,7 +1175,7 @@ /* if there is no path, `closepath' is a no-op */ if ( builder->parse_state == T1_Parse_Have_Path || builder->parse_state == T1_Parse_Have_Moveto ) - close_contour( builder ); + t1_builder_close_contour( builder ); builder->parse_state = T1_Parse_Have_Width; break; @@ -1184,7 +1183,8 @@ case op_hlineto: FT_TRACE4(( " hlineto" )); - if ( start_point( builder, x, y ) ) + if ( ( error = t1_builder_start_point( builder, x, y ) ) + != PSaux_Err_Ok ) goto Fail; x += top[0]; @@ -1205,30 +1205,34 @@ case op_hvcurveto: FT_TRACE4(( " hvcurveto" )); - if ( start_point( builder, x, y ) || - check_points( builder, 3 ) ) + if ( ( error = t1_builder_start_point( builder, x, y ) ) + != PSaux_Err_Ok || + ( error = t1_builder_check_points( builder, 3 ) ) + != PSaux_Err_Ok ) goto Fail; x += top[0]; - add_point( builder, x, y, 0 ); + t1_builder_add_point( builder, x, y, 0 ); x += top[1]; y += top[2]; - add_point( builder, x, y, 0 ); + t1_builder_add_point( builder, x, y, 0 ); y += top[3]; - add_point( builder, x, y, 1 ); + t1_builder_add_point( builder, x, y, 1 ); break; case op_rlineto: FT_TRACE4(( " rlineto" )); - if ( start_point( builder, x, y ) ) + if ( ( error = t1_builder_start_point( builder, x, y ) ) + != PSaux_Err_Ok ) goto Fail; x += top[0]; y += top[1]; Add_Line: - if ( add_point1( builder, x, y ) ) + if ( ( error = t1_builder_add_point1( builder, x, y ) ) + != PSaux_Err_Ok ) goto Fail; break; @@ -1248,43 +1252,48 @@ case op_rrcurveto: FT_TRACE4(( " rrcurveto" )); - if ( start_point( builder, x, y ) || - check_points( builder, 3 ) ) + if ( ( error = t1_builder_start_point( builder, x, y ) ) + != PSaux_Err_Ok || + ( error = t1_builder_check_points( builder, 3 ) ) + != PSaux_Err_Ok ) goto Fail; x += top[0]; y += top[1]; - add_point( builder, x, y, 0 ); + t1_builder_add_point( builder, x, y, 0 ); x += top[2]; y += top[3]; - add_point( builder, x, y, 0 ); + t1_builder_add_point( builder, x, y, 0 ); x += top[4]; y += top[5]; - add_point( builder, x, y, 1 ); + t1_builder_add_point( builder, x, y, 1 ); break; case op_vhcurveto: FT_TRACE4(( " vhcurveto" )); - if ( start_point( builder, x, y ) || - check_points( builder, 3 ) ) + if ( ( error = t1_builder_start_point( builder, x, y ) ) + != PSaux_Err_Ok || + ( error = t1_builder_check_points( builder, 3 ) ) + != PSaux_Err_Ok ) goto Fail; y += top[0]; - add_point( builder, x, y, 0 ); + t1_builder_add_point( builder, x, y, 0 ); x += top[1]; y += top[2]; - add_point( builder, x, y, 0 ); + t1_builder_add_point( builder, x, y, 0 ); x += top[3]; - add_point( builder, x, y, 1 ); + t1_builder_add_point( builder, x, y, 1 ); break; case op_vlineto: FT_TRACE4(( " vlineto" )); - if ( start_point( builder, x, y ) ) + if ( ( error = t1_builder_start_point( builder, x, y ) ) + != PSaux_Err_Ok ) goto Fail; y += top[0]; @@ -1321,7 +1330,7 @@ FT_TRACE4(( " callsubr" )); - idx = (FT_Int)( top[0] >> 16 ); + idx = Fix2Int( top[0] ); if ( idx < 0 || idx >= (FT_Int)decoder->num_subrs ) { FT_ERROR(( "t1_decoder_parse_charstrings:" |