diff --git a/src/psaux/cffdecode.c b/src/psaux/cffdecode.c index 4fbb9d1e5..6c4800652 100644 --- a/src/psaux/cffdecode.c +++ b/src/psaux/cffdecode.c @@ -4,7 +4,14 @@ /* */ /* PostScript CFF (Type 2) decoding routines (body). */ /* */ -/* Copyright notice here. */ +/* Copyright 2017 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ /* */ /***************************************************************************/ @@ -190,6 +197,7 @@ 2 /* setcurrentpoint */ }; + static FT_Error cff_operator_seac( CFF_Decoder* decoder, FT_Pos asb, @@ -201,7 +209,7 @@ FT_Error error; CFF_Builder* builder = &decoder->builder; FT_Int bchar_index, achar_index; - TT_Face face = decoder->builder.face; + TT_Face face = decoder->builder.face; FT_Vector left_bearing, advance; FT_Byte* charstring; FT_ULong charstring_len; @@ -342,7 +350,6 @@ return error; } - #endif /* CFF_CONFIG_OPTION_OLD_ENGINE */ @@ -401,8 +408,10 @@ { FT_UInt n; FT_UShort glyph_sid; + FT_Service_CFFLoad cffload; + /* CID-keyed fonts don't have glyph names */ if ( !cff->charset.sids ) return -1; @@ -414,14 +423,14 @@ #if 0 /* retrieve cffload from list of current modules */ FT_Service_CFFLoad cffload; + + + FT_FACE_FIND_GLOBAL_SERVICE( face, cffload, CFF_LOAD ); + if ( !cffload ) { - FT_FACE_FIND_GLOBAL_SERVICE( face, cffload, CFF_LOAD ); - if ( !cffload ) - { - FT_ERROR(( "cff_lookup_glyph_by_stdcharcode:" - " the `cffload' module is not available\n" )); - return FT_THROW( Unimplemented_Feature ); - } + FT_ERROR(( "cff_lookup_glyph_by_stdcharcode:" + " the `cffload' module is not available\n" )); + return FT_THROW( Unimplemented_Feature ); } #endif @@ -439,6 +448,7 @@ return -1; } + #ifdef CFF_CONFIG_OPTION_OLD_ENGINE /*************************************************************************/ @@ -483,7 +493,7 @@ FT_UShort num_axes = decoder->cff->top_font.font_dict.num_axes; - T2_Hints_Funcs hinter; + T2_Hints_Funcs hinter; /* set default width */ @@ -564,7 +574,7 @@ ( (FT_UInt32)ip[1] << 16 ) | ( (FT_UInt32)ip[2] << 8 ) | (FT_UInt32)ip[3] ); - ip += 4; + ip += 4; if ( charstring_type == 2 ) shift = 0; } @@ -630,119 +640,117 @@ op = cff_op_return; break; case 12: - { - if ( ip >= limit ) - goto Syntax_Error; - v = *ip++; + if ( ip >= limit ) + goto Syntax_Error; + v = *ip++; - switch ( v ) - { - case 0: - op = cff_op_dotsection; - break; - case 1: /* this is actually the Type1 vstem3 operator */ - op = cff_op_vstem; - break; - case 2: /* this is actually the Type1 hstem3 operator */ - op = cff_op_hstem; - break; - case 3: - op = cff_op_and; - break; - case 4: - op = cff_op_or; - break; - case 5: - op = cff_op_not; - break; - case 6: - op = cff_op_seac; - break; - case 7: - op = cff_op_sbw; - break; - case 8: - op = cff_op_store; - break; - case 9: - op = cff_op_abs; - break; - case 10: - op = cff_op_add; - break; - case 11: - op = cff_op_sub; - break; - case 12: - op = cff_op_div; - break; - case 13: - op = cff_op_load; - break; - case 14: - op = cff_op_neg; - break; - case 15: - op = cff_op_eq; - break; - case 16: - op = cff_op_callothersubr; - break; - case 17: - op = cff_op_pop; - break; - case 18: - op = cff_op_drop; - break; - case 20: - op = cff_op_put; - break; - case 21: - op = cff_op_get; - break; - case 22: - op = cff_op_ifelse; - break; - case 23: - op = cff_op_random; - break; - case 24: - op = cff_op_mul; - break; - case 26: - op = cff_op_sqrt; - break; - case 27: - op = cff_op_dup; - break; - case 28: - op = cff_op_exch; - break; - case 29: - op = cff_op_index; - break; - case 30: - op = cff_op_roll; - break; - case 33: - op = cff_op_setcurrentpoint; - break; - case 34: - op = cff_op_hflex; - break; - case 35: - op = cff_op_flex; - break; - case 36: - op = cff_op_hflex1; - break; - case 37: - op = cff_op_flex1; - break; - default: - FT_TRACE4(( " unknown op (12, %d)\n", v )); - break; - } + switch ( v ) + { + case 0: + op = cff_op_dotsection; + break; + case 1: /* this is actually the Type1 vstem3 operator */ + op = cff_op_vstem; + break; + case 2: /* this is actually the Type1 hstem3 operator */ + op = cff_op_hstem; + break; + case 3: + op = cff_op_and; + break; + case 4: + op = cff_op_or; + break; + case 5: + op = cff_op_not; + break; + case 6: + op = cff_op_seac; + break; + case 7: + op = cff_op_sbw; + break; + case 8: + op = cff_op_store; + break; + case 9: + op = cff_op_abs; + break; + case 10: + op = cff_op_add; + break; + case 11: + op = cff_op_sub; + break; + case 12: + op = cff_op_div; + break; + case 13: + op = cff_op_load; + break; + case 14: + op = cff_op_neg; + break; + case 15: + op = cff_op_eq; + break; + case 16: + op = cff_op_callothersubr; + break; + case 17: + op = cff_op_pop; + break; + case 18: + op = cff_op_drop; + break; + case 20: + op = cff_op_put; + break; + case 21: + op = cff_op_get; + break; + case 22: + op = cff_op_ifelse; + break; + case 23: + op = cff_op_random; + break; + case 24: + op = cff_op_mul; + break; + case 26: + op = cff_op_sqrt; + break; + case 27: + op = cff_op_dup; + break; + case 28: + op = cff_op_exch; + break; + case 29: + op = cff_op_index; + break; + case 30: + op = cff_op_roll; + break; + case 33: + op = cff_op_setcurrentpoint; + break; + case 34: + op = cff_op_hflex; + break; + case 35: + op = cff_op_flex; + break; + case 36: + op = cff_op_hflex1; + break; + case 37: + op = cff_op_flex1; + break; + default: + FT_TRACE4(( " unknown op (12, %d)\n", v )); + break; } break; case 13: @@ -984,7 +992,7 @@ #ifdef FT_DEBUG_LEVEL_TRACE { - FT_UInt maskbyte; + FT_UInt maskbyte; FT_TRACE4(( " (maskbytes:" )); @@ -1386,7 +1394,7 @@ case cff_op_hflex1: { - FT_Pos start_y; + FT_Pos start_y; FT_TRACE4(( " hflex1\n" )); @@ -1437,7 +1445,7 @@ case cff_op_hflex: { - FT_Pos start_y; + FT_Pos start_y; FT_TRACE4(( " hflex\n" )); @@ -1577,19 +1585,19 @@ break; case cff_op_seac: - FT_TRACE4(( " seac\n" )); + FT_TRACE4(( " seac\n" )); - error = cff_operator_seac( decoder, - args[0], args[1], args[2], - (FT_Int)( args[3] >> 16 ), - (FT_Int)( args[4] >> 16 ) ); + error = cff_operator_seac( decoder, + args[0], args[1], args[2], + (FT_Int)( args[3] >> 16 ), + (FT_Int)( args[4] >> 16 ) ); - /* add current outline to the glyph slot */ - FT_GlyphLoader_Add( builder->loader ); + /* add current outline to the glyph slot */ + FT_GlyphLoader_Add( builder->loader ); - /* return now! */ - FT_TRACE4(( "\n" )); - return error; + /* return now! */ + FT_TRACE4(( "\n" )); + return error; case cff_op_endchar: /* in dictionaries, `endchar' simply indicates end of data */ @@ -1813,7 +1821,7 @@ FT_TRACE4(( " dup\n" )); args[1] = args[0]; - args += 2; + args += 2; break; case cff_op_put: @@ -1855,7 +1863,7 @@ /* since we currently don't handle interpolation of multiple */ /* master fonts, this is a no-op */ - FT_TRACE4(( " store\n")); + FT_TRACE4(( " store\n" )); break; case cff_op_load: @@ -2253,12 +2261,12 @@ /* hint_mode :: The hinting mode. */ /* */ FT_LOCAL_DEF( void ) - cff_decoder_init( CFF_Decoder* decoder, - TT_Face face, - CFF_Size size, - CFF_GlyphSlot slot, - FT_Bool hinting, - FT_Render_Mode hint_mode, + cff_decoder_init( CFF_Decoder* decoder, + TT_Face face, + CFF_Size size, + CFF_GlyphSlot slot, + FT_Bool hinting, + FT_Render_Mode hint_mode, CFF_Decoder_Get_Glyph_Callback get_callback, CFF_Decoder_Free_Glyph_Callback free_callback ) { @@ -2279,7 +2287,7 @@ cff->top_font.font_dict.charstring_type, decoder->num_globals ); - decoder->hint_mode = hint_mode; + decoder->hint_mode = hint_mode; decoder->get_glyph_callback = get_callback; decoder->free_glyph_callback = free_callback; @@ -2300,10 +2308,12 @@ FT_Service_CFFLoad cffload = (FT_Service_CFFLoad)cff->cffload; + /* manage CID fonts */ if ( cff->num_subfonts ) { - FT_Byte fd_index = cffload->fd_select_get( &cff->fd_select, glyph_index ); + FT_Byte fd_index = cffload->fd_select_get( &cff->fd_select, + glyph_index ); if ( fd_index >= cff->num_subfonts ) @@ -2328,11 +2338,11 @@ } } - decoder->num_locals = sub->local_subrs_index.count; - decoder->locals = sub->local_subrs; - decoder->locals_bias = cff_compute_bias( - decoder->cff->top_font.font_dict.charstring_type, - decoder->num_locals ); + decoder->num_locals = sub->local_subrs_index.count; + decoder->locals = sub->local_subrs; + decoder->locals_bias = cff_compute_bias( + decoder->cff->top_font.font_dict.charstring_type, + decoder->num_locals ); decoder->glyph_width = sub->private_dict.default_width; decoder->nominal_width = sub->private_dict.nominal_width; @@ -2342,3 +2352,6 @@ Exit: return error; } + + +/* END */ diff --git a/src/psaux/cffdecode.h b/src/psaux/cffdecode.h index 4243ca699..15dfa8d62 100644 --- a/src/psaux/cffdecode.h +++ b/src/psaux/cffdecode.h @@ -4,7 +4,14 @@ /* */ /* PostScript CFF (Type 2) decoding routines (specification). */ /* */ -/* Copyright notice here. */ +/* Copyright 2017 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ /* */ /***************************************************************************/ @@ -19,14 +26,14 @@ FT_BEGIN_HEADER FT_LOCAL( void ) - cff_decoder_init( CFF_Decoder* decoder, - TT_Face face, - CFF_Size size, - CFF_GlyphSlot slot, - FT_Bool hinting, - FT_Render_Mode hint_mode, + cff_decoder_init( CFF_Decoder* decoder, + TT_Face face, + CFF_Size size, + CFF_GlyphSlot slot, + FT_Bool hinting, + FT_Render_Mode hint_mode, CFF_Decoder_Get_Glyph_Callback get_callback, - CFF_Decoder_Free_Glyph_Callback free_callback); + CFF_Decoder_Free_Glyph_Callback free_callback ); FT_LOCAL( FT_Error ) cff_decoder_prepare( CFF_Decoder* decoder, @@ -39,13 +46,13 @@ FT_BEGIN_HEADER FT_Int charcode ); - #ifdef CFF_CONFIG_OPTION_OLD_ENGINE - FT_LOCAL( FT_Error ) - cff_decoder_parse_charstrings( CFF_Decoder* decoder, - FT_Byte* charstring_base, - FT_ULong charstring_len, - FT_Bool in_dict ); - #endif +#ifdef CFF_CONFIG_OPTION_OLD_ENGINE + FT_LOCAL( FT_Error ) + cff_decoder_parse_charstrings( CFF_Decoder* decoder, + FT_Byte* charstring_base, + FT_ULong charstring_len, + FT_Bool in_dict ); +#endif FT_END_HEADER diff --git a/src/psaux/psarrst.h b/src/psaux/psarrst.h index b7d114079..b3568eb61 100644 --- a/src/psaux/psarrst.h +++ b/src/psaux/psarrst.h @@ -36,8 +36,8 @@ /***************************************************************************/ -#ifndef CF2ARRST_H_ -#define CF2ARRST_H_ +#ifndef PSARRST_H_ +#define PSARRST_H_ #include "pserror.h" @@ -94,7 +94,7 @@ FT_BEGIN_HEADER FT_END_HEADER -#endif /* CF2ARRST_H_ */ +#endif /* PSARRST_H_ */ /* END */ diff --git a/src/psaux/psauxmod.c b/src/psaux/psauxmod.c index fea60ce6d..b539b1ac1 100644 --- a/src/psaux/psauxmod.c +++ b/src/psaux/psauxmod.c @@ -87,10 +87,10 @@ FT_CALLBACK_TABLE_DEF const T1_Decoder_FuncsRec t1_decoder_funcs = { - t1_decoder_init, /* init */ - t1_decoder_done, /* done */ - t1_decoder_parse_charstrings, /* parse_charstrings_old */ - cf2_decoder_parse_charstrings /* parse_charstrings */ + t1_decoder_init, /* init */ + t1_decoder_done, /* done */ + t1_decoder_parse_charstrings, /* parse_charstrings_old */ + cf2_decoder_parse_charstrings /* parse_charstrings */ }; @@ -133,13 +133,13 @@ FT_CALLBACK_TABLE_DEF const CFF_Decoder_FuncsRec cff_decoder_funcs = { - cff_decoder_init, /* init */ - cff_decoder_prepare, /* prepare */ + cff_decoder_init, /* init */ + cff_decoder_prepare, /* prepare */ #ifdef CFF_CONFIG_OPTION_OLD_ENGINE cff_decoder_parse_charstrings, /* parse_charstrings_old */ #endif - cf2_decoder_parse_charstrings /* parse_charstrings */ + cf2_decoder_parse_charstrings /* parse_charstrings */ }; diff --git a/src/psaux/psblues.h b/src/psaux/psblues.h index 888de9f30..25ef6849c 100644 --- a/src/psaux/psblues.h +++ b/src/psaux/psblues.h @@ -65,8 +65,8 @@ */ -#ifndef CF2BLUES_H_ -#define CF2BLUES_H_ +#ifndef PSBLUES_H_ +#define PSBLUES_H_ #include "psglue.h" @@ -179,7 +179,7 @@ FT_BEGIN_HEADER FT_END_HEADER -#endif /* CF2BLUES_H_ */ +#endif /* PSBLUES_H_ */ /* END */ diff --git a/src/psaux/pserror.h b/src/psaux/pserror.h index 4a631b8df..13d52062b 100644 --- a/src/psaux/pserror.h +++ b/src/psaux/pserror.h @@ -36,8 +36,8 @@ /***************************************************************************/ -#ifndef CF2ERROR_H_ -#define CF2ERROR_H_ +#ifndef PSERROR_H_ +#define PSERROR_H_ #include FT_MODULE_ERRORS_H @@ -113,7 +113,7 @@ FT_BEGIN_HEADER FT_END_HEADER -#endif /* CF2ERROR_H_ */ +#endif /* PSERROR_H_ */ /* END */ diff --git a/src/psaux/psfixed.h b/src/psaux/psfixed.h index b93163034..219589e7f 100644 --- a/src/psaux/psfixed.h +++ b/src/psaux/psfixed.h @@ -36,8 +36,8 @@ /***************************************************************************/ -#ifndef CF2FIXED_H_ -#define CF2FIXED_H_ +#ifndef PSFIXED_H_ +#define PSFIXED_H_ FT_BEGIN_HEADER @@ -89,7 +89,7 @@ FT_BEGIN_HEADER FT_END_HEADER -#endif /* CF2FIXED_H_ */ +#endif /* PSFIXED_H_ */ /* END */ diff --git a/src/psaux/psfont.c b/src/psaux/psfont.c index ff69b828d..dde67a739 100644 --- a/src/psaux/psfont.c +++ b/src/psaux/psfont.c @@ -275,6 +275,8 @@ if ( !font->isT1 ) { FT_Service_CFFLoad cffload = (FT_Service_CFFLoad)font->cffload; + + /* check for variation vectors */ vstore = cf2_getVStore( decoder ); hasVariations = ( vstore->dataCount != 0 ); diff --git a/src/psaux/psfont.h b/src/psaux/psfont.h index 7f5341694..e611ac4bd 100644 --- a/src/psaux/psfont.h +++ b/src/psaux/psfont.h @@ -36,8 +36,8 @@ /***************************************************************************/ -#ifndef CF2FONT_H_ -#define CF2FONT_H_ +#ifndef PSFONT_H_ +#define PSFONT_H_ #include FT_SERVICE_CFF_TABLE_LOAD_H @@ -114,7 +114,7 @@ FT_BEGIN_HEADER CF2_BluesRec blues; /* computed zone data */ - FT_Service_CFFLoad cffload; /* Pointer to cff functions */ + FT_Service_CFFLoad cffload; /* pointer to cff functions */ }; @@ -128,7 +128,7 @@ FT_BEGIN_HEADER FT_END_HEADER -#endif /* CF2FONT_H_ */ +#endif /* PSFONT_H_ */ /* END */ diff --git a/src/psaux/psft.c b/src/psaux/psft.c index 8ddabc26d..6c67276d9 100644 --- a/src/psaux/psft.c +++ b/src/psaux/psft.c @@ -49,6 +49,7 @@ #include FT_SERVICE_CFF_TABLE_LOAD_H + #define CF2_MAX_SIZE cf2_intToFixed( 2000 ) /* max ppem */ @@ -479,15 +480,16 @@ CF2_UInt *len, FT_Fixed* *vec ) { - TT_Face face; + TT_Face face; FT_Service_MultiMasters mm; + FT_ASSERT( decoder && decoder->builder.face ); FT_ASSERT( vec && len ); FT_ASSERT( !decoder->builder.is_t1 ); face = (TT_Face)decoder->builder.face; - mm = (FT_Service_MultiMasters)face->mm; + mm = (FT_Service_MultiMasters)face->mm; return mm->get_var_blend( FT_FACE( face ), len, NULL, vec, NULL ); } @@ -498,8 +500,8 @@ FT_LOCAL_DEF( CF2_Fixed ) cf2_getPpemY( PS_Decoder* decoder ) { - FT_ASSERT( decoder && - decoder->builder.face && + FT_ASSERT( decoder && + decoder->builder.face && decoder->builder.face->size ); /* @@ -723,8 +725,10 @@ T1_Font type1 = &face->type1; #ifdef FT_CONFIG_OPTION_INCREMENTAL - FT_Incremental_InterfaceRec *inc = + FT_Incremental_InterfaceRec *inc = face->root.internal->incremental_interface; + + /* For incremental fonts get the character data using the */ /* callback function. */ if ( inc ) @@ -732,7 +736,7 @@ glyph_index, &glyph_data ); else #endif - /* For ordinary fonts get the character data stored in the face record. */ + /* For ordinary fonts get the character data stored in the face record. */ { glyph_data.pointer = type1->charstrings[glyph_index]; glyph_data.length = (FT_Int)type1->charstrings_len[glyph_index]; @@ -806,13 +810,13 @@ /* The CID driver stores subroutines with seed bytes. This */ /* case is taken care of when decoder->subrs_len == 0. */ if ( decoder->locals_len ) - buf->end = buf->start + decoder->locals_len[idx]; + buf->end = buf->start + decoder->locals_len[idx]; else { /* We are using subroutines from a CID font. We must adjust */ /* for the seed bytes. */ - buf->start += ( decoder->lenIV >= 0 ? decoder->lenIV : 0 ); - buf->end = decoder->locals[idx + 1]; + buf->start += ( decoder->lenIV >= 0 ? decoder->lenIV : 0 ); + buf->end = decoder->locals[idx + 1]; } if ( !buf->start ) @@ -823,7 +827,7 @@ } else { - buf->end = decoder->locals[idx + 1]; + buf->end = decoder->locals[idx + 1]; } buf->ptr = buf->start; diff --git a/src/psaux/psft.h b/src/psaux/psft.h index 28bc49c19..ab172110b 100644 --- a/src/psaux/psft.h +++ b/src/psaux/psft.h @@ -36,8 +36,8 @@ /***************************************************************************/ -#ifndef CF2FT_H_ -#define CF2FT_H_ +#ifndef PSFT_H_ +#define PSFT_H_ #include "pstypes.h" @@ -161,7 +161,7 @@ FT_BEGIN_HEADER FT_END_HEADER -#endif /* CF2FT_H_ */ +#endif /* PSFT_H_ */ /* END */ diff --git a/src/psaux/psglue.h b/src/psaux/psglue.h index 4fa544527..5545e12a5 100644 --- a/src/psaux/psglue.h +++ b/src/psaux/psglue.h @@ -36,8 +36,8 @@ /***************************************************************************/ -#ifndef CF2GLUE_H_ -#define CF2GLUE_H_ +#ifndef PSGLUE_H_ +#define PSGLUE_H_ /* common includes for other modules */ @@ -138,7 +138,7 @@ FT_BEGIN_HEADER FT_END_HEADER -#endif /* CF2GLUE_H_ */ +#endif /* PSGLUE_H_ */ /* END */ diff --git a/src/psaux/pshints.c b/src/psaux/pshints.c index c8ad4e03e..93e1587da 100644 --- a/src/psaux/pshints.c +++ b/src/psaux/pshints.c @@ -312,10 +312,11 @@ { CF2_Hint hint = &hintmap->edge[i]; + FT_TRACE6(( " %3d %7.2f %7.2f %5d %s%s%s%s\n", hint->index, hint->csCoord / 65536.0, - hint->dsCoord / (hint->scale * 1.0), + hint->dsCoord / ( hint->scale * 1.0 ), hint->scale, ( cf2_hint_isPair( hint ) ? "p" : "g" ), ( cf2_hint_isTop( hint ) ? "t" : "b" ), @@ -645,9 +646,9 @@ firstHintEdge->csCoord / 65536.0, firstHintEdge->dsCoord / 65536.0 )); if ( isPair ) - FT_TRACE7(( " Got hint at %.2f (%.2f)\n", - secondHintEdge->csCoord / 65536.0, - secondHintEdge->dsCoord / 65536.0 )); + FT_TRACE7(( " Got hint at %.2f (%.2f)\n", + secondHintEdge->csCoord / 65536.0, + secondHintEdge->dsCoord / 65536.0 )); /* * Discard any hints that overlap in character space. Most often, this @@ -767,6 +768,7 @@ /* insert first edge */ hintmap->edge[indexInsert] = *firstHintEdge; /* copy struct */ hintmap->count += 1; + FT_TRACE7(( " Inserting hint %.2f (%.2f)\n", firstHintEdge->csCoord / 65536.0, firstHintEdge->dsCoord / 65536.0 )); @@ -776,6 +778,7 @@ /* insert second edge */ hintmap->edge[indexInsert + 1] = *secondHintEdge; /* copy struct */ hintmap->count += 1; + FT_TRACE7(( " Inserting hint %.2f (%.2f)\n", secondHintEdge->csCoord / 65536.0, secondHintEdge->dsCoord / 65536.0 )); diff --git a/src/psaux/pshints.h b/src/psaux/pshints.h index 02fdc53cb..92e37e98a 100644 --- a/src/psaux/pshints.h +++ b/src/psaux/pshints.h @@ -36,9 +36,8 @@ /***************************************************************************/ -#ifndef CF2HINTS_H_ -#define CF2HINTS_H_ - +#ifndef PSHINT_H_ +#define PSHINT_H_ FT_BEGIN_HEADER @@ -283,7 +282,7 @@ FT_BEGIN_HEADER FT_END_HEADER -#endif /* CF2HINTS_H_ */ +#endif /* PSHINT_H_ */ /* END */ diff --git a/src/psaux/psintrp.c b/src/psaux/psintrp.c index ab6ed4954..a60597e3c 100644 --- a/src/psaux/psintrp.c +++ b/src/psaux/psintrp.c @@ -49,7 +49,8 @@ #include "pserror.h" #include "psobjs.h" /* for cff_random */ -#include "t1decode.h" /* for t1 seac */ +#include "t1decode.h" /* for t1 seac */ + /*************************************************************************/ /* */ @@ -292,10 +293,9 @@ CF2_Fixed position = hintOffset; if ( font->isT1 && !font->decoder->flex_state && !*haveWidth ) - { FT_ERROR(( "cf2_doStems (Type 1 mode):" " No width. Use hsbw/sbw as first op\n" )); - } + if ( !font->isT1 && hasWidthArg && !*haveWidth ) *width = ADD_INT32( cf2_stack_getReal( opStack, 0 ), cf2_getNominalWidthX( font->decoder ) ); @@ -489,10 +489,11 @@ CF2_Fixed scaleY = font->innerTransform.d; CF2_Fixed nominalWidthX = cf2_getNominalWidthX( decoder ); - /* Stuff for Type 1 */ - FT_Int known_othersubr_result_cnt = 0; - FT_Bool large_int = FALSE; - FT_Bool initial_map_ready = FALSE; + /* stuff for Type 1 */ + FT_Int known_othersubr_result_cnt = 0; + FT_Bool large_int = FALSE; + FT_Bool initial_map_ready = FALSE; + #define PS_STORAGE_SIZE 3 CF2_F16Dot16 results[PS_STORAGE_SIZE]; /* for othersubr results */ FT_Int result_cnt = 0; @@ -505,7 +506,7 @@ FT_Byte op1; /* first opcode byte */ CF2_F16Dot16 storage[CF2_STORAGE_SIZE]; /* for `put' and `get' */ - CF2_F16Dot16 flexStore[6]; /* for Type 1 flex */ + CF2_F16Dot16 flexStore[6]; /* for Type 1 flex */ /* instruction limit; 20,000,000 matches Avalon */ FT_UInt32 instructionLimit = 20000000UL; @@ -623,10 +624,8 @@ while ( 1 ) { if ( font->isT1 ) - { - FT_ASSERT( known_othersubr_result_cnt == 0 || - result_cnt == 0 ); - } + FT_ASSERT( known_othersubr_result_cnt == 0 || + result_cnt == 0 ); if ( cf2_buf_isEnd( charstring ) ) { @@ -651,14 +650,14 @@ if ( font->isT1 ) { - if ( !initial_map_ready && - !( op1 == cf2_cmdHSTEM || - op1 == cf2_cmdVSTEM || - op1 == cf2_cmdHSBW || - op1 == cf2_cmdCALLSUBR || - op1 == cf2_cmdRETURN || - op1 == cf2_cmdESC || - op1 == cf2_cmdENDCHAR || + if ( !initial_map_ready && + !( op1 == cf2_cmdHSTEM || + op1 == cf2_cmdVSTEM || + op1 == cf2_cmdHSBW || + op1 == cf2_cmdCALLSUBR || + op1 == cf2_cmdRETURN || + op1 == cf2_cmdESC || + op1 == cf2_cmdENDCHAR || op1 >= 32 /* Numbers */ ) ) { /* Skip outline commands first time round. */ @@ -668,10 +667,10 @@ continue; } - if ( result_cnt > 0 && - !( op1 == cf2_cmdCALLSUBR || - op1 == cf2_cmdRETURN || - op1 == cf2_cmdESC || + if ( result_cnt > 0 && + !( op1 == cf2_cmdCALLSUBR || + op1 == cf2_cmdRETURN || + op1 == cf2_cmdESC || op1 >= 32 /* Numbers */ ) ) { /* all operands have been transferred by previous pops */ @@ -790,7 +789,7 @@ } } - /* Add left-sidebearing correction in Type 1 mode */ + /* add left-sidebearing correction in Type 1 mode */ cf2_doStems( font, opStack, &hStemHintArray, @@ -820,7 +819,7 @@ } } - /* Add left-sidebearing correction in Type 1 mode */ + /* add left-sidebearing correction in Type 1 mode */ cf2_doStems( font, opStack, &vStemHintArray, @@ -838,10 +837,8 @@ FT_TRACE4(( " vmoveto\n" )); if ( font->isT1 && !decoder->flex_state && !haveWidth ) - { FT_ERROR(( "cf2_interpT2CharString (Type 1 mode):" " No width. Use hsbw/sbw as first op\n" )); - } if ( cf2_stack_count( opStack ) > 1 && !haveWidth ) *width = ADD_INT32( cf2_stack_getReal( opStack, 0 ), @@ -956,9 +953,7 @@ case cf2_cmdCLOSEPATH: if ( !font->isT1 ) - { FT_TRACE4(( " unknown op (%d)\n", op1 )); - } else { FT_TRACE4(( " closepath" )); @@ -979,7 +974,7 @@ FT_TRACE4(( op1 == cf2_cmdCALLGSUBR ? " callgsubr" : " callsubr" )); - if ( ( !font->isT1 && charstringIndex > CF2_MAX_SUBR ) || + if ( ( !font->isT1 && charstringIndex > CF2_MAX_SUBR ) || ( font->isT1 && charstringIndex > T1_MAX_SUBRS_CALLS ) ) { /* max subr plus one for charstring */ @@ -1001,6 +996,7 @@ size_t* val = ft_hash_num_lookup( subrNum, decoder->locals_hash ); + if ( val ) subrNum = *val; else @@ -1179,11 +1175,14 @@ if ( font->isCFF2 || op2 >= cf2_escRESERVED_38 ) FT_TRACE4(( " unknown op (12, %d)\n", op2 )); else if ( font->isT1 && result_cnt > 0 && op2 != cf2_escPOP ) + { /* all operands have been transferred by previous pops */ result_cnt = 0; + } else { - /* second switch for 2-byte operators handles CFF and Type 1 */ + /* second switch for 2-byte operators handles */ + /* CFF and Type 1 */ switch ( op2 ) { @@ -1195,10 +1194,13 @@ case cf2_escVSTEM3: case cf2_escHSTEM3: - /* Type 1: */ /* Type 2: */ - /* x0 dx0 x1 dx1 x2 dx2 vstem3 */ /* x dx {dxa dxb}* vstem */ - /* y0 dy0 y1 dy1 y2 dy2 hstem3 */ /* y dy {dya dyb}* hstem */ - /* relative to lsb point */ /* relative to zero */ + /* + * Type 1: Type 2: + * x0 dx0 x1 dx1 x2 dx2 vstem3 x dx {dxa dxb}* vstem + * y0 dy0 y1 dy1 y2 dy2 hstem3 y dy {dya dyb}* hstem + * relative to lsb point relative to zero + * + */ { if ( !font->isT1 ) FT_TRACE4(( " unknown op (12, %d)\n", op2 )); @@ -1206,26 +1208,28 @@ { CF2_F16Dot16 v0, v1, v2; - FT_Bool isV = FT_BOOL( op2 == cf2_escVSTEM3 ); + FT_Bool isV = FT_BOOL( op2 == cf2_escVSTEM3 ); FT_TRACE4(( isV ? " vstem3\n" : " hstem3\n" )); - FT_ASSERT( ( cf2_stack_count( opStack ) == 6 ) ); + FT_ASSERT( cf2_stack_count( opStack ) == 6 ); v0 = cf2_stack_getReal( opStack, 0 ); v1 = cf2_stack_getReal( opStack, 2 ); v2 = cf2_stack_getReal( opStack, 4 ); - cf2_stack_setReal( opStack, 2, - SUB_INT32( SUB_INT32( v1, v0 ), - cf2_stack_getReal( opStack, 1 ) ) ); - cf2_stack_setReal( opStack, 4, - SUB_INT32( SUB_INT32( v2, v1 ), - cf2_stack_getReal( opStack, 3 ) ) ); + cf2_stack_setReal( + opStack, 2, + SUB_INT32( SUB_INT32( v1, v0 ), + cf2_stack_getReal( opStack, 1 ) ) ); + cf2_stack_setReal( + opStack, 4, + SUB_INT32( SUB_INT32( v2, v1 ), + cf2_stack_getReal( opStack, 3 ) ) ); - /* Add left-sidebearing correction */ + /* add left-sidebearing correction */ cf2_doStems( font, opStack, isV ? &vStemHintArray : &hStemHintArray, @@ -1284,226 +1288,234 @@ continue; /* do not clear the stack */ case cf2_escSEAC: + if ( !font->isT1 ) + FT_TRACE4(( " unknown op (12, %d)\n", op2 )); + else { - if ( !font->isT1 ) - FT_TRACE4(( " unknown op (12, %d)\n", op2 )); - else + FT_Error error2; + CF2_Int bchar_index, achar_index; + FT_Vector left_bearing, advance; + +#ifdef FT_CONFIG_OPTION_INCREMENTAL + T1_Face face = (T1_Face)decoder->builder.face; +#endif + CF2_BufferRec component; + CF2_Fixed dummyWidth; + + CF2_Int achar = cf2_stack_popInt( opStack ); + CF2_Int bchar = cf2_stack_popInt( opStack ); + + FT_Pos ady = cf2_stack_popFixed ( opStack ); + FT_Pos adx = cf2_stack_popFixed ( opStack ); + FT_Pos asb = cf2_stack_popFixed ( opStack ); + + + FT_TRACE4(( " seac\n" )); + + if ( doingSeac ) { - FT_Error error2; - CF2_Int bchar_index, achar_index; - FT_Vector left_bearing, advance; + FT_ERROR(( " nested seac\n" )); + lastError = FT_THROW( Invalid_Glyph_Format ); + goto exit; /* nested seac */ + } + + if ( decoder->builder.metrics_only ) + { + FT_ERROR(( " unexpected seac\n" )); + lastError = FT_THROW( Invalid_Glyph_Format ); + goto exit; /* unexpected seac */ + } + + /* `glyph_names' is set to 0 for CID fonts which do */ + /* not include an encoding. How can we deal with */ + /* these? */ #ifdef FT_CONFIG_OPTION_INCREMENTAL - T1_Face face = (T1_Face)decoder->builder.face; -#endif - CF2_BufferRec component; - CF2_Fixed dummyWidth; - - CF2_Int achar = cf2_stack_popInt( opStack ); - CF2_Int bchar = cf2_stack_popInt( opStack ); - - FT_Pos ady = cf2_stack_popFixed ( opStack ); - FT_Pos adx = cf2_stack_popFixed ( opStack ); - FT_Pos asb = cf2_stack_popFixed ( opStack ); - - - FT_TRACE4(( " seac\n" )); - - if ( doingSeac ) - { - FT_ERROR(( " nested seac\n" )); - lastError = FT_THROW( Invalid_Glyph_Format ); - goto exit; /* nested seac */ - } - - if ( decoder->builder.metrics_only ) - { - FT_ERROR(( " unexpected seac\n" )); - lastError = FT_THROW( Invalid_Glyph_Format ); - goto exit; /* unexpected seac */ - } - - /* `glyph_names' is set to 0 for CID fonts which do not */ - /* include an encoding. How can we deal with these? */ -#ifdef FT_CONFIG_OPTION_INCREMENTAL - if ( decoder->glyph_names == 0 && - !face->root.internal->incremental_interface ) + if ( decoder->glyph_names == 0 && + !face->root.internal->incremental_interface ) #else - if ( decoder->glyph_names == 0 ) + if ( decoder->glyph_names == 0 ) #endif /* FT_CONFIG_OPTION_INCREMENTAL */ - { - FT_ERROR(( "cf2_interpT2CharString: (Type 1 seac)" - " glyph names table not available in this font\n" )); - lastError = FT_THROW( Invalid_Glyph_Format ); - goto exit; - } - - - /* seac weirdness */ - adx += decoder->builder.left_bearing->x; - -#ifdef FT_CONFIG_OPTION_INCREMENTAL - if ( face->root.internal->incremental_interface ) { - /* the caller must handle the font encoding also */ - bchar_index = bchar; - achar_index = achar; - } - else -#endif - { - bchar_index = t1_lookup_glyph_by_stdcharcode_ps( decoder, bchar ); - achar_index = t1_lookup_glyph_by_stdcharcode_ps( decoder, achar ); - } - - if ( bchar_index < 0 || achar_index < 0 ) - { - FT_ERROR(( "cf2_interpT2CharString: (Type 1 seac)" - " invalid seac character code arguments\n" )); + FT_ERROR(( + "cf2_interpT2CharString: (Type 1 seac)" + " glyph names table not available in this font\n" )); lastError = FT_THROW( Invalid_Glyph_Format ); goto exit; } - /* if we are trying to load a composite glyph, do not load the */ - /* accent character and return the array of subglyphs. */ - if ( decoder->builder.no_recurse ) - { - FT_GlyphSlot glyph = (FT_GlyphSlot)decoder->builder.glyph; - FT_GlyphLoader loader = glyph->internal->loader; - FT_SubGlyph subg; + /* seac weirdness */ + adx += decoder->builder.left_bearing->x; + +#ifdef FT_CONFIG_OPTION_INCREMENTAL + if ( face->root.internal->incremental_interface ) + { + /* the caller must handle the font encoding also */ + bchar_index = bchar; + achar_index = achar; + } + else +#endif + { + bchar_index = t1_lookup_glyph_by_stdcharcode_ps( + decoder, bchar ); + achar_index = t1_lookup_glyph_by_stdcharcode_ps( + decoder, achar ); + } + + if ( bchar_index < 0 || achar_index < 0 ) + { + FT_ERROR(( + "cf2_interpT2CharString: (Type 1 seac)" + " invalid seac character code arguments\n" )); + lastError = FT_THROW( Invalid_Glyph_Format ); + goto exit; + } + + /* if we are trying to load a composite glyph, */ + /* do not load the accent character and return */ + /* the array of subglyphs. */ + if ( decoder->builder.no_recurse ) + { + FT_GlyphSlot glyph = (FT_GlyphSlot)decoder->builder.glyph; + FT_GlyphLoader loader = glyph->internal->loader; + FT_SubGlyph subg; - /* reallocate subglyph array if necessary */ - error2 = FT_GlyphLoader_CheckSubGlyphs( loader, 2 ); - if ( error2 ) - { - lastError = error2; /* pass FreeType error through */ - goto exit; - } - - subg = loader->current.subglyphs; - - /* subglyph 0 = base character */ - subg->index = bchar_index; - subg->flags = FT_SUBGLYPH_FLAG_ARGS_ARE_XY_VALUES | - FT_SUBGLYPH_FLAG_USE_MY_METRICS; - subg->arg1 = 0; - subg->arg2 = 0; - subg++; - - /* subglyph 1 = accent character */ - subg->index = achar_index; - subg->flags = FT_SUBGLYPH_FLAG_ARGS_ARE_XY_VALUES; - subg->arg1 = (FT_Int)FIXED_TO_INT( adx - asb ); - subg->arg2 = (FT_Int)FIXED_TO_INT( ady ); - - /* set up remaining glyph fields */ - glyph->num_subglyphs = 2; - glyph->subglyphs = loader->base.subglyphs; - glyph->format = FT_GLYPH_FORMAT_COMPOSITE; - - loader->current.num_subglyphs = 2; - - goto exit; - } - - /* First load `bchar' in builder */ - /* now load the unscaled outline */ - - FT_GlyphLoader_Prepare( decoder->builder.loader ); /* prepare loader */ - - error2 = cf2_getT1SeacComponent( decoder, (FT_UInt)bchar_index, &component ); + /* reallocate subglyph array if necessary */ + error2 = FT_GlyphLoader_CheckSubGlyphs( loader, 2 ); if ( error2 ) { - lastError = error2; /* pass FreeType error through */ + lastError = error2; /* pass FreeType error through */ goto exit; } - cf2_interpT2CharString( font, - &component, - callbacks, - translation, - TRUE, - 0, - 0, - &dummyWidth ); - cf2_freeT1SeacComponent( decoder, &component ); - /* save the left bearing and width of the base character */ - /* as they will be erased by the next load. */ + subg = loader->current.subglyphs; - left_bearing = *decoder->builder.left_bearing; - advance = *decoder->builder.advance; + /* subglyph 0 = base character */ + subg->index = bchar_index; + subg->flags = FT_SUBGLYPH_FLAG_ARGS_ARE_XY_VALUES | + FT_SUBGLYPH_FLAG_USE_MY_METRICS; + subg->arg1 = 0; + subg->arg2 = 0; + subg++; - decoder->builder.left_bearing->x = 0; - decoder->builder.left_bearing->y = 0; + /* subglyph 1 = accent character */ + subg->index = achar_index; + subg->flags = FT_SUBGLYPH_FLAG_ARGS_ARE_XY_VALUES; + subg->arg1 = (FT_Int)FIXED_TO_INT( adx - asb ); + subg->arg2 = (FT_Int)FIXED_TO_INT( ady ); - /* Now load `achar' on top of */ - /* the base outline */ + /* set up remaining glyph fields */ + glyph->num_subglyphs = 2; + glyph->subglyphs = loader->base.subglyphs; + glyph->format = FT_GLYPH_FORMAT_COMPOSITE; - error2 = cf2_getT1SeacComponent( decoder, (FT_UInt)achar_index, &component ); - if ( error2 ) - { - lastError = error2; /* pass FreeType error through */ - goto exit; - } - cf2_interpT2CharString( font, - &component, - callbacks, - translation, - TRUE, - adx - asb, - ady, - &dummyWidth ); - cf2_freeT1SeacComponent( decoder, &component ); - - /* restore the left side bearing and */ - /* advance width of the base character */ - - *decoder->builder.left_bearing = left_bearing; - *decoder->builder.advance = advance; + loader->current.num_subglyphs = 2; goto exit; } + + /* First load `bchar' in builder */ + /* now load the unscaled outline */ + + /* prepare loader */ + FT_GlyphLoader_Prepare( decoder->builder.loader ); + + error2 = cf2_getT1SeacComponent( decoder, + (FT_UInt)bchar_index, + &component ); + if ( error2 ) + { + lastError = error2; /* pass FreeType error through */ + goto exit; + } + cf2_interpT2CharString( font, + &component, + callbacks, + translation, + TRUE, + 0, + 0, + &dummyWidth ); + cf2_freeT1SeacComponent( decoder, &component ); + + /* save the left bearing and width of the base */ + /* character as they will be erased by the next load */ + + left_bearing = *decoder->builder.left_bearing; + advance = *decoder->builder.advance; + + decoder->builder.left_bearing->x = 0; + decoder->builder.left_bearing->y = 0; + + /* Now load `achar' on top of */ + /* the base outline */ + + error2 = cf2_getT1SeacComponent( decoder, + (FT_UInt)achar_index, + &component ); + if ( error2 ) + { + lastError = error2; /* pass FreeType error through */ + goto exit; + } + cf2_interpT2CharString( font, + &component, + callbacks, + translation, + TRUE, + adx - asb, + ady, + &dummyWidth ); + cf2_freeT1SeacComponent( decoder, &component ); + + /* restore the left side bearing and */ + /* advance width of the base character */ + + *decoder->builder.left_bearing = left_bearing; + *decoder->builder.advance = advance; + + goto exit; } break; case cf2_escSBW: + if ( !font->isT1 ) + FT_TRACE4(( " unknown op (12, %d)\n", op2 )); + else { - if ( !font->isT1 ) - FT_TRACE4(( " unknown op (12, %d)\n", op2 )); - else + CF2_Fixed lsb_x, lsb_y; + PS_Builder* builder; + + + FT_TRACE4(( " sbw" )); + + builder = &decoder->builder; + + builder->advance->y = cf2_stack_popFixed( opStack ); + builder->advance->x = cf2_stack_popFixed( opStack ); + + lsb_y = cf2_stack_popFixed( opStack ); + lsb_x = cf2_stack_popFixed( opStack ); + + builder->left_bearing->x = + ADD_INT32( builder->left_bearing->x, lsb_x ); + builder->left_bearing->y = + ADD_INT32( builder->left_bearing->y, lsb_y ); + + haveWidth = TRUE; + + /* the `metrics_only' indicates that we only want */ + /* to compute the glyph's metrics (lsb + advance */ + /* width), not load the rest of it; so exit */ + /* immediately */ + if ( builder->metrics_only ) + goto exit; + + if ( initial_map_ready ) { - CF2_Fixed lsb_x, lsb_y; - PS_Builder* builder; - - - FT_TRACE4(( " sbw" )); - - builder = &decoder->builder; - - builder->advance->y = cf2_stack_popFixed( opStack ); - builder->advance->x = cf2_stack_popFixed( opStack ); - - lsb_y = cf2_stack_popFixed( opStack ); - lsb_x = cf2_stack_popFixed( opStack ); - - builder->left_bearing->x = ADD_INT32( builder->left_bearing->x, - lsb_x ); - builder->left_bearing->y = ADD_INT32( builder->left_bearing->y, - lsb_y ); - - haveWidth = TRUE; - - /* the `metrics_only' indicates that we only want to compute */ - /* the glyph's metrics (lsb + advance width), not load the */ - /* rest of it; so exit immediately */ - if ( builder->metrics_only ) - goto exit; - - if ( initial_map_ready ) - { - curX = ADD_INT32( curX, lsb_x ); - curY = ADD_INT32( curY, lsb_y ); - } + curX = ADD_INT32( curX, lsb_x ); + curY = ADD_INT32( curY, lsb_y ); } } break; @@ -1625,21 +1637,22 @@ CF2_UInt count; CF2_UInt opIdx = 0; + FT_TRACE4(( " callothersubr\n" )); subr_no = cf2_stack_popInt( opStack ); arg_cnt = cf2_stack_popInt( opStack ); - /***********************************************************/ - /* */ - /* remove all operands to callothersubr from the stack */ - /* */ - /* for handled othersubrs, where we know the number of */ - /* arguments, we increase the stack by the value of */ - /* known_othersubr_result_cnt */ - /* */ - /* for unhandled othersubrs the following pops adjust the */ - /* stack pointer as necessary */ + /*******************************************************/ + /* */ + /* remove all operands to callothersubr from the stack */ + /* */ + /* for handled othersubrs, where we know the number of */ + /* arguments, we increase the stack by the value of */ + /* known_othersubr_result_cnt */ + /* */ + /* for unhandled othersubrs the following pops adjust */ + /* the stack pointer as necessary */ count = cf2_stack_count( opStack ); FT_ASSERT( (CF2_UInt)arg_cnt <= count ); @@ -1647,23 +1660,25 @@ opIdx += count - (CF2_UInt)arg_cnt; known_othersubr_result_cnt = 0; - result_cnt = 0; + result_cnt = 0; - /* XXX TODO: The checks to `arg_count == ' */ - /* might not be correct; an othersubr expects a certain */ - /* number of operands on the PostScript stack (as opposed */ - /* to the T1 stack) but it doesn't have to put them there */ - /* by itself; previous othersubrs might have left the */ - /* operands there if they were not followed by an */ - /* appropriate number of pops */ - /* */ - /* On the other hand, Adobe Reader 7.0.8 for Linux doesn't */ - /* accept a font that contains charstrings like */ - /* */ - /* 100 200 2 20 callothersubr */ - /* 300 1 20 callothersubr pop */ - /* */ - /* Perhaps this is the reason why BuildCharArray exists. */ + /* XXX TODO: The checks to `arg_count == ' */ + /* might not be correct; an othersubr expects a */ + /* certain number of operands on the PostScript stack */ + /* (as opposed to the T1 stack) but it doesn't have to */ + /* put them there by itself; previous othersubrs might */ + /* have left the operands there if they were not */ + /* followed by an appropriate number of pops */ + /* */ + /* On the other hand, Adobe Reader 7.0.8 for Linux */ + /* doesn't accept a font that contains charstrings */ + /* like */ + /* */ + /* 100 200 2 20 callothersubr */ + /* 300 1 20 callothersubr pop */ + /* */ + /* Perhaps this is the reason why BuildCharArray */ + /* exists. */ switch ( subr_no ) { @@ -1681,7 +1696,8 @@ goto exit; } - /* the two `results' are popped by the following setcurrentpoint */ + /* the two `results' are popped */ + /* by the following setcurrentpoint */ cf2_stack_pushFixed( opStack, curX ); cf2_stack_pushFixed( opStack, curY ); known_othersubr_result_cnt = 2; @@ -1702,58 +1718,61 @@ break; case 2: /* add flex vectors */ - { - FT_Int idx; - FT_Int idx2; - - - if ( arg_cnt != 0 ) - goto Unexpected_OtherSubr; - - if ( !initial_map_ready ) - break; - - if ( !decoder->flex_state ) { - FT_ERROR(( "cf2_interpT2CharString (Type 1 mode):" - " missing flex start\n" )); - lastError = FT_THROW( Invalid_Glyph_Format ); - goto exit; - } + FT_Int idx; + FT_Int idx2; - /* note that we should not add a point for index 0; */ - /* this will move our current position to the flex */ - /* point without adding any point to the outline */ - idx = decoder->num_flex_vectors++; - if ( idx > 0 && idx < 7 ) - { - /* in malformed fonts it is possible to have other */ - /* opcodes in the middle of a flex (which don't */ - /* increase `num_flex_vectors'); we thus have to */ - /* check whether we can add a point */ - if ( ps_builder_check_points( &decoder->builder, 1 ) ) + + if ( arg_cnt != 0 ) + goto Unexpected_OtherSubr; + + if ( !initial_map_ready ) + break; + + if ( !decoder->flex_state ) { + FT_ERROR(( "cf2_interpT2CharString (Type 1 mode):" + " missing flex start\n" )); lastError = FT_THROW( Invalid_Glyph_Format ); goto exit; } - /* map: 1->2 2->4 3->6 4->2 5->4 6->6 */ - idx2 = ( idx > 3 ? idx - 3 : idx ) * 2; + /* note that we should not add a point for */ + /* index 0; this will move our current position */ + /* to the flex point without adding any point */ + /* to the outline */ + idx = decoder->num_flex_vectors++; + if ( idx > 0 && idx < 7 ) + { + /* in malformed fonts it is possible to have */ + /* other opcodes in the middle of a flex (which */ + /* don't increase `num_flex_vectors'); we thus */ + /* have to check whether we can add a point */ - flexStore[idx2 - 2] = curX; - flexStore[idx2 - 1] = curY; + if ( ps_builder_check_points( &decoder->builder, + 1 ) ) + { + lastError = FT_THROW( Invalid_Glyph_Format ); + goto exit; + } - if ( idx == 3 || idx == 6 ) - cf2_glyphpath_curveTo( &glyphPath, - flexStore[0], - flexStore[1], - flexStore[2], - flexStore[3], - flexStore[4], - flexStore[5] ); + /* map: 1->2 2->4 3->6 4->2 5->4 6->6 */ + idx2 = ( idx > 3 ? idx - 3 : idx ) * 2; + + flexStore[idx2 - 2] = curX; + flexStore[idx2 - 1] = curY; + + if ( idx == 3 || idx == 6 ) + cf2_glyphpath_curveTo( &glyphPath, + flexStore[0], + flexStore[1], + flexStore[2], + flexStore[3], + flexStore[4], + flexStore[5] ); + } } - } - break; + break; case 3: /* change hints */ if ( arg_cnt != 1 ) @@ -1785,221 +1804,242 @@ case 16: case 17: case 18: /* multiple masters */ - { - PS_Blend blend = decoder->blend; - FT_UInt num_points, nn, mm; - CF2_UInt delta; - CF2_UInt values; - - - if ( !blend ) { - FT_ERROR(( "t1_decoder_parse_charstrings:" - " unexpected multiple masters operator\n" )); - lastError = FT_THROW( Invalid_Glyph_Format ); - goto exit; + PS_Blend blend = decoder->blend; + FT_UInt num_points, nn, mm; + CF2_UInt delta; + CF2_UInt values; + + + if ( !blend ) + { + FT_ERROR(( + "cf2_interpT2CharString:" + " unexpected multiple masters operator\n" )); + lastError = FT_THROW( Invalid_Glyph_Format ); + goto exit; + } + + num_points = (FT_UInt)subr_no - 13 + + ( subr_no == 18 ); + if ( arg_cnt != (FT_Int)( num_points * + blend->num_designs ) ) + { + FT_ERROR(( + "cf2_interpT2CharString:" + " incorrect number of multiple masters arguments\n" )); + lastError = FT_THROW( Invalid_Glyph_Format ); + goto exit; + } + + /* We want to compute */ + /* */ + /* a0*w0 + a1*w1 + ... + ak*wk */ + /* */ + /* but we only have a0, a1-a0, a2-a0, ..., ak-a0. */ + /* */ + /* However, given that w0 + w1 + ... + wk == 1, we */ + /* can rewrite it easily as */ + /* */ + /* a0 + (a1-a0)*w1 + (a2-a0)*w2 + ... + (ak-a0)*wk */ + /* */ + /* where k == num_designs-1. */ + /* */ + /* I guess that's why it's written in this `compact' */ + /* form. */ + /* */ + delta = opIdx + num_points; + values = opIdx; + for ( nn = 0; nn < num_points; nn++ ) + { + CF2_Fixed tmp = cf2_stack_getReal( opStack, + values ); + + + for ( mm = 1; mm < blend->num_designs; mm++ ) + tmp = ADD_INT32( tmp, + FT_MulFix( + cf2_stack_getReal( opStack, + delta++ ), + blend->weight_vector[mm] ) ); + + cf2_stack_setReal( opStack, values++, tmp ); + } + cf2_stack_pop( opStack, + (CF2_UInt)arg_cnt - num_points ); + + known_othersubr_result_cnt = (FT_Int)num_points; + break; } - num_points = (FT_UInt)subr_no - 13 + ( subr_no == 18 ); - if ( arg_cnt != (FT_Int)( num_points * blend->num_designs ) ) - { - FT_ERROR(( "t1_decoder_parse_charstrings:" - " incorrect number of multiple masters arguments\n" )); - lastError = FT_THROW( Invalid_Glyph_Format ); - goto exit; - } - - /* We want to compute */ - /* */ - /* a0*w0 + a1*w1 + ... + ak*wk */ - /* */ - /* but we only have a0, a1-a0, a2-a0, ..., ak-a0. */ - /* */ - /* However, given that w0 + w1 + ... + wk == 1, we can */ - /* rewrite it easily as */ - /* */ - /* a0 + (a1-a0)*w1 + (a2-a0)*w2 + ... + (ak-a0)*wk */ - /* */ - /* where k == num_designs-1. */ - /* */ - /* I guess that's why it's written in this `compact' */ - /* form. */ - /* */ - delta = opIdx + num_points; - values = opIdx; - for ( nn = 0; nn < num_points; nn++ ) - { - CF2_Fixed tmp = cf2_stack_getReal( opStack, values ); - - - for ( mm = 1; mm < blend->num_designs; mm++ ) - tmp = ADD_INT32( tmp, - FT_MulFix( cf2_stack_getReal( opStack, delta++ ), - blend->weight_vector[mm] ) ); - - cf2_stack_setReal( opStack, values++, tmp ); - } - cf2_stack_pop( opStack, - (CF2_UInt)arg_cnt - num_points ); - - known_othersubr_result_cnt = (FT_Int)num_points; - break; - } - case 19: - /* 1 19 callothersubr */ - /* => replace elements starting from index cvi( ) */ - /* of BuildCharArray with WeightVector */ - { - FT_Int idx; - PS_Blend blend = decoder->blend; + /* 1 19 callothersubr */ + /* ==> replace elements starting from index */ + /* cvi( ) of BuildCharArray with */ + /* WeightVector */ + { + FT_Int idx; + PS_Blend blend = decoder->blend; - if ( arg_cnt != 1 || !blend ) - goto Unexpected_OtherSubr; + if ( arg_cnt != 1 || !blend ) + goto Unexpected_OtherSubr; - idx = cf2_stack_popInt( opStack ); + idx = cf2_stack_popInt( opStack ); - if ( idx < 0 || - (FT_UInt)idx + blend->num_designs > decoder->len_buildchar ) - goto Unexpected_OtherSubr; + if ( idx < 0 || + (FT_UInt)idx + blend->num_designs > + decoder->len_buildchar ) + goto Unexpected_OtherSubr; - ft_memcpy( &decoder->buildchar[idx], - blend->weight_vector, - blend->num_designs * - sizeof ( blend->weight_vector[0] ) ); - } - break; + ft_memcpy( &decoder->buildchar[idx], + blend->weight_vector, + blend->num_designs * + sizeof ( blend->weight_vector[0] ) ); + } + break; case 20: /* 2 20 callothersubr pop */ /* ==> push + onto T1 stack */ - { - CF2_F16Dot16 summand1; - CF2_F16Dot16 summand2; + { + CF2_F16Dot16 summand1; + CF2_F16Dot16 summand2; - if ( arg_cnt != 2 ) - goto Unexpected_OtherSubr; - summand2 = cf2_stack_popFixed( opStack ); - summand1 = cf2_stack_popFixed( opStack ); + if ( arg_cnt != 2 ) + goto Unexpected_OtherSubr; - cf2_stack_pushFixed( opStack, - ADD_INT32( summand1, - summand2 ) ); - known_othersubr_result_cnt = 1; - } - break; + summand2 = cf2_stack_popFixed( opStack ); + summand1 = cf2_stack_popFixed( opStack ); + + cf2_stack_pushFixed( opStack, + ADD_INT32( summand1, + summand2 ) ); + known_othersubr_result_cnt = 1; + } + break; case 21: /* 2 21 callothersubr pop */ /* ==> push - onto T1 stack */ - { - CF2_F16Dot16 minuend; - CF2_F16Dot16 subtrahend; + { + CF2_F16Dot16 minuend; + CF2_F16Dot16 subtrahend; - if ( arg_cnt != 2 ) - goto Unexpected_OtherSubr; - subtrahend = cf2_stack_popFixed( opStack ); - minuend = cf2_stack_popFixed( opStack ); + if ( arg_cnt != 2 ) + goto Unexpected_OtherSubr; - cf2_stack_pushFixed( opStack, - SUB_INT32( minuend, subtrahend ) ); - known_othersubr_result_cnt = 1; - } - break; + subtrahend = cf2_stack_popFixed( opStack ); + minuend = cf2_stack_popFixed( opStack ); + + cf2_stack_pushFixed( opStack, + SUB_INT32( minuend, + subtrahend ) ); + known_othersubr_result_cnt = 1; + } + break; case 22: /* 2 22 callothersubr pop */ /* ==> push * onto T1 stack */ - { - CF2_F16Dot16 factor1; - CF2_F16Dot16 factor2; + { + CF2_F16Dot16 factor1; + CF2_F16Dot16 factor2; - if ( arg_cnt != 2 ) - goto Unexpected_OtherSubr; - factor2 = cf2_stack_popFixed( opStack ); - factor1 = cf2_stack_popFixed( opStack ); + if ( arg_cnt != 2 ) + goto Unexpected_OtherSubr; - cf2_stack_pushFixed( opStack, - FT_MulFix( factor1, factor2 ) ); - known_othersubr_result_cnt = 1; - } - break; + factor2 = cf2_stack_popFixed( opStack ); + factor1 = cf2_stack_popFixed( opStack ); + + cf2_stack_pushFixed( opStack, + FT_MulFix( factor1, factor2 ) ); + known_othersubr_result_cnt = 1; + } + break; case 23: /* 2 23 callothersubr pop */ /* ==> push / onto T1 stack */ - { - CF2_F16Dot16 dividend; - CF2_F16Dot16 divisor; + { + CF2_F16Dot16 dividend; + CF2_F16Dot16 divisor; - if ( arg_cnt != 2 ) - goto Unexpected_OtherSubr; - divisor = cf2_stack_popFixed( opStack ); - dividend = cf2_stack_popFixed( opStack ); + if ( arg_cnt != 2 ) + goto Unexpected_OtherSubr; - if ( divisor == 0 ) - goto Unexpected_OtherSubr; + divisor = cf2_stack_popFixed( opStack ); + dividend = cf2_stack_popFixed( opStack ); - cf2_stack_pushFixed( opStack, - FT_DivFix( dividend, divisor ) ); - known_othersubr_result_cnt = 1; - } - break; + if ( divisor == 0 ) + goto Unexpected_OtherSubr; + + cf2_stack_pushFixed( opStack, + FT_DivFix( dividend, + divisor ) ); + known_othersubr_result_cnt = 1; + } + break; case 24: /* 2 24 callothersubr */ /* ==> set BuildCharArray[cvi( )] = */ - { - CF2_Int idx; - PS_Blend blend = decoder->blend; + { + CF2_Int idx; + PS_Blend blend = decoder->blend; - if ( arg_cnt != 2 || !blend ) - goto Unexpected_OtherSubr; + if ( arg_cnt != 2 || !blend ) + goto Unexpected_OtherSubr; - idx = cf2_stack_popInt( opStack ); + idx = cf2_stack_popInt( opStack ); - if ( idx < 0 || (FT_UInt) idx >= decoder->len_buildchar ) - goto Unexpected_OtherSubr; + if ( idx < 0 || + (FT_UInt)idx >= decoder->len_buildchar ) + goto Unexpected_OtherSubr; - decoder->buildchar[idx] = cf2_stack_popFixed( opStack ); - } - break; + decoder->buildchar[idx] = + cf2_stack_popFixed( opStack ); + } + break; case 25: /* 1 25 callothersubr pop */ /* ==> push BuildCharArray[cvi( idx )] */ /* onto T1 stack */ - { - CF2_Int idx; - PS_Blend blend = decoder->blend; + { + CF2_Int idx; + PS_Blend blend = decoder->blend; - if ( arg_cnt != 1 || !blend ) - goto Unexpected_OtherSubr; + if ( arg_cnt != 1 || !blend ) + goto Unexpected_OtherSubr; - idx = cf2_stack_popInt( opStack ); + idx = cf2_stack_popInt( opStack ); - if ( idx < 0 || (FT_UInt) idx >= decoder->len_buildchar ) - goto Unexpected_OtherSubr; + if ( idx < 0 || + (FT_UInt)idx >= decoder->len_buildchar ) + goto Unexpected_OtherSubr; - cf2_stack_pushFixed( opStack, - decoder->buildchar[idx] ); - known_othersubr_result_cnt = 1; - } - break; + cf2_stack_pushFixed( opStack, + decoder->buildchar[idx] ); + known_othersubr_result_cnt = 1; + } + break; #if 0 case 26: - /* mark ==> set BuildCharArray[cvi( )] = , */ - /* leave mark on T1 stack */ - /* ==> set BuildCharArray[cvi( )] = */ - XXX which routine has left its mark on the (PostScript) stack?; + /* mark */ + /* ==> set BuildCharArray[cvi( )] = , */ + /* leave mark on T1 stack */ + /* */ + /* ==> set BuildCharArray[cvi( )] = */ + XXX which routine has left its mark on the + XXX (PostScript) stack?; break; #endif @@ -2007,67 +2047,72 @@ /* 4 27 callothersubr pop */ /* ==> push onto T1 stack if <= , */ /* otherwise push */ - { - CF2_F16Dot16 arg1; - CF2_F16Dot16 arg2; - CF2_F16Dot16 cond1; - CF2_F16Dot16 cond2; + { + CF2_F16Dot16 arg1; + CF2_F16Dot16 arg2; + CF2_F16Dot16 cond1; + CF2_F16Dot16 cond2; - if ( arg_cnt != 4 ) - goto Unexpected_OtherSubr; - cond2 = cf2_stack_popFixed( opStack ); - cond1 = cf2_stack_popFixed( opStack ); - arg2 = cf2_stack_popFixed( opStack ); - arg1 = cf2_stack_popFixed( opStack ); + if ( arg_cnt != 4 ) + goto Unexpected_OtherSubr; - cf2_stack_pushFixed( opStack, - cond1 <= cond2 ? arg1 : arg2 ); - known_othersubr_result_cnt = 1; - } - break; + cond2 = cf2_stack_popFixed( opStack ); + cond1 = cf2_stack_popFixed( opStack ); + arg2 = cf2_stack_popFixed( opStack ); + arg1 = cf2_stack_popFixed( opStack ); + + cf2_stack_pushFixed( opStack, + cond1 <= cond2 ? arg1 : arg2 ); + known_othersubr_result_cnt = 1; + } + break; case 28: - /* 0 28 callothersubr pop */ - /* => push random value from interval [0, 1) onto stack */ - { - CF2_F16Dot16 r; + /* 0 28 callothersubr pop */ + /* ==> push random value from interval [0, 1) */ + /* onto stack */ + { + CF2_F16Dot16 r; - if ( arg_cnt != 0 ) - goto Unexpected_OtherSubr; - /* only use the lower 16 bits of `random' */ - /* to generate a number in the range (0;1] */ - r = (CF2_F16Dot16) - ( ( decoder->current_subfont->random & 0xFFFF ) + 1 ); + if ( arg_cnt != 0 ) + goto Unexpected_OtherSubr; - decoder->current_subfont->random = - cff_random( decoder->current_subfont->random ); + /* only use the lower 16 bits of `random' */ + /* to generate a number in the range (0;1] */ + r = (CF2_F16Dot16) + ( ( decoder->current_subfont->random & 0xFFFF ) + 1 ); - cf2_stack_pushFixed( opStack, r ); - known_othersubr_result_cnt = 1; - } - break; + decoder->current_subfont->random = + cff_random( decoder->current_subfont->random ); + + cf2_stack_pushFixed( opStack, r ); + known_othersubr_result_cnt = 1; + } + break; default: if ( arg_cnt >= 0 && subr_no >= 0 ) { FT_Int i; - FT_ERROR(( "cf2_interpT2CharString (Type 1 mode):" - " unknown othersubr [%d %d], wish me luck\n", - arg_cnt, subr_no )); - /* Store the unused args for this unhandled OtherSubr */ + FT_ERROR(( + "cf2_interpT2CharString (Type 1 mode):" + " unknown othersubr [%d %d], wish me luck\n", + arg_cnt, subr_no )); + + /* store the unused args */ + /* for this unhandled OtherSubr */ if ( arg_cnt > PS_STORAGE_SIZE ) arg_cnt = PS_STORAGE_SIZE; result_cnt = arg_cnt; for ( i = 1; i <= arg_cnt; i++ ) - { - results[result_cnt - i] = cf2_stack_popFixed( opStack ); - } + results[result_cnt - i] = + cf2_stack_popFixed( opStack ); break; } @@ -2075,7 +2120,8 @@ Unexpected_OtherSubr: FT_ERROR(( "cf2_interpT2CharString (Type 1 mode):" - " invalid othersubr [%d %d]\n", arg_cnt, subr_no )); + " invalid othersubr [%d %d]\n", + arg_cnt, subr_no )); lastError = FT_THROW( Invalid_Glyph_Format ); goto exit; } @@ -2320,23 +2366,24 @@ if ( !initial_map_ready ) break; - /* From the T1 specification, section 6.4: */ - /* */ - /* The setcurrentpoint command is used only in */ - /* conjunction with results from OtherSubrs procedures. */ + /* From the T1 specification, section 6.4: */ + /* */ + /* The setcurrentpoint command is used only in */ + /* conjunction with results from OtherSubrs */ + /* procedures. */ - /* known_othersubr_result_cnt != 0 is already handled */ - /* above. */ + /* known_othersubr_result_cnt != 0 is already handled */ + /* above. */ - /* Note, however, that both Ghostscript and Adobe */ - /* Distiller handle this situation by silently ignoring */ - /* the inappropriate `setcurrentpoint' instruction. So */ - /* we do the same. */ + /* Note, however, that both Ghostscript and Adobe */ + /* Distiller handle this situation by silently */ + /* ignoring the inappropriate `setcurrentpoint' */ + /* instruction. So we do the same. */ #if 0 if ( decoder->flex_state != 1 ) { - FT_ERROR(( "t1_decoder_parse_charstrings:" + FT_ERROR(( "cf2_interpT2CharString:" " unexpected `setcurrentpoint'\n" )); goto Syntax_Error; } @@ -2361,9 +2408,7 @@ case cf2_cmdHSBW: if ( !font->isT1 ) - { FT_TRACE4(( " unknown op (%d)\n", op1 )); - } else { CF2_Fixed lsb_x; @@ -2403,12 +2448,12 @@ FT_TRACE5(( "cf2_interpT2CharString (Type 1 mode): " "Build initial hintmap, rewinding...\n" )); - /* Trigger initial hintmap build */ + /* trigger initial hintmap build */ cf2_glyphpath_moveTo( &glyphPath, curX, curY ); initial_map_ready = TRUE; - /* Change hints routine - clear for rewind */ + /* change hints routine - clear for rewind */ cf2_arrstack_clear( &vStemHintArray ); cf2_arrstack_clear( &hStemHintArray ); @@ -2416,7 +2461,7 @@ hintMask.isValid = FALSE; hintMask.isNew = TRUE; - /* Rewind charstring */ + /* rewind charstring */ charstring->ptr = charstring->start; break; @@ -2439,7 +2484,8 @@ /* close path if still open */ cf2_glyphpath_closeOpenPath( &glyphPath ); - /* disable seac for CFF2 and Type1 (charstring ending with args on stack) */ + /* disable seac for CFF2 and Type1 */ + /* (charstring ending with args on stack) */ if ( !font->isCFF2 && !font->isT1 && cf2_stack_count( opStack ) > 1 ) { /* must be either 4 or 5 -- */ @@ -2575,10 +2621,8 @@ FT_TRACE4(( " rmoveto\n" )); if ( font->isT1 && !decoder->flex_state && !haveWidth ) - { FT_ERROR(( "cf2_interpT2CharString (Type 1 mode):" " No width. Use hsbw/sbw as first op\n" )); - } if ( cf2_stack_count( opStack ) > 2 && !haveWidth ) *width = ADD_INT32( cf2_stack_getReal( opStack, 0 ), @@ -2602,10 +2646,8 @@ FT_TRACE4(( " hmoveto\n" )); if ( font->isT1 && !decoder->flex_state && !haveWidth ) - { FT_ERROR(( "cf2_interpT2CharString (Type 1 mode):" " No width. Use hsbw/sbw as first op\n" )); - } if ( cf2_stack_count( opStack ) > 1 && !haveWidth ) *width = ADD_INT32( cf2_stack_getReal( opStack, 0 ), @@ -2910,25 +2952,28 @@ ( byte3 << 8 ) | byte4 ); - /* For Type 1: */ - /* According to the specification, values > 32000 or < -32000 must */ - /* be followed by a `div' operator to make the result be in the */ - /* range [-32000;32000]. We expect that the second argument of */ - /* `div' is not a large number. Additionally, we don't handle */ - /* stuff like ` div div' or */ - /* div div'. This is probably not allowed */ - /* anyway. */ - /* + div is not checked but should not be */ - /* allowed as the large value remains untouched. */ + /* + * For Type 1: + * + * According to the specification, values > 32000 or < -32000 + * must be followed by a `div' operator to make the result be + * in the range [-32000;32000]. We expect that the second + * argument of `div' is not a large number. Additionally, we + * don't handle stuff like ` div + * div' or div div'. This is probably + * not allowed anyway. + * + * + div is not checked but should not be + * allowed as the large value remains untouched. + * + */ if ( font->isT1 ) { if ( v > 32000 || v < -32000 ) { if ( large_int ) - { FT_ERROR(( "cf2_interpT2CharString (Type 1 mode):" " no `div' after large integer\n" )); - } else large_int = TRUE; } @@ -2943,7 +2988,6 @@ cf2_stack_pushFixed( opStack, v ); } - } } continue; /* don't clear stack */ diff --git a/src/psaux/psintrp.h b/src/psaux/psintrp.h index ec22ddcb7..4790aaa30 100644 --- a/src/psaux/psintrp.h +++ b/src/psaux/psintrp.h @@ -36,8 +36,8 @@ /***************************************************************************/ -#ifndef CF2INTRP_H_ -#define CF2INTRP_H_ +#ifndef PSINTRP_H_ +#define PSINTRP_H_ #include "psft.h" @@ -77,7 +77,7 @@ FT_BEGIN_HEADER FT_END_HEADER -#endif /* CF2INTRP_H_ */ +#endif /* PSINTRP_H_ */ /* END */ diff --git a/src/psaux/psobjs.c b/src/psaux/psobjs.c index 1b0b094c0..72442058c 100644 --- a/src/psaux/psobjs.c +++ b/src/psaux/psobjs.c @@ -2064,53 +2064,55 @@ { T1_Builder t1builder = (T1_Builder)builder; - ps_builder->memory = t1builder->memory; - ps_builder->face = (FT_Face)t1builder->face; - ps_builder->glyph = (CFF_GlyphSlot)t1builder->glyph; - ps_builder->loader = t1builder->loader; - ps_builder->base = t1builder->base; - ps_builder->current = t1builder->current; - ps_builder->pos_x = &t1builder->pos_x; - ps_builder->pos_y = &t1builder->pos_y; + ps_builder->memory = t1builder->memory; + ps_builder->face = (FT_Face)t1builder->face; + ps_builder->glyph = (CFF_GlyphSlot)t1builder->glyph; + ps_builder->loader = t1builder->loader; + ps_builder->base = t1builder->base; + ps_builder->current = t1builder->current; - ps_builder->left_bearing = &t1builder->left_bearing; - ps_builder->advance = &t1builder->advance; + ps_builder->pos_x = &t1builder->pos_x; + ps_builder->pos_y = &t1builder->pos_y; - ps_builder->bbox = &t1builder->bbox; - ps_builder->path_begun = 0; - ps_builder->load_points = t1builder->load_points; - ps_builder->no_recurse = t1builder->no_recurse; + ps_builder->left_bearing = &t1builder->left_bearing; + ps_builder->advance = &t1builder->advance; - ps_builder->metrics_only = t1builder->metrics_only; + ps_builder->bbox = &t1builder->bbox; + ps_builder->path_begun = 0; + ps_builder->load_points = t1builder->load_points; + ps_builder->no_recurse = t1builder->no_recurse; + + ps_builder->metrics_only = t1builder->metrics_only; } else { CFF_Builder* cffbuilder = (CFF_Builder*)builder; - ps_builder->memory = cffbuilder->memory; - ps_builder->face = (FT_Face)cffbuilder->face; - ps_builder->glyph = cffbuilder->glyph; - ps_builder->loader = cffbuilder->loader; - ps_builder->base = cffbuilder->base; - ps_builder->current = cffbuilder->current; - ps_builder->pos_x = &cffbuilder->pos_x; - ps_builder->pos_y = &cffbuilder->pos_y; + ps_builder->memory = cffbuilder->memory; + ps_builder->face = (FT_Face)cffbuilder->face; + ps_builder->glyph = cffbuilder->glyph; + ps_builder->loader = cffbuilder->loader; + ps_builder->base = cffbuilder->base; + ps_builder->current = cffbuilder->current; - ps_builder->left_bearing = &cffbuilder->left_bearing; - ps_builder->advance = &cffbuilder->advance; + ps_builder->pos_x = &cffbuilder->pos_x; + ps_builder->pos_y = &cffbuilder->pos_y; - ps_builder->bbox = &cffbuilder->bbox; - ps_builder->path_begun = cffbuilder->path_begun; - ps_builder->load_points = cffbuilder->load_points; - ps_builder->no_recurse = cffbuilder->no_recurse; + ps_builder->left_bearing = &cffbuilder->left_bearing; + ps_builder->advance = &cffbuilder->advance; - ps_builder->metrics_only = cffbuilder->metrics_only; + ps_builder->bbox = &cffbuilder->bbox; + ps_builder->path_begun = cffbuilder->path_begun; + ps_builder->load_points = cffbuilder->load_points; + ps_builder->no_recurse = cffbuilder->no_recurse; + + ps_builder->metrics_only = cffbuilder->metrics_only; } - ps_builder->is_t1 = is_t1; - ps_builder->funcs = ps_builder_funcs; + ps_builder->is_t1 = is_t1; + ps_builder->funcs = ps_builder_funcs; } @@ -2164,6 +2166,7 @@ PS_Driver driver = (PS_Driver)FT_FACE_DRIVER( builder->face ); + #ifdef CFF_CONFIG_OPTION_OLD_ENGINE if ( !builder->is_t1 && driver->hinting_engine == FT_CFF_HINTING_FREETYPE ) @@ -2219,7 +2222,7 @@ /* this might happen in invalid fonts */ if ( !outline ) { - FT_ERROR(( "t1_builder_add_contour: no outline to add points to\n" )); + FT_ERROR(( "ps_builder_add_contour: no outline to add points to\n" )); return FT_THROW( Invalid_File_Format ); } @@ -2356,61 +2359,63 @@ { T1_Decoder t1_decoder = (T1_Decoder)decoder; + ps_builder_init( &ps_decoder->builder, &t1_decoder->builder, is_t1 ); - ps_decoder->cf2_instance = &t1_decoder->cf2_instance; - ps_decoder->psnames = t1_decoder->psnames; + ps_decoder->cf2_instance = &t1_decoder->cf2_instance; + ps_decoder->psnames = t1_decoder->psnames; - ps_decoder->num_glyphs = t1_decoder->num_glyphs; - ps_decoder->glyph_names = t1_decoder->glyph_names; - ps_decoder->hint_mode = t1_decoder->hint_mode; - ps_decoder->blend = t1_decoder->blend; + ps_decoder->num_glyphs = t1_decoder->num_glyphs; + ps_decoder->glyph_names = t1_decoder->glyph_names; + ps_decoder->hint_mode = t1_decoder->hint_mode; + ps_decoder->blend = t1_decoder->blend; - ps_decoder->num_locals = (FT_UInt)t1_decoder->num_subrs; - ps_decoder->locals = t1_decoder->subrs; - ps_decoder->locals_len = t1_decoder->subrs_len; - ps_decoder->locals_hash = t1_decoder->subrs_hash; + ps_decoder->num_locals = (FT_UInt)t1_decoder->num_subrs; + ps_decoder->locals = t1_decoder->subrs; + ps_decoder->locals_len = t1_decoder->subrs_len; + ps_decoder->locals_hash = t1_decoder->subrs_hash; - ps_decoder->buildchar = t1_decoder->buildchar; - ps_decoder->len_buildchar = t1_decoder->len_buildchar; + ps_decoder->buildchar = t1_decoder->buildchar; + ps_decoder->len_buildchar = t1_decoder->len_buildchar; - ps_decoder->lenIV = t1_decoder->lenIV; + ps_decoder->lenIV = t1_decoder->lenIV; } else { CFF_Decoder* cff_decoder = (CFF_Decoder*)decoder; + ps_builder_init( &ps_decoder->builder, &cff_decoder->builder, is_t1 ); - ps_decoder->cff = cff_decoder->cff; - ps_decoder->cf2_instance = &cff_decoder->cff->cf2_instance; - ps_decoder->current_subfont = cff_decoder->current_subfont; + ps_decoder->cff = cff_decoder->cff; + ps_decoder->cf2_instance = &cff_decoder->cff->cf2_instance; + ps_decoder->current_subfont = cff_decoder->current_subfont; - ps_decoder->num_globals = cff_decoder->num_globals; - ps_decoder->globals = cff_decoder->globals; - ps_decoder->globals_bias = cff_decoder->globals_bias; - ps_decoder->num_locals = cff_decoder->num_locals; - ps_decoder->locals = cff_decoder->locals; - ps_decoder->locals_bias = cff_decoder->locals_bias; + ps_decoder->num_globals = cff_decoder->num_globals; + ps_decoder->globals = cff_decoder->globals; + ps_decoder->globals_bias = cff_decoder->globals_bias; + ps_decoder->num_locals = cff_decoder->num_locals; + ps_decoder->locals = cff_decoder->locals; + ps_decoder->locals_bias = cff_decoder->locals_bias; - ps_decoder->glyph_width = cff_decoder->glyph_width; - ps_decoder->nominal_width = cff_decoder->nominal_width; - ps_decoder->width_only = cff_decoder->width_only; + ps_decoder->glyph_width = cff_decoder->glyph_width; + ps_decoder->nominal_width = cff_decoder->nominal_width; + ps_decoder->width_only = cff_decoder->width_only; - ps_decoder->hint_mode = cff_decoder->hint_mode; + ps_decoder->hint_mode = cff_decoder->hint_mode; - ps_decoder->get_glyph_callback = cff_decoder->get_glyph_callback; - ps_decoder->free_glyph_callback = cff_decoder->free_glyph_callback; + ps_decoder->get_glyph_callback = cff_decoder->get_glyph_callback; + ps_decoder->free_glyph_callback = cff_decoder->free_glyph_callback; } } /* Synthesize a SubFont object for Type 1 fonts, for use in the */ - /* new interpreter to access Private dict data */ + /* new interpreter to access Private dict data. */ FT_LOCAL_DEF( void ) t1_make_subfont( FT_Face face, PS_Private priv, @@ -2419,6 +2424,7 @@ CFF_Private cpriv = &subfont->private_dict; FT_UInt n, count; + FT_ZERO( subfont ); FT_ZERO( cpriv ); @@ -2442,8 +2448,8 @@ cpriv->blue_shift = (FT_Pos)priv->blue_shift; cpriv->blue_fuzz = (FT_Pos)priv->blue_fuzz; - cpriv->standard_width = (FT_Pos)priv->standard_width[0]; - cpriv->standard_height = (FT_Pos)priv->standard_height[0]; + cpriv->standard_width = (FT_Pos)priv->standard_width[0]; + cpriv->standard_height = (FT_Pos)priv->standard_height[0]; count = cpriv->num_snap_widths = priv->num_snap_widths; for ( n = 0; n < count; n++ ) @@ -2458,14 +2464,14 @@ cpriv->language_group = priv->language_group; cpriv->expansion_factor = priv->expansion_factor; - cpriv->subfont = subfont; + cpriv->subfont = subfont; /* Initialize the random number generator. */ if ( face->internal->random_seed != -1 ) { - /* . If we have a face-specific seed, use it. */ - /* If non-zero, update it to a positive value. */ + /* If we have a face-specific seed, use it. */ + /* If non-zero, update it to a positive value. */ subfont->random = (FT_UInt32)face->internal->random_seed; if ( face->internal->random_seed ) { @@ -2473,6 +2479,7 @@ { face->internal->random_seed = (FT_Int32)cff_random( (FT_UInt32)face->internal->random_seed ); + } while ( face->internal->random_seed < 0 ); } } @@ -2480,6 +2487,7 @@ { FT_UInt32 seed; + /* compute random seed from some memory addresses */ seed = (FT_UInt32)( (FT_Offset)(char*)&seed ^ (FT_Offset)(char*)&face ^ diff --git a/src/psaux/psread.h b/src/psaux/psread.h index 9e2119509..464b29ba7 100644 --- a/src/psaux/psread.h +++ b/src/psaux/psread.h @@ -36,8 +36,8 @@ /***************************************************************************/ -#ifndef CF2READ_H_ -#define CF2READ_H_ +#ifndef PSREAD_H_ +#define PSREAD_H_ FT_BEGIN_HEADER @@ -62,7 +62,7 @@ FT_BEGIN_HEADER FT_END_HEADER -#endif /* CF2READ_H_ */ +#endif /* PSREAD_H_ */ /* END */ diff --git a/src/psaux/psstack.h b/src/psaux/psstack.h index 1b9865dea..38f7b41c6 100644 --- a/src/psaux/psstack.h +++ b/src/psaux/psstack.h @@ -36,8 +36,8 @@ /***************************************************************************/ -#ifndef CF2STACK_H_ -#define CF2STACK_H_ +#ifndef PSSTACK_H_ +#define PSSTACK_H_ FT_BEGIN_HEADER @@ -115,7 +115,7 @@ FT_BEGIN_HEADER FT_END_HEADER -#endif /* CF2STACK_H_ */ +#endif /* PSSTACK_H_ */ /* END */ diff --git a/src/psaux/pstypes.h b/src/psaux/pstypes.h index 9f31493f2..dfbaa3d47 100644 --- a/src/psaux/pstypes.h +++ b/src/psaux/pstypes.h @@ -36,8 +36,8 @@ /***************************************************************************/ -#ifndef CF2TYPES_H_ -#define CF2TYPES_H_ +#ifndef PSTYPES_H_ +#define PSTYPES_H_ #include #include FT_FREETYPE_H @@ -72,7 +72,7 @@ FT_BEGIN_HEADER FT_END_HEADER -#endif /* CF2TYPES_H_ */ +#endif /* PSTYPES_H_ */ /* END */ diff --git a/src/psaux/t1decode.c b/src/psaux/t1decode.c index 37790c50b..e68b76dac 100644 --- a/src/psaux/t1decode.c +++ b/src/psaux/t1decode.c @@ -1692,6 +1692,7 @@ { FT_Memory memory = decoder->builder.memory; + t1_builder_done( &decoder->builder ); if ( decoder->cf2_instance.finalizer )