- Merge from trunk up to r45543
[reactos.git] / lib / 3rdparty / freetype / src / otvalid / otvmod.c
1 /***************************************************************************/
2 /* */
3 /* otvmod.c */
4 /* */
5 /* FreeType's OpenType validation module implementation (body). */
6 /* */
7 /* Copyright 2004, 2005, 2006 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 #include <ft2build.h>
20 #include FT_TRUETYPE_TABLES_H
21 #include FT_TRUETYPE_TAGS_H
22 #include FT_OPENTYPE_VALIDATE_H
23 #include FT_INTERNAL_OBJECTS_H
24 #include FT_SERVICE_OPENTYPE_VALIDATE_H
25
26 #include "otvmod.h"
27 #include "otvalid.h"
28 #include "otvcommn.h"
29
30
31 /*************************************************************************/
32 /* */
33 /* The macro FT_COMPONENT is used in trace mode. It is an implicit */
34 /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */
35 /* messages during execution. */
36 /* */
37 #undef FT_COMPONENT
38 #define FT_COMPONENT trace_otvmodule
39
40
41 static FT_Error
42 otv_load_table( FT_Face face,
43 FT_Tag tag,
44 FT_Byte* volatile* table,
45 FT_ULong* table_len )
46 {
47 FT_Error error;
48 FT_Memory memory = FT_FACE_MEMORY( face );
49
50
51 error = FT_Load_Sfnt_Table( face, tag, 0, NULL, table_len );
52 if ( error == OTV_Err_Table_Missing )
53 return OTV_Err_Ok;
54 if ( error )
55 goto Exit;
56
57 if ( FT_ALLOC( *table, *table_len ) )
58 goto Exit;
59
60 error = FT_Load_Sfnt_Table( face, tag, 0, *table, table_len );
61
62 Exit:
63 return error;
64 }
65
66
67 static FT_Error
68 otv_validate( FT_Face volatile face,
69 FT_UInt ot_flags,
70 FT_Bytes *ot_base,
71 FT_Bytes *ot_gdef,
72 FT_Bytes *ot_gpos,
73 FT_Bytes *ot_gsub,
74 FT_Bytes *ot_jstf )
75 {
76 FT_Error error = OTV_Err_Ok;
77 FT_Byte* volatile base;
78 FT_Byte* volatile gdef;
79 FT_Byte* volatile gpos;
80 FT_Byte* volatile gsub;
81 FT_Byte* volatile jstf;
82 FT_ULong len_base, len_gdef, len_gpos, len_gsub, len_jstf;
83 FT_ValidatorRec volatile valid;
84
85
86 base = gdef = gpos = gsub = jstf = NULL;
87 len_base = len_gdef = len_gpos = len_gsub = len_jstf = 0;
88
89 /* load tables */
90
91 if ( ot_flags & FT_VALIDATE_BASE )
92 {
93 error = otv_load_table( face, TTAG_BASE, &base, &len_base );
94 if ( error )
95 goto Exit;
96 }
97
98 if ( ot_flags & FT_VALIDATE_GDEF )
99 {
100 error = otv_load_table( face, TTAG_GDEF, &gdef, &len_gdef );
101 if ( error )
102 goto Exit;
103 }
104
105 if ( ot_flags & FT_VALIDATE_GPOS )
106 {
107 error = otv_load_table( face, TTAG_GPOS, &gpos, &len_gpos );
108 if ( error )
109 goto Exit;
110 }
111
112 if ( ot_flags & FT_VALIDATE_GSUB )
113 {
114 error = otv_load_table( face, TTAG_GSUB, &gsub, &len_gsub );
115 if ( error )
116 goto Exit;
117 }
118
119 if ( ot_flags & FT_VALIDATE_JSTF )
120 {
121 error = otv_load_table( face, TTAG_JSTF, &jstf, &len_jstf );
122 if ( error )
123 goto Exit;
124 }
125
126 /* validate tables */
127
128 if ( base )
129 {
130 ft_validator_init( &valid, base, base + len_base, FT_VALIDATE_DEFAULT );
131 if ( ft_setjmp( valid.jump_buffer ) == 0 )
132 otv_BASE_validate( base, &valid );
133 error = valid.error;
134 if ( error )
135 goto Exit;
136 }
137
138 if ( gpos )
139 {
140 ft_validator_init( &valid, gpos, gpos + len_gpos, FT_VALIDATE_DEFAULT );
141 if ( ft_setjmp( valid.jump_buffer ) == 0 )
142 otv_GPOS_validate( gpos, face->num_glyphs, &valid );
143 error = valid.error;
144 if ( error )
145 goto Exit;
146 }
147
148 if ( gsub )
149 {
150 ft_validator_init( &valid, gsub, gsub + len_gsub, FT_VALIDATE_DEFAULT );
151 if ( ft_setjmp( valid.jump_buffer ) == 0 )
152 otv_GSUB_validate( gsub, face->num_glyphs, &valid );
153 error = valid.error;
154 if ( error )
155 goto Exit;
156 }
157
158 if ( gdef )
159 {
160 ft_validator_init( &valid, gdef, gdef + len_gdef, FT_VALIDATE_DEFAULT );
161 if ( ft_setjmp( valid.jump_buffer ) == 0 )
162 otv_GDEF_validate( gdef, gsub, gpos, &valid );
163 error = valid.error;
164 if ( error )
165 goto Exit;
166 }
167
168 if ( jstf )
169 {
170 ft_validator_init( &valid, jstf, jstf + len_jstf, FT_VALIDATE_DEFAULT );
171 if ( ft_setjmp( valid.jump_buffer ) == 0 )
172 otv_JSTF_validate( jstf, gsub, gpos, face->num_glyphs, &valid );
173 error = valid.error;
174 if ( error )
175 goto Exit;
176 }
177
178 *ot_base = (FT_Bytes)base;
179 *ot_gdef = (FT_Bytes)gdef;
180 *ot_gpos = (FT_Bytes)gpos;
181 *ot_gsub = (FT_Bytes)gsub;
182 *ot_jstf = (FT_Bytes)jstf;
183
184 Exit:
185 if ( error ) {
186 FT_Memory memory = FT_FACE_MEMORY( face );
187
188
189 FT_FREE( base );
190 FT_FREE( gdef );
191 FT_FREE( gpos );
192 FT_FREE( gsub );
193 FT_FREE( jstf );
194 }
195
196 return error;
197 }
198
199
200 static
201 const FT_Service_OTvalidateRec otvalid_interface =
202 {
203 otv_validate
204 };
205
206
207 static
208 const FT_ServiceDescRec otvalid_services[] =
209 {
210 { FT_SERVICE_ID_OPENTYPE_VALIDATE, &otvalid_interface },
211 { NULL, NULL }
212 };
213
214
215 static FT_Pointer
216 otvalid_get_service( FT_Module module,
217 const char* service_id )
218 {
219 FT_UNUSED( module );
220
221 return ft_service_list_lookup( otvalid_services, service_id );
222 }
223
224
225 FT_CALLBACK_TABLE_DEF
226 const FT_Module_Class otv_module_class =
227 {
228 0,
229 sizeof( FT_ModuleRec ),
230 "otvalid",
231 0x10000L,
232 0x20000L,
233
234 0, /* module-specific interface */
235
236 (FT_Module_Constructor)0,
237 (FT_Module_Destructor) 0,
238 (FT_Module_Requester) otvalid_get_service
239 };
240
241
242 /* END */