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