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 /***************************************************************************/ |
|
17 |
|
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 /***************************************************************************/ |
|
25 |
|
26 |
|
27 /* |
|
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. |
|
36 * |
|
37 * _MIN, _MAX: Should be added to the tail of macros, as INT_MIN, etc. |
|
38 */ |
|
39 |
|
40 |
|
41 #ifndef __GXVCOMMN_H__ |
|
42 #define __GXVCOMMN_H__ |
|
43 |
|
44 |
|
45 #include <ft2build.h> |
|
46 #include "gxvalid.h" |
|
47 #include FT_INTERNAL_DEBUG_H |
|
48 #include FT_SFNT_NAMES_H |
|
49 |
|
50 |
|
51 FT_BEGIN_HEADER |
|
52 |
|
53 |
|
54 /*************************************************************************/ |
|
55 /*************************************************************************/ |
|
56 /***** *****/ |
|
57 /***** VALIDATION *****/ |
|
58 /***** *****/ |
|
59 /*************************************************************************/ |
|
60 /*************************************************************************/ |
|
61 |
|
62 typedef struct GXV_ValidatorRec_* GXV_Validator; |
|
63 |
|
64 |
|
65 #define DUMMY_LIMIT 0 |
|
66 |
|
67 typedef void |
|
68 (*GXV_Validate_Func)( FT_Bytes table, |
|
69 FT_Bytes limit, |
|
70 GXV_Validator valid ); |
|
71 |
|
72 |
|
73 /* ====================== LookupTable Validator ======================== */ |
|
74 |
|
75 typedef union GXV_LookupValueDesc_ |
|
76 { |
|
77 FT_UShort u; |
|
78 FT_Short s; |
|
79 |
|
80 } GXV_LookupValueDesc; |
|
81 |
|
82 typedef const GXV_LookupValueDesc* GXV_LookupValueCPtr; |
|
83 |
|
84 typedef enum GXV_LookupValue_SignSpec_ |
|
85 { |
|
86 GXV_LOOKUPVALUE_UNSIGNED = 0, |
|
87 GXV_LOOKUPVALUE_SIGNED |
|
88 |
|
89 } GXV_LookupValue_SignSpec; |
|
90 |
|
91 |
|
92 typedef void |
|
93 (*GXV_Lookup_Value_Validate_Func)( FT_UShort glyph, |
|
94 GXV_LookupValueCPtr value_p, |
|
95 GXV_Validator valid ); |
|
96 |
|
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 ); |
|
102 |
|
103 |
|
104 /* ====================== StateTable Validator ========================= */ |
|
105 |
|
106 typedef enum GXV_GlyphOffset_Format_ |
|
107 { |
|
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 |
|
115 |
|
116 } GXV_GlyphOffset_Format; |
|
117 |
|
118 |
|
119 #define GXV_GLYPHOFFSET_FMT( table ) \ |
|
120 ( valid->table.entry_glyphoffset_fmt ) |
|
121 |
|
122 #define GXV_GLYPHOFFSET_SIZE( table ) \ |
|
123 ( valid->table.entry_glyphoffset_fmt / 2 ) |
|
124 |
|
125 |
|
126 /* ----------------------- 16bit StateTable ---------------------------- */ |
|
127 |
|
128 typedef union GXV_StateTable_GlyphOffsetDesc_ |
|
129 { |
|
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; |
|
136 |
|
137 } GXV_StateTable_GlyphOffsetDesc; |
|
138 |
|
139 typedef const GXV_StateTable_GlyphOffsetDesc* GXV_StateTable_GlyphOffsetCPtr; |
|
140 |
|
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 ); |
|
150 |
|
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 ); |
|
159 |
|
160 typedef void |
|
161 (*GXV_StateTable_OptData_Load_Func)( FT_Bytes table, |
|
162 FT_Bytes limit, |
|
163 GXV_Validator valid ); |
|
164 |
|
165 typedef struct GXV_StateTable_ValidatorRec_ |
|
166 { |
|
167 GXV_GlyphOffset_Format entry_glyphoffset_fmt; |
|
168 void* optdata; |
|
169 |
|
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; |
|
173 |
|
174 } GXV_StateTable_ValidatorRec, *GXV_StateTable_ValidatorRecData; |
|
175 |
|
176 |
|
177 /* ---------------------- 32bit XStateTable ---------------------------- */ |
|
178 |
|
179 typedef GXV_StateTable_GlyphOffsetDesc GXV_XStateTable_GlyphOffsetDesc; |
|
180 |
|
181 typedef const GXV_XStateTable_GlyphOffsetDesc* GXV_XStateTable_GlyphOffsetCPtr; |
|
182 |
|
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 ); |
|
192 |
|
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 ); |
|
201 |
|
202 |
|
203 typedef GXV_StateTable_OptData_Load_Func GXV_XStateTable_OptData_Load_Func; |
|
204 |
|
205 |
|
206 typedef struct GXV_XStateTable_ValidatorRec_ |
|
207 { |
|
208 int entry_glyphoffset_fmt; |
|
209 void* optdata; |
|
210 |
|
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; |
|
214 |
|
215 FT_ULong nClasses; |
|
216 FT_UShort maxClassID; |
|
217 |
|
218 } GXV_XStateTable_ValidatorRec, *GXV_XStateTable_ValidatorRecData; |
|
219 |
|
220 |
|
221 /* ===================================================================== */ |
|
222 |
|
223 typedef struct GXV_ValidatorRec_ |
|
224 { |
|
225 FT_Validator root; |
|
226 |
|
227 FT_Face face; |
|
228 void* table_data; |
|
229 |
|
230 FT_ULong subtable_length; |
|
231 |
|
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; |
|
236 |
|
237 GXV_StateTable_ValidatorRec statetable; |
|
238 GXV_XStateTable_ValidatorRec xstatetable; |
|
239 |
|
240 #ifdef FT_DEBUG_LEVEL_TRACE |
|
241 FT_UInt debug_indent; |
|
242 const FT_String* debug_function_name[3]; |
|
243 #endif |
|
244 |
|
245 } GXV_ValidatorRec; |
|
246 |
|
247 |
|
248 #define GXV_TABLE_DATA( tag, field ) \ |
|
249 ( ( (GXV_ ## tag ## _Data)valid->table_data )->field ) |
|
250 |
|
251 #undef FT_INVALID_ |
|
252 #define FT_INVALID_( _prefix, _error ) \ |
|
253 ft_validator_error( valid->root, _prefix ## _error ) |
|
254 |
|
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 |
|
260 |
|
261 |
|
262 #ifdef FT_DEBUG_LEVEL_TRACE |
|
263 |
|
264 #define GXV_INIT valid->debug_indent = 0 |
|
265 |
|
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 |
|
272 |
|
273 #define GXV_EXIT valid->debug_indent -= 2 |
|
274 |
|
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 |
|
280 |
|
281 #else /* !FT_DEBUG_LEVEL_TRACE */ |
|
282 |
|
283 #define GXV_INIT do { } while ( 0 ) |
|
284 #define GXV_NAME_ENTER( name ) do { } while ( 0 ) |
|
285 #define GXV_EXIT do { } while ( 0 ) |
|
286 |
|
287 #define GXV_TRACE( s ) do { } while ( 0 ) |
|
288 |
|
289 #endif /* !FT_DEBUG_LEVEL_TRACE */ |
|
290 |
|
291 |
|
292 /*************************************************************************/ |
|
293 /*************************************************************************/ |
|
294 /***** *****/ |
|
295 /***** 32bit alignment checking *****/ |
|
296 /***** *****/ |
|
297 /*************************************************************************/ |
|
298 /*************************************************************************/ |
|
299 |
|
300 #define GXV_32BIT_ALIGNMENT_VALIDATE( a ) \ |
|
301 FT_BEGIN_STMNT \ |
|
302 { \ |
|
303 if ( 0 != ( (a) % 4 ) ) \ |
|
304 FT_INVALID_OFFSET ; \ |
|
305 } \ |
|
306 FT_END_STMNT |
|
307 |
|
308 |
|
309 /*************************************************************************/ |
|
310 /*************************************************************************/ |
|
311 /***** *****/ |
|
312 /***** Dumping Binary Data *****/ |
|
313 /***** *****/ |
|
314 /*************************************************************************/ |
|
315 /*************************************************************************/ |
|
316 |
|
317 #define GXV_TRACE_HEXDUMP( p, len ) \ |
|
318 FT_BEGIN_STMNT \ |
|
319 { \ |
|
320 FT_Bytes b; \ |
|
321 \ |
|
322 \ |
|
323 for ( b = p; b < (FT_Bytes)p + len; b++ ) \ |
|
324 FT_TRACE1(("\\x%02x", *b)) ; \ |
|
325 } \ |
|
326 FT_END_STMNT |
|
327 |
|
328 #define GXV_TRACE_HEXDUMP_C( p, len ) \ |
|
329 FT_BEGIN_STMNT \ |
|
330 { \ |
|
331 FT_Bytes b; \ |
|
332 \ |
|
333 \ |
|
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)) ; \ |
|
339 } \ |
|
340 FT_END_STMNT |
|
341 |
|
342 #define GXV_TRACE_HEXDUMP_SFNTNAME( n ) \ |
|
343 GXV_TRACE_HEXDUMP( n.string, n.string_len ) |
|
344 |
|
345 |
|
346 /*************************************************************************/ |
|
347 /*************************************************************************/ |
|
348 /***** *****/ |
|
349 /***** LOOKUP TABLE *****/ |
|
350 /***** *****/ |
|
351 /*************************************************************************/ |
|
352 /*************************************************************************/ |
|
353 |
|
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 ); |
|
360 |
|
361 FT_LOCAL( void ) |
|
362 gxv_LookupTable_validate( FT_Bytes table, |
|
363 FT_Bytes limit, |
|
364 GXV_Validator valid ); |
|
365 |
|
366 |
|
367 /*************************************************************************/ |
|
368 /*************************************************************************/ |
|
369 /***** *****/ |
|
370 /***** Glyph ID *****/ |
|
371 /***** *****/ |
|
372 /*************************************************************************/ |
|
373 /*************************************************************************/ |
|
374 |
|
375 FT_LOCAL( FT_Int ) |
|
376 gxv_glyphid_validate( FT_UShort gid, |
|
377 GXV_Validator valid ); |
|
378 |
|
379 |
|
380 /*************************************************************************/ |
|
381 /*************************************************************************/ |
|
382 /***** *****/ |
|
383 /***** CONTROL POINT *****/ |
|
384 /***** *****/ |
|
385 /*************************************************************************/ |
|
386 /*************************************************************************/ |
|
387 |
|
388 FT_LOCAL( void ) |
|
389 gxv_ctlPoint_validate( FT_UShort gid, |
|
390 FT_Short ctl_point, |
|
391 GXV_Validator valid ); |
|
392 |
|
393 |
|
394 /*************************************************************************/ |
|
395 /*************************************************************************/ |
|
396 /***** *****/ |
|
397 /***** SFNT NAME *****/ |
|
398 /***** *****/ |
|
399 /*************************************************************************/ |
|
400 /*************************************************************************/ |
|
401 |
|
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 ); |
|
407 |
|
408 |
|
409 /*************************************************************************/ |
|
410 /*************************************************************************/ |
|
411 /***** *****/ |
|
412 /***** STATE TABLE *****/ |
|
413 /***** *****/ |
|
414 /*************************************************************************/ |
|
415 /*************************************************************************/ |
|
416 |
|
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 ); |
|
426 |
|
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 ); |
|
436 |
|
437 FT_LOCAL( void ) |
|
438 gxv_StateTable_validate( FT_Bytes table, |
|
439 FT_Bytes limit, |
|
440 GXV_Validator valid ); |
|
441 |
|
442 FT_LOCAL( void ) |
|
443 gxv_XStateTable_validate( FT_Bytes table, |
|
444 FT_Bytes limit, |
|
445 GXV_Validator valid ); |
|
446 |
|
447 |
|
448 /*************************************************************************/ |
|
449 /*************************************************************************/ |
|
450 /***** *****/ |
|
451 /***** UTILITY MACROS AND FUNCTIONS *****/ |
|
452 /***** *****/ |
|
453 /*************************************************************************/ |
|
454 /*************************************************************************/ |
|
455 |
|
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 ); |
|
462 |
|
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 ); |
|
469 |
|
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 ); |
|
477 |
|
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); |
|
485 |
|
486 |
|
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 |
|
492 |
|
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 |
|
499 |
|
500 #define GXV_USHORT_TO_SHORT( _us ) \ |
|
501 ( ( 0x8000U < ( _us ) ) ? ( ( _us ) - 0x8000U ) : ( _us ) ) |
|
502 |
|
503 #define GXV_STATETABLE_HEADER_SIZE ( 2 + 2 + 2 + 2 ) |
|
504 #define GXV_STATEHEADER_SIZE GXV_STATETABLE_HEADER_SIZE |
|
505 |
|
506 #define GXV_XSTATETABLE_HEADER_SIZE ( 4 + 4 + 4 + 4 ) |
|
507 #define GXV_XSTATEHEADER_SIZE GXV_XSTATETABLE_HEADER_SIZE |
|
508 |
|
509 |
|
510 /*************************************************************************/ |
|
511 /*************************************************************************/ |
|
512 /***** *****/ |
|
513 /***** Table overlapping *****/ |
|
514 /***** *****/ |
|
515 /*************************************************************************/ |
|
516 /*************************************************************************/ |
|
517 |
|
518 typedef struct GXV_odtect_DataRec_ |
|
519 { |
|
520 FT_Bytes start; |
|
521 FT_ULong length; |
|
522 FT_String* name; |
|
523 |
|
524 } GXV_odtect_DataRec, *GXV_odtect_Data; |
|
525 |
|
526 typedef struct GXV_odtect_RangeRec_ |
|
527 { |
|
528 FT_UInt nRanges; |
|
529 GXV_odtect_Data range; |
|
530 |
|
531 } GXV_odtect_RangeRec, *GXV_odtect_Range; |
|
532 |
|
533 |
|
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 ); |
|
539 |
|
540 FT_LOCAL( void ) |
|
541 gxv_odtect_validate( GXV_odtect_Range odtect, |
|
542 GXV_Validator valid ); |
|
543 |
|
544 |
|
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 |
|
549 |
|
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 |
|
556 |
|
557 |
|
558 /* */ |
|
559 |
|
560 FT_END_HEADER |
|
561 |
|
562 #endif /* __GXVCOMMN_H__ */ |
|
563 |
|
564 |
|
565 /* END */ |
|