1 | /**************************************************************************** |
2 | * |
3 | * otvcommn.h |
4 | * |
5 | * OpenType common tables validation (specification). |
6 | * |
7 | * Copyright (C) 2004-2023 by |
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 | #ifndef OTVCOMMN_H_ |
20 | #define OTVCOMMN_H_ |
21 | |
22 | |
23 | #include "otvalid.h" |
24 | #include <freetype/internal/ftdebug.h> |
25 | |
26 | |
27 | FT_BEGIN_HEADER |
28 | |
29 | |
30 | /*************************************************************************/ |
31 | /*************************************************************************/ |
32 | /***** *****/ |
33 | /***** VALIDATION *****/ |
34 | /***** *****/ |
35 | /*************************************************************************/ |
36 | /*************************************************************************/ |
37 | |
38 | typedef struct OTV_ValidatorRec_* OTV_Validator; |
39 | |
40 | typedef void (*OTV_Validate_Func)( FT_Bytes table, |
41 | OTV_Validator otvalid ); |
42 | |
43 | typedef struct OTV_ValidatorRec_ |
44 | { |
45 | FT_Validator root; |
46 | FT_UInt type_count; |
47 | OTV_Validate_Func* type_funcs; |
48 | |
49 | FT_UInt lookup_count; |
50 | FT_UInt glyph_count; |
51 | |
52 | FT_UInt nesting_level; |
53 | |
54 | OTV_Validate_Func func[3]; |
55 | |
56 | FT_UInt ; /* for passing parameters */ |
57 | FT_UInt ; |
58 | FT_Bytes ; |
59 | |
60 | #ifdef FT_DEBUG_LEVEL_TRACE |
61 | FT_UInt debug_indent; |
62 | const FT_String* debug_function_name[3]; |
63 | #endif |
64 | |
65 | } OTV_ValidatorRec; |
66 | |
67 | |
68 | #undef FT_INVALID_ |
69 | #define FT_INVALID_( _error ) \ |
70 | ft_validator_error( otvalid->root, FT_THROW( _error ) ) |
71 | |
72 | #define OTV_OPTIONAL_TABLE( _table ) FT_UShort _table; \ |
73 | FT_Bytes _table ## _p |
74 | |
75 | #define OTV_OPTIONAL_TABLE32( _table ) FT_ULong _table; \ |
76 | FT_Bytes _table ## _p |
77 | |
78 | #define OTV_OPTIONAL_OFFSET( _offset ) \ |
79 | FT_BEGIN_STMNT \ |
80 | _offset ## _p = p; \ |
81 | _offset = FT_NEXT_USHORT( p ); \ |
82 | FT_END_STMNT |
83 | |
84 | #define OTV_OPTIONAL_OFFSET32( _offset ) \ |
85 | FT_BEGIN_STMNT \ |
86 | _offset ## _p = p; \ |
87 | _offset = FT_NEXT_ULONG( p ); \ |
88 | FT_END_STMNT |
89 | |
90 | #define OTV_LIMIT_CHECK( _count ) \ |
91 | FT_BEGIN_STMNT \ |
92 | if ( p + (_count) > otvalid->root->limit ) \ |
93 | FT_INVALID_TOO_SHORT; \ |
94 | FT_END_STMNT |
95 | |
96 | #define OTV_SIZE_CHECK( _size ) \ |
97 | FT_BEGIN_STMNT \ |
98 | if ( _size > 0 && _size < table_size ) \ |
99 | { \ |
100 | if ( otvalid->root->level == FT_VALIDATE_PARANOID ) \ |
101 | FT_INVALID_OFFSET; \ |
102 | else \ |
103 | { \ |
104 | /* strip off `const' */ \ |
105 | FT_Byte* pp = (FT_Byte*)_size ## _p; \ |
106 | \ |
107 | \ |
108 | FT_TRACE3(( "\n" )); \ |
109 | FT_TRACE3(( "Invalid offset to optional table `%s'" \ |
110 | " set to zero.\n", \ |
111 | #_size )); \ |
112 | FT_TRACE3(( "\n" )); \ |
113 | \ |
114 | _size = pp[0] = pp[1] = 0; \ |
115 | } \ |
116 | } \ |
117 | FT_END_STMNT |
118 | |
119 | #define OTV_SIZE_CHECK32( _size ) \ |
120 | FT_BEGIN_STMNT \ |
121 | if ( _size > 0 && _size < table_size ) \ |
122 | { \ |
123 | if ( otvalid->root->level == FT_VALIDATE_PARANOID ) \ |
124 | FT_INVALID_OFFSET; \ |
125 | else \ |
126 | { \ |
127 | /* strip off `const' */ \ |
128 | FT_Byte* pp = (FT_Byte*)_size ## _p; \ |
129 | \ |
130 | \ |
131 | FT_TRACE3(( "\n" )); \ |
132 | FT_TRACE3(( "Invalid offset to optional table `%s'" \ |
133 | " set to zero.\n", \ |
134 | #_size )); \ |
135 | FT_TRACE3(( "\n" )); \ |
136 | \ |
137 | _size = pp[0] = pp[1] = pp[2] = pp[3] = 0; \ |
138 | } \ |
139 | } \ |
140 | FT_END_STMNT |
141 | |
142 | |
143 | #define OTV_NAME_(x) #x |
144 | #define OTV_NAME(x) OTV_NAME_(x) |
145 | |
146 | #define OTV_FUNC_(x) x##Func |
147 | #define OTV_FUNC(x) OTV_FUNC_(x) |
148 | |
149 | #ifdef FT_DEBUG_LEVEL_TRACE |
150 | |
151 | #define OTV_NEST1( x ) \ |
152 | FT_BEGIN_STMNT \ |
153 | otvalid->nesting_level = 0; \ |
154 | otvalid->func[0] = OTV_FUNC( x ); \ |
155 | otvalid->debug_function_name[0] = OTV_NAME( x ); \ |
156 | FT_END_STMNT |
157 | |
158 | #define OTV_NEST2( x, y ) \ |
159 | FT_BEGIN_STMNT \ |
160 | otvalid->nesting_level = 0; \ |
161 | otvalid->func[0] = OTV_FUNC( x ); \ |
162 | otvalid->func[1] = OTV_FUNC( y ); \ |
163 | otvalid->debug_function_name[0] = OTV_NAME( x ); \ |
164 | otvalid->debug_function_name[1] = OTV_NAME( y ); \ |
165 | FT_END_STMNT |
166 | |
167 | #define OTV_NEST3( x, y, z ) \ |
168 | FT_BEGIN_STMNT \ |
169 | otvalid->nesting_level = 0; \ |
170 | otvalid->func[0] = OTV_FUNC( x ); \ |
171 | otvalid->func[1] = OTV_FUNC( y ); \ |
172 | otvalid->func[2] = OTV_FUNC( z ); \ |
173 | otvalid->debug_function_name[0] = OTV_NAME( x ); \ |
174 | otvalid->debug_function_name[1] = OTV_NAME( y ); \ |
175 | otvalid->debug_function_name[2] = OTV_NAME( z ); \ |
176 | FT_END_STMNT |
177 | |
178 | #define OTV_INIT otvalid->debug_indent = 0 |
179 | |
180 | #define OTV_ENTER \ |
181 | FT_BEGIN_STMNT \ |
182 | otvalid->debug_indent += 2; \ |
183 | FT_TRACE4(( "%*.s", otvalid->debug_indent, "" )); \ |
184 | FT_TRACE4(( "%s table\n", \ |
185 | otvalid->debug_function_name[otvalid->nesting_level] )); \ |
186 | FT_END_STMNT |
187 | |
188 | #define OTV_NAME_ENTER( name ) \ |
189 | FT_BEGIN_STMNT \ |
190 | otvalid->debug_indent += 2; \ |
191 | FT_TRACE4(( "%*.s", otvalid->debug_indent, "" )); \ |
192 | FT_TRACE4(( "%s table\n", name )); \ |
193 | FT_END_STMNT |
194 | |
195 | #define OTV_EXIT otvalid->debug_indent -= 2 |
196 | |
197 | #define OTV_TRACE( s ) \ |
198 | FT_BEGIN_STMNT \ |
199 | FT_TRACE4(( "%*.s", otvalid->debug_indent, "" )); \ |
200 | FT_TRACE4( s ); \ |
201 | FT_END_STMNT |
202 | |
203 | #else /* !FT_DEBUG_LEVEL_TRACE */ |
204 | |
205 | #define OTV_NEST1( x ) \ |
206 | FT_BEGIN_STMNT \ |
207 | otvalid->nesting_level = 0; \ |
208 | otvalid->func[0] = OTV_FUNC( x ); \ |
209 | FT_END_STMNT |
210 | |
211 | #define OTV_NEST2( x, y ) \ |
212 | FT_BEGIN_STMNT \ |
213 | otvalid->nesting_level = 0; \ |
214 | otvalid->func[0] = OTV_FUNC( x ); \ |
215 | otvalid->func[1] = OTV_FUNC( y ); \ |
216 | FT_END_STMNT |
217 | |
218 | #define OTV_NEST3( x, y, z ) \ |
219 | FT_BEGIN_STMNT \ |
220 | otvalid->nesting_level = 0; \ |
221 | otvalid->func[0] = OTV_FUNC( x ); \ |
222 | otvalid->func[1] = OTV_FUNC( y ); \ |
223 | otvalid->func[2] = OTV_FUNC( z ); \ |
224 | FT_END_STMNT |
225 | |
226 | #define OTV_INIT do { } while ( 0 ) |
227 | #define OTV_ENTER do { } while ( 0 ) |
228 | #define OTV_NAME_ENTER( name ) do { } while ( 0 ) |
229 | #define OTV_EXIT do { } while ( 0 ) |
230 | |
231 | #define OTV_TRACE( s ) do { } while ( 0 ) |
232 | |
233 | #endif /* !FT_DEBUG_LEVEL_TRACE */ |
234 | |
235 | |
236 | #define OTV_RUN otvalid->func[0] |
237 | |
238 | |
239 | /*************************************************************************/ |
240 | /*************************************************************************/ |
241 | /***** *****/ |
242 | /***** COVERAGE TABLE *****/ |
243 | /***** *****/ |
244 | /*************************************************************************/ |
245 | /*************************************************************************/ |
246 | |
247 | FT_LOCAL( void ) |
248 | otv_Coverage_validate( FT_Bytes table, |
249 | OTV_Validator otvalid, |
250 | FT_Int expected_count ); |
251 | |
252 | /* return first covered glyph */ |
253 | FT_LOCAL( FT_UInt ) |
254 | otv_Coverage_get_first( FT_Bytes table ); |
255 | |
256 | /* return last covered glyph */ |
257 | FT_LOCAL( FT_UInt ) |
258 | otv_Coverage_get_last( FT_Bytes table ); |
259 | |
260 | /* return number of covered glyphs */ |
261 | FT_LOCAL( FT_UInt ) |
262 | otv_Coverage_get_count( FT_Bytes table ); |
263 | |
264 | |
265 | /*************************************************************************/ |
266 | /*************************************************************************/ |
267 | /***** *****/ |
268 | /***** CLASS DEFINITION TABLE *****/ |
269 | /***** *****/ |
270 | /*************************************************************************/ |
271 | /*************************************************************************/ |
272 | |
273 | FT_LOCAL( void ) |
274 | otv_ClassDef_validate( FT_Bytes table, |
275 | OTV_Validator otvalid ); |
276 | |
277 | |
278 | /*************************************************************************/ |
279 | /*************************************************************************/ |
280 | /***** *****/ |
281 | /***** DEVICE TABLE *****/ |
282 | /***** *****/ |
283 | /*************************************************************************/ |
284 | /*************************************************************************/ |
285 | |
286 | FT_LOCAL( void ) |
287 | otv_Device_validate( FT_Bytes table, |
288 | OTV_Validator otvalid ); |
289 | |
290 | |
291 | /*************************************************************************/ |
292 | /*************************************************************************/ |
293 | /***** *****/ |
294 | /***** LOOKUPS *****/ |
295 | /***** *****/ |
296 | /*************************************************************************/ |
297 | /*************************************************************************/ |
298 | |
299 | FT_LOCAL( void ) |
300 | otv_Lookup_validate( FT_Bytes table, |
301 | OTV_Validator otvalid ); |
302 | |
303 | FT_LOCAL( void ) |
304 | otv_LookupList_validate( FT_Bytes table, |
305 | OTV_Validator otvalid ); |
306 | |
307 | |
308 | /*************************************************************************/ |
309 | /*************************************************************************/ |
310 | /***** *****/ |
311 | /***** FEATURES *****/ |
312 | /***** *****/ |
313 | /*************************************************************************/ |
314 | /*************************************************************************/ |
315 | |
316 | FT_LOCAL( void ) |
317 | otv_Feature_validate( FT_Bytes table, |
318 | OTV_Validator otvalid ); |
319 | |
320 | /* lookups must already be validated */ |
321 | FT_LOCAL( void ) |
322 | otv_FeatureList_validate( FT_Bytes table, |
323 | FT_Bytes lookups, |
324 | OTV_Validator otvalid ); |
325 | |
326 | |
327 | /*************************************************************************/ |
328 | /*************************************************************************/ |
329 | /***** *****/ |
330 | /***** LANGUAGE SYSTEM *****/ |
331 | /***** *****/ |
332 | /*************************************************************************/ |
333 | /*************************************************************************/ |
334 | |
335 | FT_LOCAL( void ) |
336 | otv_LangSys_validate( FT_Bytes table, |
337 | OTV_Validator otvalid ); |
338 | |
339 | |
340 | /*************************************************************************/ |
341 | /*************************************************************************/ |
342 | /***** *****/ |
343 | /***** SCRIPTS *****/ |
344 | /***** *****/ |
345 | /*************************************************************************/ |
346 | /*************************************************************************/ |
347 | |
348 | FT_LOCAL( void ) |
349 | otv_Script_validate( FT_Bytes table, |
350 | OTV_Validator otvalid ); |
351 | |
352 | /* features must already be validated */ |
353 | FT_LOCAL( void ) |
354 | otv_ScriptList_validate( FT_Bytes table, |
355 | FT_Bytes features, |
356 | OTV_Validator otvalid ); |
357 | |
358 | |
359 | /*************************************************************************/ |
360 | /*************************************************************************/ |
361 | /***** *****/ |
362 | /***** UTILITY FUNCTIONS *****/ |
363 | /***** *****/ |
364 | /*************************************************************************/ |
365 | /*************************************************************************/ |
366 | |
367 | #define ChainPosClassSetFunc otv_x_Ox |
368 | #define ChainPosRuleSetFunc otv_x_Ox |
369 | #define ChainSubClassSetFunc otv_x_Ox |
370 | #define ChainSubRuleSetFunc otv_x_Ox |
371 | #define JstfLangSysFunc otv_x_Ox |
372 | #define JstfMaxFunc otv_x_Ox |
373 | #define LigGlyphFunc otv_x_Ox |
374 | #define LigatureArrayFunc otv_x_Ox |
375 | #define LigatureSetFunc otv_x_Ox |
376 | #define PosClassSetFunc otv_x_Ox |
377 | #define PosRuleSetFunc otv_x_Ox |
378 | #define SubClassSetFunc otv_x_Ox |
379 | #define SubRuleSetFunc otv_x_Ox |
380 | |
381 | FT_LOCAL( void ) |
382 | otv_x_Ox ( FT_Bytes table, |
383 | OTV_Validator otvalid ); |
384 | |
385 | #define AlternateSubstFormat1Func otv_u_C_x_Ox |
386 | #define ChainContextPosFormat1Func otv_u_C_x_Ox |
387 | #define ChainContextSubstFormat1Func otv_u_C_x_Ox |
388 | #define ContextPosFormat1Func otv_u_C_x_Ox |
389 | #define ContextSubstFormat1Func otv_u_C_x_Ox |
390 | #define LigatureSubstFormat1Func otv_u_C_x_Ox |
391 | #define MultipleSubstFormat1Func otv_u_C_x_Ox |
392 | |
393 | FT_LOCAL( void ) |
394 | otv_u_C_x_Ox( FT_Bytes table, |
395 | OTV_Validator otvalid ); |
396 | |
397 | #define AlternateSetFunc otv_x_ux |
398 | #define AttachPointFunc otv_x_ux |
399 | #define ExtenderGlyphFunc otv_x_ux |
400 | #define JstfGPOSModListFunc otv_x_ux |
401 | #define JstfGSUBModListFunc otv_x_ux |
402 | #define SequenceFunc otv_x_ux |
403 | |
404 | FT_LOCAL( void ) |
405 | otv_x_ux( FT_Bytes table, |
406 | OTV_Validator otvalid ); |
407 | |
408 | #define PosClassRuleFunc otv_x_y_ux_sy |
409 | #define PosRuleFunc otv_x_y_ux_sy |
410 | #define SubClassRuleFunc otv_x_y_ux_sy |
411 | #define SubRuleFunc otv_x_y_ux_sy |
412 | |
413 | FT_LOCAL( void ) |
414 | otv_x_y_ux_sy( FT_Bytes table, |
415 | OTV_Validator otvalid ); |
416 | |
417 | #define ChainPosClassRuleFunc otv_x_ux_y_uy_z_uz_p_sp |
418 | #define ChainPosRuleFunc otv_x_ux_y_uy_z_uz_p_sp |
419 | #define ChainSubClassRuleFunc otv_x_ux_y_uy_z_uz_p_sp |
420 | #define ChainSubRuleFunc otv_x_ux_y_uy_z_uz_p_sp |
421 | |
422 | FT_LOCAL( void ) |
423 | otv_x_ux_y_uy_z_uz_p_sp( FT_Bytes table, |
424 | OTV_Validator otvalid ); |
425 | |
426 | #define ContextPosFormat2Func otv_u_O_O_x_Onx |
427 | #define ContextSubstFormat2Func otv_u_O_O_x_Onx |
428 | |
429 | FT_LOCAL( void ) |
430 | otv_u_O_O_x_Onx( FT_Bytes table, |
431 | OTV_Validator otvalid ); |
432 | |
433 | #define ContextPosFormat3Func otv_u_x_y_Ox_sy |
434 | #define ContextSubstFormat3Func otv_u_x_y_Ox_sy |
435 | |
436 | FT_LOCAL( void ) |
437 | otv_u_x_y_Ox_sy( FT_Bytes table, |
438 | OTV_Validator otvalid ); |
439 | |
440 | #define ChainContextPosFormat2Func otv_u_O_O_O_O_x_Onx |
441 | #define ChainContextSubstFormat2Func otv_u_O_O_O_O_x_Onx |
442 | |
443 | FT_LOCAL( void ) |
444 | otv_u_O_O_O_O_x_Onx( FT_Bytes table, |
445 | OTV_Validator otvalid ); |
446 | |
447 | #define ChainContextPosFormat3Func otv_u_x_Ox_y_Oy_z_Oz_p_sp |
448 | #define ChainContextSubstFormat3Func otv_u_x_Ox_y_Oy_z_Oz_p_sp |
449 | |
450 | FT_LOCAL( void ) |
451 | otv_u_x_Ox_y_Oy_z_Oz_p_sp( FT_Bytes table, |
452 | OTV_Validator otvalid ); |
453 | |
454 | |
455 | FT_LOCAL( FT_UInt ) |
456 | otv_GSUBGPOS_get_Lookup_count( FT_Bytes table ); |
457 | |
458 | FT_LOCAL( FT_UInt ) |
459 | otv_GSUBGPOS_have_MarkAttachmentType_flag( FT_Bytes table ); |
460 | |
461 | /* */ |
462 | |
463 | FT_END_HEADER |
464 | |
465 | #endif /* OTVCOMMN_H_ */ |
466 | |
467 | |
468 | /* END */ |
469 | |