1 /***************************************************************************/
5 /* OpenType common tables validation (specification). */
7 /* Copyright 2004, 2005 by */
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 /***************************************************************************/
19 #ifndef __OTVCOMMN_H__
20 #define __OTVCOMMN_H__
25 #include FT_INTERNAL_DEBUG_H
31 /*************************************************************************/
32 /*************************************************************************/
34 /***** VALIDATION *****/
36 /*************************************************************************/
37 /*************************************************************************/
39 typedef struct OTV_ValidatorRec_
* OTV_Validator
;
41 typedef void (*OTV_Validate_Func
)( FT_Bytes table
,
42 OTV_Validator valid
);
44 typedef struct OTV_ValidatorRec_
48 OTV_Validate_Func
* type_funcs
;
53 FT_UInt nesting_level
;
55 OTV_Validate_Func func
[3];
57 FT_UInt extra1
; /* for passing parameters */
61 #ifdef FT_DEBUG_LEVEL_TRACE
63 const FT_String
* debug_function_name
[3];
70 #define FT_INVALID_( _prefix, _error ) \
71 ft_validator_error( valid->root, _prefix ## _error )
73 #define OTV_OPTIONAL_TABLE( _table ) FT_UShort _table; \
76 #define OTV_OPTIONAL_OFFSET( _offset ) \
79 _offset = FT_NEXT_USHORT( p ); \
82 #define OTV_LIMIT_CHECK( _count ) \
84 if ( p + (_count) > valid->root->limit ) \
85 FT_INVALID_TOO_SHORT; \
88 #define OTV_SIZE_CHECK( _size ) \
90 if ( _size > 0 && _size < table_size ) \
92 if ( valid->root->level == FT_VALIDATE_PARANOID ) \
96 /* strip off `const' */ \
97 FT_Byte* pp = (FT_Byte*)_size ## _p; \
101 "Invalid offset to optional table `%s'!\n" \
105 /* always assume 16bit entities */ \
106 _size = pp[0] = pp[1] = 0; \
112 #define OTV_NAME_(x) #x
113 #define OTV_NAME(x) OTV_NAME_(x)
115 #define OTV_FUNC_(x) x##Func
116 #define OTV_FUNC(x) OTV_FUNC_(x)
118 #ifdef FT_DEBUG_LEVEL_TRACE
120 #define OTV_NEST1( x ) \
122 valid->nesting_level = 0; \
123 valid->func[0] = OTV_FUNC( x ); \
124 valid->debug_function_name[0] = OTV_NAME( x ); \
127 #define OTV_NEST2( x, y ) \
129 valid->nesting_level = 0; \
130 valid->func[0] = OTV_FUNC( x ); \
131 valid->func[1] = OTV_FUNC( y ); \
132 valid->debug_function_name[0] = OTV_NAME( x ); \
133 valid->debug_function_name[1] = OTV_NAME( y ); \
136 #define OTV_NEST3( x, y, z ) \
138 valid->nesting_level = 0; \
139 valid->func[0] = OTV_FUNC( x ); \
140 valid->func[1] = OTV_FUNC( y ); \
141 valid->func[2] = OTV_FUNC( z ); \
142 valid->debug_function_name[0] = OTV_NAME( x ); \
143 valid->debug_function_name[1] = OTV_NAME( y ); \
144 valid->debug_function_name[2] = OTV_NAME( z ); \
147 #define OTV_INIT valid->debug_indent = 0
151 valid->debug_indent += 2; \
152 FT_TRACE4(( "%*.s", valid->debug_indent, 0 )); \
153 FT_TRACE4(( "%s table\n", \
154 valid->debug_function_name[valid->nesting_level] )); \
157 #define OTV_NAME_ENTER( name ) \
159 valid->debug_indent += 2; \
160 FT_TRACE4(( "%*.s", valid->debug_indent, 0 )); \
161 FT_TRACE4(( "%s table\n", name )); \
164 #define OTV_EXIT valid->debug_indent -= 2
166 #define OTV_TRACE( s ) \
168 FT_TRACE4(( "%*.s", valid->debug_indent, 0 )); \
172 #else /* !FT_DEBUG_LEVEL_TRACE */
174 #define OTV_NEST1( x ) \
176 valid->nesting_level = 0; \
177 valid->func[0] = OTV_FUNC( x ); \
180 #define OTV_NEST2( x, y ) \
182 valid->nesting_level = 0; \
183 valid->func[0] = OTV_FUNC( x ); \
184 valid->func[1] = OTV_FUNC( y ); \
187 #define OTV_NEST3( x, y, z ) \
189 valid->nesting_level = 0; \
190 valid->func[0] = OTV_FUNC( x ); \
191 valid->func[1] = OTV_FUNC( y ); \
192 valid->func[2] = OTV_FUNC( z ); \
195 #define OTV_INIT do ; while ( 0 )
196 #define OTV_ENTER do ; while ( 0 )
197 #define OTV_NAME_ENTER( name ) do ; while ( 0 )
198 #define OTV_EXIT do ; while ( 0 )
200 #define OTV_TRACE( s ) do ; while ( 0 )
202 #endif /* !FT_DEBUG_LEVEL_TRACE */
205 #define OTV_RUN valid->func[0]
208 /*************************************************************************/
209 /*************************************************************************/
211 /***** COVERAGE TABLE *****/
213 /*************************************************************************/
214 /*************************************************************************/
217 otv_Coverage_validate( FT_Bytes table
,
218 OTV_Validator valid
);
220 /* return first covered glyph */
222 otv_Coverage_get_first( FT_Bytes table
);
224 /* return last covered glyph */
226 otv_Coverage_get_last( FT_Bytes table
);
228 /* return number of covered glyphs */
230 otv_Coverage_get_count( FT_Bytes table
);
233 /*************************************************************************/
234 /*************************************************************************/
236 /***** CLASS DEFINITION TABLE *****/
238 /*************************************************************************/
239 /*************************************************************************/
242 otv_ClassDef_validate( FT_Bytes table
,
243 OTV_Validator valid
);
246 /*************************************************************************/
247 /*************************************************************************/
249 /***** DEVICE TABLE *****/
251 /*************************************************************************/
252 /*************************************************************************/
255 otv_Device_validate( FT_Bytes table
,
256 OTV_Validator valid
);
259 /*************************************************************************/
260 /*************************************************************************/
262 /***** LOOKUPS *****/
264 /*************************************************************************/
265 /*************************************************************************/
268 otv_Lookup_validate( FT_Bytes table
,
269 OTV_Validator valid
);
272 otv_LookupList_validate( FT_Bytes table
,
273 OTV_Validator valid
);
276 /*************************************************************************/
277 /*************************************************************************/
279 /***** FEATURES *****/
281 /*************************************************************************/
282 /*************************************************************************/
285 otv_Feature_validate( FT_Bytes table
,
286 OTV_Validator valid
);
288 /* lookups must already be validated */
290 otv_FeatureList_validate( FT_Bytes table
,
292 OTV_Validator valid
);
295 /*************************************************************************/
296 /*************************************************************************/
298 /***** LANGUAGE SYSTEM *****/
300 /*************************************************************************/
301 /*************************************************************************/
304 otv_LangSys_validate( FT_Bytes table
,
305 OTV_Validator valid
);
308 /*************************************************************************/
309 /*************************************************************************/
311 /***** SCRIPTS *****/
313 /*************************************************************************/
314 /*************************************************************************/
317 otv_Script_validate( FT_Bytes table
,
318 OTV_Validator valid
);
320 /* features must already be validated */
322 otv_ScriptList_validate( FT_Bytes table
,
324 OTV_Validator valid
);
327 /*************************************************************************/
328 /*************************************************************************/
330 /***** UTILITY FUNCTIONS *****/
332 /*************************************************************************/
333 /*************************************************************************/
335 #define ChainPosClassSetFunc otv_x_Ox
336 #define ChainPosRuleSetFunc otv_x_Ox
337 #define ChainSubClassSetFunc otv_x_Ox
338 #define ChainSubRuleSetFunc otv_x_Ox
339 #define JstfLangSysFunc otv_x_Ox
340 #define JstfMaxFunc otv_x_Ox
341 #define LigGlyphFunc otv_x_Ox
342 #define LigatureArrayFunc otv_x_Ox
343 #define LigatureSetFunc otv_x_Ox
344 #define PosClassSetFunc otv_x_Ox
345 #define PosRuleSetFunc otv_x_Ox
346 #define SubClassSetFunc otv_x_Ox
347 #define SubRuleSetFunc otv_x_Ox
350 otv_x_Ox ( FT_Bytes table
,
351 OTV_Validator valid
);
353 #define AlternateSubstFormat1Func otv_u_C_x_Ox
354 #define ChainContextPosFormat1Func otv_u_C_x_Ox
355 #define ChainContextSubstFormat1Func otv_u_C_x_Ox
356 #define ContextPosFormat1Func otv_u_C_x_Ox
357 #define ContextSubstFormat1Func otv_u_C_x_Ox
358 #define LigatureSubstFormat1Func otv_u_C_x_Ox
359 #define MultipleSubstFormat1Func otv_u_C_x_Ox
362 otv_u_C_x_Ox( FT_Bytes table
,
363 OTV_Validator valid
);
365 #define AlternateSetFunc otv_x_ux
366 #define AttachPointFunc otv_x_ux
367 #define ExtenderGlyphFunc otv_x_ux
368 #define JstfGPOSModListFunc otv_x_ux
369 #define JstfGSUBModListFunc otv_x_ux
370 #define SequenceFunc otv_x_ux
373 otv_x_ux( FT_Bytes table
,
374 OTV_Validator valid
);
376 #define PosClassRuleFunc otv_x_y_ux_sy
377 #define PosRuleFunc otv_x_y_ux_sy
378 #define SubClassRuleFunc otv_x_y_ux_sy
379 #define SubRuleFunc otv_x_y_ux_sy
382 otv_x_y_ux_sy( FT_Bytes table
,
383 OTV_Validator valid
);
385 #define ChainPosClassRuleFunc otv_x_ux_y_uy_z_uz_p_sp
386 #define ChainPosRuleFunc otv_x_ux_y_uy_z_uz_p_sp
387 #define ChainSubClassRuleFunc otv_x_ux_y_uy_z_uz_p_sp
388 #define ChainSubRuleFunc otv_x_ux_y_uy_z_uz_p_sp
391 otv_x_ux_y_uy_z_uz_p_sp( FT_Bytes table
,
392 OTV_Validator valid
);
394 #define ContextPosFormat2Func otv_u_O_O_x_Onx
395 #define ContextSubstFormat2Func otv_u_O_O_x_Onx
398 otv_u_O_O_x_Onx( FT_Bytes table
,
399 OTV_Validator valid
);
401 #define ContextPosFormat3Func otv_u_x_y_Ox_sy
402 #define ContextSubstFormat3Func otv_u_x_y_Ox_sy
405 otv_u_x_y_Ox_sy( FT_Bytes table
,
406 OTV_Validator valid
);
408 #define ChainContextPosFormat2Func otv_u_O_O_O_O_x_Onx
409 #define ChainContextSubstFormat2Func otv_u_O_O_O_O_x_Onx
412 otv_u_O_O_O_O_x_Onx( FT_Bytes table
,
413 OTV_Validator valid
);
415 #define ChainContextPosFormat3Func otv_u_x_Ox_y_Oy_z_Oz_p_sp
416 #define ChainContextSubstFormat3Func otv_u_x_Ox_y_Oy_z_Oz_p_sp
419 otv_u_x_Ox_y_Oy_z_Oz_p_sp( FT_Bytes table
,
420 OTV_Validator valid
);
424 otv_GSUBGPOS_get_Lookup_count( FT_Bytes table
);
427 otv_GSUBGPOS_have_MarkAttachmentType_flag( FT_Bytes table
);
433 #endif /* __OTVCOMMN_H__ */