1 /***************************************************************************/
5 /* TrueTypeGX/AAT common tables validation (specification). */
7 /* Copyright 2004, 2005 by suzuki toshiya, Masatake YAMATO, Red Hat K.K., */
8 /* David Turner, Robert Wilhelm, and Werner Lemberg. */
10 /* This file is part of the FreeType project, and may only be used, */
11 /* modified, and distributed under the terms of the FreeType project */
12 /* license, LICENSE.TXT. By continuing to use, modify, or distribute */
13 /* this file you indicate that you have read the license and */
14 /* understand and accept it fully. */
16 /***************************************************************************/
18 /***************************************************************************/
20 /* gxvalid is derived from both gxlayout module and otvalid module. */
21 /* Development of gxlayout is supported by the Information-technology */
22 /* Promotion Agency(IPA), Japan. */
24 /***************************************************************************/
28 * keywords in variable naming
29 * ---------------------------
30 * table: Of type FT_Bytes, pointing to the start of this table/subtable.
31 * limit: Of type FT_Bytes, pointing to the end of this table/subtable,
32 * including padding for alignment.
33 * offset: Of type FT_UInt, the number of octets from the start to target.
34 * length: Of type FT_UInt, the number of octets from the start to the
35 * end in this table/subtable, including padding for alignment.
37 * _MIN, _MAX: Should be added to the tail of macros, as INT_MIN, etc.
41 #ifndef __GXVCOMMN_H__
42 #define __GXVCOMMN_H__
47 #include FT_INTERNAL_DEBUG_H
48 #include FT_SFNT_NAMES_H
54 /*************************************************************************/
55 /*************************************************************************/
57 /***** VALIDATION *****/
59 /*************************************************************************/
60 /*************************************************************************/
62 typedef struct GXV_ValidatorRec_
* GXV_Validator
;
68 (*GXV_Validate_Func
)( FT_Bytes table
,
70 GXV_Validator valid
);
73 /* ====================== LookupTable Validator ======================== */
75 typedef union GXV_LookupValueDesc_
80 } GXV_LookupValueDesc
;
82 typedef const GXV_LookupValueDesc
* GXV_LookupValueCPtr
;
84 typedef enum GXV_LookupValue_SignSpec_
86 GXV_LOOKUPVALUE_UNSIGNED
= 0,
87 GXV_LOOKUPVALUE_SIGNED
89 } GXV_LookupValue_SignSpec
;
93 (*GXV_Lookup_Value_Validate_Func
)( FT_UShort glyph
,
94 GXV_LookupValueCPtr value_p
,
95 GXV_Validator valid
);
97 typedef GXV_LookupValueDesc
98 (*GXV_Lookup_Fmt4_Transit_Func
)( FT_UShort relative_gindex
,
99 GXV_LookupValueCPtr base_value_p
,
100 FT_Bytes lookuptbl_limit
,
101 GXV_Validator valid
);
104 /* ====================== StateTable Validator ========================= */
106 typedef enum GXV_GlyphOffset_Format_
108 GXV_GLYPHOFFSET_NONE
= -1,
109 GXV_GLYPHOFFSET_UCHAR
= 2,
110 GXV_GLYPHOFFSET_CHAR
,
111 GXV_GLYPHOFFSET_USHORT
= 4,
112 GXV_GLYPHOFFSET_SHORT
,
113 GXV_GLYPHOFFSET_ULONG
= 8,
116 } GXV_GlyphOffset_Format
;
119 #define GXV_GLYPHOFFSET_FMT( table ) \
120 ( valid->table.entry_glyphoffset_fmt )
122 #define GXV_GLYPHOFFSET_SIZE( table ) \
123 ( valid->table.entry_glyphoffset_fmt / 2 )
126 /* ----------------------- 16bit StateTable ---------------------------- */
128 typedef union GXV_StateTable_GlyphOffsetDesc_
131 FT_UShort u
; /* same as GXV_LookupValueDesc */
134 FT_Short s
; /* same as GXV_LookupValueDesc */
137 } GXV_StateTable_GlyphOffsetDesc
;
139 typedef const GXV_StateTable_GlyphOffsetDesc
* GXV_StateTable_GlyphOffsetCPtr
;
142 (*GXV_StateTable_Subtable_Setup_Func
)( FT_UShort table_size
,
143 FT_UShort classTable
,
144 FT_UShort stateArray
,
145 FT_UShort entryTable
,
146 FT_UShort
* classTable_length_p
,
147 FT_UShort
* stateArray_length_p
,
148 FT_UShort
* entryTable_length_p
,
149 GXV_Validator valid
);
152 (*GXV_StateTable_Entry_Validate_Func
)(
155 GXV_StateTable_GlyphOffsetCPtr glyphOffset_p
,
156 FT_Bytes statetable_table
,
157 FT_Bytes statetable_limit
,
158 GXV_Validator valid
);
161 (*GXV_StateTable_OptData_Load_Func
)( FT_Bytes table
,
163 GXV_Validator valid
);
165 typedef struct GXV_StateTable_ValidatorRec_
167 GXV_GlyphOffset_Format entry_glyphoffset_fmt
;
170 GXV_StateTable_Subtable_Setup_Func subtable_setup_func
;
171 GXV_StateTable_Entry_Validate_Func entry_validate_func
;
172 GXV_StateTable_OptData_Load_Func optdata_load_func
;
174 } GXV_StateTable_ValidatorRec
, *GXV_StateTable_ValidatorRecData
;
177 /* ---------------------- 32bit XStateTable ---------------------------- */
179 typedef GXV_StateTable_GlyphOffsetDesc GXV_XStateTable_GlyphOffsetDesc
;
181 typedef const GXV_XStateTable_GlyphOffsetDesc
* GXV_XStateTable_GlyphOffsetCPtr
;
184 (*GXV_XStateTable_Subtable_Setup_Func
)( FT_ULong table_size
,
188 FT_ULong
* classTable_length_p
,
189 FT_ULong
* stateArray_length_p
,
190 FT_ULong
* entryTable_length_p
,
191 GXV_Validator valid
);
194 (*GXV_XStateTable_Entry_Validate_Func
)(
197 GXV_StateTable_GlyphOffsetCPtr glyphOffset_p
,
198 FT_Bytes xstatetable_table
,
199 FT_Bytes xstatetable_limit
,
200 GXV_Validator valid
);
203 typedef GXV_StateTable_OptData_Load_Func GXV_XStateTable_OptData_Load_Func
;
206 typedef struct GXV_XStateTable_ValidatorRec_
208 int entry_glyphoffset_fmt
;
211 GXV_XStateTable_Subtable_Setup_Func subtable_setup_func
;
212 GXV_XStateTable_Entry_Validate_Func entry_validate_func
;
213 GXV_XStateTable_OptData_Load_Func optdata_load_func
;
216 FT_UShort maxClassID
;
218 } GXV_XStateTable_ValidatorRec
, *GXV_XStateTable_ValidatorRecData
;
221 /* ===================================================================== */
223 typedef struct GXV_ValidatorRec_
230 FT_ULong subtable_length
;
232 GXV_LookupValue_SignSpec lookupval_sign
;
233 GXV_Lookup_Value_Validate_Func lookupval_func
;
234 GXV_Lookup_Fmt4_Transit_Func lookupfmt4_trans
;
235 FT_Bytes lookuptbl_head
;
237 GXV_StateTable_ValidatorRec statetable
;
238 GXV_XStateTable_ValidatorRec xstatetable
;
240 #ifdef FT_DEBUG_LEVEL_TRACE
241 FT_UInt debug_indent
;
242 const FT_String
* debug_function_name
[3];
248 #define GXV_TABLE_DATA( tag, field ) \
249 ( ( (GXV_ ## tag ## _Data)valid->table_data )->field )
252 #define FT_INVALID_( _prefix, _error ) \
253 ft_validator_error( valid->root, _prefix ## _error )
255 #define GXV_LIMIT_CHECK( _count ) \
257 if ( p + _count > ( limit? limit : valid->root->limit ) ) \
258 FT_INVALID_TOO_SHORT; \
262 #ifdef FT_DEBUG_LEVEL_TRACE
264 #define GXV_INIT valid->debug_indent = 0
266 #define GXV_NAME_ENTER( name ) \
268 valid->debug_indent += 2; \
269 FT_TRACE4(( "%*.s", valid->debug_indent, 0 )); \
270 FT_TRACE4(( "%s table\n", name )); \
273 #define GXV_EXIT valid->debug_indent -= 2
275 #define GXV_TRACE( s ) \
277 FT_TRACE4(( "%*.s", valid->debug_indent, 0 )); \
281 #else /* !FT_DEBUG_LEVEL_TRACE */
283 #define GXV_INIT do { } while ( 0 )
284 #define GXV_NAME_ENTER( name ) do { } while ( 0 )
285 #define GXV_EXIT do { } while ( 0 )
287 #define GXV_TRACE( s ) do { } while ( 0 )
289 #endif /* !FT_DEBUG_LEVEL_TRACE */
292 /*************************************************************************/
293 /*************************************************************************/
295 /***** 32bit alignment checking *****/
297 /*************************************************************************/
298 /*************************************************************************/
300 #define GXV_32BIT_ALIGNMENT_VALIDATE( a ) \
303 if ( 0 != ( (a) % 4 ) ) \
304 FT_INVALID_OFFSET ; \
309 /*************************************************************************/
310 /*************************************************************************/
312 /***** Dumping Binary Data *****/
314 /*************************************************************************/
315 /*************************************************************************/
317 #define GXV_TRACE_HEXDUMP( p, len ) \
323 for ( b = p; b < (FT_Bytes)p + len; b++ ) \
324 FT_TRACE1(("\\x%02x", *b)) ; \
328 #define GXV_TRACE_HEXDUMP_C( p, len ) \
334 for ( b = p; b < (FT_Bytes)p + len; b++ ) \
335 if ( 0x40 < *b && *b < 0x7e ) \
336 FT_TRACE1(("%c", *b)) ; \
338 FT_TRACE1(("\\x%02x", *b)) ; \
342 #define GXV_TRACE_HEXDUMP_SFNTNAME( n ) \
343 GXV_TRACE_HEXDUMP( n.string, n.string_len )
346 /*************************************************************************/
347 /*************************************************************************/
349 /***** LOOKUP TABLE *****/
351 /*************************************************************************/
352 /*************************************************************************/
355 gxv_BinSrchHeader_validate( FT_Bytes p
,
357 FT_UShort
* unitSize_p
,
359 GXV_Validator valid
);
362 gxv_LookupTable_validate( FT_Bytes table
,
364 GXV_Validator valid
);
367 /*************************************************************************/
368 /*************************************************************************/
370 /***** Glyph ID *****/
372 /*************************************************************************/
373 /*************************************************************************/
376 gxv_glyphid_validate( FT_UShort gid
,
377 GXV_Validator valid
);
380 /*************************************************************************/
381 /*************************************************************************/
383 /***** CONTROL POINT *****/
385 /*************************************************************************/
386 /*************************************************************************/
389 gxv_ctlPoint_validate( FT_UShort gid
,
391 GXV_Validator valid
);
394 /*************************************************************************/
395 /*************************************************************************/
397 /***** SFNT NAME *****/
399 /*************************************************************************/
400 /*************************************************************************/
403 gxv_sfntName_validate( FT_UShort name_index
,
406 GXV_Validator valid
);
409 /*************************************************************************/
410 /*************************************************************************/
412 /***** STATE TABLE *****/
414 /*************************************************************************/
415 /*************************************************************************/
418 gxv_StateTable_subtable_setup( FT_UShort table_size
,
419 FT_UShort classTable
,
420 FT_UShort stateArray
,
421 FT_UShort entryTable
,
422 FT_UShort
* classTable_length_p
,
423 FT_UShort
* stateArray_length_p
,
424 FT_UShort
* entryTable_length_p
,
425 GXV_Validator valid
);
428 gxv_XStateTable_subtable_setup( FT_ULong table_size
,
432 FT_ULong
* classTable_length_p
,
433 FT_ULong
* stateArray_length_p
,
434 FT_ULong
* entryTable_length_p
,
435 GXV_Validator valid
);
438 gxv_StateTable_validate( FT_Bytes table
,
440 GXV_Validator valid
);
443 gxv_XStateTable_validate( FT_Bytes table
,
445 GXV_Validator valid
);
448 /*************************************************************************/
449 /*************************************************************************/
451 /***** UTILITY MACROS AND FUNCTIONS *****/
453 /*************************************************************************/
454 /*************************************************************************/
457 gxv_array_getlimits_byte( FT_Bytes table
,
461 GXV_Validator valid
);
464 gxv_array_getlimits_ushort( FT_Bytes table
,
468 GXV_Validator valid
);
471 gxv_set_length_by_ushort_offset( FT_UShort
* offset
,
476 GXV_Validator valid
);
479 gxv_set_length_by_ulong_offset( FT_ULong
* offset
,
484 GXV_Validator valid
);
487 #define GXV_SUBTABLE_OFFSET_CHECK( _offset ) \
489 if ( (_offset) > valid->subtable_length ) \
493 #define GXV_SUBTABLE_LIMIT_CHECK( _count ) \
495 if ( ( p + (_count) - valid->subtable_start ) > \
496 valid->subtable_length ) \
497 FT_INVALID_TOO_SHORT; \
500 #define GXV_USHORT_TO_SHORT( _us ) \
501 ( ( 0x8000U < ( _us ) ) ? ( ( _us ) - 0x8000U ) : ( _us ) )
503 #define GXV_STATETABLE_HEADER_SIZE ( 2 + 2 + 2 + 2 )
504 #define GXV_STATEHEADER_SIZE GXV_STATETABLE_HEADER_SIZE
506 #define GXV_XSTATETABLE_HEADER_SIZE ( 4 + 4 + 4 + 4 )
507 #define GXV_XSTATEHEADER_SIZE GXV_XSTATETABLE_HEADER_SIZE
510 /*************************************************************************/
511 /*************************************************************************/
513 /***** Table overlapping *****/
515 /*************************************************************************/
516 /*************************************************************************/
518 typedef struct GXV_odtect_DataRec_
524 } GXV_odtect_DataRec
, *GXV_odtect_Data
;
526 typedef struct GXV_odtect_RangeRec_
529 GXV_odtect_Data range
;
531 } GXV_odtect_RangeRec
, *GXV_odtect_Range
;
535 gxv_odtect_add_range( FT_Bytes start
,
537 const FT_String
* name
,
538 GXV_odtect_Range odtect
);
541 gxv_odtect_validate( GXV_odtect_Range odtect
,
542 GXV_Validator valid
);
545 #define GXV_ODTECT( n, odtect ) \
546 GXV_odtect_DataRec odtect ## _range[n]; \
547 GXV_odtect_RangeRec odtect ## _rec = { 0, NULL }; \
548 GXV_odtect_Range odtect = NULL
550 #define GXV_ODTECT_INIT( odtect ) \
552 odtect ## _rec.nRanges = 0; \
553 odtect ## _rec.range = odtect ## _range; \
554 odtect = & odtect ## _rec; \
562 #endif /* __GXVCOMMN_H__ */