From 6cfd5e41061f989aa3b155faf15f1ec870a5af5c Mon Sep 17 00:00:00 2001 From: Crayon2000 Date: Wed, 1 Dec 2010 23:41:40 +0000 Subject: [PATCH] [CHG] FreeType updated to version 2.4.4 --- .../lib/freetype/include/freetype/freetype.h | 2 +- .../lib/freetype/include/freetype/ftcache.h | 12 ++ GRRLIB/lib/freetype/src/base/ftbase.h | 11 + GRRLIB/lib/freetype/src/base/ftdbgmem.c | 6 +- GRRLIB/lib/freetype/src/base/ftobjs.c | 17 ++ GRRLIB/lib/freetype/src/base/ftrfork.c | 80 ++++++-- GRRLIB/lib/freetype/src/base/ftsystem.c | 17 +- GRRLIB/lib/freetype/src/cache/ftcbasic.c | 8 +- GRRLIB/lib/freetype/src/cache/ftccache.c | 6 +- GRRLIB/lib/freetype/src/cache/ftccache.h | 11 +- GRRLIB/lib/freetype/src/cache/ftccmap.c | 4 +- GRRLIB/lib/freetype/src/cache/ftcglyph.c | 2 +- GRRLIB/lib/freetype/src/cache/ftcglyph.h | 2 +- GRRLIB/lib/freetype/src/cache/ftcmanag.h | 2 +- GRRLIB/lib/freetype/src/psaux/t1decode.c | 75 +++---- GRRLIB/lib/freetype/src/raster/ftraster.c | 17 +- GRRLIB/lib/freetype/src/sfnt/sfobjs.c | 4 +- GRRLIB/lib/freetype/src/sfnt/ttload.c | 9 +- GRRLIB/lib/freetype/src/sfnt/ttpost.c | 1 + GRRLIB/lib/freetype/src/smooth/ftgrays.c | 66 +++--- GRRLIB/lib/freetype/src/truetype/ttgxvar.c | 6 +- GRRLIB/lib/freetype/src/truetype/ttinterp.c | 18 +- GRRLIB/lib/freetype/src/truetype/ttobjs.c | 192 +++++++++++++++++- GRRLIB/lib/freetype/src/truetype/ttpload.c | 10 +- GRRLIB/lib/freetype/src/type1/t1load.c | 18 +- 25 files changed, 450 insertions(+), 146 deletions(-) diff --git a/GRRLIB/lib/freetype/include/freetype/freetype.h b/GRRLIB/lib/freetype/include/freetype/freetype.h index 3b30332..70c3900 100644 --- a/GRRLIB/lib/freetype/include/freetype/freetype.h +++ b/GRRLIB/lib/freetype/include/freetype/freetype.h @@ -3808,7 +3808,7 @@ FT_BEGIN_HEADER */ #define FREETYPE_MAJOR 2 #define FREETYPE_MINOR 4 -#define FREETYPE_PATCH 3 +#define FREETYPE_PATCH 4 /*************************************************************************/ diff --git a/GRRLIB/lib/freetype/include/freetype/ftcache.h b/GRRLIB/lib/freetype/include/freetype/ftcache.h index fe8664d..6af5306 100644 --- a/GRRLIB/lib/freetype/include/freetype/ftcache.h +++ b/GRRLIB/lib/freetype/include/freetype/ftcache.h @@ -214,12 +214,17 @@ FT_BEGIN_HEADER /* */ +#ifdef FT_CONFIG_OPTION_OLD_INTERNALS + + /* these macros are incompatible with LLP64, should not be used */ + #define FT_POINTER_TO_ULONG( p ) ( (FT_ULong)(FT_Pointer)(p) ) #define FTC_FACE_ID_HASH( i ) \ ((FT_UInt32)(( FT_POINTER_TO_ULONG( i ) >> 3 ) ^ \ ( FT_POINTER_TO_ULONG( i ) << 7 ) ) ) +#endif /* FT_CONFIG_OPTION_OLD_INTERNALS */ /*************************************************************************/ /*************************************************************************/ @@ -700,11 +705,17 @@ FT_BEGIN_HEADER (d1)->width == (d2)->width && \ (d1)->flags == (d2)->flags ) +#ifdef FT_CONFIG_OPTION_OLD_INTERNALS + + /* this macro is incompatible with LLP64, should not be used */ + #define FTC_IMAGE_TYPE_HASH( d ) \ (FT_UFast)( FTC_FACE_ID_HASH( (d)->face_id ) ^ \ ( (d)->width << 8 ) ^ (d)->height ^ \ ( (d)->flags << 4 ) ) +#endif /* FT_CONFIG_OPTION_OLD_INTERNALS */ + /*************************************************************************/ /* */ @@ -1096,6 +1107,7 @@ FT_BEGIN_HEADER (f1)->pix_width == (f2)->pix_width && \ (f1)->pix_height == (f2)->pix_height ) + /* this macro is incompatible with LLP64, should not be used */ #define FTC_FONT_HASH( f ) \ (FT_UInt32)( FTC_FACE_ID_HASH((f)->face_id) ^ \ ((f)->pix_width << 8) ^ \ diff --git a/GRRLIB/lib/freetype/src/base/ftbase.h b/GRRLIB/lib/freetype/src/base/ftbase.h index 1dc49f3..6375613 100644 --- a/GRRLIB/lib/freetype/src/base/ftbase.h +++ b/GRRLIB/lib/freetype/src/base/ftbase.h @@ -49,6 +49,17 @@ FT_BEGIN_HEADER FT_Face *aface ); +#ifdef FT_CONFIG_OPTION_GUESSING_EMBEDDED_RFORK + /* Mac OS X/Darwin kernel often changes recommended method to access */ + /* the resource fork and older methods makes the kernel issue the */ + /* warning of deprecated method. To calm it down, the methods based */ + /* on Darwin VFS should be grouped and skip the rest methods after */ + /* the case the resource is opened but found to lack a font in it. */ + FT_LOCAL( FT_Bool ) + raccess_rule_by_darwin_vfs( FT_UInt rule_index ); +#endif /* FT_CONFIG_OPTION_GUESSING_EMBEDDED_RFORK */ + + FT_END_HEADER #endif /* __FTBASE_H__ */ diff --git a/GRRLIB/lib/freetype/src/base/ftdbgmem.c b/GRRLIB/lib/freetype/src/base/ftdbgmem.c index 160269d..12fed04 100644 --- a/GRRLIB/lib/freetype/src/base/ftdbgmem.c +++ b/GRRLIB/lib/freetype/src/base/ftdbgmem.c @@ -47,7 +47,7 @@ typedef struct FT_MemTableRec_* FT_MemTable; -#define FT_MEM_VAL( addr ) ((FT_ULong)(FT_Pointer)( addr )) +#define FT_MEM_VAL( addr ) ((FT_PtrDist)(FT_Pointer)( addr )) /* * This structure holds statistics for a single allocation/release @@ -275,7 +275,7 @@ for ( i = 0; i < table->size; i++ ) { FT_MemNode node, next, *pnode; - FT_ULong hash; + FT_PtrDist hash; node = table->buckets[i]; @@ -430,7 +430,7 @@ ft_mem_table_get_nodep( FT_MemTable table, FT_Byte* address ) { - FT_ULong hash; + FT_PtrDist hash; FT_MemNode *pnode, node; diff --git a/GRRLIB/lib/freetype/src/base/ftobjs.c b/GRRLIB/lib/freetype/src/base/ftobjs.c index 7f38df0..cb44b8c 100644 --- a/GRRLIB/lib/freetype/src/base/ftobjs.c +++ b/GRRLIB/lib/freetype/src/base/ftobjs.c @@ -1062,6 +1062,7 @@ if ( cur[0]->platform_id == TT_PLATFORM_APPLE_UNICODE && cur[0]->encoding_id == TT_APPLE_ID_VARIANT_SELECTOR && FT_Get_CMap_Format( cur[0] ) == 14 ) + { #ifdef FT_MAX_CHARMAP_CACHEABLE if ( cur - first > FT_MAX_CHARMAP_CACHEABLE ) { @@ -1071,6 +1072,7 @@ } #endif return cur[0]; + } } return NULL; @@ -1849,6 +1851,7 @@ char * file_names[FT_RACCESS_N_RULES]; FT_Long offsets[FT_RACCESS_N_RULES]; FT_Error errors[FT_RACCESS_N_RULES]; + FT_Bool is_darwin_vfs, vfs_rfork_has_no_font = FALSE; /* not tested */ FT_Open_Args args2; FT_Stream stream2 = 0; @@ -1859,6 +1862,15 @@ for ( i = 0; i < FT_RACCESS_N_RULES; i++ ) { + is_darwin_vfs = raccess_rule_by_darwin_vfs( i ); + if ( is_darwin_vfs && vfs_rfork_has_no_font ) + { + FT_TRACE3(( "Skip rule %d: darwin vfs resource fork" + " is already checked and" + " no font is found\n", i )); + continue; + } + if ( errors[i] ) { FT_TRACE3(( "Error[%d] has occurred in rule %d\n", errors[i], i )); @@ -1872,6 +1884,9 @@ i, args2.pathname, offsets[i] )); error = FT_Stream_New( library, &args2, &stream2 ); + if ( is_darwin_vfs && error == FT_Err_Cannot_Open_Stream ) + vfs_rfork_has_no_font = TRUE; + if ( error ) { FT_TRACE3(( "failed\n" )); @@ -1886,6 +1901,8 @@ if ( !error ) break; + else if ( is_darwin_vfs ) + vfs_rfork_has_no_font = TRUE; } for (i = 0; i < FT_RACCESS_N_RULES; i++) diff --git a/GRRLIB/lib/freetype/src/base/ftrfork.c b/GRRLIB/lib/freetype/src/base/ftrfork.c index f64d28b..6df2def 100644 --- a/GRRLIB/lib/freetype/src/base/ftrfork.c +++ b/GRRLIB/lib/freetype/src/base/ftrfork.c @@ -349,6 +349,42 @@ const char *insertion ); + typedef enum FT_RFork_Rule_ { + FT_RFork_Rule_invalid = -2, + FT_RFork_Rule_uknown, /* -1 */ + FT_RFork_Rule_apple_double, + FT_RFork_Rule_apple_single, + FT_RFork_Rule_darwin_ufs_export, + FT_RFork_Rule_darwin_newvfs, + FT_RFork_Rule_darwin_hfsplus, + FT_RFork_Rule_vfat, + FT_RFork_Rule_linux_cap, + FT_RFork_Rule_linux_double, + FT_RFork_Rule_linux_netatalk + } FT_RFork_Rule; + + /* For fast translation between rule index and rule type, + * the macros FT_RFORK_xxx should be kept consistent with + * the raccess_guess_funcs table + */ + typedef struct raccess_guess_rec_ { + raccess_guess_func func; + FT_RFork_Rule type; + } raccess_guess_rec; + + static raccess_guess_rec raccess_guess_table[FT_RACCESS_N_RULES] = + { + { raccess_guess_apple_double, FT_RFork_Rule_apple_double, }, + { raccess_guess_apple_single, FT_RFork_Rule_apple_single, }, + { raccess_guess_darwin_ufs_export, FT_RFork_Rule_darwin_ufs_export, }, + { raccess_guess_darwin_newvfs, FT_RFork_Rule_darwin_newvfs, }, + { raccess_guess_darwin_hfsplus, FT_RFork_Rule_darwin_hfsplus, }, + { raccess_guess_vfat, FT_RFork_Rule_vfat, }, + { raccess_guess_linux_cap, FT_RFork_Rule_linux_cap, }, + { raccess_guess_linux_double, FT_RFork_Rule_linux_double, }, + { raccess_guess_linux_netatalk, FT_RFork_Rule_linux_netatalk, }, + }; + FT_BASE_DEF( void ) FT_Raccess_Guess( FT_Library library, FT_Stream stream, @@ -360,19 +396,6 @@ FT_Long i; - raccess_guess_func funcs[FT_RACCESS_N_RULES] = - { - raccess_guess_apple_double, - raccess_guess_apple_single, - raccess_guess_darwin_ufs_export, - raccess_guess_darwin_newvfs, - raccess_guess_darwin_hfsplus, - raccess_guess_vfat, - raccess_guess_linux_cap, - raccess_guess_linux_double, - raccess_guess_linux_netatalk, - }; - for ( i = 0; i < FT_RACCESS_N_RULES; i++ ) { new_names[i] = NULL; @@ -384,14 +407,41 @@ if ( errors[i] ) continue ; - errors[i] = (funcs[i])( library, stream, base_name, - &(new_names[i]), &(offsets[i]) ); + errors[i] = (raccess_guess_table[i].func)( library, + stream, base_name, + &(new_names[i]), + &(offsets[i]) ); } return; } + static FT_RFork_Rule + raccess_get_rule_type_from_rule_index( FT_UInt rule_index ) + { + if ( rule_index >= FT_RACCESS_N_RULES ) + return FT_RFork_Rule_invalid; + + return raccess_guess_table[rule_index].type; + } + + + FT_LOCAL_DEF( FT_Bool ) + raccess_rule_by_darwin_vfs( FT_UInt rule_index ) + { + switch( raccess_get_rule_type_from_rule_index( rule_index ) ) + { + case FT_RFork_Rule_darwin_newvfs: + case FT_RFork_Rule_darwin_hfsplus: + return TRUE; + + default: + return FALSE; + } + } + + static FT_Error raccess_guess_apple_double( FT_Library library, FT_Stream stream, diff --git a/GRRLIB/lib/freetype/src/base/ftsystem.c b/GRRLIB/lib/freetype/src/base/ftsystem.c index ba86005..66c5d76 100644 --- a/GRRLIB/lib/freetype/src/base/ftsystem.c +++ b/GRRLIB/lib/freetype/src/base/ftsystem.c @@ -229,6 +229,13 @@ if ( !stream ) return FT_Err_Invalid_Stream_Handle; + stream->descriptor.pointer = NULL; + stream->pathname.pointer = (char*)filepathname; + stream->base = 0; + stream->pos = 0; + stream->read = NULL; + stream->close = NULL; + file = ft_fopen( filepathname, "rb" ); if ( !file ) { @@ -240,12 +247,16 @@ ft_fseek( file, 0, SEEK_END ); stream->size = ft_ftell( file ); + if ( !stream->size ) + { + FT_ERROR(( "FT_Stream_Open:" )); + FT_ERROR(( " opened `%s' but zero-sized\n", filepathname )); + ft_fclose( file ); + return FT_Err_Cannot_Open_Stream; + } ft_fseek( file, 0, SEEK_SET ); stream->descriptor.pointer = file; - stream->pathname.pointer = (char*)filepathname; - stream->pos = 0; - stream->read = ft_ansi_stream_io; stream->close = ft_ansi_stream_close; diff --git a/GRRLIB/lib/freetype/src/cache/ftcbasic.c b/GRRLIB/lib/freetype/src/cache/ftcbasic.c index 9fb6ddb..609ff78 100644 --- a/GRRLIB/lib/freetype/src/cache/ftcbasic.c +++ b/GRRLIB/lib/freetype/src/cache/ftcbasic.c @@ -318,7 +318,7 @@ FTC_BasicQueryRec query; FTC_Node node = 0; /* make compiler happy */ FT_Error error; - FT_UInt32 hash; + FT_PtrDist hash; /* some argument checks are delayed to FTC_Cache_Lookup */ @@ -414,7 +414,7 @@ FTC_BasicQueryRec query; FTC_Node node = 0; /* make compiler happy */ FT_Error error; - FT_UInt32 hash; + FT_PtrDist hash; /* some argument checks are delayed to FTC_Cache_Lookup */ @@ -656,7 +656,7 @@ FT_Error error; FTC_BasicQueryRec query; FTC_Node node = 0; /* make compiler happy */ - FT_UInt32 hash; + FT_PtrDist hash; if ( anode ) @@ -753,7 +753,7 @@ FT_Error error; FTC_BasicQueryRec query; FTC_Node node = 0; /* make compiler happy */ - FT_UInt32 hash; + FT_PtrDist hash; if ( anode ) diff --git a/GRRLIB/lib/freetype/src/cache/ftccache.c b/GRRLIB/lib/freetype/src/cache/ftccache.c index e0d43d5..a5a915e 100644 --- a/GRRLIB/lib/freetype/src/cache/ftccache.c +++ b/GRRLIB/lib/freetype/src/cache/ftccache.c @@ -410,7 +410,7 @@ static void ftc_cache_add( FTC_Cache cache, - FT_UInt32 hash, + FT_PtrDist hash, FTC_Node node ) { node->hash = hash; @@ -438,7 +438,7 @@ FT_LOCAL_DEF( FT_Error ) FTC_Cache_NewNode( FTC_Cache cache, - FT_UInt32 hash, + FT_PtrDist hash, FT_Pointer query, FTC_Node *anode ) { @@ -477,7 +477,7 @@ FT_LOCAL_DEF( FT_Error ) FTC_Cache_Lookup( FTC_Cache cache, - FT_UInt32 hash, + FT_PtrDist hash, FT_Pointer query, FTC_Node *anode ) { diff --git a/GRRLIB/lib/freetype/src/cache/ftccache.h b/GRRLIB/lib/freetype/src/cache/ftccache.h index 1b69584..10830a9 100644 --- a/GRRLIB/lib/freetype/src/cache/ftccache.h +++ b/GRRLIB/lib/freetype/src/cache/ftccache.h @@ -24,6 +24,9 @@ FT_BEGIN_HEADER +#define _FTC_FACE_ID_HASH( i ) \ + ((FT_PtrDist)(( (FT_PtrDist)(i) >> 3 ) ^ ( (FT_PtrDist)(i) << 7 ))) + /* handle to cache object */ typedef struct FTC_CacheRec_* FTC_Cache; @@ -56,7 +59,7 @@ FT_BEGIN_HEADER { FTC_MruNodeRec mru; /* circular mru list pointer */ FTC_Node link; /* used for hashing */ - FT_UInt32 hash; /* used for hashing too */ + FT_PtrDist hash; /* used for hashing too */ FT_UShort cache_index; /* index of cache the node belongs to */ FT_Short ref_count; /* reference count for this node */ @@ -168,14 +171,14 @@ FT_BEGIN_HEADER #ifndef FTC_INLINE FT_LOCAL( FT_Error ) FTC_Cache_Lookup( FTC_Cache cache, - FT_UInt32 hash, + FT_PtrDist hash, FT_Pointer query, FTC_Node *anode ); #endif FT_LOCAL( FT_Error ) FTC_Cache_NewNode( FTC_Cache cache, - FT_UInt32 hash, + FT_PtrDist hash, FT_Pointer query, FTC_Node *anode ); @@ -200,7 +203,7 @@ FT_BEGIN_HEADER FT_BEGIN_STMNT \ FTC_Node *_bucket, *_pnode, _node; \ FTC_Cache _cache = FTC_CACHE(cache); \ - FT_UInt32 _hash = (FT_UInt32)(hash); \ + FT_PtrDist _hash = (FT_PtrDist)(hash); \ FTC_Node_CompareFunc _nodcomp = (FTC_Node_CompareFunc)(nodecmp); \ FT_UFast _idx; \ \ diff --git a/GRRLIB/lib/freetype/src/cache/ftccmap.c b/GRRLIB/lib/freetype/src/cache/ftccmap.c index 1210492..15060ba 100644 --- a/GRRLIB/lib/freetype/src/cache/ftccmap.c +++ b/GRRLIB/lib/freetype/src/cache/ftccmap.c @@ -87,7 +87,7 @@ /* compute a query/node hash */ #define FTC_CMAP_HASH( faceid, index, charcode ) \ - ( FTC_FACE_ID_HASH( faceid ) + 211 * (index) + \ + ( _FTC_FACE_ID_HASH( faceid ) + 211 * (index) + \ ( (charcode) / FTC_CMAP_INDICES_MAX ) ) /* the charmap query */ @@ -287,7 +287,7 @@ FTC_Node node; FT_Error error; FT_UInt gindex = 0; - FT_UInt32 hash; + FT_PtrDist hash; FT_Int no_cmap_change = 0; diff --git a/GRRLIB/lib/freetype/src/cache/ftcglyph.c b/GRRLIB/lib/freetype/src/cache/ftcglyph.c index a9ab0c3..a73e243 100644 --- a/GRRLIB/lib/freetype/src/cache/ftcglyph.c +++ b/GRRLIB/lib/freetype/src/cache/ftcglyph.c @@ -175,7 +175,7 @@ FT_LOCAL_DEF( FT_Error ) FTC_GCache_Lookup( FTC_GCache cache, - FT_UInt32 hash, + FT_PtrDist hash, FT_UInt gindex, FTC_GQuery query, FTC_Node *anode ) diff --git a/GRRLIB/lib/freetype/src/cache/ftcglyph.h b/GRRLIB/lib/freetype/src/cache/ftcglyph.h index c18f9c3..2bc5624 100644 --- a/GRRLIB/lib/freetype/src/cache/ftcglyph.h +++ b/GRRLIB/lib/freetype/src/cache/ftcglyph.h @@ -254,7 +254,7 @@ FT_BEGIN_HEADER #ifndef FTC_INLINE FT_LOCAL( FT_Error ) FTC_GCache_Lookup( FTC_GCache cache, - FT_UInt32 hash, + FT_PtrDist hash, FT_UInt gindex, FTC_GQuery query, FTC_Node *anode ); diff --git a/GRRLIB/lib/freetype/src/cache/ftcmanag.h b/GRRLIB/lib/freetype/src/cache/ftcmanag.h index 3fdc2c7..13f26bb 100644 --- a/GRRLIB/lib/freetype/src/cache/ftcmanag.h +++ b/GRRLIB/lib/freetype/src/cache/ftcmanag.h @@ -161,7 +161,7 @@ FT_BEGIN_HEADER (a)->y_res == (b)->y_res ) ) ) #define FTC_SCALER_HASH( q ) \ - ( FTC_FACE_ID_HASH( (q)->face_id ) + \ + ( _FTC_FACE_ID_HASH( (q)->face_id ) + \ (q)->width + (q)->height*7 + \ ( (q)->pixel ? 0 : ( (q)->x_res*33 ^ (q)->y_res*61 ) ) ) diff --git a/GRRLIB/lib/freetype/src/psaux/t1decode.c b/GRRLIB/lib/freetype/src/psaux/t1decode.c index babf3ba..ea31c51 100644 --- a/GRRLIB/lib/freetype/src/psaux/t1decode.c +++ b/GRRLIB/lib/freetype/src/psaux/t1decode.c @@ -373,15 +373,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 ^ @@ -739,8 +730,10 @@ 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,10 +750,10 @@ /* 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; @@ -1077,7 +1070,7 @@ case op_endchar: FT_TRACE4(( " endchar\n" )); - close_contour( builder ); + t1_builder_close_contour( builder ); /* close hints recording session */ if ( hinter ) @@ -1176,7 +1169,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 +1177,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 +1199,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 +1246,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]; diff --git a/GRRLIB/lib/freetype/src/raster/ftraster.c b/GRRLIB/lib/freetype/src/raster/ftraster.c index 8feba2b..9638dfb 100644 --- a/GRRLIB/lib/freetype/src/raster/ftraster.c +++ b/GRRLIB/lib/freetype/src/raster/ftraster.c @@ -302,7 +302,6 @@ typedef short Short; typedef unsigned short UShort, *PUShort; typedef long Long, *PLong; - typedef unsigned long ULong; typedef unsigned char Byte, *PByte; typedef char Bool; @@ -448,7 +447,6 @@ Int precision_bits; /* precision related variables */ Int precision; Int precision_half; - Long precision_mask; Int precision_shift; Int precision_step; Int precision_jitter; @@ -671,7 +669,6 @@ ras.precision = 1 << ras.precision_bits; ras.precision_half = ras.precision / 2; ras.precision_shift = ras.precision_bits - Pixel_Bits; - ras.precision_mask = -ras.precision; } @@ -725,13 +722,13 @@ if ( overshoot ) ras.cProfile->flags |= Overshoot_Bottom; - FT_TRACE6(( "New ascending profile = %lx\n", (long)ras.cProfile )); + FT_TRACE6(( "New ascending profile = %p\n", ras.cProfile )); break; case Descending_State: if ( overshoot ) ras.cProfile->flags |= Overshoot_Top; - FT_TRACE6(( "New descending profile = %lx\n", (long)ras.cProfile )); + FT_TRACE6(( "New descending profile = %p\n", ras.cProfile )); break; default: @@ -784,8 +781,8 @@ if ( h > 0 ) { - FT_TRACE6(( "Ending profile %lx, start = %ld, height = %ld\n", - (long)ras.cProfile, ras.cProfile->start, h )); + FT_TRACE6(( "Ending profile %p, start = %ld, height = %ld\n", + ras.cProfile, ras.cProfile->start, h )); ras.cProfile->height = h; if ( overshoot ) @@ -1094,7 +1091,7 @@ return SUCCESS; else { - x1 += FMulDiv( Dx, ras.precision - f1, Dy ); + x1 += SMulDiv( Dx, ras.precision - f1, Dy ); e1 += 1; } } @@ -1122,13 +1119,13 @@ if ( Dx > 0 ) { - Ix = SMulDiv( ras.precision, Dx, Dy); + Ix = SMulDiv( ras.precision, Dx, Dy); Rx = ( ras.precision * Dx ) % Dy; Dx = 1; } else { - Ix = SMulDiv( ras.precision, -Dx, Dy) * -1; + Ix = SMulDiv( ras.precision, -Dx, Dy) * -1; Rx = ( ras.precision * -Dx ) % Dy; Dx = -1; } diff --git a/GRRLIB/lib/freetype/src/sfnt/sfobjs.c b/GRRLIB/lib/freetype/src/sfnt/sfobjs.c index 6e35e2d..5a1d003 100644 --- a/GRRLIB/lib/freetype/src/sfnt/sfobjs.c +++ b/GRRLIB/lib/freetype/src/sfnt/sfobjs.c @@ -691,9 +691,7 @@ LOAD_( os2 ); if ( error ) { - if ( error != SFNT_Err_Table_Missing ) - goto Exit; - + /* we treat the table as missing if there are any errors */ face->os2.version = 0xFFFFU; } } diff --git a/GRRLIB/lib/freetype/src/sfnt/ttload.c b/GRRLIB/lib/freetype/src/sfnt/ttload.c index 84aef2d..20bac73 100644 --- a/GRRLIB/lib/freetype/src/sfnt/ttload.c +++ b/GRRLIB/lib/freetype/src/sfnt/ttload.c @@ -384,6 +384,10 @@ entry = face->dir_tables; + FT_TRACE2(( "\n" + " tag offset length checksum\n" + " ----------------------------------\n" )); + for ( nn = 0; nn < sfnt.num_tables; nn++ ) { entry->Tag = FT_GET_TAG4(); @@ -396,13 +400,14 @@ continue; else { - FT_TRACE2(( " %c%c%c%c - %08lx - %08lx\n", + FT_TRACE2(( " %c%c%c%c %08lx %08lx %08lx\n", (FT_Char)( entry->Tag >> 24 ), (FT_Char)( entry->Tag >> 16 ), (FT_Char)( entry->Tag >> 8 ), (FT_Char)( entry->Tag ), entry->Offset, - entry->Length )); + entry->Length, + entry->CheckSum )); entry++; } } diff --git a/GRRLIB/lib/freetype/src/sfnt/ttpost.c b/GRRLIB/lib/freetype/src/sfnt/ttpost.c index b672d09..6f4bb1d 100644 --- a/GRRLIB/lib/freetype/src/sfnt/ttpost.c +++ b/GRRLIB/lib/freetype/src/sfnt/ttpost.c @@ -26,6 +26,7 @@ #include +#include FT_INTERNAL_DEBUG_H #include FT_INTERNAL_STREAM_H #include FT_TRUETYPE_TAGS_H #include "ttpost.h" diff --git a/GRRLIB/lib/freetype/src/smooth/ftgrays.c b/GRRLIB/lib/freetype/src/smooth/ftgrays.c index 17d172f..a85e160 100644 --- a/GRRLIB/lib/freetype/src/smooth/ftgrays.c +++ b/GRRLIB/lib/freetype/src/smooth/ftgrays.c @@ -91,11 +91,6 @@ #define FT_COMPONENT trace_smooth - /* The maximum distance of a curve from the chord, in 64ths of a pixel; */ - /* used when flattening curves. */ -#define FT_MAX_CURVE_DEVIATION 16 - - #ifdef _STANDALONE_ @@ -882,34 +877,7 @@ typedef ptrdiff_t FT_PtrDist; FT_Vector* arc; - dx = DOWNSCALE( ras.x ) + to->x - ( control->x << 1 ); - if ( dx < 0 ) - dx = -dx; - dy = DOWNSCALE( ras.y ) + to->y - ( control->y << 1 ); - if ( dy < 0 ) - dy = -dy; - if ( dx < dy ) - dx = dy; - - if ( dx <= FT_MAX_CURVE_DEVIATION ) - { - gray_render_line( RAS_VAR_ UPSCALE( to->x ), UPSCALE( to->y ) ); - return; - } - - level = 1; - dx /= FT_MAX_CURVE_DEVIATION; - while ( dx > 1 ) - { - dx >>= 2; - level++; - } - - arc = ras.bez_stack; - levels = ras.lev_stack; - top = 0; - levels[0] = level; - + arc = ras.bez_stack; arc[0].x = UPSCALE( to->x ); arc[0].y = UPSCALE( to->y ); arc[1].x = UPSCALE( control->x ); @@ -917,6 +885,28 @@ typedef ptrdiff_t FT_PtrDist; arc[2].x = ras.x; arc[2].y = ras.y; + dx = FT_ABS( arc[2].x + arc[0].x - 2 * arc[1].x ); + dy = FT_ABS( arc[2].y + arc[0].y - 2 * arc[1].y ); + if ( dx < dy ) + dx = dy; + + if ( dx <= ONE_PIXEL / 4 ) + { + gray_render_line( RAS_VAR_ arc[0].x, arc[0].y ); + return; + } + + level = 0; + while ( dx > ONE_PIXEL / 4 ) + { + dx >>= 2; + level++; + } + + levels = ras.lev_stack; + levels[0] = level; + top = 0; + while ( top >= 0 ) { level = levels[top]; @@ -1067,14 +1057,20 @@ typedef ptrdiff_t FT_PtrDist; dx_ = FT_ABS( dx ); dy_ = FT_ABS( dy ); - L = ( 236 * FT_MAX( dx_, dy_ ) + 97 * FT_MIN( dx_, dy_ ) ) >> 8; + + /* This is the same as */ + /* */ + /* L = ( 236 * FT_MAX( dx_, dy_ ) */ + /* + 97 * FT_MIN( dx_, dy_ ) ) >> 8; */ + L = ( dx_ > dy_ ? 236 * dx_ + 97 * dy_ + : 97 * dx_ + 236 * dy_ ) >> 8; /* Avoid possible arithmetic overflow below by splitting. */ if ( L > 32767 ) goto Split; /* Max deviation may be as much as (s/L) * 3/4 (if Hain's v = 1). */ - s_limit = L * (TPos)( FT_MAX_CURVE_DEVIATION / 0.75 ); + s_limit = L * (TPos)( ONE_PIXEL / 6 ); /* s is L * the perpendicular distance from P1 to the line P0-P3. */ dx1 = arc[1].x - arc[0].x; diff --git a/GRRLIB/lib/freetype/src/truetype/ttgxvar.c b/GRRLIB/lib/freetype/src/truetype/ttgxvar.c index 653d9d5..47bb9fc 100644 --- a/GRRLIB/lib/freetype/src/truetype/ttgxvar.c +++ b/GRRLIB/lib/freetype/src/truetype/ttgxvar.c @@ -130,7 +130,7 @@ FT_Int j; FT_Int first; FT_Memory memory = stream->memory; - FT_Error error = TT_Err_Ok; + FT_Error error = TT_Err_Ok; FT_UNUSED( error ); @@ -154,7 +154,7 @@ runcnt = runcnt & GX_PT_POINT_RUN_COUNT_MASK; first = points[i++] = FT_GET_USHORT(); - if ( runcnt < 1 ) + if ( runcnt < 1 || i + runcnt >= n ) goto Exit; /* first point not included in runcount */ @@ -165,7 +165,7 @@ { first = points[i++] = FT_GET_BYTE(); - if ( runcnt < 1 ) + if ( runcnt < 1 || i + runcnt >= n ) goto Exit; for ( j = 0; j < runcnt; ++j ) diff --git a/GRRLIB/lib/freetype/src/truetype/ttinterp.c b/GRRLIB/lib/freetype/src/truetype/ttinterp.c index bf9189c..f55b8ee 100644 --- a/GRRLIB/lib/freetype/src/truetype/ttinterp.c +++ b/GRRLIB/lib/freetype/src/truetype/ttinterp.c @@ -478,8 +478,7 @@ return TT_Err_Ok; Fail_Memory: - FT_ERROR(( "Init_Context: not enough memory for 0x%08lx\n", - (FT_Long)exec )); + FT_ERROR(( "Init_Context: not enough memory for %p\n", exec )); TT_Done_Context( exec ); return error; @@ -596,6 +595,12 @@ exec->storage = size->storage; exec->twilight = size->twilight; + + /* In case of multi-threading it can happen that the old size object */ + /* no longer exists, thus we must clear all glyph zone references. */ + ft_memset( &exec->zp0, 0, sizeof ( exec->zp0 ) ); + exec->zp1 = exec->zp0; + exec->zp2 = exec->zp0; } /* XXX: We reserve a little more elements on the stack to deal safely */ @@ -5795,7 +5800,16 @@ if ( CUR.GS.gep2 == 0 && CUR.zp2.n_points > 0 ) last_point = (FT_UShort)( CUR.zp2.n_points - 1 ); else if ( CUR.GS.gep2 == 1 && CUR.zp2.n_contours > 0 ) + { last_point = (FT_UShort)( CUR.zp2.contours[CUR.zp2.n_contours - 1] ); + + if ( BOUNDS( last_point, CUR.zp2.n_points ) ) + { + if ( CUR.pedantic_hinting ) + CUR.error = TT_Err_Invalid_Reference; + return; + } + } else last_point = 0; diff --git a/GRRLIB/lib/freetype/src/truetype/ttobjs.c b/GRRLIB/lib/freetype/src/truetype/ttobjs.c index c884402..8fe86ad 100644 --- a/GRRLIB/lib/freetype/src/truetype/ttobjs.c +++ b/GRRLIB/lib/freetype/src/truetype/ttobjs.c @@ -147,11 +147,14 @@ /* This list shall be expanded as we find more of them. */ static FT_Bool - tt_check_trickyness( FT_String* name ) + tt_check_trickyness_family( FT_String* name ) { + #define TRICK_NAMES_MAX_CHARACTERS 16 -#define TRICK_NAMES_COUNT 8 - static const char trick_names[TRICK_NAMES_COUNT][TRICK_NAMES_MAX_CHARACTERS+1] = +#define TRICK_NAMES_COUNT 8 + + static const char trick_names[TRICK_NAMES_COUNT] + [TRICK_NAMES_MAX_CHARACTERS + 1] = { "DFKaiSho-SB", /* dfkaisb.ttf */ "DFKaiShu", @@ -162,14 +165,10 @@ "PMingLiU", /* mingliu.ttc */ "MingLi43", /* mingli.ttf */ }; + int nn; - if ( !name ) - return TRUE; - - /* Note that we only check the face name at the moment; it might */ - /* be worth to do more checks for a few special cases. */ for ( nn = 0; nn < TRICK_NAMES_COUNT; nn++ ) if ( ft_strstr( name, trick_names[nn] ) ) return TRUE; @@ -178,6 +177,181 @@ } + /* XXX: This function should be in the `sfnt' module. */ + + /* Some PDF generators clear the checksums in the TrueType header table. */ + /* For example, Quartz ContextPDF clears all entries, or Bullzip PDF */ + /* Printer clears the entries for subsetted subtables. We thus have to */ + /* recalculate the checksums where necessary. */ + + static FT_UInt32 + tt_synth_sfnt_checksum( FT_Stream stream, + FT_ULong length ) + { + FT_Error error; + FT_UInt32 checksum = 0; + int i; + + + if ( FT_FRAME_ENTER( length ) ) + return 0; + + for ( ; length > 3; length -= 4 ) + checksum += (FT_UInt32)FT_GET_ULONG(); + + for ( i = 3; length > 0; length --, i-- ) + checksum += (FT_UInt32)( FT_GET_BYTE() << ( i * 8 ) ); + + FT_FRAME_EXIT(); + + return checksum; + } + + + /* XXX: This function should be in the `sfnt' module. */ + + static FT_ULong + tt_get_sfnt_checksum( TT_Face face, + FT_UShort i ) + { + if ( face->dir_tables[i].CheckSum ) + return face->dir_tables[i].CheckSum; + + else if ( !face->goto_table ) + return 0; + + else if ( !face->goto_table( face, + face->dir_tables[i].Tag, + face->root.stream, + NULL ) ) + return 0; + + return (FT_ULong)tt_synth_sfnt_checksum( face->root.stream, + face->dir_tables[i].Length ); + } + + + typedef struct tt_sfnt_id_rec_ + { + FT_ULong CheckSum; + FT_ULong Length; + + } tt_sfnt_id_rec; + + + static FT_Bool + tt_check_trickyness_sfnt_ids( TT_Face face ) + { +#define TRICK_SFNT_IDS_PER_FACE 3 +#define TRICK_SFNT_IDS_NUM_FACES 5 + + static const tt_sfnt_id_rec sfnt_id[TRICK_SFNT_IDS_NUM_FACES] + [TRICK_SFNT_IDS_PER_FACE] = { + +#define TRICK_SFNT_ID_cvt 0 +#define TRICK_SFNT_ID_fpgm 1 +#define TRICK_SFNT_ID_prep 2 + + { /* MingLiU 1995 */ + { 0x05bcf058, 0x000002e4 }, /* cvt */ + { 0x28233bf1, 0x000087c4 }, /* fpgm */ + { 0xa344a1ea, 0x000001e1 } /* prep */ + }, + { /* MingLiU 1996- */ + { 0x05bcf058, 0x000002e4 }, /* cvt */ + { 0x28233bf1, 0x000087c4 }, /* fpgm */ + { 0xa344a1eb, 0x000001e1 } /* prep */ + }, + { /* DFKaiShu */ + { 0x11e5ead4, 0x00000350 }, /* cvt */ + { 0x5a30ca3b, 0x00009063 }, /* fpgm */ + { 0x13a42602, 0x0000007e } /* prep */ + }, + { /* HuaTianKaiTi */ + { 0xfffbfffc, 0x00000008 }, /* cvt */ + { 0x9c9e48b8, 0x0000bea2 }, /* fpgm */ + { 0x70020112, 0x00000008 } /* prep */ + }, + { /* HuaTianSongTi */ + { 0xfffbfffc, 0x00000008 }, /* cvt */ + { 0x0a5a0483, 0x00017c39 }, /* fpgm */ + { 0x70020112, 0x00000008 } /* prep */ + } + }; + + FT_ULong checksum; + int num_matched_ids[TRICK_SFNT_IDS_NUM_FACES]; + int i, j, k; + + + FT_MEM_SET( num_matched_ids, 0, + sizeof( int ) * TRICK_SFNT_IDS_NUM_FACES ); + + for ( i = 0; i < face->num_tables; i++ ) + { + checksum = 0; + + switch( face->dir_tables[i].Tag ) + { + case TTAG_cvt: + k = TRICK_SFNT_ID_cvt; + break; + + case TTAG_fpgm: + k = TRICK_SFNT_ID_fpgm; + break; + + case TTAG_prep: + k = TRICK_SFNT_ID_prep; + break; + + default: + continue; + } + + for ( j = 0; j < TRICK_SFNT_IDS_NUM_FACES; j++ ) + if ( face->dir_tables[i].Length == sfnt_id[j][k].Length ) + { + if ( !checksum ) + checksum = tt_get_sfnt_checksum( face, i ); + + if ( sfnt_id[j][k].CheckSum == checksum ) + num_matched_ids[j]++; + + if ( num_matched_ids[j] == TRICK_SFNT_IDS_PER_FACE ) + return TRUE; + } + } + + return FALSE; + } + + + static FT_Bool + tt_check_trickyness( FT_Face face ) + { + if ( !face ) + return FALSE; + + /* First, check the face name. */ + if ( face->family_name ) + { + if ( tt_check_trickyness_family( face->family_name ) ) + return TRUE; + else + return FALSE; + } + + /* Type42 fonts may lack `name' tables, we thus try to identify */ + /* tricky fonts by checking the checksums of Type42-persistent */ + /* sfnt tables (`cvt', `fpgm', and `prep'). */ + if ( tt_check_trickyness_sfnt_ids( (TT_Face)face ) ) + return TRUE; + + return FALSE; + } + + /*************************************************************************/ /* */ /* */ @@ -252,7 +426,7 @@ if ( error ) goto Exit; - if ( tt_check_trickyness( ttface->family_name ) ) + if ( tt_check_trickyness( ttface ) ) ttface->face_flags |= FT_FACE_FLAG_TRICKY; error = tt_face_load_hdmx( face, stream ); diff --git a/GRRLIB/lib/freetype/src/truetype/ttpload.c b/GRRLIB/lib/freetype/src/truetype/ttpload.c index c531733..68a5453 100644 --- a/GRRLIB/lib/freetype/src/truetype/ttpload.c +++ b/GRRLIB/lib/freetype/src/truetype/ttpload.c @@ -4,7 +4,7 @@ /* */ /* TrueType-specific tables loader (body). */ /* */ -/* Copyright 1996-2001, 2002, 2004, 2005, 2006, 2007, 2008, 2009 by */ +/* Copyright 1996-2001, 2002, 2004, 2005, 2006, 2007, 2008, 2009, 2010 by */ /* David Turner, Robert Wilhelm, and Werner Lemberg. */ /* */ /* This file is part of the FreeType project, and may only be used, */ @@ -137,6 +137,12 @@ dist = diff; } + if ( entry == limit ) + { + /* `loca' is the last table */ + dist = stream->size - pos; + } + if ( new_loca_len <= dist ) { face->num_locations = face->root.num_glyphs; @@ -307,7 +313,7 @@ FT_Short* limit = cur + face->cvt_size; - for ( ; cur < limit; cur++ ) + for ( ; cur < limit; cur++ ) *cur = FT_GET_SHORT(); } diff --git a/GRRLIB/lib/freetype/src/type1/t1load.c b/GRRLIB/lib/freetype/src/type1/t1load.c index d867e94..c9b6c1d 100644 --- a/GRRLIB/lib/freetype/src/type1/t1load.c +++ b/GRRLIB/lib/freetype/src/type1/t1load.c @@ -4,7 +4,8 @@ /* */ /* Type 1 font loader (body). */ /* */ -/* Copyright 1996-2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 by */ +/* Copyright 1996-2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, */ +/* 2010 by */ /* David Turner, Robert Wilhelm, and Werner Lemberg. */ /* */ /* This file is part of the FreeType project, and may only be used, */ @@ -1045,7 +1046,8 @@ if ( cur < limit && ft_isdigit( *cur ) ) { - *size = T1_ToInt( parser ); + FT_Long s = T1_ToInt( parser ); + T1_Skip_PS_Token( parser ); /* `RD' or `-|' or something else */ @@ -1053,8 +1055,12 @@ /* `RD' or `-|' token */ *base = parser->root.cursor + 1; - parser->root.cursor += *size + 1; - return !parser->root.error; + if ( s >= 0 && s < limit - *base ) + { + parser->root.cursor += s + 1; + *size = s; + return !parser->root.error; + } } FT_ERROR(( "read_binary_data: invalid size field\n" )); @@ -1111,7 +1117,7 @@ temp[2] = FT_DivFix( temp[2], temp_scale ); temp[4] = FT_DivFix( temp[4], temp_scale ); temp[5] = FT_DivFix( temp[5], temp_scale ); - temp[3] = 0x10000L; + temp[3] = temp[3] < 0 ? -0x10000L : 0x10000L; } matrix->xx = temp[0]; @@ -2180,7 +2186,7 @@ /* OK, we do the following: for each element in the encoding */ /* table, look up the index of the glyph having the same name */ /* the index is then stored in type1.encoding.char_index, and */ - /* a the name to type1.encoding.char_name */ + /* the name to type1.encoding.char_name */ min_char = 0; max_char = 0;