From a4aa1c5bee675fb4396f2ab3f4843ee97601a1e4 Mon Sep 17 00:00:00 2001 From: Werner Lemberg Date: Wed, 31 Aug 2005 22:39:23 +0000 Subject: * src/gxvalid/gxvbsln.c (gxv_bsln_validate): Fix tracing message. * src/gxvalid/gxvcommn.c (gxv_odtect_add_range): Use `const'. * src/gxvalid/gxvfeat.c, src/gxvalid/gxvjust.c, src/gxvalid/gxvkern.c, src/gxvalid/gxvlcar.c, src/gxvalid/gxvmod.c, src/gxvalid/gxvmort0.c, src/gxvalid/gxvmort1.c, src/gxvalid/gxvmort2.c, src/gxvalid/gxvmort4.c, src/gxvalid/gxvmort5.c, src/gxvalid/gxvmort.c: Improve tracing messages. Decorate constants with `U' and `L' where appropriate. Fix compiler warnings. --- src/gxvalid/gxvbsln.c | 2 +- src/gxvalid/gxvcommn.c | 4 +- src/gxvalid/gxvcommn.h | 341 +++++++++++++++++++++++++++---------------------- src/gxvalid/gxverror.h | 7 +- src/gxvalid/gxvfeat.c | 85 ++++++------ src/gxvalid/gxvfgen.c | 61 +++++---- src/gxvalid/gxvjust.c | 200 +++++++++++++++++------------ src/gxvalid/gxvkern.c | 283 +++++++++++++++++++++------------------- src/gxvalid/gxvlcar.c | 36 +++--- src/gxvalid/gxvmod.c | 83 ++++++------ src/gxvalid/gxvmod.h | 9 +- src/gxvalid/gxvmort.c | 54 +++++--- src/gxvalid/gxvmort.h | 31 ++--- src/gxvalid/gxvmort0.c | 53 +++++--- src/gxvalid/gxvmort1.c | 120 ++++++++++------- src/gxvalid/gxvmort2.c | 127 +++++++++++------- src/gxvalid/gxvmort4.c | 27 ++-- src/gxvalid/gxvmort5.c | 86 ++++++++----- 18 files changed, 939 insertions(+), 670 deletions(-) (limited to 'src/gxvalid') diff --git a/src/gxvalid/gxvbsln.c b/src/gxvalid/gxvbsln.c index ab29c7fba..468125027 100644 --- a/src/gxvalid/gxvbsln.c +++ b/src/gxvalid/gxvbsln.c @@ -295,7 +295,7 @@ valid->table_data = bsln; valid->face = face; - FT_TRACE3(( "validation bsln table\n" )); + FT_TRACE3(( "validating `bsln' table\n" )); GXV_INIT; diff --git a/src/gxvalid/gxvcommn.c b/src/gxvalid/gxvcommn.c index 0747603af..5e0b6f37d 100644 --- a/src/gxvalid/gxvcommn.c +++ b/src/gxvalid/gxvcommn.c @@ -1700,12 +1700,12 @@ FT_LOCAL_DEF( void ) gxv_odtect_add_range( FT_Bytes start, FT_ULong length, - FT_String* name, + const FT_String* name, GXV_odtect_Range odtect ) { odtect->range[ odtect->nRanges ].start = start; odtect->range[ odtect->nRanges ].length = length; - odtect->range[ odtect->nRanges ].name = name; + odtect->range[ odtect->nRanges ].name = (FT_String*)name; odtect->nRanges++; } diff --git a/src/gxvalid/gxvcommn.h b/src/gxvalid/gxvcommn.h index 7bc9852a5..3b83c007f 100644 --- a/src/gxvalid/gxvcommn.h +++ b/src/gxvalid/gxvcommn.h @@ -16,23 +16,27 @@ /***************************************************************************/ /***************************************************************************/ +/* */ /* gxvalid is derived from both gxlayout module and otvalid module. */ -/* Development of gxlayout was support of Information-technology Promotion */ -/* Agency(IPA), Japan. */ +/* Development of gxlayout is supported by the Information-technology */ +/* Promotion Agency(IPA), Japan. */ +/* */ /***************************************************************************/ -/* - * keywords in variable naming - * --------------------------- - * table: FT_Bytes typed, pointing the start of this table/subtable. - * limit: FT_Bytes typed, pointing the end of this table/subtable - * including padding for alignment. - * offset: FT_UInt typed, the number of octets from the start to target. - * length: FT_UInt typed, the number of octets from the start to the end. - * in this table/subtable, including padding for alignment. - * - * _MIN, _MAX: should be added to the tail of macros, as INT_MIN etc. - */ + + /* + * keywords in variable naming + * --------------------------- + * table: Of type FT_Bytes, pointing to the start of this table/subtable. + * limit: Of type FT_Bytes, pointing to the end of this table/subtable, + * including padding for alignment. + * offset: Of type FT_UInt, the number of octets from the start to target. + * length: Of type FT_UInt, the number of octets from the start to the + * end in this table/subtable, including padding for alignment. + * + * _MIN, _MAX: Should be added to the tail of macros, as INT_MIN, etc. + */ + #ifndef __GXVCOMMN_H__ #define __GXVCOMMN_H__ @@ -43,8 +47,8 @@ #include FT_INTERNAL_DEBUG_H #include FT_SFNT_NAMES_H -FT_BEGIN_HEADER +FT_BEGIN_HEADER /*************************************************************************/ @@ -55,16 +59,20 @@ FT_BEGIN_HEADER /*************************************************************************/ /*************************************************************************/ - typedef struct GXV_ValidatorRec_* GXV_Validator; + typedef struct GXV_ValidatorRec_* GXV_Validator; + #define DUMMY_LIMIT 0 - typedef void (*GXV_Validate_Func)( FT_Bytes table, - FT_Bytes limit, - GXV_Validator valid ); + + typedef void + (*GXV_Validate_Func)( FT_Bytes table, + FT_Bytes limit, + GXV_Validator valid ); + /* ====================== LookupTable Validator ======================== */ - typedef union GXV_LookupValueDesc_ + typedef union GXV_LookupValueDesc_ { FT_UShort u; FT_Short s; @@ -78,15 +86,17 @@ FT_BEGIN_HEADER } GXV_LookupValue_SignSpec; - typedef void (*GXV_Lookup_Value_Validate_Func)( FT_UShort glyph, - GXV_LookupValueDesc value, - GXV_Validator valid ); - typedef GXV_LookupValueDesc (*GXV_Lookup_Fmt4_Transit_Func) - ( FT_UShort relative_gindex, - GXV_LookupValueDesc base_value, - FT_Bytes lookuptbl_limit, - GXV_Validator valid ); + typedef void + (*GXV_Lookup_Value_Validate_Func)( FT_UShort glyph, + GXV_LookupValueDesc value, + GXV_Validator valid ); + + typedef GXV_LookupValueDesc + (*GXV_Lookup_Fmt4_Transit_Func)( FT_UShort relative_gindex, + GXV_LookupValueDesc base_value, + FT_Bytes lookuptbl_limit, + GXV_Validator valid ); /* ====================== StateTable Validator ========================= */ @@ -104,100 +114,108 @@ FT_BEGIN_HEADER } GXV_GlyphOffset_Format; -#define GXV_GLYPHOFFSET_FMT( table ) \ - ( valid-> table . entry_glyphoffset_fmt ) +#define GXV_GLYPHOFFSET_FMT( table ) \ + ( valid->table.entry_glyphoffset_fmt ) + +#define GXV_GLYPHOFFSET_SIZE( table ) \ + ( valid->table.entry_glyphoffset_fmt / 2 ) -#define GXV_GLYPHOFFSET_SIZE( table ) \ - ( ( valid-> table . entry_glyphoffset_fmt ) / 2 ) /* ----------------------- 16bit StateTable ---------------------------- */ typedef union GXV_StateTable_GlyphOffsetDesc_ { - FT_Byte uc; - FT_UShort u; /* same with GXV_LookupValueDesc */ - FT_ULong ul; - FT_Char c; - FT_Short s; /* same with GXV_LookupValueDesc */ - FT_Long l; + FT_Byte uc; + FT_UShort u; /* same as GXV_LookupValueDesc */ + FT_ULong ul; + FT_Char c; + FT_Short s; /* same as GXV_LookupValueDesc */ + FT_Long l; } GXV_StateTable_GlyphOffsetDesc; - typedef void (*GXV_StateTable_Subtable_Setup_Func)( FT_UShort table_size, - FT_UShort classTable, - FT_UShort stateArray, - FT_UShort entryTable, - FT_UShort* classTable_length_p, - FT_UShort* stateArray_length_p, - FT_UShort* entryTable_length_p, - GXV_Validator valid ); - - typedef void (*GXV_StateTable_Entry_Validate_Func)( FT_Byte state, - FT_UShort flags, - GXV_StateTable_GlyphOffsetDesc glyphOffset, - FT_Bytes statetable_table, - FT_Bytes statetable_limit, - GXV_Validator valid ); - - typedef void (*GXV_StateTable_OptData_Load_Func)( FT_Bytes table, - FT_Bytes limit, - GXV_Validator valid ); - - typedef struct GXV_StateTable_ValidatorRec_ + + typedef void + (*GXV_StateTable_Subtable_Setup_Func)( FT_UShort table_size, + FT_UShort classTable, + FT_UShort stateArray, + FT_UShort entryTable, + FT_UShort* classTable_length_p, + FT_UShort* stateArray_length_p, + FT_UShort* entryTable_length_p, + GXV_Validator valid ); + + typedef void + (*GXV_StateTable_Entry_Validate_Func)( + FT_Byte state, + FT_UShort flags, + GXV_StateTable_GlyphOffsetDesc glyphOffset, + FT_Bytes statetable_table, + FT_Bytes statetable_limit, + GXV_Validator valid ); + + typedef void + (*GXV_StateTable_OptData_Load_Func)( FT_Bytes table, + FT_Bytes limit, + GXV_Validator valid ); + + typedef struct GXV_StateTable_ValidatorRec_ { - GXV_GlyphOffset_Format entry_glyphoffset_fmt; - void* optdata; - GXV_StateTable_Subtable_Setup_Func - subtable_setup_func; - GXV_StateTable_Entry_Validate_Func - entry_validate_func; - GXV_StateTable_OptData_Load_Func - optdata_load_func; + GXV_GlyphOffset_Format entry_glyphoffset_fmt; + void* optdata; + + GXV_StateTable_Subtable_Setup_Func subtable_setup_func; + GXV_StateTable_Entry_Validate_Func entry_validate_func; + GXV_StateTable_OptData_Load_Func optdata_load_func; } GXV_StateTable_ValidatorRec, *GXV_StateTable_ValidatorRecData; /* ---------------------- 32bit XStateTable ---------------------------- */ - typedef GXV_StateTable_GlyphOffsetDesc GXV_XStateTable_GlyphOffsetDesc; + typedef GXV_StateTable_GlyphOffsetDesc GXV_XStateTable_GlyphOffsetDesc; - typedef void (*GXV_XStateTable_Subtable_Setup_Func)( FT_ULong table_size, - FT_ULong classTable, - FT_ULong stateArray, - FT_ULong entryTable, - FT_ULong* classTable_length_p, - FT_ULong* stateArray_length_p, - FT_ULong* entryTable_length_p, - GXV_Validator valid ); + typedef void + (*GXV_XStateTable_Subtable_Setup_Func)( FT_ULong table_size, + FT_ULong classTable, + FT_ULong stateArray, + FT_ULong entryTable, + FT_ULong* classTable_length_p, + FT_ULong* stateArray_length_p, + FT_ULong* entryTable_length_p, + GXV_Validator valid ); - typedef void (*GXV_XStateTable_Entry_Validate_Func)( FT_UShort state, - FT_UShort flags, - GXV_StateTable_GlyphOffsetDesc - glyphOffset, - FT_Bytes xstatetable_table, - FT_Bytes xstatetable_limit, - GXV_Validator valid ); + typedef void + (*GXV_XStateTable_Entry_Validate_Func)( + FT_UShort state, + FT_UShort flags, + GXV_StateTable_GlyphOffsetDesc glyphOffset, + FT_Bytes xstatetable_table, + FT_Bytes xstatetable_limit, + GXV_Validator valid ); - typedef GXV_StateTable_OptData_Load_Func GXV_XStateTable_OptData_Load_Func; - typedef struct GXV_XStateTable_ValidatorRec_ + typedef GXV_StateTable_OptData_Load_Func GXV_XStateTable_OptData_Load_Func; + + + typedef struct GXV_XStateTable_ValidatorRec_ { - int entry_glyphoffset_fmt; - void* optdata; - GXV_XStateTable_Subtable_Setup_Func - subtable_setup_func; - GXV_XStateTable_Entry_Validate_Func - entry_validate_func; - GXV_XStateTable_OptData_Load_Func - optdata_load_func; - FT_ULong nClasses; - FT_UShort maxClassID; + int entry_glyphoffset_fmt; + void* optdata; + + GXV_XStateTable_Subtable_Setup_Func subtable_setup_func; + GXV_XStateTable_Entry_Validate_Func entry_validate_func; + GXV_XStateTable_OptData_Load_Func optdata_load_func; + + FT_ULong nClasses; + FT_UShort maxClassID; } GXV_XStateTable_ValidatorRec, *GXV_XStateTable_ValidatorRecData; + /* ===================================================================== */ - typedef struct GXV_ValidatorRec_ + typedef struct GXV_ValidatorRec_ { FT_Validator root; @@ -221,20 +239,23 @@ FT_BEGIN_HEADER } GXV_ValidatorRec; -#define GXV_TABLE_DATA( tag, field ) \ + +#define GXV_TABLE_DATA( tag, field ) \ ( ( (GXV_ ## tag ## _Data)valid->table_data )->field ) #undef FT_INVALID_ #define FT_INVALID_( _prefix, _error ) \ ft_validator_error( valid->root, _prefix ## _error ) -#define GXV_LIMIT_CHECK( _count ) \ - FT_BEGIN_STMNT \ - if ( p + _count > ( limit? limit : valid->root->limit ) ) \ - FT_INVALID_TOO_SHORT; \ +#define GXV_LIMIT_CHECK( _count ) \ + FT_BEGIN_STMNT \ + if ( p + _count > ( limit? limit : valid->root->limit ) ) \ + FT_INVALID_TOO_SHORT; \ FT_END_STMNT + #ifdef FT_DEBUG_LEVEL_TRACE + #define GXV_INIT valid->debug_indent = 0 #define GXV_NAME_ENTER( name ) \ @@ -252,7 +273,8 @@ FT_BEGIN_HEADER FT_TRACE4( s ); \ FT_END_STMNT -#else /* !FT_DEBUG_LEVEL_TRACE */ +#else /* !FT_DEBUG_LEVEL_TRACE */ + #define GXV_INIT do ; while ( 0 ) #define GXV_NAME_ENTER( name ) do ; while ( 0 ) #define GXV_EXIT do ; while ( 0 ) @@ -261,6 +283,7 @@ FT_BEGIN_HEADER #endif /* !FT_DEBUG_LEVEL_TRACE */ + /*************************************************************************/ /*************************************************************************/ /***** *****/ @@ -269,12 +292,13 @@ FT_BEGIN_HEADER /*************************************************************************/ /*************************************************************************/ -#define GXV_32BIT_ALIGNMENT_VALIDATE( a ) \ - FT_BEGIN_STMNT \ - { \ - if ( 0 != ( (a) % 4 ) ) FT_INVALID_OFFSET ; \ - } \ - FT_END_STMNT +#define GXV_32BIT_ALIGNMENT_VALIDATE( a ) \ + FT_BEGIN_STMNT \ + { \ + if ( 0 != ( (a) % 4 ) ) \ + FT_INVALID_OFFSET ; \ + } \ + FT_END_STMNT /*************************************************************************/ @@ -285,28 +309,34 @@ FT_BEGIN_HEADER /*************************************************************************/ /*************************************************************************/ -#define GXV_TRACE_HEXDUMP( p, len ) \ - FT_BEGIN_STMNT \ - { \ - FT_Bytes b; \ - for (b = p; b < (FT_Bytes)p + len; b++) \ - FT_TRACE1(("\\x%02x", *b)) ; \ - } \ - FT_END_STMNT +#define GXV_TRACE_HEXDUMP( p, len ) \ + FT_BEGIN_STMNT \ + { \ + FT_Bytes b; \ + \ + \ + for ( b = p; b < (FT_Bytes)p + len; b++ ) \ + FT_TRACE1(("\\x%02x", *b)) ; \ + } \ + FT_END_STMNT -#define GXV_TRACE_HEXDUMP_C( p, len ) \ - FT_BEGIN_STMNT \ - { \ - FT_Bytes b; \ - for (b = p; b < (FT_Bytes)p + len; b++) \ - if (0x40 < *b && *b < 0x7e) \ - FT_TRACE1(("%c", *b)) ; \ - else \ - FT_TRACE1(("\\x%02x", *b)) ; \ - } \ - FT_END_STMNT +#define GXV_TRACE_HEXDUMP_C( p, len ) \ + FT_BEGIN_STMNT \ + { \ + FT_Bytes b; \ + \ + \ + for ( b = p; b < (FT_Bytes)p + len; b++ ) \ + if ( 0x40 < *b && *b < 0x7e ) \ + FT_TRACE1(("%c", *b)) ; \ + else \ + FT_TRACE1(("\\x%02x", *b)) ; \ + } \ + FT_END_STMNT + +#define GXV_TRACE_HEXDUMP_SFNTNAME( n ) \ + GXV_TRACE_HEXDUMP( n.string, n.string_len ) -#define GXV_TRACE_HEXDUMP_SFNTNAME( n ) GXV_TRACE_HEXDUMP( n.string, n.string_len ) /*************************************************************************/ /*************************************************************************/ @@ -341,6 +371,7 @@ FT_BEGIN_HEADER gxv_glyphid_validate( FT_UShort gid, GXV_Validator valid ); + /*************************************************************************/ /*************************************************************************/ /***** *****/ @@ -392,20 +423,22 @@ FT_BEGIN_HEADER /*************************************************************************/ /*************************************************************************/ -#define GXV_SUBTABLE_OFFSET_CHECK( _offset ) \ - FT_BEGIN_STMNT \ - if ( (_offset) > valid->subtable_length ) \ - FT_INVALID_OFFSET; \ - FT_END_STMNT +#define GXV_SUBTABLE_OFFSET_CHECK( _offset ) \ + FT_BEGIN_STMNT \ + if ( (_offset) > valid->subtable_length ) \ + FT_INVALID_OFFSET; \ + FT_END_STMNT + +#define GXV_SUBTABLE_LIMIT_CHECK( _count ) \ + FT_BEGIN_STMNT \ + if ( ( p + (_count) - valid->subtable_start ) > \ + valid->subtable_length ) \ + FT_INVALID_TOO_SHORT; \ + FT_END_STMNT -#define GXV_SUBTABLE_LIMIT_CHECK( _count ) \ - FT_BEGIN_STMNT \ - if ( ( p + (_count) - valid->subtable_start ) > valid->subtable_length ) \ - FT_INVALID_TOO_SHORT; \ - FT_END_STMNT +#define GXV_USHORT_TO_SHORT( _us ) \ + ( ( 0x8000U < ( _us ) ) ? ( ( _us ) - 0x8000U ) : ( _us ) ) -#define GXV_USHORT_TO_SHORT( _us ) \ - ( ( 0x8000 < ( _us ) ) ? ( ( _us ) - 0x8000 ) : ( _us ) ) /*************************************************************************/ /*************************************************************************/ @@ -415,7 +448,7 @@ FT_BEGIN_HEADER /*************************************************************************/ /*************************************************************************/ - typedef struct GXV_odtect_DataRec_ + typedef struct GXV_odtect_DataRec_ { FT_Bytes start; FT_ULong length; @@ -423,30 +456,32 @@ FT_BEGIN_HEADER } GXV_odtect_DataRec, *GXV_odtect_Data; - typedef struct GXV_odtect_RangeRec_ + typedef struct GXV_odtect_RangeRec_ { FT_UInt nRanges; GXV_odtect_Data range; } GXV_odtect_RangeRec, *GXV_odtect_Range; -#define GXV_ODTECT( n, odtect ) \ - GXV_odtect_DataRec odtect ## _range[ n ]; \ - GXV_odtect_RangeRec odtect ## _rec = { 0, NULL }; \ - GXV_odtect_Range odtect = NULL -#define GXV_ODTECT_INIT( odtect ) \ - FT_BEGIN_STMNT \ - odtect ## _rec.nRanges = 0; \ - odtect ## _rec.range = odtect ## _range; \ - odtect = & odtect ## _rec; \ - FT_END_STMNT +#define GXV_ODTECT( n, odtect ) \ + GXV_odtect_DataRec odtect ## _range[n]; \ + GXV_odtect_RangeRec odtect ## _rec = { 0, NULL }; \ + GXV_odtect_Range odtect = NULL + +#define GXV_ODTECT_INIT( odtect ) \ + FT_BEGIN_STMNT \ + odtect ## _rec.nRanges = 0; \ + odtect ## _rec.range = odtect ## _range; \ + odtect = & odtect ## _rec; \ + FT_END_STMNT + /* */ FT_END_HEADER -#endif /* Not def: __GXVCOMMN_H__ */ +#endif /* __GXVCOMMN_H__ */ /* END */ diff --git a/src/gxvalid/gxverror.h b/src/gxvalid/gxverror.h index d3fb62560..019619922 100644 --- a/src/gxvalid/gxverror.h +++ b/src/gxvalid/gxverror.h @@ -16,11 +16,14 @@ /***************************************************************************/ /***************************************************************************/ +/* */ /* gxvalid is derived from both gxlayout module and otvalid module. */ -/* Development of gxlayout was support of Information-technology Promotion */ -/* Agency(IPA), Japan. */ +/* Development of gxlayout is supported by the Information-technology */ +/* Promotion Agency(IPA), Japan. */ +/* */ /***************************************************************************/ + /*************************************************************************/ /* */ /* This file is used to define the OpenType validation module error */ diff --git a/src/gxvalid/gxvfeat.c b/src/gxvalid/gxvfeat.c index 574edf41f..ceeff9f5c 100644 --- a/src/gxvalid/gxvfeat.c +++ b/src/gxvalid/gxvfeat.c @@ -16,9 +16,11 @@ /***************************************************************************/ /***************************************************************************/ +/* */ /* gxvalid is derived from both gxlayout module and otvalid module. */ -/* Development of gxlayout was support of Information-technology Promotion */ -/* Agency(IPA), Japan. */ +/* Development of gxlayout is supported by the Information-technology */ +/* Promotion Agency(IPA), Japan. */ +/* */ /***************************************************************************/ @@ -26,7 +28,6 @@ #include "gxvcommn.h" - /*************************************************************************/ /* */ /* The macro FT_COMPONENT is used in trace mode. It is an implicit */ @@ -54,9 +55,14 @@ FT_Byte nSettings; } GX_Feature_RegistryRec; -#define gxv_feat_registry_length ( sizeof ( gxv_feat_registry ) / sizeof ( GX_Feature_RegistryRec ) ) - static GX_Feature_RegistryRec gxv_feat_registry [] = + +#define gxv_feat_registry_length \ + ( sizeof ( gxv_feat_registry ) / \ + sizeof ( GX_Feature_RegistryRec ) ) + + + static GX_Feature_RegistryRec gxv_feat_registry[] = { /* Generated from gxvfgen.c */ {1, 0, 0, 1}, /* All Typographic Features */ @@ -165,7 +171,7 @@ {1, 0, 1, 4}, /* CJK Roman Spacing */ }; - + /*************************************************************************/ /*************************************************************************/ /***** *****/ @@ -174,7 +180,6 @@ /*************************************************************************/ /*************************************************************************/ - typedef struct GXV_feat_DataRec_ { FT_UInt reserved_size; @@ -182,18 +187,21 @@ FT_UShort setting; } GXV_feat_DataRec, *GXV_feat_Data; -#define GXV_FEAT_DATA(field) GXV_TABLE_DATA( feat, field ) + + +#define GXV_FEAT_DATA( field ) GXV_TABLE_DATA( feat, field ) + typedef enum { - GXV_FEAT_MASK_EXCLUSIVE_SETTINGS = 0x8000, + GXV_FEAT_MASK_EXCLUSIVE_SETTINGS = 0x8000U, GXV_FEAT_MASK_DYNAMIC_DEFAULT = 0x4000, GXV_FEAT_MASK_UNUSED = 0x3F00, GXV_FEAT_MASK_DEFAULT_SETTING = 0x00FF - } GXV_FeatureFlagsMask ; + } GXV_FeatureFlagsMask; + - /*************************************************************************/ /*************************************************************************/ /***** *****/ @@ -215,7 +223,7 @@ if ( feature >= gxv_feat_registry_length ) { GXV_TRACE(( "feature number %d is out of range %d\n", - feature, gxv_feat_registry_length )); + feature, gxv_feat_registry_length )); if ( valid->root->level == FT_VALIDATE_PARANOID ) FT_INVALID_DATA; goto Exit; @@ -223,8 +231,8 @@ if ( gxv_feat_registry[feature].existence == 0 ) { - GXV_TRACE(( "feature number %d is in define range but inexistent\n", - feature )); + GXV_TRACE(( "feature number %d is in defined range but doesn't exist\n", + feature )); if ( valid->root->level == FT_VALIDATE_PARANOID ) FT_INVALID_DATA; goto Exit; @@ -233,8 +241,7 @@ if ( gxv_feat_registry[feature].apple_reserved ) { /* Don't use here. Apple is reserved. */ - GXV_TRACE(( "feature number %d is reserved by Apple\n", - feature )); + GXV_TRACE(( "feature number %d is reserved by Apple\n", feature )); if ( valid->root->level >= FT_VALIDATE_TIGHT ) FT_INVALID_DATA; } @@ -242,7 +249,8 @@ if ( nSettings != gxv_feat_registry[feature].nSettings ) { GXV_TRACE(( "feature %d: nSettings %d != defined nSettings %d\n", - feature, nSettings, gxv_feat_registry[feature].nSettings )); + feature, nSettings, + gxv_feat_registry[feature].nSettings )); if ( valid->root->level >= FT_VALIDATE_TIGHT ) FT_INVALID_DATA; } @@ -250,7 +258,7 @@ if ( exclusive != gxv_feat_registry[feature].exclusive ) { GXV_TRACE(( "exclusive flag %d differs from predefined value\n", - exclusive )); + exclusive )); if ( valid->root->level >= FT_VALIDATE_TIGHT ) FT_INVALID_DATA; } @@ -265,9 +273,9 @@ FT_Bytes limit, GXV_Validator valid ) { - FT_Bytes p = table; + FT_Bytes p = table; - FT_Short nameIndex; + FT_Short nameIndex; GXV_NAME_ENTER( "nameIndex" ); @@ -278,12 +286,13 @@ gxv_sfntName_validate( (FT_UShort)nameIndex, 255, - 32768, + 32768U, valid ); GXV_EXIT; } + static void gxv_feat_setting_validate( FT_Bytes table, FT_Bytes limit, @@ -293,14 +302,15 @@ FT_Bytes p = table; FT_UShort setting; + GXV_NAME_ENTER( "setting" ); GXV_LIMIT_CHECK( 2 ); setting = FT_NEXT_USHORT( p ); - /* If exclusive setting, setting should be odd. */ - if ( exclusive && ( ( setting % 2 ) == 0 ) ) + /* If we have exclusive setting, the setting should be odd. */ + if ( exclusive && ( setting % 2 ) == 0 ) FT_INVALID_DATA; gxv_feat_name_index_validate( p, limit, valid ); @@ -326,7 +336,7 @@ FT_Bool exclusive; FT_Int last_setting; - FT_Int i; + FT_UInt i; GXV_NAME_ENTER( "name" ); @@ -344,17 +354,17 @@ if ( settingTable < reserved_size ) FT_INVALID_OFFSET; - if ( valid->root->level == FT_VALIDATE_PARANOID && - (featureFlags & GXV_FEAT_MASK_UNUSED) == 0 ) + if ( valid->root->level == FT_VALIDATE_PARANOID && + ( featureFlags & GXV_FEAT_MASK_UNUSED ) == 0 ) FT_INVALID_DATA; - exclusive = featureFlags & GXV_FEAT_MASK_EXCLUSIVE_SETTINGS; + exclusive = featureFlags & GXV_FEAT_MASK_EXCLUSIVE_SETTINGS; if ( exclusive ) { - FT_Byte dynamic_default; + FT_Byte dynamic_default; - if (featureFlags & GXV_FEAT_MASK_DYNAMIC_DEFAULT) + if ( featureFlags & GXV_FEAT_MASK_DYNAMIC_DEFAULT ) dynamic_default = featureFlags & GXV_FEAT_MASK_DEFAULT_SETTING; else dynamic_default = 0; @@ -373,7 +383,7 @@ { gxv_feat_setting_validate( p, limit, exclusive, valid ); - if ( valid->root->level == FT_VALIDATE_PARANOID && + if ( valid->root->level == FT_VALIDATE_PARANOID && (FT_Int)GXV_FEAT_DATA( setting ) <= last_setting ) FT_INVALID_FORMAT; @@ -410,7 +420,7 @@ FT_UInt featureNameCount; - FT_Int i; + FT_UInt i; FT_Int last_feature; @@ -418,7 +428,7 @@ valid->table_data = feat; valid->face = face; - FT_TRACE3(( "validation feat table\n" )); + FT_TRACE3(( "validating `feat' table\n" )); GXV_INIT; feat->reserved_size = 0; @@ -444,17 +454,18 @@ FT_INVALID_DATA; } - feat->reserved_size += ( featureNameCount * ( 2 + 2 + 4 + 2 + 2 ) ); - for( last_feature = -1, i = 0; i < featureNameCount; i++ ) + feat->reserved_size += featureNameCount * ( 2 + 2 + 4 + 2 + 2 ); + + for ( last_feature = -1, i = 0; i < featureNameCount; i++ ) { gxv_feat_name_validate( p, limit, valid ); - if ( valid->root->level == FT_VALIDATE_PARANOID && - (FT_Int)GXV_FEAT_DATA( feature ) <= last_feature ) + if ( valid->root->level == FT_VALIDATE_PARANOID && + (FT_Int)GXV_FEAT_DATA( feature ) <= last_feature ) FT_INVALID_FORMAT; last_feature = GXV_FEAT_DATA( feature ); - p += ( 2 + 2 + 4 + 2 + 2 ); + p += 2 + 2 + 4 + 2 + 2; } FT_TRACE4(( "\n" )); diff --git a/src/gxvalid/gxvfgen.c b/src/gxvalid/gxvfgen.c index 4741a3e07..ca077b156 100644 --- a/src/gxvalid/gxvfgen.c +++ b/src/gxvalid/gxvfgen.c @@ -2,7 +2,7 @@ /* */ /* gxfgen.c */ /* */ -/* Generate feature registry infomations for gxv feat validator. */ +/* Generate feature registry data for gxv `feat' validator. */ /* This program is derived from gxfeatreg.c in gxlayout. */ /* */ /* Copyright 2004, 2005 by Masatake YAMATO and Redhat K.K. */ @@ -35,13 +35,16 @@ /***************************************************************************/ /***************************************************************************/ -/* Development of gxfeatreg.c is support of */ +/* */ +/* Development of gxfeatreg.c is supported by */ /* Information-technology Promotion Agency, Japan. */ +/* */ /***************************************************************************/ + /***************************************************************************/ /* */ -/* This file is compiled to a standalone executable. */ +/* This file is compiled as a stand-alone executable. */ /* This file is never compiled into `libfreetype2'. */ /* The output of this file is used in `gxvfeat.c'. */ /* ----------------------------------------------------------------------- */ @@ -50,22 +53,26 @@ /* */ /***************************************************************************/ - /***************************************************************************/ - /* WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING */ - /***************************************************************************/ + /*******************************************************************/ + /* WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING */ + /*******************************************************************/ + /* - * If you add a new setting to a feature, check the number of setting - * in the feature. If the number is greater than value defined as + * If you add a new setting to a feature, check the number of settings + * in the feature. If the number is greater than the value defined as * FEATREG_MAX_SETTING, update the value. */ -#define FEATREG_MAX_SETTING 12 - /***************************************************************************/ - /* WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING */ - /***************************************************************************/ +#define FEATREG_MAX_SETTING 12 + + /*******************************************************************/ + /* WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING */ + /*******************************************************************/ + #include #include + /*************************************************************************/ /*************************************************************************/ /***** *****/ @@ -74,7 +81,6 @@ /*************************************************************************/ /*************************************************************************/ - #define APPLE_RESERVED "Apple Reserved" #define APPLE_RESERVED_LENGTH 14 @@ -82,13 +88,16 @@ { const char* feat_name; char exclusive; - char* setting_name [FEATREG_MAX_SETTING]; + char* setting_name[FEATREG_MAX_SETTING]; } GX_Feature_RegistryRec; + #define EMPTYFEAT {0, 0, {NULL}} - static GX_Feature_RegistryRec featreg_table [] = { - { /* 0 */ + + + static GX_Feature_RegistryRec featreg_table[] = { + { /* 0 */ "All Typographic Features", 0, { @@ -293,7 +302,7 @@ "Traditional Characters, Alternative Set 4", "Traditional Characters, Alternative Set 5", "Expert Characters", - NULL /* count=>12 */ + NULL /* count => 12 */ } }, { /* 21 */ "Number Case", @@ -360,7 +369,7 @@ "Proportional", NULL } - }, EMPTYFEAT, EMPTYFEAT, EMPTYFEAT, EMPTYFEAT, /* 27-30 */ + }, EMPTYFEAT, EMPTYFEAT, EMPTYFEAT, EMPTYFEAT, /* 27-30 */ EMPTYFEAT, EMPTYFEAT, EMPTYFEAT, EMPTYFEAT, EMPTYFEAT, /* 31-35 */ EMPTYFEAT, EMPTYFEAT, EMPTYFEAT, EMPTYFEAT, EMPTYFEAT, /* 36-40 */ EMPTYFEAT, EMPTYFEAT, EMPTYFEAT, EMPTYFEAT, EMPTYFEAT, /* 40-45 */ @@ -374,8 +383,8 @@ EMPTYFEAT, EMPTYFEAT, EMPTYFEAT, EMPTYFEAT, EMPTYFEAT, /* 81-85 */ EMPTYFEAT, EMPTYFEAT, EMPTYFEAT, EMPTYFEAT, EMPTYFEAT, /* 86-90 */ EMPTYFEAT, EMPTYFEAT, EMPTYFEAT, EMPTYFEAT, EMPTYFEAT, /* 91-95 */ - EMPTYFEAT, EMPTYFEAT, EMPTYFEAT, /* 96-98 */ - EMPTYFEAT, /* 99 */ { /* 100 => 22*/ + EMPTYFEAT, EMPTYFEAT, EMPTYFEAT, /* 96-98 */ + EMPTYFEAT, /* 99 */ { /* 100 => 22 */ "Text Spacing", 1, { @@ -422,7 +431,6 @@ }; - /*************************************************************************/ /*************************************************************************/ /***** *****/ @@ -447,16 +455,18 @@ const char* feat_name; int nSettings; - feat_name = featreg_table[i].feat_name; + + feat_name = featreg_table[i].feat_name; for ( nSettings = 0; featreg_table[i].setting_name[nSettings]; nSettings++) - 0; /* Do nothing */ + ; /* Do nothing */ printf( " {%1d, %1d, %1d, %2d}, /* %s */\n", feat_name ? 1 : 0, - ( feat_name && - ( strncmp( feat_name, APPLE_RESERVED, APPLE_RESERVED_LENGTH ) == 0 ) + ( feat_name && + ( strncmp( feat_name, + APPLE_RESERVED, APPLE_RESERVED_LENGTH ) == 0 ) ) ? 1 : 0, featreg_table[i].exclusive ? 1 : 0, nSettings, @@ -468,4 +478,5 @@ return 0; } + /* END */ diff --git a/src/gxvalid/gxvjust.c b/src/gxvalid/gxvjust.c index 97ab17d3c..a841b406f 100644 --- a/src/gxvalid/gxvjust.c +++ b/src/gxvalid/gxvjust.c @@ -16,20 +16,20 @@ /***************************************************************************/ /***************************************************************************/ +/* */ /* gxvalid is derived from both gxlayout module and otvalid module. */ -/* Development of gxlayout was support of Information-technology Promotion */ -/* Agency(IPA), Japan. */ +/* Development of gxlayout is supported by the Information-technology */ +/* Promotion Agency(IPA), Japan. */ +/* */ /***************************************************************************/ + #include "gxvalid.h" #include "gxvcommn.h" #include FT_SFNT_NAMES_H - - - /*************************************************************************/ /* */ /* The macro FT_COMPONENT is used in trace mode. It is an implicit */ @@ -39,18 +39,19 @@ #undef FT_COMPONENT #define FT_COMPONENT trace_gxvjust - /* - * refered just table format specification: - * http://developer.apple.com/fonts/TTRefMan/RM06/Chap6just.html - * last update is 2000. - * ---------------------------------------------- - * [JUST HEADER]: GXV_JUST_HEADER_SIZE - * version (fixed: 32bit) = 0x00010000 - * format (uint16: 16bit) = 0 is only defined (2000) - * horizOffset (uint16: 16bit) - * vertOffset (uint16: 16bit) - * ---------------------------------------------- - */ + /* + * referred `just' table format specification: + * http://developer.apple.com/fonts/TTRefMan/RM06/Chap6just.html + * last updated 2000. + * ---------------------------------------------- + * [JUST HEADER]: GXV_JUST_HEADER_SIZE + * version (fixed: 32bit) = 0x00010000 + * format (uint16: 16bit) = 0 is only defined (2000) + * horizOffset (uint16: 16bit) + * vertOffset (uint16: 16bit) + * ---------------------------------------------- + */ + typedef struct GXV_just_DataRec_ { FT_UShort wdc_offset_max; @@ -60,8 +61,10 @@ } GXV_just_DataRec, *GXV_just_Data; + #define GXV_JUST_DATA( a ) GXV_TABLE_DATA( just, a ) + static void gxv_just_wdp_entry_validate( FT_Bytes table, FT_Bytes limit, @@ -86,9 +89,9 @@ growFlags = FT_NEXT_USHORT( p ); shrinkFlags = FT_NEXT_USHORT( p ); - /* TODO: decode flags for human readabilty */ + /* TODO: decode flags for human readability */ - valid->subtable_length = ( p - table ); + valid->subtable_length = p - table; } @@ -110,30 +113,33 @@ p += valid->subtable_length; } - valid->subtable_length = ( p - table ); + valid->subtable_length = p - table; } + static void gxv_just_widthDeltaClusters_validate( FT_Bytes table, FT_Bytes limit, GXV_Validator valid ) { - FT_Bytes p = table ; - FT_Bytes wdc_end = table + GXV_JUST_DATA( wdc_offset_max ); - FT_UInt i; + FT_Bytes p = table ; + FT_Bytes wdc_end = table + GXV_JUST_DATA( wdc_offset_max ); + FT_UInt i; GXV_NAME_ENTER( "just justDeltaClusters" ); if ( limit <= wdc_end ) FT_INVALID_OFFSET; + for ( i = 0; p <= wdc_end; i++ ) { gxv_just_wdc_entry_validate( p, limit, valid ); p += valid->subtable_length; } - valid->subtable_length = ( p - table ); + valid->subtable_length = p - table; + GXV_EXIT; } @@ -143,12 +149,15 @@ FT_Bytes limit, GXV_Validator valid ) { - FT_Bytes p = table; - FT_Fixed lowerLimit; - FT_Fixed upperLimit; - FT_UShort order; - FT_UShort decomposedCount; - FT_UInt i; + FT_Bytes p = table; + + FT_Fixed lowerLimit; + FT_Fixed upperLimit; + + FT_UShort order; + FT_UShort decomposedCount; + + FT_UInt i; GXV_LIMIT_CHECK( 4 + 4 + 2 + 2 ); @@ -166,7 +175,7 @@ glyphs = FT_NEXT_USHORT( p ); } - valid->subtable_length = ( p - table ); + valid->subtable_length = p - table; } @@ -175,14 +184,14 @@ FT_Bytes limit, GXV_Validator valid ) { - FT_Bytes p = table; - FT_UShort addGlyph; + FT_Bytes p = table; + FT_UShort addGlyph; GXV_LIMIT_CHECK( 2 ); addGlyph = FT_NEXT_USHORT( p ); - valid->subtable_length = ( p - table ); + valid->subtable_length = p - table; } @@ -202,9 +211,10 @@ addGlyph = FT_NEXT_USHORT( p ); substGlyph = FT_NEXT_USHORT( p ); - valid->subtable_length = ( p - table ); + valid->subtable_length = p - table; } + static void gxv_just_actSubrecord_type4_validate( FT_Bytes table, FT_Bytes limit, @@ -223,9 +233,10 @@ noStretchValue = FT_NEXT_ULONG( p ); maximumLimit = FT_NEXT_ULONG( p ); - valid->subtable_length = ( p - table ); + valid->subtable_length = p - table; } + static void gxv_just_actSubrecord_type5_validate( FT_Bytes table, FT_Bytes limit, @@ -240,20 +251,20 @@ flags = FT_NEXT_USHORT( p ); glyph = FT_NEXT_USHORT( p ); - valid->subtable_length = ( p - table ); + valid->subtable_length = p - table; } /* parse single actSubrecord */ static void - gxv_just_actSubrecord_validate( FT_Bytes table, - FT_Bytes limit, - GXV_Validator valid ) + gxv_just_actSubrecord_validate( FT_Bytes table, + FT_Bytes limit, + GXV_Validator valid ) { - FT_Bytes p = table; - FT_UShort actionClass; - FT_UShort actionType; - FT_ULong actionLength; + FT_Bytes p = table; + FT_UShort actionClass; + FT_UShort actionType; + FT_ULong actionLength; GXV_NAME_ENTER( "just actSubrecord" ); @@ -270,7 +281,7 @@ else if ( actionType == 2 ) gxv_just_actSubrecord_type2_validate( p, limit, valid ); else if ( actionType == 3 ) - ; /* Stretch glyph action: no actionData */ + ; /* Stretch glyph action: no actionData */ else if ( actionType == 4 ) gxv_just_actSubrecord_type4_validate( p, limit, valid ); else if ( actionType == 5 ) @@ -279,6 +290,7 @@ FT_INVALID_DATA; valid->subtable_length = actionLength; + GXV_EXIT; } @@ -303,7 +315,8 @@ p += valid->subtable_length; } - valid->subtable_length = ( p - table ); + valid->subtable_length = p - table; + GXV_EXIT; } @@ -313,6 +326,8 @@ GXV_LookupValueDesc value, GXV_Validator valid ) { + FT_UNUSED( glyph ); + if ( value.u > GXV_JUST_DATA( pc_offset_max ) ) GXV_JUST_DATA( pc_offset_max ) = value.u; if ( value.u < GXV_JUST_DATA( pc_offset_max ) ) @@ -327,14 +342,18 @@ { FT_Bytes p = table; + GXV_NAME_ENTER( "just pcLookupTable" ); GXV_JUST_DATA( pc_offset_max ) = 0x0000; - GXV_JUST_DATA( pc_offset_min ) = 0xFFFF; + GXV_JUST_DATA( pc_offset_min ) = 0xFFFFU; valid->lookupval_sign = GXV_LOOKUPVALUE_UNSIGNED; valid->lookupval_func = gxv_just_pcTable_LookupValue_entry_validate; + gxv_LookupTable_validate( p, limit, valid ); + /* subtable_length is set by gxv_LookupTable_validate() */ + GXV_EXIT; } @@ -344,39 +363,49 @@ FT_Bytes limit, GXV_Validator valid ) { - FT_Bytes p = table; + FT_Bytes p = table; GXV_NAME_ENTER( "just postcompTable" ); gxv_just_pcLookupTable_validate( p, limit, valid ); p += valid->subtable_length; + gxv_just_pcActionRecord_validate( p, limit, valid ); p += valid->subtable_length; - valid->subtable_length = ( p - table ); + valid->subtable_length = p - table; + GXV_EXIT; } static void - gxv_just_classTable_entry_validate( FT_Byte state, - FT_UShort flags, - GXV_StateTable_GlyphOffsetDesc glyphOffset, - FT_Bytes table, - FT_Bytes limit, - GXV_Validator valid ) + gxv_just_classTable_entry_validate( + FT_Byte state, + FT_UShort flags, + GXV_StateTable_GlyphOffsetDesc glyphOffset, + FT_Bytes table, + FT_Bytes limit, + GXV_Validator valid ) { FT_UShort setMark; FT_UShort dontAdvance; FT_UShort markClass; FT_UShort currentClass; + FT_UNUSED( state ); + FT_UNUSED( glyphOffset ); + FT_UNUSED( table ); + FT_UNUSED( limit ); + FT_UNUSED( valid ); + + + setMark = ( 0x8000U & flags ) / 0x8000U; + dontAdvance = ( 0x4000 & flags ) / 0x4000; + markClass = ( 0x3F80 & flags ) / 0x0080; + currentClass = 0x007F & flags ; - setMark = ( 0x8000 & flags ) / 0x8000; - dontAdvance = ( 0x4000 & flags ) / 0x4000; - markClass = ( 0x3F80 & flags ) / 0x0080; - currentClass = 0x007F & flags ; /* TODO: validate markClass & currentClass */ } @@ -399,19 +428,22 @@ coverage = FT_NEXT_USHORT( p ); subFeatureFlags = FT_NEXT_ULONG( p ); - GXV_TRACE(( " justClassTable: coverage = 0x%04x (%s)", coverage, - (0x4000 & coverage) == 0 ? "ascending" : "descending" - )); + GXV_TRACE(( " justClassTable: coverage = 0x%04x (%s)", + coverage, + ( 0x4000 & coverage ) == 0 ? "ascending" : "descending" )); valid->statetable.optdata = NULL; valid->statetable.optdata_load_func = NULL; valid->statetable.subtable_setup_func = NULL; valid->statetable.entry_glyphoffset_fmt = GXV_GLYPHOFFSET_NONE; - valid->statetable.entry_validate_func = gxv_just_classTable_entry_validate; + valid->statetable.entry_validate_func = + gxv_just_classTable_entry_validate; + gxv_StateTable_validate( p, table + length, valid ); + /* subtable_length is set by gxv_LookupTable_validate() */ - GXV_EXIT; + GXV_EXIT; } @@ -420,6 +452,8 @@ GXV_LookupValueDesc value, GXV_Validator valid ) { + FT_UNUSED( glyph ); + if ( value.u > GXV_JUST_DATA( wdc_offset_max ) ) GXV_JUST_DATA( wdc_offset_max ) = value.u; if ( value.u < GXV_JUST_DATA( wdc_offset_min ) ) @@ -432,15 +466,19 @@ FT_Bytes limit, GXV_Validator valid ) { - FT_Bytes p = table; + FT_Bytes p = table; GXV_JUST_DATA( wdc_offset_max ) = 0x0000; - GXV_JUST_DATA( wdc_offset_min ) = 0xFFFF; + GXV_JUST_DATA( wdc_offset_min ) = 0xFFFFU; + valid->lookupval_sign = GXV_LOOKUPVALUE_UNSIGNED; valid->lookupval_func = gxv_just_wdcTable_LookupValue_validate; + gxv_LookupTable_validate( p, limit, valid ); + /* subtable_length is set by gxv_LookupTable_validate() */ + GXV_EXIT; } @@ -449,17 +487,19 @@ * gxv_just_justData_validate() parses and validates horizData, vertData. */ static void - gxv_just_justData_validate ( FT_Bytes table, - FT_Bytes limit, - GXV_Validator valid ) + gxv_just_justData_validate( FT_Bytes table, + FT_Bytes limit, + GXV_Validator valid ) { - /* following 3 offsets are measured from the start of just - * which table points to), not justData + /* + * following 3 offsets are measured from the start of `just' + * (which table points to), not justData */ FT_UShort justClassTableOffset; FT_UShort wdcTableOffset; FT_UShort pcTableOffset; FT_Bytes p = table; + GXV_ODTECT( 4, odtect ); @@ -475,14 +515,14 @@ GXV_TRACE(( " (wdcTableOffset = 0x%04x)\n", wdcTableOffset )); GXV_TRACE(( " (pcTableOffset = 0x%04x)\n", pcTableOffset )); - gxv_just_justData_lookuptable_validate( p, limit, valid ); - gxv_odtect_add_range( p, valid->subtable_length, "just_LookupTable", odtect ); + gxv_odtect_add_range( p, valid->subtable_length, + "just_LookupTable", odtect ); if ( wdcTableOffset ) { - gxv_just_widthDeltaClusters_validate( valid->root->base + wdcTableOffset, - limit, valid ); + gxv_just_widthDeltaClusters_validate( + valid->root->base + wdcTableOffset, limit, valid ); gxv_odtect_add_range( valid->root->base + wdcTableOffset, valid->subtable_length, "just_wdcTable", odtect ); } @@ -497,10 +537,11 @@ if ( justClassTableOffset ) { - gxv_just_justClassTable_validate( valid->root->base + justClassTableOffset, - limit, valid ); + gxv_just_justClassTable_validate( + valid->root->base + justClassTableOffset, limit, valid ); gxv_odtect_add_range( valid->root->base + justClassTableOffset, - valid->subtable_length, "just_justClassTable", odtect ); + valid->subtable_length, "just_justClassTable", + odtect ); } gxv_odtect_validate( odtect, valid ); @@ -537,11 +578,12 @@ valid->table_data = just; valid->face = face; - FT_TRACE3(( "validation just table\n" )); + FT_TRACE3(( "validating `just' table\n" )); GXV_INIT; limit = valid->root->limit; table_size = limit - table; + GXV_LIMIT_CHECK( 4 + 2 + 2 + 2 ); version = FT_NEXT_ULONG( p ); format = FT_NEXT_USHORT( p ); diff --git a/src/gxvalid/gxvkern.c b/src/gxvalid/gxvkern.c index d69bec26e..645c4ff4a 100644 --- a/src/gxvalid/gxvkern.c +++ b/src/gxvalid/gxvkern.c @@ -16,9 +16,11 @@ /***************************************************************************/ /***************************************************************************/ +/* */ /* gxvalid is derived from both gxlayout module and otvalid module. */ -/* Development of gxlayout was support of Information-technology Promotion */ -/* Agency(IPA), Japan. */ +/* Development of gxlayout is supported by the Information-technology */ +/* Promotion Agency(IPA), Japan. */ +/* */ /***************************************************************************/ @@ -29,7 +31,6 @@ #include FT_SERVICE_GX_VALIDATE_H - /*************************************************************************/ /* */ /* The macro FT_COMPONENT is used in trace mode. It is an implicit */ @@ -48,21 +49,23 @@ /*************************************************************************/ /*************************************************************************/ - typedef enum GXV_kern_Version_ + typedef enum GXV_kern_Version_ { KERN_VERSION_CLASSIC = 0x0000, KERN_VERSION_NEW = 0x0001 } GXV_kern_Version; + typedef enum GXV_kern_Dialect_ { - KERN_DIALECT_MS = FT_VALIDATE_MS, - KERN_DIALECT_APPLE = FT_VALIDATE_APPLE, - KERN_DIALECT_ANY = FT_VALIDATE_CKERN + KERN_DIALECT_MS = FT_VALIDATE_MS, + KERN_DIALECT_APPLE = FT_VALIDATE_APPLE, + KERN_DIALECT_ANY = FT_VALIDATE_CKERN } GXV_kern_Dialect; + typedef struct GXV_kern_DataRec_ { GXV_kern_Version version; @@ -71,16 +74,22 @@ } GXV_kern_DataRec, *GXV_kern_Data; -#define GXV_KERN_DATA( field ) GXV_TABLE_DATA( kern, field ) -#define KERN_IS_CLASSIC( valid ) ( KERN_VERSION_CLASSIC == GXV_KERN_DATA( version ) ) -#define KERN_IS_NEW( valid ) ( KERN_VERSION_NEW == GXV_KERN_DATA( version ) ) +#define GXV_KERN_DATA( field ) GXV_TABLE_DATA( kern, field ) + +#define KERN_IS_CLASSIC( valid ) \ + ( KERN_VERSION_CLASSIC == GXV_KERN_DATA( version ) ) +#define KERN_IS_NEW( valid ) \ + ( KERN_VERSION_NEW == GXV_KERN_DATA( version ) ) -#define KERN_DIALECT( valid ) GXV_KERN_DATA( dialect_request ) -#define KERN_ALLOWS_MS( valid ) ( KERN_DIALECT( valid ) & KERN_DIALECT_MS ) -#define KERN_ALLOWS_APPLE( valid ) ( KERN_DIALECT( valid ) & KERN_DIALECT_APPLE ) +#define KERN_DIALECT( valid ) \ + GXV_KERN_DATA( dialect_request ) +#define KERN_ALLOWS_MS( valid ) \ + ( KERN_DIALECT( valid ) & KERN_DIALECT_MS ) +#define KERN_ALLOWS_APPLE( valid ) \ + ( KERN_DIALECT( valid ) & KERN_DIALECT_APPLE ) -#define GXV_KERN_HEADER_SIZE ( KERN_IS_NEW( valid ) ? 8 : 4 ) +#define GXV_KERN_HEADER_SIZE ( KERN_IS_NEW( valid ) ? 8 : 4 ) #define GXV_KERN_SUBTABLE_HEADER_SIZE ( KERN_IS_NEW( valid ) ? 8 : 6 ) @@ -95,7 +104,6 @@ /* ============================= format 0 ============================== */ - static void gxv_kern_subtable_fmt0_validate( FT_Bytes table, FT_Bytes limit, @@ -108,9 +116,9 @@ FT_UShort i; - GXV_NAME_ENTER("kern subtable format0"); + GXV_NAME_ENTER( "kern subtable format0" ); - unitSize = ( 2 + 2 + 2 ); + unitSize = 2 + 2 + 2; nPairs = 0; /* nPairs, searchRange, entrySelector, rangeShift */ @@ -123,8 +131,10 @@ FT_UShort gid_left; FT_UShort gid_right; FT_Short kernValue; + /* TODO: should be checked pairs are unique. */ + /* left */ gid_left = FT_NEXT_USHORT( p ); gxv_glyphid_validate( gid_left, valid ); @@ -160,6 +170,7 @@ FT_Bytes p = table; GXV_kern_fmt1_StateOptRecData optdata = valid->statetable.optdata; + GXV_LIMIT_CHECK( 2 ); optdata->valueTable = FT_NEXT_USHORT( p ); } @@ -181,6 +192,7 @@ FT_UShort o[4]; FT_UShort *l[4]; FT_UShort buff[5]; + GXV_kern_fmt1_StateOptRecData optdata = valid->statetable.optdata; @@ -198,23 +210,28 @@ /* - * passed table & limit are of whole of StateTable, not included subtables. + * passed table & limit are of whole StateTable, not including subtables */ static void - gxv_kern_subtable_fmt1_entry_validate( FT_Byte state, - FT_UShort flags, - GXV_StateTable_GlyphOffsetDesc glyphOffset, - FT_Bytes table, - FT_Bytes limit, - GXV_Validator valid ) + gxv_kern_subtable_fmt1_entry_validate( + FT_Byte state, + FT_UShort flags, + GXV_StateTable_GlyphOffsetDesc glyphOffset, + FT_Bytes table, + FT_Bytes limit, + GXV_Validator valid ) { - FT_UShort push; - FT_UShort dontAdvance; - FT_UShort valueOffset; - FT_UShort kernAction; - FT_UShort kernValue; + FT_UShort push; + FT_UShort dontAdvance; + FT_UShort valueOffset; + FT_UShort kernAction; + FT_UShort kernValue; - push = flags / 0x8000; + FT_UNUSED( state ); + FT_UNUSED( glyphOffset ); + + + push = flags / 0x8000U; dontAdvance = ( flags & 0x4000 ) / 0x4000; valueOffset = flags & 0x3FFF; @@ -222,6 +239,7 @@ GXV_kern_fmt1_StateOptRecData vt_rec = valid->statetable.optdata; FT_Bytes p; + if ( valueOffset < vt_rec->valueTable ) FT_INVALID_OFFSET; @@ -240,28 +258,36 @@ FT_Bytes limit, GXV_Validator valid ) { - FT_Bytes p = table; - GXV_kern_fmt1_StateOptRec vt_rec; + FT_Bytes p = table; + GXV_kern_fmt1_StateOptRec vt_rec; - GXV_NAME_ENTER("kern subtable format1"); - valid->statetable.optdata = &vt_rec; - valid->statetable.optdata_load_func = gxv_kern_subtable_fmt1_valueTable_load; - valid->statetable.subtable_setup_func = gxv_kern_subtable_fmt1_subtable_setup; - valid->statetable.entry_glyphoffset_fmt = GXV_GLYPHOFFSET_NONE; - valid->statetable.entry_validate_func = gxv_kern_subtable_fmt1_entry_validate; + GXV_NAME_ENTER( "kern subtable format1" ); + + valid->statetable.optdata = + &vt_rec; + valid->statetable.optdata_load_func = + gxv_kern_subtable_fmt1_valueTable_load; + valid->statetable.subtable_setup_func = + gxv_kern_subtable_fmt1_subtable_setup; + valid->statetable.entry_glyphoffset_fmt = + GXV_GLYPHOFFSET_NONE; + valid->statetable.entry_validate_func = + gxv_kern_subtable_fmt1_entry_validate; + gxv_StateTable_validate( p, limit, valid ); GXV_EXIT; } - /* ================ Data for Class-Based Subtables 2, 3 ================ */ + /* ================ Data for Class-Based Subtables 2, 3 ================ */ - typedef enum GXV_kern_ClassSpec_ + typedef enum GXV_kern_ClassSpec_ { GXV_KERN_CLS_L = 0, GXV_KERN_CLS_R + } GXV_kern_ClassSpec; @@ -271,20 +297,22 @@ typedef struct GXV_kern_subtable_fmt2_DataRec_ { - FT_UShort rowWidth; - FT_UShort array; - FT_UShort offset_min[2]; - FT_UShort offset_max[2]; - FT_String* class_tag[2]; + FT_UShort rowWidth; + FT_UShort array; + FT_UShort offset_min[2]; + FT_UShort offset_max[2]; + const FT_String* class_tag[2]; GXV_odtect_Range odtect; } GXV_kern_subtable_fmt2_DataRec, *GXV_kern_subtable_fmt2_Data; -#define GXV_KERN_FMT2_DATA( field ) \ - (((GXV_kern_subtable_fmt2_DataRec *)(GXV_KERN_DATA( subtable_data )))-> field ) - /* -------------------------- utility functions ----------------------- */ +#define GXV_KERN_FMT2_DATA( field ) \ + ( ( (GXV_kern_subtable_fmt2_DataRec *) \ + ( GXV_KERN_DATA( subtable_data ) ) )->field ) + + /* -------------------------- utility functions ----------------------- */ static void gxv_kern_subtable_fmt2_clstbl_validate( FT_Bytes table, @@ -292,7 +320,7 @@ GXV_kern_ClassSpec spec, GXV_Validator valid ) { - FT_String* tag = GXV_KERN_FMT2_DATA( class_tag[spec] ); + const FT_String* tag = GXV_KERN_FMT2_DATA( class_tag[spec] ); GXV_odtect_Range odtect = GXV_KERN_FMT2_DATA( odtect ); FT_Bytes p = table; @@ -300,26 +328,23 @@ FT_UShort nGlyphs; - GXV_NAME_ENTER(( "kern format 2 classTable" )); - + GXV_NAME_ENTER( "kern format 2 classTable" ); GXV_LIMIT_CHECK( 2 + 2 ); firstGlyph = FT_NEXT_USHORT( p ); nGlyphs = FT_NEXT_USHORT( p ); - GXV_TRACE(( " %s firstGlyph=%d, nGlyphs=%d\n", tag, firstGlyph, nGlyphs )); - + GXV_TRACE(( " %s firstGlyph=%d, nGlyphs=%d\n", + tag, firstGlyph, nGlyphs )); gxv_glyphid_validate( firstGlyph, valid ); gxv_glyphid_validate( firstGlyph + nGlyphs - 1, valid ); - gxv_array_getlimits_ushort( p, p + ( 2 * nGlyphs ), &( GXV_KERN_FMT2_DATA( offset_min[spec] ) ), &( GXV_KERN_FMT2_DATA( offset_max[spec] ) ), valid ); - - gxv_odtect_add_range( table, ( 2 * nGlyphs ), tag, odtect ); + gxv_odtect_add_range( table, 2 * nGlyphs, tag, odtect ); GXV_EXIT; } @@ -339,7 +364,7 @@ FT_UShort rightOffsetTable; - GXV_NAME_ENTER("kern subtable format2"); + GXV_NAME_ENTER( "kern subtable format2" ); GXV_ODTECT_INIT( odtect ); fmt2_rec.odtect = odtect; @@ -358,20 +383,17 @@ GXV_LIMIT_CHECK( rightOffsetTable ); GXV_LIMIT_CHECK( GXV_KERN_FMT2_DATA( array ) ); - gxv_kern_subtable_fmt2_clstbl_validate( table + leftOffsetTable, limit, GXV_KERN_CLS_L, valid ); - gxv_kern_subtable_fmt2_clstbl_validate( table + rightOffsetTable, limit, GXV_KERN_CLS_R, valid ); - if ( GXV_KERN_FMT2_DATA( offset_min[GXV_KERN_CLS_L] ) - + GXV_KERN_FMT2_DATA( offset_min[GXV_KERN_CLS_R] ) - < GXV_KERN_FMT2_DATA( array ) ) + if ( GXV_KERN_FMT2_DATA( offset_min[GXV_KERN_CLS_L] ) + + GXV_KERN_FMT2_DATA( offset_min[GXV_KERN_CLS_R] ) + < GXV_KERN_FMT2_DATA( array ) ) FT_INVALID_OFFSET; - gxv_odtect_add_range( table + GXV_KERN_FMT2_DATA( array ), GXV_KERN_FMT2_DATA( offset_max[GXV_KERN_CLS_L] ) + GXV_KERN_FMT2_DATA( offset_max[GXV_KERN_CLS_R] ) @@ -386,7 +408,6 @@ /* ============================= format 3 ============================== */ - static void gxv_kern_subtable_fmt3_validate( FT_Bytes table, FT_Bytes limit, @@ -400,7 +421,7 @@ FT_Byte flags; - GXV_NAME_ENTER("kern subtable format3"); + GXV_NAME_ENTER( "kern subtable format3" ); GXV_LIMIT_CHECK( 2 + 1 + 1 + 1 + 1 ); glyphCount = FT_NEXT_USHORT( p ); @@ -409,21 +430,19 @@ rightClassCount = FT_NEXT_BYTE( p ); flags = FT_NEXT_BYTE( p ); - if ( valid->face->num_glyphs != glyphCount ) { - GXV_TRACE(( "maxGID=%d, but glyphCount=%d\n", valid->face->num_glyphs, glyphCount )); + GXV_TRACE(( "maxGID=%d, but glyphCount=%d\n", + valid->face->num_glyphs, glyphCount )); if ( valid->root->level >= FT_VALIDATE_PARANOID ) FT_INVALID_GLYPH_ID; } - /* - * Just skip kernValue[kernValueCount] + * just skip kernValue[kernValueCount] */ GXV_LIMIT_CHECK( 2 * kernValueCount ); - p += ( 2 * kernValueCount ); - + p += 2 * kernValueCount; /* * check leftClass[gid] < leftClassCount @@ -431,6 +450,7 @@ { FT_Byte min, max; + GXV_LIMIT_CHECK( glyphCount ); gxv_array_getlimits_byte( p, p + glyphCount, &min, &max, valid ); p += valid->subtable_length; @@ -439,13 +459,13 @@ FT_INVALID_DATA; } - /* * check rightClass[gid] < rightClassCount */ { FT_Byte min, max; + GXV_LIMIT_CHECK( glyphCount ); gxv_array_getlimits_byte( p, p + glyphCount, &min, &max, valid ); p += valid->subtable_length; @@ -454,15 +474,16 @@ FT_INVALID_DATA; } - /* * check kernIndex[i, j] < kernValueCount */ { FT_UShort i, j; - for ( i = 0; i < leftClassCount; i ++ ) + + + for ( i = 0; i < leftClassCount; i++ ) { - for ( j = 0; j < rightClassCount; j ++ ) + for ( j = 0; j < rightClassCount; j++ ) { GXV_LIMIT_CHECK( 1 ); if ( kernValueCount < FT_NEXT_BYTE( p ) ) @@ -471,7 +492,7 @@ } } - valid->subtable_length = ( p - table ); + valid->subtable_length = p - table; GXV_EXIT; } @@ -490,8 +511,7 @@ /* reserved bits = 0 */ if ( coverage & 0x1FFC ) - return FALSE; - + return 0; kernVertical = ( coverage >> 15 ) & 1; kernCrossStream = ( coverage >> 14 ) & 1; @@ -503,7 +523,8 @@ !kernVertical, kernCrossStream, kernVariation, *format )); GXV_TRACE(( "kerning values in Apple format subtable are ignored\n" )); - return TRUE; + + return 1; } @@ -517,14 +538,13 @@ FT_Bool cross_stream; - /* expected flags but don't check if MS-dialect is impossible */ + /* check expected flags, but don't check if MS-dialect is impossible */ if ( !( coverage & 0xFD00 ) && KERN_ALLOWS_MS( valid ) ) - return FALSE; + return 0; /* reserved bits = 0 */ if ( coverage & 0x02FC ) - return FALSE; - + return 0; horizontal = ( coverage >> 15 ) & 1; cross_stream = ( coverage >> 13 ) & 1; @@ -534,12 +554,13 @@ "horizontal=%d, cross-stream=%d, format=%d\n", horizontal, cross_stream, *format )); - /* format1 requires GX State Machine, too new for classic */ + /* format 1 requires GX State Machine, too new for classic */ if ( *format == 1 ) - return FALSE; + return 0; GXV_TRACE(( "kerning values in Apple format subtable are ignored\n" )); - return TRUE; + + return 1; } @@ -554,9 +575,10 @@ FT_Bool cross_stream; FT_Bool override; + /* reserved bits = 0 */ if ( coverage & 0xFDF0 ) - return FALSE; + return 0; horizontal = coverage & 1; minimum = ( coverage >> 1 ) & 1; @@ -565,15 +587,18 @@ *format = ( coverage >> 8 ) & 0x0003; GXV_TRACE(( "classic Microsoft-dialect: " - "horizontal=%d, minimum=%d, cross-stream=%d, override=%d, format=%d\n", - horizontal, minimum, cross_stream, override, *format )); + "horizontal=%d, minimum=%d, cross-stream=%d, " + "override=%d, format=%d\n", + horizontal, minimum, cross_stream, override, *format )); if ( *format == 2 ) - GXV_TRACE(( "kerning values in Microsoft format 2 subtable are ignored\n" )); + GXV_TRACE(( + "kerning values in Microsoft format 2 subtable are ignored\n" )); - return TRUE; + return 1; } + /*************************************************************************/ /*************************************************************************/ /***** *****/ @@ -582,16 +607,15 @@ /*************************************************************************/ /*************************************************************************/ - static GXV_kern_Dialect - gxv_kern_coverage_validate ( FT_UShort coverage, - FT_UShort* format, - GXV_Validator valid ) + gxv_kern_coverage_validate( FT_UShort coverage, + FT_UShort* format, + GXV_Validator valid ) { - FT_Int result = 0; + FT_Int result = 0; - GXV_NAME_ENTER(( "validate coverage" )); + GXV_NAME_ENTER( "validate coverage" ); GXV_TRACE(( "interprete coverage 0x%04x by Apple style\n", coverage )); @@ -635,6 +659,7 @@ return result; } + static void gxv_kern_subtable_validate( FT_Bytes table, FT_Bytes limit, @@ -649,7 +674,7 @@ FT_UShort format = 255; /* subtable format */ - GXV_NAME_ENTER("kern subtable"); + GXV_NAME_ENTER( "kern subtable" ); GXV_LIMIT_CHECK( 2 + 2 + 2 ); u16[0] = FT_NEXT_USHORT( p ); /* Apple: length_hi MS: version */ @@ -658,34 +683,36 @@ switch ( gxv_kern_coverage_validate( coverage, &format, valid ) ) { - case KERN_DIALECT_MS: - version = u16[0]; - length = u16[1]; - tupleIndex = 0; - GXV_TRACE(( "Subtable version = %d\n", version )); - GXV_TRACE(( "Subtable length = %d\n", length )); - break; - case KERN_DIALECT_APPLE: - version = 0; - length = ( u16[0] << 16 ) + u16[1]; - tupleIndex = 0; - GXV_TRACE(( "Subtable length = %d\n", length )); - - if ( KERN_IS_NEW( valid )) - { - GXV_LIMIT_CHECK( 2 ); - tupleIndex = FT_NEXT_USHORT( p ); - GXV_TRACE(( "Subtable tupleIndex = %d\n", tupleIndex )); - } - break; - default: - length = u16[1]; - GXV_TRACE(( "cannot detect subtable dialect, " - "just skip %d byte\n", length )); - goto Exit; + case KERN_DIALECT_MS: + version = u16[0]; + length = u16[1]; + tupleIndex = 0; + GXV_TRACE(( "Subtable version = %d\n", version )); + GXV_TRACE(( "Subtable length = %d\n", length )); + break; + + case KERN_DIALECT_APPLE: + version = 0; + length = ( u16[0] << 16 ) + u16[1]; + tupleIndex = 0; + GXV_TRACE(( "Subtable length = %d\n", length )); + + if ( KERN_IS_NEW( valid ) ) + { + GXV_LIMIT_CHECK( 2 ); + tupleIndex = FT_NEXT_USHORT( p ); + GXV_TRACE(( "Subtable tupleIndex = %d\n", tupleIndex )); + } + break; + + default: + length = u16[1]; + GXV_TRACE(( "cannot detect subtable dialect, " + "just skip %d byte\n", length )); + goto Exit; } - /* fmt1, 2, 3 requires the position of the start of this subtable */ + /* formats 1, 2, 3 require the position of the start of this subtable */ if ( format == 0 ) gxv_kern_subtable_fmt0_validate( table, table + length, valid ); else if ( format == 1 ) @@ -735,13 +762,14 @@ valid->table_data = kern; valid->face = face; - FT_TRACE3(( "validation kern table\n" )); + FT_TRACE3(( "validating `kern' table\n" )); GXV_INIT; KERN_DIALECT( valid ) = dialect_request; GXV_LIMIT_CHECK( 2 ); GXV_KERN_DATA( version ) = FT_NEXT_USHORT( p ); - GXV_TRACE(( "version 0x%04x (higher 16bit)\n", GXV_KERN_DATA( version ) )); + GXV_TRACE(( "version 0x%04x (higher 16bit)\n", + GXV_KERN_DATA( version ) )); if ( 0x0001 < GXV_KERN_DATA( version ) ) FT_INVALID_FORMAT; @@ -762,7 +790,6 @@ nTables = FT_NEXT_ULONG( p ); } - for ( i = 0; i < nTables; i++ ) { GXV_TRACE(( "validate subtable %d/%d\n", i, nTables )); @@ -790,7 +817,7 @@ FT_Int dialect_flags, FT_Validator ftvalid ) { - GXV_kern_Dialect dialect_request; + GXV_kern_Dialect dialect_request; dialect_request = dialect_flags; diff --git a/src/gxvalid/gxvlcar.c b/src/gxvalid/gxvlcar.c index 82a085f98..042457cc6 100644 --- a/src/gxvalid/gxvlcar.c +++ b/src/gxvalid/gxvlcar.c @@ -4,7 +4,7 @@ /* */ /* TrueTypeGX/AAT lcar table validation (body). */ /* */ -/* Copyright 2004 by suzuki toshiya, Masatake YAMATO, Red Hat K.K., */ +/* Copyright 2004, 2005 by suzuki toshiya, Masatake YAMATO, Red Hat K.K., */ /* David Turner, Robert Wilhelm, and Werner Lemberg. */ /* */ /* This file is part of the FreeType project, and may only be used, */ @@ -16,15 +16,18 @@ /***************************************************************************/ /***************************************************************************/ +/* */ /* gxvalid is derived from both gxlayout module and otvalid module. */ -/* Development of gxlayout was support of Information-technology Promotion */ -/* Agency(IPA), Japan. */ +/* Development of gxlayout is supported by the Information-technology */ +/* Promotion Agency(IPA), Japan. */ +/* */ /***************************************************************************/ #include "gxvalid.h" #include "gxvcommn.h" + /*************************************************************************/ /* */ /* The macro FT_COMPONENT is used in trace mode. It is an implicit */ @@ -35,7 +38,6 @@ #define FT_COMPONENT trace_gxvlcar - /*************************************************************************/ /*************************************************************************/ /***** *****/ @@ -50,7 +52,7 @@ } GXV_lcar_DataRec, *GXV_lcar_Data; -#define GXV_LCAR_DATA(FIELD) GXV_TABLE_DATA( lcar, FIELD ) +#define GXV_LCAR_DATA(FIELD) GXV_TABLE_DATA( lcar, FIELD ) /*************************************************************************/ @@ -83,16 +85,15 @@ GXV_LookupValueDesc value, GXV_Validator valid ) { - FT_Bytes p = valid->root->base + value.u; - FT_Bytes limit = valid->root->limit; - FT_UShort count; - FT_Short partial; - unsigned int i; + FT_Bytes p = valid->root->base + value.u; + FT_Bytes limit = valid->root->limit; + FT_UShort count; + FT_Short partial; + FT_UShort i; GXV_NAME_ENTER( "element in lookupTable" ); - GXV_LIMIT_CHECK( 2 ); count = FT_NEXT_USHORT( p ); @@ -106,6 +107,7 @@ GXV_EXIT; } + /* +------ lcar --------------------+ | | @@ -138,7 +140,8 @@ | | | - +----> lcar values...handled by lcar callback function */ + +----> lcar values...handled by lcar callback function + */ static GXV_LookupValueDesc gxv_lcar_LookupFmt4_transit( FT_UShort relative_gindex, @@ -151,8 +154,10 @@ FT_UShort offset; GXV_LookupValueDesc value; + FT_UNUSED( lookuptbl_limit ); - offset = base_value.u + ( relative_gindex * sizeof ( FT_UShort ) ); + + offset = base_value.u + relative_gindex * sizeof ( FT_UShort ); p = valid->root->base + offset; limit = valid->root->limit; @@ -191,20 +196,19 @@ valid->table_data = lcar; valid->face = face; - FT_TRACE3(( "validation lcar table\n" )); + FT_TRACE3(( "validating `lcar' table\n" )); GXV_INIT; GXV_LIMIT_CHECK( 4 + 2 ); version = FT_NEXT_ULONG( p ); GXV_LCAR_DATA( format ) = FT_NEXT_USHORT( p ); - if ( version != 0x00010000) + if ( version != 0x00010000UL) FT_INVALID_FORMAT; if ( GXV_LCAR_DATA( format ) > 1 ) FT_INVALID_FORMAT; - valid->lookupval_sign = GXV_LOOKUPVALUE_UNSIGNED; valid->lookupval_func = gxv_lcar_LookupValue_validate; valid->lookupfmt4_trans = gxv_lcar_LookupFmt4_transit; diff --git a/src/gxvalid/gxvmod.c b/src/gxvalid/gxvmod.c index 5c1132950..7bcfef4f8 100644 --- a/src/gxvalid/gxvmod.c +++ b/src/gxvalid/gxvmod.c @@ -16,9 +16,11 @@ /***************************************************************************/ /***************************************************************************/ +/* */ /* gxvalid is derived from both gxlayout module and otvalid module. */ -/* Development of gxlayout was support of Information-technology Promotion */ -/* Agency(IPA), Japan. */ +/* Development of gxlayout is supported by the Information-technology */ +/* Promotion Agency(IPA), Japan. */ +/* */ /***************************************************************************/ @@ -69,46 +71,50 @@ return error; } -#define GXV_TABLE_DECL( _sfnt ) \ - FT_Byte * _sfnt = NULL; \ - FT_ULong len_##_sfnt = 0 - -#define GXV_TABLE_LOAD( _sfnt ) \ - if ( ( FT_VALIDATE_##_sfnt##_INDEX < table_count ) && \ - ( gx_flags & FT_VALIDATE_##_sfnt ) ) \ - { \ - error = gxv_load_table( face, TTAG_##_sfnt, &_sfnt, &len_##_sfnt ); \ - if ( error ) \ - goto Exit; \ - } - -#define GXV_TABLE_VALIDATE( _sfnt ) \ - if ( _sfnt ) \ - { \ - ft_validator_init( &valid, _sfnt, _sfnt + len_##_sfnt, FT_VALIDATE_DEFAULT ); \ - if ( ft_validator_run( &valid ) == 0 ) \ - gxv_##_sfnt##_validate( _sfnt, face, &valid ); \ - error = valid.error; \ - if ( error ) \ - goto Exit; \ - } - -#define GXV_TABLE_SET( _sfnt ) \ - if ( FT_VALIDATE_##_sfnt##_INDEX < table_count ) \ - tables[FT_VALIDATE_##_sfnt##_INDEX] = (FT_Bytes)_sfnt + +#define GXV_TABLE_DECL( _sfnt ) \ + FT_Byte *_sfnt = NULL; \ + FT_ULong len_ ## _sfnt = 0 + +#define GXV_TABLE_LOAD( _sfnt ) \ + if ( ( FT_VALIDATE_ ## _sfnt ## _INDEX < table_count ) && \ + ( gx_flags & FT_VALIDATE_ ## _sfnt ) ) \ + { \ + error = gxv_load_table( face, TTAG_ ## _sfnt, \ + &_sfnt, &len_ ## _sfnt ); \ + if ( error ) \ + goto Exit; \ + } + +#define GXV_TABLE_VALIDATE( _sfnt ) \ + if ( _sfnt ) \ + { \ + ft_validator_init( &valid, _sfnt, _sfnt + len_ ## _sfnt, \ + FT_VALIDATE_DEFAULT ); \ + if ( ft_validator_run( &valid ) == 0 ) \ + gxv_ ## _sfnt ## _validate( _sfnt, face, &valid ); \ + error = valid.error; \ + if ( error ) \ + goto Exit; \ + } + +#define GXV_TABLE_SET( _sfnt ) \ + if ( FT_VALIDATE_ ## _sfnt ## _INDEX < table_count ) \ + tables[FT_VALIDATE_ ## _sfnt ## _INDEX] = (FT_Bytes)_sfnt + static FT_Error - gxv_validate( FT_Face face, - FT_UInt gx_flags, - FT_Bytes tables[FT_VALIDATE_GX_LENGTH], - FT_UInt table_count ) + gxv_validate( FT_Face face, + FT_UInt gx_flags, + FT_Bytes tables[FT_VALIDATE_GX_LENGTH], + FT_UInt table_count ) { FT_Memory memory = FT_FACE_MEMORY( face ); FT_Error error = GXV_Err_Ok; FT_ValidatorRec valid; - int i; + FT_UInt i; GXV_TABLE_DECL( feat ); @@ -122,7 +128,6 @@ GXV_TABLE_DECL( prop ); GXV_TABLE_DECL( lcar ); - for ( i = 0; i < table_count; i++ ) tables[i] = 0; @@ -138,7 +143,6 @@ GXV_TABLE_LOAD( prop ); GXV_TABLE_LOAD( lcar ); - /* validate tables */ GXV_TABLE_VALIDATE( feat ); GXV_TABLE_VALIDATE( bsln ); @@ -177,6 +181,7 @@ FT_FREE( prop ); FT_FREE( lcar ); } + return error; } @@ -203,7 +208,8 @@ if ( ckern ) { - ft_validator_init( &valid, ckern, ckern + len_ckern, FT_VALIDATE_DEFAULT ); + ft_validator_init( &valid, ckern, ckern + len_ckern, + FT_VALIDATE_DEFAULT ); if ( ft_validator_run( &valid ) == 0 ) gxv_kern_validate_classic( ckern, face, ckern_flags & FT_VALIDATE_CKERN, &valid ); @@ -221,6 +227,7 @@ return error; } + static const FT_Service_GXvalidateRec gxvalid_interface = { @@ -238,7 +245,7 @@ static const FT_ServiceDescRec gxvalid_services[] = { - { FT_SERVICE_ID_GX_VALIDATE, &gxvalid_interface }, + { FT_SERVICE_ID_GX_VALIDATE, &gxvalid_interface }, { FT_SERVICE_ID_CLASSICKERN_VALIDATE, &ckernvalid_interface }, { NULL, NULL } }; diff --git a/src/gxvalid/gxvmod.h b/src/gxvalid/gxvmod.h index 8e68f22e8..466584ef4 100644 --- a/src/gxvalid/gxvmod.h +++ b/src/gxvalid/gxvmod.h @@ -17,16 +17,17 @@ /***************************************************************************/ /***************************************************************************/ +/* */ /* gxvalid is derived from both gxlayout module and otvalid module. */ -/* Development of gxlayout was support of Information-technology Promotion */ -/* Agency(IPA), Japan. */ +/* Development of gxlayout is supported by the Information-technology */ +/* Promotion Agency(IPA), Japan. */ +/* */ /***************************************************************************/ #ifndef __GXVMOD_H__ #define __GXVMOD_H__ - #include #include FT_MODULE_H @@ -39,7 +40,7 @@ FT_BEGIN_HEADER FT_END_HEADER -#endif /* Not def: __GXVMOD_H__ */ +#endif /* __GXVMOD_H__ */ /* END */ diff --git a/src/gxvalid/gxvmort.c b/src/gxvalid/gxvmort.c index 0cffb388b..376ca916f 100644 --- a/src/gxvalid/gxvmort.c +++ b/src/gxvalid/gxvmort.c @@ -16,14 +16,17 @@ /***************************************************************************/ /***************************************************************************/ +/* */ /* gxvalid is derived from both gxlayout module and otvalid module. */ -/* Development of gxlayout was support of Information-technology Promotion */ -/* Agency(IPA), Japan. */ +/* Development of gxlayout is supported by the Information-technology */ +/* Promotion Agency(IPA), Japan. */ +/* */ /***************************************************************************/ #include "gxvmort.h" + /*************************************************************************/ /* */ /* The macro FT_COMPONENT is used in trace mode. It is an implicit */ @@ -42,7 +45,7 @@ { GXV_TRACE(( "featureType %d is out of registered range, " "setting %d is unchecked\n", - f->featureType, f->featureSetting )); + f->featureType, f->featureSetting )); if ( valid->root->level >= FT_VALIDATE_PARANOID ) FT_INVALID_DATA; } @@ -50,7 +53,7 @@ { GXV_TRACE(( "featureType %d is within registered area " "but undefined, setting %d is unchecked\n", - f->featureType, f->featureSetting )); + f->featureType, f->featureSetting )); if ( valid->root->level >= FT_VALIDATE_PARANOID ) FT_INVALID_DATA; } @@ -58,6 +61,7 @@ { FT_Byte nSettings_max; + /* nSettings in gxvfeat.c is halved for exclusive on/off settings */ if ( gxv_feat_registry[f->featureType].exclusive ) nSettings_max = 2 * gxv_feat_registry[f->featureType].nSettings; @@ -66,6 +70,7 @@ GXV_TRACE(( "featureType %d is registered", f->featureType )); GXV_TRACE(( "setting %d", f->featureSetting )); + if ( f->featureSetting > nSettings_max ) { GXV_TRACE(( "out of defined range %d", nSettings_max )); @@ -78,6 +83,7 @@ /* TODO: enableFlags must be unique value in specified chain? */ } + /* * nFeatureFlags is typed to FT_UInt to accept that in * mort (typed FT_UShort) and morx (typed FT_ULong). @@ -90,6 +96,7 @@ { FT_Bytes p = table; FT_UInt i; + GXV_mort_featureRec f = GXV_MORT_FEATURE_OFF; @@ -105,29 +112,33 @@ gxv_mort_feature_validate( &f, valid ); } - if ( !IS_GXV_MORT_FEATURE_OFF(f) ) + if ( !IS_GXV_MORT_FEATURE_OFF( f ) ) FT_INVALID_DATA; - valid->subtable_length = ( p - table ); + valid->subtable_length = p - table; GXV_EXIT; } + static void gxv_mort_coverage_validate( FT_UShort coverage, GXV_Validator valid ) { - if ( coverage & 0x8000 ) + if ( coverage & 0x8000U ) GXV_TRACE(( " this subtable is for vertical text only\n" )); else GXV_TRACE(( " this subtable is for horizontal text only\n" )); if ( coverage & 0x4000 ) - GXV_TRACE(( " this subtable is applied to glyph array in descending order\n" )); + GXV_TRACE(( " this subtable is applied to glyph array " + "in descending order\n" )); else - GXV_TRACE(( " this subtable is applied to glyph array in ascending order\n" )); + GXV_TRACE(( " this subtable is applied to glyph array " + "in ascending order\n" )); if ( coverage & 0x2000 ) - GXV_TRACE(( " this subtable is forcibly applied to vertical/horizontal text\n" )); + GXV_TRACE(( " this subtable is forcibly applied to " + "vertical/horizontal text\n" )); if ( coverage & 0x1FF8 ) GXV_TRACE(( " coverage has non-zero bits in reserved area\n" )); @@ -140,8 +151,9 @@ FT_UShort nSubtables, GXV_Validator valid ) { - FT_Bytes p = table; - GXV_Validate_Func fmt_funcs_table [] = + FT_Bytes p = table; + + GXV_Validate_Func fmt_funcs_table[] = { gxv_mort_subtable_type0_validate, /* 0 */ gxv_mort_subtable_type1_validate, /* 1 */ @@ -151,11 +163,12 @@ gxv_mort_subtable_type5_validate, /* 5 */ }; - GXV_Validate_Func func; - FT_UShort i; + GXV_Validate_Func func; + FT_UShort i; - GXV_NAME_ENTER(( "subtables in a chain" )); + + GXV_NAME_ENTER( "subtables in a chain" ); for ( i = 0; i < nSubtables; i++ ) { @@ -172,7 +185,7 @@ subFeatureFlags = FT_NEXT_ULONG( p ); GXV_TRACE(( "validate chain subtable %d/%d (%d bytes)\n", - i + 1, nSubtables, length )); + i + 1, nSubtables, length )); type = coverage & 0x0007; rest = length - ( 2 + 2 + 4 ); @@ -191,7 +204,8 @@ p += rest; } - valid->subtable_length = ( p - table ); + valid->subtable_length = p - table; + GXV_EXIT; } @@ -216,7 +230,8 @@ nFeatureFlags = FT_NEXT_USHORT( p ); nSubtables = FT_NEXT_USHORT( p ); - gxv_mort_featurearray_validate( p, table + chainLength, nFeatureFlags, valid ); + gxv_mort_featurearray_validate( p, table + chainLength, + nFeatureFlags, valid ); p += valid->subtable_length; gxv_mort_subtables_validate( p, table + chainLength, nSubtables, valid ); valid->subtable_length = chainLength; @@ -224,6 +239,7 @@ GXV_EXIT; } + FT_LOCAL_DEF( void ) gxv_mort_validate( FT_Bytes table, FT_Face face, @@ -249,7 +265,7 @@ version = FT_NEXT_ULONG( p ); nChains = FT_NEXT_ULONG( p ); - if (version != 0x00010000) + if (version != 0x00010000UL) FT_INVALID_FORMAT; for ( i = 0; i < nChains; i++ ) diff --git a/src/gxvalid/gxvmort.h b/src/gxvalid/gxvmort.h index 03daaf0d5..009162e6c 100644 --- a/src/gxvalid/gxvmort.h +++ b/src/gxvalid/gxvmort.h @@ -16,15 +16,17 @@ /***************************************************************************/ /***************************************************************************/ +/* */ /* gxvalid is derived from both gxlayout module and otvalid module. */ -/* Development of gxlayout was support of Information-technology Promotion */ -/* Agency(IPA), Japan. */ +/* Development of gxlayout is supported by the Information-technology */ +/* Promotion Agency(IPA), Japan. */ +/* */ /***************************************************************************/ + #ifndef __GXVMORT_H__ #define __GXVMORT_H__ - #include "gxvalid.h" #include "gxvcommn.h" @@ -33,21 +35,20 @@ typedef struct GXV_mort_featureRec_ { - FT_UShort featureType; - FT_UShort featureSetting; - FT_ULong enableFlags; - FT_ULong disableFlags; + FT_UShort featureType; + FT_UShort featureSetting; + FT_ULong enableFlags; + FT_ULong disableFlags; } GXV_mort_featureRec, *GXV_mort_feature; -#define GXV_MORT_FEATURE_OFF \ - {0, 1, 0x00000000UL, 0x00000000UL} +#define GXV_MORT_FEATURE_OFF {0, 1, 0x00000000UL, 0x00000000UL} -#define IS_GXV_MORT_FEATURE_OFF( f ) \ - ( (f).featureType == 0 || \ - (f).featureSetting == 1 || \ - (f).enableFlags == 0x00000000UL || \ - (f).disableFlags == 0x00000000UL ) +#define IS_GXV_MORT_FEATURE_OFF( f ) \ + ( (f).featureType == 0 || \ + (f).featureSetting == 1 || \ + (f).enableFlags == 0x00000000UL || \ + (f).disableFlags == 0x00000000UL ) FT_LOCAL( void ) @@ -90,7 +91,7 @@ GXV_Validator valid ); -#endif /* Not def: __GXVMORT_H__ */ +#endif /* __GXVMORT_H__ */ /* END */ diff --git a/src/gxvalid/gxvmort0.c b/src/gxvalid/gxvmort0.c index 4764ed00d..ddc37d29c 100644 --- a/src/gxvalid/gxvmort0.c +++ b/src/gxvalid/gxvmort0.c @@ -17,11 +17,14 @@ /***************************************************************************/ /***************************************************************************/ +/* */ /* gxvalid is derived from both gxlayout module and otvalid module. */ -/* Development of gxlayout was support of Information-technology Promotion */ -/* Agency(IPA), Japan. */ +/* Development of gxlayout is supported by the Information-technology */ +/* Promotion Agency(IPA), Japan. */ +/* */ /***************************************************************************/ + #include "gxvmort.h" @@ -35,7 +38,7 @@ #define FT_COMPONENT trace_gxvmort - static char* GXV_Mort_IndicScript_Msg [] = + static const char* GXV_Mort_IndicScript_Msg[] = { "no change", "Ax => xA", @@ -58,21 +61,26 @@ static void - gxv_mort_subtable_type0_entry_validate( FT_Byte state, - FT_UShort flags, - GXV_StateTable_GlyphOffsetDesc glyphOffset, - FT_Bytes table, - FT_Bytes limit, - GXV_Validator valid ) + gxv_mort_subtable_type0_entry_validate( + FT_Byte state, + FT_UShort flags, + GXV_StateTable_GlyphOffsetDesc glyphOffset, + FT_Bytes table, + FT_Bytes limit, + GXV_Validator valid ) { - FT_UShort markFirst; - FT_UShort dontAdvance; - FT_UShort markLast; - FT_UShort reserved; - FT_UShort verb; + FT_UShort markFirst; + FT_UShort dontAdvance; + FT_UShort markLast; + FT_UShort reserved; + FT_UShort verb; + FT_UNUSED( state ); + FT_UNUSED( table ); + FT_UNUSED( limit ); - markFirst = flags / 0x8000; + + markFirst = flags / 0x8000U; dontAdvance = ( flags & 0x4000 ) / 0x4000; markLast = ( flags & 0x2000 ) / 0x2000; reserved = flags & 0x1FF0; @@ -80,23 +88,24 @@ FT_UNUSED( GXV_Mort_IndicScript_Msg[verb] ); - GXV_TRACE(( " IndicScript MorphRule for glyphOffset 0x%04x", glyphOffset.u )); + GXV_TRACE(( " IndicScript MorphRule for glyphOffset 0x%04x", + glyphOffset.u )); GXV_TRACE(( " markFirst=%01d", markFirst )); GXV_TRACE(( " dontAdvance=%01d", dontAdvance )); GXV_TRACE(( " markLast=%01d", markLast )); GXV_TRACE(( " %02d", verb )); GXV_TRACE(( " %s\n", GXV_Mort_IndicScript_Msg[verb] )); + if ( 0 < reserved ) { GXV_TRACE(( " non-zero bits found in reserved range\n" )); FT_INVALID_DATA; } else - { GXV_TRACE(( "\n" )); - } } + static void gxv_mort_subtable_type0_validate( FT_Bytes table, FT_Bytes limit, @@ -105,7 +114,8 @@ FT_Bytes p = table; - GXV_NAME_ENTER( "mort chain subtable type0 (Indic-Script Rearrangement)" ); + GXV_NAME_ENTER( + "mort chain subtable type0 (Indic-Script Rearrangement)" ); GXV_LIMIT_CHECK( GXV_STATETABLE_HEADER_SIZE ); @@ -113,8 +123,11 @@ valid->statetable.optdata_load_func = NULL; valid->statetable.subtable_setup_func = NULL; valid->statetable.entry_glyphoffset_fmt = GXV_GLYPHOFFSET_NONE; - valid->statetable.entry_validate_func = gxv_mort_subtable_type0_entry_validate; + valid->statetable.entry_validate_func = + gxv_mort_subtable_type0_entry_validate; + gxv_StateTable_validate( p, limit, valid ); + GXV_EXIT; } diff --git a/src/gxvalid/gxvmort1.c b/src/gxvalid/gxvmort1.c index e06e98447..68e334c4e 100644 --- a/src/gxvalid/gxvmort1.c +++ b/src/gxvalid/gxvmort1.c @@ -17,13 +17,17 @@ /***************************************************************************/ /***************************************************************************/ +/* */ /* gxvalid is derived from both gxlayout module and otvalid module. */ -/* Development of gxlayout was support of Information-technology Promotion */ -/* Agency(IPA), Japan. */ +/* Development of gxlayout is supported by the Information-technology */ +/* Promotion Agency(IPA), Japan. */ +/* */ /***************************************************************************/ + #include "gxvmort.h" + /*************************************************************************/ /* */ /* The macro FT_COMPONENT is used in trace mode. It is an implicit */ @@ -42,7 +46,8 @@ } GXV_mort_subtable_type1_StateOptRec, *GXV_mort_subtable_type1_StateOptRecData; -#define GXV_MORT_SUBTABLE_TYPE1_HEADER_SIZE ( GXV_STATETABLE_HEADER_SIZE + 2 ) +#define GXV_MORT_SUBTABLE_TYPE1_HEADER_SIZE GXV_STATETABLE_HEADER_SIZE + 2 + static void gxv_mort_subtable_type1_substitutionTable_load( FT_Bytes table, @@ -50,7 +55,9 @@ GXV_Validator valid ) { FT_Bytes p = table; - GXV_mort_subtable_type1_StateOptRecData optdata = valid->statetable.optdata; + + GXV_mort_subtable_type1_StateOptRecData optdata = + valid->statetable.optdata; GXV_LIMIT_CHECK( 2 ); @@ -71,7 +78,9 @@ FT_UShort o[4]; FT_UShort *l[4]; FT_UShort buff[5]; - GXV_mort_subtable_type1_StateOptRecData optdata = valid->statetable.optdata; + + GXV_mort_subtable_type1_StateOptRecData optdata = + valid->statetable.optdata; o[0] = classTable; @@ -81,31 +90,36 @@ l[0] = classTable_length_p; l[1] = stateArray_length_p; l[2] = entryTable_length_p; - l[3] = &(optdata->substitutionTable_length); + l[3] = &( optdata->substitutionTable_length ); gxv_set_length_by_ushort_offset( o, l, buff, 4, table_size, valid ); } static void - gxv_mort_subtable_type1_offset_to_subst_validate( FT_Short wordOffset, - FT_String* tag, - FT_Byte state, - GXV_Validator valid ) + gxv_mort_subtable_type1_offset_to_subst_validate( + FT_Short wordOffset, + const FT_String* tag, + FT_Byte state, + GXV_Validator valid ) { FT_UShort substTable; FT_UShort substTable_limit; FT_UShort min_gid; FT_UShort max_gid; + FT_UNUSED( tag ); + FT_UNUSED( state ); + + substTable = ((GXV_mort_subtable_type1_StateOptRec *) (valid->statetable.optdata))->substitutionTable; substTable_limit = substTable + ((GXV_mort_subtable_type1_StateOptRec *) (valid->statetable.optdata))->substitutionTable_length; - min_gid = ( substTable - ( wordOffset * 2 ) ) / 2; - max_gid = ( substTable_limit - ( wordOffset * 2 ) ) / 2; + min_gid = ( substTable - wordOffset * 2 ) / 2; + max_gid = ( substTable_limit - wordOffset * 2 ) / 2; max_gid = FT_MAX( max_gid, valid->face->num_glyphs ); /* TODO: min_gid & max_gid comparison with ClassTable contents */ @@ -113,25 +127,29 @@ static void - gxv_mort_subtable_type1_entry_validate( FT_Byte state, - FT_UShort flags, - GXV_StateTable_GlyphOffsetDesc glyphOffset, - FT_Bytes table, - FT_Bytes limit, - GXV_Validator valid ) + gxv_mort_subtable_type1_entry_validate( + FT_Byte state, + FT_UShort flags, + GXV_StateTable_GlyphOffsetDesc glyphOffset, + FT_Bytes table, + FT_Bytes limit, + GXV_Validator valid ) { - FT_UShort setMark; - FT_UShort dontAdvance; - FT_UShort reserved; - FT_Short markOffset; - FT_Short currentOffset; + FT_UShort setMark; + FT_UShort dontAdvance; + FT_UShort reserved; + FT_Short markOffset; + FT_Short currentOffset; + + FT_UNUSED( table ); + FT_UNUSED( limit ); - setMark = flags / 0x8000; + setMark = flags / 0x8000U; dontAdvance = ( flags & 0x4000 ) / 0x4000; reserved = flags & 0x3FFF; - markOffset = GXV_USHORT_TO_SHORT( glyphOffset.ul / 0x00010000 ); - currentOffset = GXV_USHORT_TO_SHORT( glyphOffset.ul & 0x0000FFFF ); + markOffset = GXV_USHORT_TO_SHORT( glyphOffset.ul / 0x00010000UL ); + currentOffset = GXV_USHORT_TO_SHORT( glyphOffset.ul & 0x0000FFFFUL ); if ( 0 < reserved ) { @@ -151,19 +169,20 @@ valid ); } + static void gxv_mort_subtable_type1_substTable_validate( FT_Bytes table, FT_Bytes limit, GXV_Validator valid ) { FT_Bytes p = table; - FT_UShort num_gids = ((GXV_mort_subtable_type1_StateOptRec *) - (valid->statetable.optdata))->substitutionTable_length - / 2; + FT_UShort num_gids = + ((GXV_mort_subtable_type1_StateOptRec *) + (valid->statetable.optdata))->substitutionTable_length / 2; FT_UShort i; - GXV_NAME_ENTER(( "validate contents in substitionTable" )); + GXV_NAME_ENTER( "validate contents in substitionTable" ); for ( i = 0; i < num_gids ; i ++ ) { FT_UShort dst_gid; @@ -172,13 +191,14 @@ GXV_LIMIT_CHECK( 2 ); dst_gid = FT_NEXT_USHORT( p ); - if ( dst_gid >= 0xFFFF ) + if ( dst_gid >= 0xFFFFU ) continue; if ( dst_gid > valid->face->num_glyphs ) { - GXV_TRACE(( "substTable include too-large gid[%d]=%d > max defined gid #%d\n", - i, dst_gid, valid->face->num_glyphs )); + GXV_TRACE(( "substTable include toolarge gid[%d]=%d >" + " max defined gid #%d\n", + i, dst_gid, valid->face->num_glyphs )); if ( valid->root->level >= FT_VALIDATE_PARANOID ) FT_INVALID_GLYPH_ID; } @@ -187,10 +207,11 @@ GXV_EXIT; } + /* - * subtable for Contextual glyph substition is modified StateTable. - * In addition classTable, stateArray, entryTable, "substitutionTable" - * is added. + * subtable for Contextual glyph substition is a modified StateTable. + * In addition to classTable, stateArray, and entryTable, the field + * `substitutionTable' is added. */ static void gxv_mort_subtable_type1_validate( FT_Bytes table, @@ -198,6 +219,7 @@ GXV_Validator valid ) { FT_Bytes p = table; + GXV_mort_subtable_type1_StateOptRec st_rec; @@ -205,19 +227,23 @@ GXV_LIMIT_CHECK( GXV_MORT_SUBTABLE_TYPE1_HEADER_SIZE ); - valid->statetable.optdata = &st_rec; - valid->statetable.optdata_load_func = gxv_mort_subtable_type1_substitutionTable_load; - valid->statetable.subtable_setup_func = gxv_mort_subtable_type1_subtable_setup; - valid->statetable.entry_glyphoffset_fmt = GXV_GLYPHOFFSET_ULONG; - valid->statetable.entry_validate_func = gxv_mort_subtable_type1_entry_validate; + valid->statetable.optdata = + &st_rec; + valid->statetable.optdata_load_func = + gxv_mort_subtable_type1_substitutionTable_load; + valid->statetable.subtable_setup_func = + gxv_mort_subtable_type1_subtable_setup; + valid->statetable.entry_glyphoffset_fmt = + GXV_GLYPHOFFSET_ULONG; + valid->statetable.entry_validate_func = + + gxv_mort_subtable_type1_entry_validate; gxv_StateTable_validate( p, limit, valid ); - gxv_mort_subtable_type1_substTable_validate( table - + st_rec.substitutionTable, - table - + st_rec.substitutionTable - + st_rec.substitutionTable_length, - valid ); + gxv_mort_subtable_type1_substTable_validate( + table + st_rec.substitutionTable, + table + st_rec.substitutionTable + st_rec.substitutionTable_length, + valid ); GXV_EXIT; } diff --git a/src/gxvalid/gxvmort2.c b/src/gxvalid/gxvmort2.c index ba1892bf3..d63fd3ddb 100644 --- a/src/gxvalid/gxvmort2.c +++ b/src/gxvalid/gxvmort2.c @@ -17,13 +17,17 @@ /***************************************************************************/ /***************************************************************************/ +/* */ /* gxvalid is derived from both gxlayout module and otvalid module. */ -/* Development of gxlayout was support of Information-technology Promotion */ -/* Agency(IPA), Japan. */ +/* Development of gxlayout is supported by the Information-technology */ +/* Promotion Agency(IPA), Japan. */ +/* */ /***************************************************************************/ + #include "gxvmort.h" + /*************************************************************************/ /* */ /* The macro FT_COMPONENT is used in trace mode. It is an implicit */ @@ -46,7 +50,9 @@ } GXV_mort_subtable_type2_StateOptRec, *GXV_mort_subtable_type2_StateOptRecData; - #define GXV_MORT_SUBTABLE_TYPE2_HEADER_SIZE ( GXV_STATETABLE_HEADER_SIZE + 2 + 2 + 2 ) +#define GXV_MORT_SUBTABLE_TYPE2_HEADER_SIZE \ + GXV_STATETABLE_HEADER_SIZE + 2 + 2 + 2 + static void gxv_mort_subtable_type2_opttable_load( FT_Bytes table, @@ -54,7 +60,8 @@ GXV_Validator valid ) { FT_Bytes p = table; - GXV_mort_subtable_type2_StateOptRecData optdata = valid->statetable.optdata; + GXV_mort_subtable_type2_StateOptRecData optdata = + valid->statetable.optdata; GXV_LIMIT_CHECK( 2 + 2 + 2 ); @@ -62,11 +69,15 @@ optdata->componentTable = FT_NEXT_USHORT( p ); optdata->ligatureTable = FT_NEXT_USHORT( p ); - GXV_TRACE(( "offset to ligActionTable=0x%04x\n", optdata->ligActionTable )); - GXV_TRACE(( "offset to componentTable=0x%04x\n", optdata->componentTable )); - GXV_TRACE(( "offset to ligatureTable=0x%04x\n", optdata->ligatureTable )); + GXV_TRACE(( "offset to ligActionTable=0x%04x\n", + optdata->ligActionTable )); + GXV_TRACE(( "offset to componentTable=0x%04x\n", + optdata->componentTable )); + GXV_TRACE(( "offset to ligatureTable=0x%04x\n", + optdata->ligatureTable )); } + static void gxv_mort_subtable_type2_subtable_setup( FT_UShort table_size, FT_UShort classTable, @@ -80,7 +91,9 @@ FT_UShort o[6]; FT_UShort *l[6]; FT_UShort buff[7]; - GXV_mort_subtable_type2_StateOptRecData optdata = valid->statetable.optdata; + + GXV_mort_subtable_type2_StateOptRecData optdata = + valid->statetable.optdata; GXV_NAME_ENTER( "subtable boundaries setup" ); @@ -101,32 +114,35 @@ gxv_set_length_by_ushort_offset( o, l, buff, 6, table_size, valid ); GXV_TRACE(( "classTable: offset=0x%04x length=0x%04x\n", - classTable, *classTable_length_p)); + classTable, *classTable_length_p )); GXV_TRACE(( "stateArray: offset=0x%04x length=0x%04x\n", - stateArray, *stateArray_length_p)); + stateArray, *stateArray_length_p )); GXV_TRACE(( "entryTable: offset=0x%04x length=0x%04x\n", - entryTable, *entryTable_length_p)); + entryTable, *entryTable_length_p )); GXV_TRACE(( "ligActionTable: offset=0x%04x length=0x%04x\n", - optdata->ligActionTable, - optdata->ligActionTable_length)); + optdata->ligActionTable, + optdata->ligActionTable_length )); GXV_TRACE(( "componentTable: offset=0x%04x length=0x%04x\n", - optdata->componentTable, - optdata->componentTable_length)); + optdata->componentTable, + optdata->componentTable_length )); GXV_TRACE(( "ligatureTable: offset=0x%04x length=0x%04x\n", - optdata->ligatureTable, - optdata->ligatureTable_length)); + optdata->ligatureTable, + optdata->ligatureTable_length )); + GXV_EXIT; } - static void - gxv_mort_subtable_type2_ligActionOffset_validate( FT_Bytes table, - FT_UShort ligActionOffset, - GXV_Validator valid ) + gxv_mort_subtable_type2_ligActionOffset_validate( + FT_Bytes table, + FT_UShort ligActionOffset, + GXV_Validator valid ) { /* access ligActionTable */ - GXV_mort_subtable_type2_StateOptRecData optdata = valid->statetable.optdata; + GXV_mort_subtable_type2_StateOptRecData optdata = + valid->statetable.optdata; + FT_Bytes lat_base = table + optdata->ligActionTable; FT_Bytes p = table + ligActionOffset; FT_Bytes lat_limit = lat_base + optdata->ligActionTable; @@ -136,18 +152,18 @@ if ( p < lat_base ) { GXV_TRACE(( "too short offset 0x%04x: p < lat_base (%d byte rewind)\n", - ligActionOffset, lat_base - p )); + ligActionOffset, lat_base - p )); - /* FontValidator, ftxvalidator, ftxdumperfuser warns but continues */ + /* FontValidator, ftxvalidator, ftxdumperfuser warn but continue */ if ( valid->root->level >= FT_VALIDATE_PARANOID ) FT_INVALID_OFFSET; } else if ( lat_limit < p ) { GXV_TRACE(( "too large offset 0x%04x: lat_limit < p (%d byte overrun)\n", - ligActionOffset, p - lat_limit )); + ligActionOffset, p - lat_limit )); - /* FontValidator, ftxvalidator, ftxdumperfuser warns but continues */ + /* FontValidator, ftxvalidator, ftxdumperfuser warn but continue */ if ( valid->root->level >= FT_VALIDATE_PARANOID ) FT_INVALID_OFFSET; } @@ -161,42 +177,53 @@ lig_action = FT_NEXT_ULONG( p ); - last = (lig_action & 0x80000000) / 0x80000000; - store = (lig_action & 0x40000000) / 0x40000000; - offset = lig_action & 0x3FFFFFFF; + last = (lig_action & 0x80000000UL) / 0x80000000UL; + store = (lig_action & 0x40000000UL) / 0x40000000UL; + offset = lig_action & 0x3FFFFFFFUL; } } + static void - gxv_mort_subtable_type2_entry_validate( FT_Byte state, - FT_UShort flags, - GXV_StateTable_GlyphOffsetDesc glyphOffset, - FT_Bytes table, - FT_Bytes limit, - GXV_Validator valid ) + gxv_mort_subtable_type2_entry_validate( + FT_Byte state, + FT_UShort flags, + GXV_StateTable_GlyphOffsetDesc glyphOffset, + FT_Bytes table, + FT_Bytes limit, + GXV_Validator valid ) { FT_UShort setComponent; FT_UShort dontAdvance; FT_UShort offset; + FT_UNUSED( state ); + FT_UNUSED( glyphOffset ); + FT_UNUSED( limit ); + - setComponent = ( flags & 0x8000 ) / 0x8000; - dontAdvance = ( flags & 0x4000 ) / 0x4000; + setComponent = ( flags & 0x8000U ) / 0x8000U; + dontAdvance = ( flags & 0x4000 ) / 0x4000; offset = flags & 0x3FFF; if ( 0 < offset ) - gxv_mort_subtable_type2_ligActionOffset_validate( table, offset, valid ); + gxv_mort_subtable_type2_ligActionOffset_validate( table, offset, + valid ); } + static void gxv_mort_subtable_type2_ligatureTable_validate( FT_Bytes table, GXV_Validator valid ) { - GXV_mort_subtable_type2_StateOptRecData optdata = valid->statetable.optdata; + GXV_mort_subtable_type2_StateOptRecData optdata = + valid->statetable.optdata; + FT_Bytes p = table + optdata->ligatureTable; FT_Bytes limit = table + optdata->ligatureTable + optdata->ligatureTable_length; + GXV_NAME_ENTER( "mort chain subtable type2 - substitutionTable" ); if ( 0 != optdata->ligatureTable ) { @@ -213,12 +240,14 @@ GXV_EXIT; } + static void gxv_mort_subtable_type2_validate( FT_Bytes table, FT_Bytes limit, GXV_Validator valid ) { FT_Bytes p = table; + GXV_mort_subtable_type2_StateOptRec lig_rec; @@ -226,16 +255,24 @@ GXV_LIMIT_CHECK( GXV_MORT_SUBTABLE_TYPE2_HEADER_SIZE ); - valid->statetable.optdata = &lig_rec; - valid->statetable.optdata_load_func = gxv_mort_subtable_type2_opttable_load; - valid->statetable.subtable_setup_func = gxv_mort_subtable_type2_subtable_setup; - valid->statetable.entry_glyphoffset_fmt = GXV_GLYPHOFFSET_NONE; - valid->statetable.entry_validate_func = gxv_mort_subtable_type2_entry_validate; + valid->statetable.optdata = + &lig_rec; + valid->statetable.optdata_load_func = + gxv_mort_subtable_type2_opttable_load; + valid->statetable.subtable_setup_func = + gxv_mort_subtable_type2_subtable_setup; + valid->statetable.entry_glyphoffset_fmt = + GXV_GLYPHOFFSET_NONE; + valid->statetable.entry_validate_func = + gxv_mort_subtable_type2_entry_validate; + gxv_StateTable_validate( p, limit, valid ); + p += valid->subtable_length; gxv_mort_subtable_type2_ligatureTable_validate( table, valid ); - valid->subtable_length = ( p - table ); + valid->subtable_length = p - table; + GXV_EXIT; } diff --git a/src/gxvalid/gxvmort4.c b/src/gxvalid/gxvmort4.c index fbd6db818..b6f1f02a8 100644 --- a/src/gxvalid/gxvmort4.c +++ b/src/gxvalid/gxvmort4.c @@ -17,13 +17,17 @@ /***************************************************************************/ /***************************************************************************/ +/* */ /* gxvalid is derived from both gxlayout module and otvalid module. */ -/* Development of gxlayout was support of Information-technology Promotion */ -/* Agency(IPA), Japan. */ +/* Development of gxlayout is supported by the Information-technology */ +/* Promotion Agency(IPA), Japan. */ +/* */ /***************************************************************************/ + #include "gxvmort.h" + /*************************************************************************/ /* */ /* The macro FT_COMPONENT is used in trace mode. It is an implicit */ @@ -39,6 +43,8 @@ GXV_LookupValueDesc value, GXV_Validator valid ) { + FT_UNUSED( glyph ); + gxv_glyphid_validate( value.u, valid ); } @@ -68,11 +74,13 @@ | value | <-------+ .... */ + static GXV_LookupValueDesc - gxv_mort_subtable_type4_lookupfmt4_transit( FT_UShort relative_gindex, - GXV_LookupValueDesc base_value, - FT_Bytes lookuptbl_limit, - GXV_Validator valid ) + gxv_mort_subtable_type4_lookupfmt4_transit( + FT_UShort relative_gindex, + GXV_LookupValueDesc base_value, + FT_Bytes lookuptbl_limit, + GXV_Validator valid ) { FT_Bytes p; FT_Bytes limit; @@ -80,7 +88,7 @@ GXV_LookupValueDesc value; - offset = base_value.u + ( relative_gindex * sizeof ( FT_UShort ) ); + offset = base_value.u + relative_gindex * sizeof ( FT_UShort ); p = valid->lookuptbl_head + offset; limit = lookuptbl_limit; @@ -91,6 +99,7 @@ return value; } + static void gxv_mort_subtable_type4_validate( FT_Bytes table, FT_Bytes limit, @@ -99,11 +108,13 @@ FT_Bytes p = table; - GXV_NAME_ENTER( "mort chain subtable type4 (Non-Contextual Glyph Substitution)" ); + GXV_NAME_ENTER( "mort chain subtable type4 " + "(Non-Contextual Glyph Substitution)" ); valid->lookupval_sign = GXV_LOOKUPVALUE_UNSIGNED; valid->lookupval_func = gxv_mort_subtable_type4_lookupval_validate; valid->lookupfmt4_trans = gxv_mort_subtable_type4_lookupfmt4_transit; + gxv_LookupTable_validate( p, limit, valid ); GXV_EXIT; diff --git a/src/gxvalid/gxvmort5.c b/src/gxvalid/gxvmort5.c index e2848bf3e..70529b86f 100644 --- a/src/gxvalid/gxvmort5.c +++ b/src/gxvalid/gxvmort5.c @@ -17,13 +17,17 @@ /***************************************************************************/ /***************************************************************************/ +/* */ /* gxvalid is derived from both gxlayout module and otvalid module. */ -/* Development of gxlayout was support of Information-technology Promotion */ -/* Agency(IPA), Japan. */ +/* Development of gxlayout is supported by the Information-technology */ +/* Promotion Agency(IPA), Japan. */ +/* */ /***************************************************************************/ + #include "gxvmort.h" + /*************************************************************************/ /* */ /* The macro FT_COMPONENT is used in trace mode. It is an implicit */ @@ -34,23 +38,26 @@ #define FT_COMPONENT trace_gxvmort -/* - * mort subtable type5 (Contextual Glyph Insertion) - * has format of StateTable with insertion-glyph-list - * without name. the offset is given by glyphOffset in - * entryTable. there's no table location declaration - * like xxxTable. - */ + /* + * mort subtable type5 (Contextual Glyph Insertion) + * has the format of StateTable with insertion-glyph-list, + * but without name. The offset is given by glyphOffset in + * entryTable. There is no table location declaration + * like xxxTable. + */ typedef struct GXV_mort_subtable_type5_StateOptRec_ { FT_UShort classTable; FT_UShort stateArray; FT_UShort entryTable; -#define GXV_MORT_SUBTABLE_TYPE5_HEADER_SIZE GXV_STATETABLE_HEADER_SIZE + +#define GXV_MORT_SUBTABLE_TYPE5_HEADER_SIZE GXV_STATETABLE_HEADER_SIZE + FT_UShort* classTable_length_p; FT_UShort* stateArray_length_p; FT_UShort* entryTable_length_p; + } GXV_mort_subtable_type5_StateOptRec, *GXV_mort_subtable_type5_StateOptRecData; @@ -65,7 +72,10 @@ FT_UShort* entryTable_length_p, GXV_Validator valid ) { - GXV_mort_subtable_type5_StateOptRecData optdata = valid->statetable.optdata; + GXV_mort_subtable_type5_StateOptRecData optdata = + valid->statetable.optdata; + + gxv_StateTable_subtable_setup( table_size, classTable, stateArray, @@ -78,13 +88,13 @@ optdata->classTable = classTable; optdata->stateArray = stateArray; optdata->entryTable = entryTable; + optdata->classTable_length_p = classTable_length_p; optdata->stateArray_length_p = stateArray_length_p; optdata->entryTable_length_p = entryTable_length_p; } - static void gxv_mort_subtable_type5_InsertList_validate( FT_UShort offset, FT_UShort count, @@ -93,19 +103,21 @@ GXV_Validator valid ) { /* - * we don't know the range of insertion-glyph-list. - * set range by whole of state table + * We don't know the range of insertion-glyph-list. + * Set range by whole of state table. */ FT_Bytes p = table + offset; - GXV_mort_subtable_type5_StateOptRecData optdata = valid->statetable.optdata; - if ( optdata->classTable < offset && + GXV_mort_subtable_type5_StateOptRecData optdata = + valid->statetable.optdata; + + if ( optdata->classTable < offset && offset < optdata->classTable + *(optdata->classTable_length_p) ) GXV_TRACE(( " offset runs into ClassTable" )); - if ( optdata->stateArray < offset && + if ( optdata->stateArray < offset && offset < optdata->stateArray + *(optdata->stateArray_length_p) ) GXV_TRACE(( " offset runs into StateArray" )); - if ( optdata->entryTable < offset && + if ( optdata->entryTable < offset && offset < optdata->entryTable + *(optdata->entryTable_length_p) ) GXV_TRACE(( " offset runs into EntryTable" )); @@ -113,6 +125,7 @@ { FT_UShort insert_glyphID; + GXV_LIMIT_CHECK( 2 ); insert_glyphID = FT_NEXT_USHORT( p ); GXV_TRACE(( " 0x%04x", insert_glyphID )); @@ -123,12 +136,13 @@ static void - gxv_mort_subtable_type5_entry_validate( FT_Byte state, - FT_UShort flags, - GXV_StateTable_GlyphOffsetDesc glyphOffset, - FT_Bytes table, - FT_Bytes limit, - GXV_Validator valid ) + gxv_mort_subtable_type5_entry_validate( + FT_Byte state, + FT_UShort flags, + GXV_StateTable_GlyphOffsetDesc glyphOffset, + FT_Bytes table, + FT_Bytes limit, + GXV_Validator valid ) { FT_Bool setMark; FT_Bool dontAdvance; @@ -141,6 +155,8 @@ FT_UShort currentInsertList; FT_UShort markedInsertList; + FT_UNUSED( state ); + setMark = ( flags >> 15 ) & 1; dontAdvance = ( flags >> 14 ) & 1; @@ -150,8 +166,8 @@ markedInsertBefore = ( flags >> 10 ) & 1; currentInsertCount = ( flags & 0x03E0 ) / 0x0020; markedInsertCount = ( flags & 0x001F ); - currentInsertList = glyphOffset.ul / 0x00010000; - markedInsertList = glyphOffset.ul & 0x0000FFFF; + currentInsertList = glyphOffset.ul / 0x00010000UL; + markedInsertList = glyphOffset.ul & 0x0000FFFFUL; if ( 0 != currentInsertList && 0 != currentInsertCount ) { @@ -179,6 +195,7 @@ GXV_Validator valid ) { FT_Bytes p = table; + GXV_mort_subtable_type5_StateOptRec et_rec; GXV_mort_subtable_type5_StateOptRecData et = &et_rec; @@ -187,12 +204,19 @@ GXV_LIMIT_CHECK( GXV_MORT_SUBTABLE_TYPE5_HEADER_SIZE ); - valid->statetable.optdata = et; - valid->statetable.optdata_load_func = NULL; - valid->statetable.subtable_setup_func = gxv_mort_subtable_type5_subtable_setup; - valid->statetable.entry_glyphoffset_fmt = GXV_GLYPHOFFSET_ULONG; - valid->statetable.entry_validate_func = gxv_mort_subtable_type5_entry_validate; + valid->statetable.optdata = + et; + valid->statetable.optdata_load_func = + NULL; + valid->statetable.subtable_setup_func = + gxv_mort_subtable_type5_subtable_setup; + valid->statetable.entry_glyphoffset_fmt = + GXV_GLYPHOFFSET_ULONG; + valid->statetable.entry_validate_func = + gxv_mort_subtable_type5_entry_validate; + gxv_StateTable_validate( p, limit, valid ); + GXV_EXIT; } -- cgit v1.2.1