ReactOS  0.4.15-dev-499-g1f31905
ftvalid.h
Go to the documentation of this file.
1 /***************************************************************************/
2 /* */
3 /* ftvalid.h */
4 /* */
5 /* FreeType validation support (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 FTVALID_H_
20 #define FTVALID_H_
21 
22 #include <ft2build.h>
23 #include FT_CONFIG_STANDARD_LIBRARY_H /* for ft_setjmp and ft_longjmp */
24 
25 
27 
28 
29  /*************************************************************************/
30  /*************************************************************************/
31  /*************************************************************************/
32  /**** ****/
33  /**** ****/
34  /**** V A L I D A T I O N ****/
35  /**** ****/
36  /**** ****/
37  /*************************************************************************/
38  /*************************************************************************/
39  /*************************************************************************/
40 
41  /* handle to a validation object */
43 
44 
45  /*************************************************************************/
46  /* */
47  /* There are three distinct validation levels defined here: */
48  /* */
49  /* FT_VALIDATE_DEFAULT :: */
50  /* A table that passes this validation level can be used reliably by */
51  /* FreeType. It generally means that all offsets have been checked to */
52  /* prevent out-of-bound reads, that array counts are correct, etc. */
53  /* */
54  /* FT_VALIDATE_TIGHT :: */
55  /* A table that passes this validation level can be used reliably and */
56  /* doesn't contain invalid data. For example, a charmap table that */
57  /* returns invalid glyph indices will not pass, even though it can */
58  /* be used with FreeType in default mode (the library will simply */
59  /* return an error later when trying to load the glyph). */
60  /* */
61  /* It also checks that fields which must be a multiple of 2, 4, or 8, */
62  /* don't have incorrect values, etc. */
63  /* */
64  /* FT_VALIDATE_PARANOID :: */
65  /* Only for font debugging. Checks that a table follows the */
66  /* specification by 100%. Very few fonts will be able to pass this */
67  /* level anyway but it can be useful for certain tools like font */
68  /* editors/converters. */
69  /* */
70  typedef enum FT_ValidationLevel_
71  {
75 
77 
78 
79 #if defined( _MSC_VER ) /* Visual C++ (and Intel C++) */
80  /* We disable the warning `structure was padded due to */
81  /* __declspec(align())' in order to compile cleanly with */
82  /* the maximum level of warnings. */
83 #pragma warning( push )
84 #pragma warning( disable : 4324 )
85 #endif /* _MSC_VER */
86 
87  /* validator structure */
88  typedef struct FT_ValidatorRec_
89  {
90  ft_jmp_buf jump_buffer; /* used for exception handling */
91 
92  const FT_Byte* base; /* address of table in memory */
93  const FT_Byte* limit; /* `base' + sizeof(table) in memory */
94  FT_ValidationLevel level; /* validation level */
95  FT_Error error; /* error returned. 0 means success */
96 
98 
99 #if defined( _MSC_VER )
100 #pragma warning( pop )
101 #endif
102 
103 #define FT_VALIDATOR( x ) ( (FT_Validator)( x ) )
104 
105 
106  FT_BASE( void )
108  const FT_Byte* base,
109  const FT_Byte* limit,
111 
112  /* Do not use this. It's broken and will cause your validator to crash */
113  /* if you run it on an invalid font. */
114  FT_BASE( FT_Int )
116 
117  /* Sets the error field in a validator, then calls `longjmp' to return */
118  /* to high-level caller. Using `setjmp/longjmp' avoids many stupid */
119  /* error checks within the validation routines. */
120  /* */
121  FT_BASE( void )
123  FT_Error error );
124 
125 
126  /* Calls ft_validate_error. Assumes that the `valid' local variable */
127  /* holds a pointer to the current validator object. */
128  /* */
129 #define FT_INVALID( _error ) FT_INVALID_( _error )
130 #define FT_INVALID_( _error ) \
131  ft_validator_error( valid, FT_THROW( _error ) )
132 
133  /* called when a broken table is detected */
134 #define FT_INVALID_TOO_SHORT \
135  FT_INVALID( Invalid_Table )
136 
137  /* called when an invalid offset is detected */
138 #define FT_INVALID_OFFSET \
139  FT_INVALID( Invalid_Offset )
140 
141  /* called when an invalid format/value is detected */
142 #define FT_INVALID_FORMAT \
143  FT_INVALID( Invalid_Table )
144 
145  /* called when an invalid glyph index is detected */
146 #define FT_INVALID_GLYPH_ID \
147  FT_INVALID( Invalid_Glyph_Index )
148 
149  /* called when an invalid field value is detected */
150 #define FT_INVALID_DATA \
151  FT_INVALID( Invalid_Table )
152 
153 
155 
156 #endif /* FTVALID_H_ */
157 
158 
159 /* END */
#define ft_jmp_buf
Definition: ftstdlib.h:158
int FT_Error
Definition: fttypes.h:300
GLint level
Definition: gl.h:1546
FT_ValidationLevel level
Definition: ftvalid.h:94
#define error(str)
Definition: mkdosfs.c:1605
struct FT_ValidatorRec_ FT_ValidatorRec
#define FT_END_HEADER
Definition: ftheader.h:54
signed int FT_Int
Definition: fttypes.h:220
enum FT_ValidationLevel_ FT_ValidationLevel
ft_jmp_buf jump_buffer
Definition: ftvalid.h:90
ft_validator_run(FT_Validator valid)
Definition: ftobjs.c:135
GLint limit
Definition: glext.h:10326
unsigned char FT_Byte
Definition: fttypes.h:154
#define FT_BEGIN_HEADER
Definition: ftheader.h:36
#define volatile
Definition: prototyp.h:117
FT_ValidationLevel_
Definition: ftvalid.h:70
typedefFT_BEGIN_HEADER struct FT_ValidatorRec_ volatile * FT_Validator
Definition: ftvalid.h:42
ft_validator_error(FT_Validator valid, FT_Error error)
Definition: ftobjs.c:145
const FT_Byte * limit
Definition: ftvalid.h:93
FT_Error error
Definition: ftvalid.h:95
ft_validator_init(FT_Validator valid, const FT_Byte *base, const FT_Byte *limit, FT_ValidationLevel level)
Definition: ftobjs.c:122
const FT_Byte * base
Definition: ftvalid.h:92
#define FT_BASE(x)
Definition: ftconfig.h:408