mgh: fix for default HDD DMA mode, that wasn't correctly set
[open-ps2-loader.git] / thirdparty / freetype-2.3.12 / src / gxvalid / gxvcommn.h
blob404c07ffad9ce285fddb1641f26330b654198573
1 /***************************************************************************/
2 /* */
3 /* gxvcommn.h */
4 /* */
5 /* TrueTypeGX/AAT common tables validation (specification). */
6 /* */
7 /* Copyright 2004, 2005 by suzuki toshiya, Masatake YAMATO, Red Hat K.K., */
8 /* David Turner, Robert Wilhelm, and Werner Lemberg. */
9 /* */
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. */
15 /* */
16 /***************************************************************************/
18 /***************************************************************************/
19 /* */
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. */
23 /* */
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__
45 #include <ft2build.h>
46 #include "gxvalid.h"
47 #include FT_INTERNAL_DEBUG_H
48 #include FT_SFNT_NAMES_H
51 FT_BEGIN_HEADER
54 /*************************************************************************/
55 /*************************************************************************/
56 /***** *****/
57 /***** VALIDATION *****/
58 /***** *****/
59 /*************************************************************************/
60 /*************************************************************************/
62 typedef struct GXV_ValidatorRec_* GXV_Validator;
65 #define DUMMY_LIMIT 0
67 typedef void
68 (*GXV_Validate_Func)( FT_Bytes table,
69 FT_Bytes limit,
70 GXV_Validator valid );
73 /* ====================== LookupTable Validator ======================== */
75 typedef union GXV_LookupValueDesc_
77 FT_UShort u;
78 FT_Short s;
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;
92 typedef void
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,
114 GXV_GLYPHOFFSET_LONG
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_
130 FT_Byte uc;
131 FT_UShort u; /* same as GXV_LookupValueDesc */
132 FT_ULong ul;
133 FT_Char c;
134 FT_Short s; /* same as GXV_LookupValueDesc */
135 FT_Long l;
137 } GXV_StateTable_GlyphOffsetDesc;
139 typedef const GXV_StateTable_GlyphOffsetDesc* GXV_StateTable_GlyphOffsetCPtr;
141 typedef void
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 );
151 typedef void
152 (*GXV_StateTable_Entry_Validate_Func)(
153 FT_Byte state,
154 FT_UShort flags,
155 GXV_StateTable_GlyphOffsetCPtr glyphOffset_p,
156 FT_Bytes statetable_table,
157 FT_Bytes statetable_limit,
158 GXV_Validator valid );
160 typedef void
161 (*GXV_StateTable_OptData_Load_Func)( FT_Bytes table,
162 FT_Bytes limit,
163 GXV_Validator valid );
165 typedef struct GXV_StateTable_ValidatorRec_
167 GXV_GlyphOffset_Format entry_glyphoffset_fmt;
168 void* optdata;
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;
183 typedef void
184 (*GXV_XStateTable_Subtable_Setup_Func)( FT_ULong table_size,
185 FT_ULong classTable,
186 FT_ULong stateArray,
187 FT_ULong entryTable,
188 FT_ULong* classTable_length_p,
189 FT_ULong* stateArray_length_p,
190 FT_ULong* entryTable_length_p,
191 GXV_Validator valid );
193 typedef void
194 (*GXV_XStateTable_Entry_Validate_Func)(
195 FT_UShort state,
196 FT_UShort flags,
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;
209 void* optdata;
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;
215 FT_ULong nClasses;
216 FT_UShort maxClassID;
218 } GXV_XStateTable_ValidatorRec, *GXV_XStateTable_ValidatorRecData;
221 /* ===================================================================== */
223 typedef struct GXV_ValidatorRec_
225 FT_Validator root;
227 FT_Face face;
228 void* table_data;
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];
243 #endif
245 } GXV_ValidatorRec;
248 #define GXV_TABLE_DATA( tag, field ) \
249 ( ( (GXV_ ## tag ## _Data)valid->table_data )->field )
251 #undef FT_INVALID_
252 #define FT_INVALID_( _prefix, _error ) \
253 ft_validator_error( valid->root, _prefix ## _error )
255 #define GXV_LIMIT_CHECK( _count ) \
256 FT_BEGIN_STMNT \
257 if ( p + _count > ( limit? limit : valid->root->limit ) ) \
258 FT_INVALID_TOO_SHORT; \
259 FT_END_STMNT
262 #ifdef FT_DEBUG_LEVEL_TRACE
264 #define GXV_INIT valid->debug_indent = 0
266 #define GXV_NAME_ENTER( name ) \
267 FT_BEGIN_STMNT \
268 valid->debug_indent += 2; \
269 FT_TRACE4(( "%*.s", valid->debug_indent, 0 )); \
270 FT_TRACE4(( "%s table\n", name )); \
271 FT_END_STMNT
273 #define GXV_EXIT valid->debug_indent -= 2
275 #define GXV_TRACE( s ) \
276 FT_BEGIN_STMNT \
277 FT_TRACE4(( "%*.s", valid->debug_indent, 0 )); \
278 FT_TRACE4( s ); \
279 FT_END_STMNT
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 /*************************************************************************/
294 /***** *****/
295 /***** 32bit alignment checking *****/
296 /***** *****/
297 /*************************************************************************/
298 /*************************************************************************/
300 #define GXV_32BIT_ALIGNMENT_VALIDATE( a ) \
301 FT_BEGIN_STMNT \
303 if ( 0 != ( (a) % 4 ) ) \
304 FT_INVALID_OFFSET ; \
306 FT_END_STMNT
309 /*************************************************************************/
310 /*************************************************************************/
311 /***** *****/
312 /***** Dumping Binary Data *****/
313 /***** *****/
314 /*************************************************************************/
315 /*************************************************************************/
317 #define GXV_TRACE_HEXDUMP( p, len ) \
318 FT_BEGIN_STMNT \
320 FT_Bytes b; \
323 for ( b = p; b < (FT_Bytes)p + len; b++ ) \
324 FT_TRACE1(("\\x%02x", *b)) ; \
326 FT_END_STMNT
328 #define GXV_TRACE_HEXDUMP_C( p, len ) \
329 FT_BEGIN_STMNT \
331 FT_Bytes b; \
334 for ( b = p; b < (FT_Bytes)p + len; b++ ) \
335 if ( 0x40 < *b && *b < 0x7e ) \
336 FT_TRACE1(("%c", *b)) ; \
337 else \
338 FT_TRACE1(("\\x%02x", *b)) ; \
340 FT_END_STMNT
342 #define GXV_TRACE_HEXDUMP_SFNTNAME( n ) \
343 GXV_TRACE_HEXDUMP( n.string, n.string_len )
346 /*************************************************************************/
347 /*************************************************************************/
348 /***** *****/
349 /***** LOOKUP TABLE *****/
350 /***** *****/
351 /*************************************************************************/
352 /*************************************************************************/
354 FT_LOCAL( void )
355 gxv_BinSrchHeader_validate( FT_Bytes p,
356 FT_Bytes limit,
357 FT_UShort* unitSize_p,
358 FT_UShort* nUnits_p,
359 GXV_Validator valid );
361 FT_LOCAL( void )
362 gxv_LookupTable_validate( FT_Bytes table,
363 FT_Bytes limit,
364 GXV_Validator valid );
367 /*************************************************************************/
368 /*************************************************************************/
369 /***** *****/
370 /***** Glyph ID *****/
371 /***** *****/
372 /*************************************************************************/
373 /*************************************************************************/
375 FT_LOCAL( FT_Int )
376 gxv_glyphid_validate( FT_UShort gid,
377 GXV_Validator valid );
380 /*************************************************************************/
381 /*************************************************************************/
382 /***** *****/
383 /***** CONTROL POINT *****/
384 /***** *****/
385 /*************************************************************************/
386 /*************************************************************************/
388 FT_LOCAL( void )
389 gxv_ctlPoint_validate( FT_UShort gid,
390 FT_Short ctl_point,
391 GXV_Validator valid );
394 /*************************************************************************/
395 /*************************************************************************/
396 /***** *****/
397 /***** SFNT NAME *****/
398 /***** *****/
399 /*************************************************************************/
400 /*************************************************************************/
402 FT_LOCAL( void )
403 gxv_sfntName_validate( FT_UShort name_index,
404 FT_UShort min_index,
405 FT_UShort max_index,
406 GXV_Validator valid );
409 /*************************************************************************/
410 /*************************************************************************/
411 /***** *****/
412 /***** STATE TABLE *****/
413 /***** *****/
414 /*************************************************************************/
415 /*************************************************************************/
417 FT_LOCAL( void )
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 );
427 FT_LOCAL( void )
428 gxv_XStateTable_subtable_setup( FT_ULong table_size,
429 FT_ULong classTable,
430 FT_ULong stateArray,
431 FT_ULong entryTable,
432 FT_ULong* classTable_length_p,
433 FT_ULong* stateArray_length_p,
434 FT_ULong* entryTable_length_p,
435 GXV_Validator valid );
437 FT_LOCAL( void )
438 gxv_StateTable_validate( FT_Bytes table,
439 FT_Bytes limit,
440 GXV_Validator valid );
442 FT_LOCAL( void )
443 gxv_XStateTable_validate( FT_Bytes table,
444 FT_Bytes limit,
445 GXV_Validator valid );
448 /*************************************************************************/
449 /*************************************************************************/
450 /***** *****/
451 /***** UTILITY MACROS AND FUNCTIONS *****/
452 /***** *****/
453 /*************************************************************************/
454 /*************************************************************************/
456 FT_LOCAL( void )
457 gxv_array_getlimits_byte( FT_Bytes table,
458 FT_Bytes limit,
459 FT_Byte* min,
460 FT_Byte* max,
461 GXV_Validator valid );
463 FT_LOCAL( void )
464 gxv_array_getlimits_ushort( FT_Bytes table,
465 FT_Bytes limit,
466 FT_UShort* min,
467 FT_UShort* max,
468 GXV_Validator valid );
470 FT_LOCAL( void )
471 gxv_set_length_by_ushort_offset( FT_UShort* offset,
472 FT_UShort** length,
473 FT_UShort* buff,
474 FT_UInt nmemb,
475 FT_UShort limit,
476 GXV_Validator valid );
478 FT_LOCAL( void )
479 gxv_set_length_by_ulong_offset( FT_ULong* offset,
480 FT_ULong** length,
481 FT_ULong* buff,
482 FT_UInt nmemb,
483 FT_ULong limit,
484 GXV_Validator valid);
487 #define GXV_SUBTABLE_OFFSET_CHECK( _offset ) \
488 FT_BEGIN_STMNT \
489 if ( (_offset) > valid->subtable_length ) \
490 FT_INVALID_OFFSET; \
491 FT_END_STMNT
493 #define GXV_SUBTABLE_LIMIT_CHECK( _count ) \
494 FT_BEGIN_STMNT \
495 if ( ( p + (_count) - valid->subtable_start ) > \
496 valid->subtable_length ) \
497 FT_INVALID_TOO_SHORT; \
498 FT_END_STMNT
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 /*************************************************************************/
512 /***** *****/
513 /***** Table overlapping *****/
514 /***** *****/
515 /*************************************************************************/
516 /*************************************************************************/
518 typedef struct GXV_odtect_DataRec_
520 FT_Bytes start;
521 FT_ULong length;
522 FT_String* name;
524 } GXV_odtect_DataRec, *GXV_odtect_Data;
526 typedef struct GXV_odtect_RangeRec_
528 FT_UInt nRanges;
529 GXV_odtect_Data range;
531 } GXV_odtect_RangeRec, *GXV_odtect_Range;
534 FT_LOCAL( void )
535 gxv_odtect_add_range( FT_Bytes start,
536 FT_ULong length,
537 const FT_String* name,
538 GXV_odtect_Range odtect );
540 FT_LOCAL( void )
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 ) \
551 FT_BEGIN_STMNT \
552 odtect ## _rec.nRanges = 0; \
553 odtect ## _rec.range = odtect ## _range; \
554 odtect = & odtect ## _rec; \
555 FT_END_STMNT
558 /* */
560 FT_END_HEADER
562 #endif /* __GXVCOMMN_H__ */
565 /* END */