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