1 /***************************************************************************/
5 /* OpenType common tables validation (specification). */
7 /* Copyright 2004, 2005, 2007, 2009 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'" \
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
,
219 FT_Int expected_count
);
221 /* return first covered glyph */
223 otv_Coverage_get_first( FT_Bytes table
);
225 /* return last covered glyph */
227 otv_Coverage_get_last( FT_Bytes table
);
229 /* return number of covered glyphs */
231 otv_Coverage_get_count( FT_Bytes table
);
234 /*************************************************************************/
235 /*************************************************************************/
237 /***** CLASS DEFINITION TABLE *****/
239 /*************************************************************************/
240 /*************************************************************************/
243 otv_ClassDef_validate( FT_Bytes table
,
244 OTV_Validator valid
);
247 /*************************************************************************/
248 /*************************************************************************/
250 /***** DEVICE TABLE *****/
252 /*************************************************************************/
253 /*************************************************************************/
256 otv_Device_validate( FT_Bytes table
,
257 OTV_Validator valid
);
260 /*************************************************************************/
261 /*************************************************************************/
263 /***** LOOKUPS *****/
265 /*************************************************************************/
266 /*************************************************************************/
269 otv_Lookup_validate( FT_Bytes table
,
270 OTV_Validator valid
);
273 otv_LookupList_validate( FT_Bytes table
,
274 OTV_Validator valid
);
277 /*************************************************************************/
278 /*************************************************************************/
280 /***** FEATURES *****/
282 /*************************************************************************/
283 /*************************************************************************/
286 otv_Feature_validate( FT_Bytes table
,
287 OTV_Validator valid
);
289 /* lookups must already be validated */
291 otv_FeatureList_validate( FT_Bytes table
,
293 OTV_Validator valid
);
296 /*************************************************************************/
297 /*************************************************************************/
299 /***** LANGUAGE SYSTEM *****/
301 /*************************************************************************/
302 /*************************************************************************/
305 otv_LangSys_validate( FT_Bytes table
,
306 OTV_Validator valid
);
309 /*************************************************************************/
310 /*************************************************************************/
312 /***** SCRIPTS *****/
314 /*************************************************************************/
315 /*************************************************************************/
318 otv_Script_validate( FT_Bytes table
,
319 OTV_Validator valid
);
321 /* features must already be validated */
323 otv_ScriptList_validate( FT_Bytes table
,
325 OTV_Validator valid
);
328 /*************************************************************************/
329 /*************************************************************************/
331 /***** UTILITY FUNCTIONS *****/
333 /*************************************************************************/
334 /*************************************************************************/
336 #define ChainPosClassSetFunc otv_x_Ox
337 #define ChainPosRuleSetFunc otv_x_Ox
338 #define ChainSubClassSetFunc otv_x_Ox
339 #define ChainSubRuleSetFunc otv_x_Ox
340 #define JstfLangSysFunc otv_x_Ox
341 #define JstfMaxFunc otv_x_Ox
342 #define LigGlyphFunc otv_x_Ox
343 #define LigatureArrayFunc otv_x_Ox
344 #define LigatureSetFunc otv_x_Ox
345 #define PosClassSetFunc otv_x_Ox
346 #define PosRuleSetFunc otv_x_Ox
347 #define SubClassSetFunc otv_x_Ox
348 #define SubRuleSetFunc otv_x_Ox
351 otv_x_Ox ( FT_Bytes table
,
352 OTV_Validator valid
);
354 #define AlternateSubstFormat1Func otv_u_C_x_Ox
355 #define ChainContextPosFormat1Func otv_u_C_x_Ox
356 #define ChainContextSubstFormat1Func otv_u_C_x_Ox
357 #define ContextPosFormat1Func otv_u_C_x_Ox
358 #define ContextSubstFormat1Func otv_u_C_x_Ox
359 #define LigatureSubstFormat1Func otv_u_C_x_Ox
360 #define MultipleSubstFormat1Func otv_u_C_x_Ox
363 otv_u_C_x_Ox( FT_Bytes table
,
364 OTV_Validator valid
);
366 #define AlternateSetFunc otv_x_ux
367 #define AttachPointFunc otv_x_ux
368 #define ExtenderGlyphFunc otv_x_ux
369 #define JstfGPOSModListFunc otv_x_ux
370 #define JstfGSUBModListFunc otv_x_ux
371 #define SequenceFunc otv_x_ux
374 otv_x_ux( FT_Bytes table
,
375 OTV_Validator valid
);
377 #define PosClassRuleFunc otv_x_y_ux_sy
378 #define PosRuleFunc otv_x_y_ux_sy
379 #define SubClassRuleFunc otv_x_y_ux_sy
380 #define SubRuleFunc otv_x_y_ux_sy
383 otv_x_y_ux_sy( FT_Bytes table
,
384 OTV_Validator valid
);
386 #define ChainPosClassRuleFunc otv_x_ux_y_uy_z_uz_p_sp
387 #define ChainPosRuleFunc otv_x_ux_y_uy_z_uz_p_sp
388 #define ChainSubClassRuleFunc otv_x_ux_y_uy_z_uz_p_sp
389 #define ChainSubRuleFunc otv_x_ux_y_uy_z_uz_p_sp
392 otv_x_ux_y_uy_z_uz_p_sp( FT_Bytes table
,
393 OTV_Validator valid
);
395 #define ContextPosFormat2Func otv_u_O_O_x_Onx
396 #define ContextSubstFormat2Func otv_u_O_O_x_Onx
399 otv_u_O_O_x_Onx( FT_Bytes table
,
400 OTV_Validator valid
);
402 #define ContextPosFormat3Func otv_u_x_y_Ox_sy
403 #define ContextSubstFormat3Func otv_u_x_y_Ox_sy
406 otv_u_x_y_Ox_sy( FT_Bytes table
,
407 OTV_Validator valid
);
409 #define ChainContextPosFormat2Func otv_u_O_O_O_O_x_Onx
410 #define ChainContextSubstFormat2Func otv_u_O_O_O_O_x_Onx
413 otv_u_O_O_O_O_x_Onx( FT_Bytes table
,
414 OTV_Validator valid
);
416 #define ChainContextPosFormat3Func otv_u_x_Ox_y_Oy_z_Oz_p_sp
417 #define ChainContextSubstFormat3Func otv_u_x_Ox_y_Oy_z_Oz_p_sp
420 otv_u_x_Ox_y_Oy_z_Oz_p_sp( FT_Bytes table
,
421 OTV_Validator valid
);
425 otv_GSUBGPOS_get_Lookup_count( FT_Bytes table
);
428 otv_GSUBGPOS_have_MarkAttachmentType_flag( FT_Bytes table
);
434 #endif /* __OTVCOMMN_H__ */