1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
|
/***************************************************************************/
/* */
/* otvcommn.h */
/* */
/* OpenType common tables validation (specification). */
/* */
/* Copyright 2004, 2005 by */
/* David Turner, Robert Wilhelm, and Werner Lemberg. */
/* */
/* This file is part of the FreeType project, and may only be used, */
/* modified, and distributed under the terms of the FreeType project */
/* license, LICENSE.TXT. By continuing to use, modify, or distribute */
/* this file you indicate that you have read the license and */
/* understand and accept it fully. */
/* */
/***************************************************************************/
#ifndef __OTVCOMMN_H__
#define __OTVCOMMN_H__
#include <ft2build.h>
#include "otvalid.h"
#include FT_INTERNAL_DEBUG_H
FT_BEGIN_HEADER
/*************************************************************************/
/*************************************************************************/
/***** *****/
/***** VALIDATION *****/
/***** *****/
/*************************************************************************/
/*************************************************************************/
typedef struct OTV_ValidatorRec_* OTV_Validator;
typedef void (*OTV_Validate_Func)( FT_Bytes table,
OTV_Validator valid );
typedef struct OTV_ValidatorRec_
{
FT_Validator root;
FT_UInt type_count;
OTV_Validate_Func* type_funcs;
FT_UInt lookup_count;
FT_UInt glyph_count;
FT_UInt nesting_level;
OTV_Validate_Func func[3];
FT_UInt extra1; /* for passing parameters */
FT_UInt extra2;
FT_Bytes extra3;
#ifdef FT_DEBUG_LEVEL_TRACE
FT_UInt debug_indent;
const FT_String* debug_function_name[3];
#endif
} OTV_ValidatorRec;
#undef FT_INVALID_
#define FT_INVALID_( _prefix, _error ) \
ft_validator_error( valid->root, _prefix ## _error )
#define OTV_OPTIONAL_TABLE( _table ) FT_UShort _table; \
FT_Bytes _table ## _p
#define OTV_OPTIONAL_OFFSET( _offset ) \
FT_BEGIN_STMNT \
_offset ## _p = p; \
_offset = FT_NEXT_USHORT( p ); \
FT_END_STMNT
#define OTV_LIMIT_CHECK( _count ) \
FT_BEGIN_STMNT \
if ( p + (_count) > valid->root->limit ) \
FT_INVALID_TOO_SHORT; \
FT_END_STMNT
#define OTV_SIZE_CHECK( _size ) \
FT_BEGIN_STMNT \
if ( _size > 0 && _size < table_size ) \
{ \
if ( valid->root->level == FT_VALIDATE_PARANOID ) \
FT_INVALID_OFFSET; \
else \
{ \
/* strip off `const' */ \
FT_Byte* pp = (FT_Byte*)_size ## _p; \
\
\
FT_TRACE3(( "\n" \
"Invalid offset to optional table `%s'!\n" \
"Set to zero.\n" \
"\n", #_size )); \
\
/* always assume 16bit entities */ \
_size = pp[0] = pp[1] = 0; \
} \
} \
FT_END_STMNT
#define OTV_NAME_(x) #x
#define OTV_NAME(x) OTV_NAME_(x)
#define OTV_FUNC_(x) x##Func
#define OTV_FUNC(x) OTV_FUNC_(x)
#ifdef FT_DEBUG_LEVEL_TRACE
/* use preprocessor's argument prescan to expand one argument into two */
#define OTV_NEST1( x ) \
FT_BEGIN_STMNT \
valid->nesting_level = 0; \
valid->func[0] = OTV_FUNC(x); \
valid->debug_function_name[0] = OTV_NAME(x); \
FT_END_STMNT
/* use preprocessor's argument prescan to expand two arguments into four */
#define OTV_NEST2( x, y ) \
FT_BEGIN_STMNT \
valid->nesting_level = 0; \
valid->func[0] = OTV_FUNC(x); \
valid->func[1] = OTV_FUNC(y); \
valid->debug_function_name[0] = OTV_NAME(x); \
valid->debug_function_name[1] = OTV_NAME(y); \
FT_END_STMNT
/* use preprocessor's argument prescan to expand three arguments into six */
#define OTV_NEST3( x, y, z ) \
FT_BEGIN_STMNT \
valid->nesting_level = 0; \
valid->func[0] = OTV_FUNC(x); \
valid->func[1] = OTV_FUNC(y); \
valid->func[2] = OTV_FUNC(z); \
valid->debug_function_name[0] = OTV_NAME(x); \
valid->debug_function_name[1] = OTV_NAME(y); \
valid->debug_function_name[2] = OTV_NAME(z); \
FT_END_STMNT
#define OTV_INIT valid->debug_indent = 0
#define OTV_ENTER \
FT_BEGIN_STMNT \
valid->debug_indent += 2; \
FT_TRACE4(( "%*.s", valid->debug_indent, 0 )); \
FT_TRACE4(( "%s table\n", \
valid->debug_function_name[valid->nesting_level] )); \
FT_END_STMNT
#define OTV_NAME_ENTER( name ) \
FT_BEGIN_STMNT \
valid->debug_indent += 2; \
FT_TRACE4(( "%*.s", valid->debug_indent, 0 )); \
FT_TRACE4(( "%s table\n", name )); \
FT_END_STMNT
#define OTV_EXIT valid->debug_indent -= 2
#define OTV_TRACE( s ) \
FT_BEGIN_STMNT \
FT_TRACE4(( "%*.s", valid->debug_indent, 0 )); \
FT_TRACE4( s ); \
FT_END_STMNT
#else /* !FT_DEBUG_LEVEL_TRACE */
/* use preprocessor's argument prescan to expand one argument into two */
#define OTV_NEST1( x ) \
FT_BEGIN_STMNT \
valid->nesting_level = 0; \
valid->func[0] = OTV_FUNC(x); \
FT_END_STMNT
/* use preprocessor's argument prescan to expand two arguments into four */
#define OTV_NEST2( x, y ) \
FT_BEGIN_STMNT \
valid->nesting_level = 0; \
valid->func[0] = OTV_FUNC(x); \
valid->func[1] = OTV_FUNC(y); \
FT_END_STMNT
/* use preprocessor's argument prescan to expand three arguments into six */
#define OTV_NEST3( x, y, z ) \
FT_BEGIN_STMNT \
valid->nesting_level = 0; \
valid->func[0] = OTV_FUNC(x); \
valid->func[1] = OTV_FUNC(y); \
valid->func[2] = OTV_FUNC(z); \
FT_END_STMNT
#define OTV_INIT do ; while ( 0 )
#define OTV_ENTER do ; while ( 0 )
#define OTV_NAME_ENTER( name ) do ; while ( 0 )
#define OTV_EXIT do ; while ( 0 )
#define OTV_TRACE( s ) do ; while ( 0 )
#endif /* !FT_DEBUG_LEVEL_TRACE */
#define OTV_RUN valid->func[0]
/*************************************************************************/
/*************************************************************************/
/***** *****/
/***** COVERAGE TABLE *****/
/***** *****/
/*************************************************************************/
/*************************************************************************/
FT_LOCAL( void )
otv_Coverage_validate( FT_Bytes table,
OTV_Validator valid );
/* return first covered glyph */
FT_LOCAL( FT_UInt )
otv_Coverage_get_first( FT_Bytes table );
/* return last covered glyph */
FT_LOCAL( FT_UInt )
otv_Coverage_get_last( FT_Bytes table );
/* return number of covered glyphs */
FT_LOCAL( FT_UInt )
otv_Coverage_get_count( FT_Bytes table );
/*************************************************************************/
/*************************************************************************/
/***** *****/
/***** CLASS DEFINITION TABLE *****/
/***** *****/
/*************************************************************************/
/*************************************************************************/
FT_LOCAL( void )
otv_ClassDef_validate( FT_Bytes table,
OTV_Validator valid );
/*************************************************************************/
/*************************************************************************/
/***** *****/
/***** DEVICE TABLE *****/
/***** *****/
/*************************************************************************/
/*************************************************************************/
FT_LOCAL( void )
otv_Device_validate( FT_Bytes table,
OTV_Validator valid );
/*************************************************************************/
/*************************************************************************/
/***** *****/
/***** LOOKUPS *****/
/***** *****/
/*************************************************************************/
/*************************************************************************/
FT_LOCAL( void )
otv_Lookup_validate( FT_Bytes table,
OTV_Validator valid );
FT_LOCAL( void )
otv_LookupList_validate( FT_Bytes table,
OTV_Validator valid );
/*************************************************************************/
/*************************************************************************/
/***** *****/
/***** FEATURES *****/
/***** *****/
/*************************************************************************/
/*************************************************************************/
FT_LOCAL( void )
otv_Feature_validate( FT_Bytes table,
OTV_Validator valid );
/* lookups must already be validated */
FT_LOCAL( void )
otv_FeatureList_validate( FT_Bytes table,
FT_Bytes lookups,
OTV_Validator valid );
/*************************************************************************/
/*************************************************************************/
/***** *****/
/***** LANGUAGE SYSTEM *****/
/***** *****/
/*************************************************************************/
/*************************************************************************/
FT_LOCAL( void )
otv_LangSys_validate( FT_Bytes table,
OTV_Validator valid );
/*************************************************************************/
/*************************************************************************/
/***** *****/
/***** SCRIPTS *****/
/***** *****/
/*************************************************************************/
/*************************************************************************/
FT_LOCAL( void )
otv_Script_validate( FT_Bytes table,
OTV_Validator valid );
/* features must already be validated */
FT_LOCAL( void )
otv_ScriptList_validate( FT_Bytes table,
FT_Bytes features,
OTV_Validator valid );
/*************************************************************************/
/*************************************************************************/
/***** *****/
/***** UTILITY FUNCTIONS *****/
/***** *****/
/*************************************************************************/
/*************************************************************************/
#if 0
#define ChainPosClassSet otv_x_Ox, "ChainPosClassSet"
#define ChainPosRuleSet otv_x_Ox, "ChainPosRuleSet"
#define ChainSubClassSet otv_x_Ox, "ChainSubClassSet"
#define ChainSubRuleSet otv_x_Ox, "ChainSubRuleSet"
#define JstfLangSys otv_x_Ox, "JstfLangSys"
#define JstfMax otv_x_Ox, "JstfMax"
#define LigGlyph otv_x_Ox, "LigGlyph"
#define LigatureArray otv_x_Ox, "LigatureArray"
#define LigatureSet otv_x_Ox, "LigatureSet"
#define PosClassSet otv_x_Ox, "PosClassSet"
#define PosRuleSet otv_x_Ox, "PosRuleSet"
#define SubClassSet otv_x_Ox, "SubClassSet"
#define SubRuleSet otv_x_Ox, "SubRuleSet"
#endif
#define ChainPosClassSetFunc otv_x_Ox
#define ChainPosRuleSetFunc otv_x_Ox
#define ChainSubClassSetFunc otv_x_Ox
#define ChainSubRuleSetFunc otv_x_Ox
#define JstfLangSysFunc otv_x_Ox
#define JstfMaxFunc otv_x_Ox
#define LigGlyphFunc otv_x_Ox
#define LigatureArrayFunc otv_x_Ox
#define LigatureSetFunc otv_x_Ox
#define PosClassSetFunc otv_x_Ox
#define PosRuleSetFunc otv_x_Ox
#define SubClassSetFunc otv_x_Ox
#define SubRuleSetFunc otv_x_Ox
FT_LOCAL( void )
otv_x_Ox ( FT_Bytes table,
OTV_Validator valid );
#if 0
#define AlternateSubstFormat1 otv_u_C_x_Ox, "AlternateSubstFormat1"
#define ChainContextPosFormat1 otv_u_C_x_Ox, "ChainContextPosFormat1"
#define ChainContextSubstFormat1 otv_u_C_x_Ox, "ChainContextSubstFormat1"
#define ContextPosFormat1 otv_u_C_x_Ox, "ContextPosFormat1"
#define ContextSubstFormat1 otv_u_C_x_Ox, "ContextSubstFormat1"
#define LigatureSubstFormat1 otv_u_C_x_Ox, "LigatureSubstFormat1"
#define MultipleSubstFormat1 otv_u_C_x_Ox, "MultipleSubstFormat1"
#endif
#define AlternateSubstFormat1Func otv_u_C_x_Ox
#define ChainContextPosFormat1Func otv_u_C_x_Ox
#define ChainContextSubstFormat1Func otv_u_C_x_Ox
#define ContextPosFormat1Func otv_u_C_x_Ox
#define ContextSubstFormat1Func otv_u_C_x_Ox
#define LigatureSubstFormat1Func otv_u_C_x_Ox
#define MultipleSubstFormat1Func otv_u_C_x_Ox
FT_LOCAL( void )
otv_u_C_x_Ox( FT_Bytes table,
OTV_Validator valid );
#if 0
#define AlternateSet otv_x_ux, "AlternateSet"
#define AttachPoint otv_x_ux, "AttachPoint"
#define ExtenderGlyph otv_x_ux, "ExtenderGlyph"
#define JstfGPOSModList otv_x_ux, "JstfGPOSModList"
#define JstfGSUBModList otv_x_ux, "JstfGSUBModList"
#define Sequence otv_x_ux, "Sequence"
#endif
#define AlternateSetFunc otv_x_ux
#define AttachPointFunc otv_x_ux
#define ExtenderGlyphFunc otv_x_ux
#define JstfGPOSModListFunc otv_x_ux
#define JstfGSUBModListFunc otv_x_ux
#define SequenceFunc otv_x_ux
FT_LOCAL( void )
otv_x_ux( FT_Bytes table,
OTV_Validator valid );
#if 0
#define PosClassRule otv_x_y_ux_sy, "PosClassRule"
#define PosRule otv_x_y_ux_sy, "PosRule"
#define SubClassRule otv_x_y_ux_sy, "SubClassRule"
#define SubRule otv_x_y_ux_sy, "SubRule"
#endif
#define PosClassRuleFunc otv_x_y_ux_sy
#define PosRuleFunc otv_x_y_ux_sy
#define SubClassRuleFunc otv_x_y_ux_sy
#define SubRuleFunc otv_x_y_ux_sy
FT_LOCAL( void )
otv_x_y_ux_sy( FT_Bytes table,
OTV_Validator valid );
#if 0
#define ChainPosClassRule otv_x_ux_y_uy_z_uz_p_sp, "ChainPosClassRule"
#define ChainPosRule otv_x_ux_y_uy_z_uz_p_sp, "ChainPosRule"
#define ChainSubClassRule otv_x_ux_y_uy_z_uz_p_sp, "ChainSubClassRule"
#define ChainSubRule otv_x_ux_y_uy_z_uz_p_sp, "ChainSubRule"
#endif
#define ChainPosClassRuleFunc otv_x_ux_y_uy_z_uz_p_sp
#define ChainPosRuleFunc otv_x_ux_y_uy_z_uz_p_sp
#define ChainSubClassRuleFunc otv_x_ux_y_uy_z_uz_p_sp
#define ChainSubRuleFunc otv_x_ux_y_uy_z_uz_p_sp
FT_LOCAL( void )
otv_x_ux_y_uy_z_uz_p_sp( FT_Bytes table,
OTV_Validator valid );
#if 0
#define ContextPosFormat2 otv_u_O_O_x_Onx, "ContextPosFormat2"
#define ContextSubstFormat2 otv_u_O_O_x_Onx, "ContextSubstFormat2"
#endif
#define ContextPosFormat2Func otv_u_O_O_x_Onx
#define ContextSubstFormat2Func otv_u_O_O_x_Onx
FT_LOCAL( void )
otv_u_O_O_x_Onx( FT_Bytes table,
OTV_Validator valid );
#if 0
#define ContextPosFormat3 otv_u_x_y_Ox_sy, "ContextPosFormat3"
#define ContextSubstFormat3 otv_u_x_y_Ox_sy, "ContextSubstFormat3"
#endif
#define ContextPosFormat3Func otv_u_x_y_Ox_sy
#define ContextSubstFormat3Func otv_u_x_y_Ox_sy
FT_LOCAL( void )
otv_u_x_y_Ox_sy( FT_Bytes table,
OTV_Validator valid );
#if 0
#define ChainContextPosFormat2 otv_u_O_O_O_O_x_Onx, "ChainContextPosFormat2"
#define ChainContextSubstFormat2 otv_u_O_O_O_O_x_Onx, "ChainContextSubstFormat2"
#endif
#define ChainContextPosFormat2Func otv_u_O_O_O_O_x_Onx
#define ChainContextSubstFormat2Func otv_u_O_O_O_O_x_Onx
FT_LOCAL( void )
otv_u_O_O_O_O_x_Onx( FT_Bytes table,
OTV_Validator valid );
#if 0
#define ChainContextPosFormat3 otv_u_x_Ox_y_Oy_z_Oz_p_sp, "ChainContextPosFormat3"
#define ChainContextSubstFormat3 otv_u_x_Ox_y_Oy_z_Oz_p_sp, "ChainContextSubstFormat3"
#endif
#define ChainContextPosFormat3Func otv_u_x_Ox_y_Oy_z_Oz_p_sp
#define ChainContextSubstFormat3Func otv_u_x_Ox_y_Oy_z_Oz_p_sp
FT_LOCAL( void )
otv_u_x_Ox_y_Oy_z_Oz_p_sp( FT_Bytes table,
OTV_Validator valid );
FT_LOCAL( FT_UInt )
otv_GSUBGPOS_get_Lookup_count( FT_Bytes table );
FT_LOCAL( FT_UInt )
otv_GSUBGPOS_have_MarkAttachmentType_flag( FT_Bytes table );
/* */
FT_END_HEADER
#endif /* __OTVCOMMN_H__ */
/* END */
|