ReactOS 0.4.16-dev-297-gc569aee
gxvprop.c
Go to the documentation of this file.
1/***************************************************************************/
2/* */
3/* gxvprop.c */
4/* */
5/* TrueTypeGX/AAT prop table validation (body). */
6/* */
7/* Copyright 2004-2018 by */
8/* suzuki toshiya, Masatake YAMATO, Red Hat K.K., */
9/* David Turner, Robert Wilhelm, and Werner Lemberg. */
10/* */
11/* This file is part of the FreeType project, and may only be used, */
12/* modified, and distributed under the terms of the FreeType project */
13/* license, LICENSE.TXT. By continuing to use, modify, or distribute */
14/* this file you indicate that you have read the license and */
15/* understand and accept it fully. */
16/* */
17/***************************************************************************/
18
19/***************************************************************************/
20/* */
21/* gxvalid is derived from both gxlayout module and otvalid module. */
22/* Development of gxlayout is supported by the Information-technology */
23/* Promotion Agency(IPA), Japan. */
24/* */
25/***************************************************************************/
26
27
28#include "gxvalid.h"
29#include "gxvcommn.h"
30
31
32 /*************************************************************************/
33 /* */
34 /* The macro FT_COMPONENT is used in trace mode. It is an implicit */
35 /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */
36 /* messages during execution. */
37 /* */
38#undef FT_COMPONENT
39#define FT_COMPONENT trace_gxvprop
40
41
42 /*************************************************************************/
43 /*************************************************************************/
44 /***** *****/
45 /***** Data and Types *****/
46 /***** *****/
47 /*************************************************************************/
48 /*************************************************************************/
49
50#define GXV_PROP_HEADER_SIZE ( 4 + 2 + 2 )
51#define GXV_PROP_SIZE_MIN GXV_PROP_HEADER_SIZE
52
53 typedef struct GXV_prop_DataRec_
54 {
56
58
59#define GXV_PROP_DATA( field ) GXV_TABLE_DATA( prop, field )
60
61#define GXV_PROP_FLOATER 0x8000U
62#define GXV_PROP_USE_COMPLEMENTARY_BRACKET 0x1000U
63#define GXV_PROP_COMPLEMENTARY_BRACKET_OFFSET 0x0F00U
64#define GXV_PROP_ATTACHING_TO_RIGHT 0x0080U
65#define GXV_PROP_RESERVED 0x0060U
66#define GXV_PROP_DIRECTIONALITY_CLASS 0x001FU
67
68
69 /*************************************************************************/
70 /*************************************************************************/
71 /***** *****/
72 /***** UTILITY FUNCTIONS *****/
73 /***** *****/
74 /*************************************************************************/
75 /*************************************************************************/
76
77 static void
79 GXV_Validator gxvalid )
80 {
83 FT_GlyphSlot glyph;
84
85
86 GXV_NAME_ENTER( "zero advance" );
87
88 face = gxvalid->face;
89
91 gid,
93 if ( error )
95
96 glyph = face->glyph;
97
98 if ( glyph->advance.x != (FT_Pos)0 ||
99 glyph->advance.y != (FT_Pos)0 )
100 {
101 GXV_TRACE(( " found non-zero advance in zero-advance glyph\n" ));
103 }
104
105 GXV_EXIT;
106 }
107
108
109 /* Pass 0 as GLYPH to check the default property */
110 static void
112 FT_UShort glyph,
113 GXV_Validator gxvalid )
114 {
115 if ( glyph != 0 && ( property & GXV_PROP_FLOATER ) )
116 gxv_prop_zero_advance_validate( glyph, gxvalid );
117
119 {
121 char complement;
122
123
125 if ( offset == 0 )
126 {
127 GXV_TRACE(( " found zero offset to property\n" ));
129 }
130
131 complement = (char)( offset >> 8 );
132 if ( complement & 0x08 )
133 {
134 /* Top bit is set: negative */
135
136 /* Calculate the absolute offset */
137 complement = (char)( ( complement & 0x07 ) + 1 );
138
139 /* The gid for complement must be greater than 0 */
140 if ( glyph <= complement )
141 {
142 GXV_TRACE(( " found non-positive glyph complement\n" ));
144 }
145 }
146 else
147 {
148 /* The gid for complement must be the face. */
149 gxv_glyphid_validate( (FT_UShort)( glyph + complement ), gxvalid );
150 }
151 }
152 else
153 {
155 GXV_TRACE(( "glyph %d cannot have complementary bracketing\n",
156 glyph ));
157 }
158
159 /* this is introduced in version 2.0 */
161 {
162 if ( GXV_PROP_DATA( version ) == 0x00010000UL )
163 {
164 GXV_TRACE(( " found older version (1.0) in new version table\n" ));
166 }
167 }
168
170 {
171 GXV_TRACE(( " found non-zero bits in reserved bits\n" ));
173 }
174
176 {
177 /* TODO: Too restricted. Use the validation level. */
178 if ( GXV_PROP_DATA( version ) == 0x00010000UL ||
179 GXV_PROP_DATA( version ) == 0x00020000UL )
180 {
181 GXV_TRACE(( " found too old version in directionality class\n" ));
183 }
184 }
185 }
186
187
188 static void
190 GXV_LookupValueCPtr value_p,
191 GXV_Validator gxvalid )
192 {
193 gxv_prop_property_validate( value_p->u, glyph, gxvalid );
194 }
195
196
197 /*
198 +===============+ --------+
199 | lookup header | |
200 +===============+ |
201 | BinSrchHeader | |
202 +===============+ |
203 | lastGlyph[0] | |
204 +---------------+ |
205 | firstGlyph[0] | | head of lookup table
206 +---------------+ | +
207 | offset[0] | -> | offset [byte]
208 +===============+ | +
209 | lastGlyph[1] | | (glyphID - firstGlyph) * 2 [byte]
210 +---------------+ |
211 | firstGlyph[1] | |
212 +---------------+ |
213 | offset[1] | |
214 +===============+ |
215 |
216 ... |
217 |
218 16bit value array |
219 +===============+ |
220 | value | <-------+
221 ...
222 */
223
226 GXV_LookupValueCPtr base_value_p,
227 FT_Bytes lookuptbl_limit,
228 GXV_Validator gxvalid )
229 {
230 FT_Bytes p;
234
235 /* XXX: check range? */
236 offset = (FT_UShort)( base_value_p->u +
237 relative_gindex * sizeof ( FT_UShort ) );
238 p = gxvalid->lookuptbl_head + offset;
239 limit = lookuptbl_limit;
240
241 GXV_LIMIT_CHECK ( 2 );
242 value.u = FT_NEXT_USHORT( p );
243
244 return value;
245 }
246
247
248 /*************************************************************************/
249 /*************************************************************************/
250 /***** *****/
251 /***** prop TABLE *****/
252 /***** *****/
253 /*************************************************************************/
254 /*************************************************************************/
255
256 FT_LOCAL_DEF( void )
259 FT_Validator ftvalid )
260 {
261 FT_Bytes p = table;
262 FT_Bytes limit = 0;
263 GXV_ValidatorRec gxvalidrec;
264 GXV_Validator gxvalid = &gxvalidrec;
265
266 GXV_prop_DataRec proprec;
267 GXV_prop_Data prop = &proprec;
268
271 FT_UShort defaultProp;
272
273
274 gxvalid->root = ftvalid;
275 gxvalid->table_data = prop;
276 gxvalid->face = face;
277
278 FT_TRACE3(( "validating `prop' table\n" ));
279 GXV_INIT;
280
281 GXV_LIMIT_CHECK( 4 + 2 + 2 );
284 defaultProp = FT_NEXT_USHORT( p );
285
286 GXV_TRACE(( " version 0x%08x\n", version ));
287 GXV_TRACE(( " format 0x%04x\n", format ));
288 GXV_TRACE(( " defaultProp 0x%04x\n", defaultProp ));
289
290 /* only versions 1.0, 2.0, 3.0 are defined (1996) */
291 if ( version != 0x00010000UL &&
292 version != 0x00020000UL &&
293 version != 0x00030000UL )
294 {
295 GXV_TRACE(( " found unknown version\n" ));
297 }
298
299
300 /* only formats 0x0000, 0x0001 are defined (1996) */
301 if ( format > 1 )
302 {
303 GXV_TRACE(( " found unknown format\n" ));
305 }
306
307 gxv_prop_property_validate( defaultProp, 0, gxvalid );
308
309 if ( format == 0 )
310 {
311 FT_TRACE3(( "(format 0, no per-glyph properties, "
312 "remaining %d bytes are skipped)", limit - p ));
313 goto Exit;
314 }
315
316 /* format == 1 */
318
322
323 gxv_LookupTable_validate( p, limit, gxvalid );
324
325 Exit:
326 FT_TRACE4(( "\n" ));
327 }
328
329
330/* END */
WORD face[3]
Definition: mesh.c:4747
static const WCHAR version[]
Definition: asmname.c:66
unsigned char
Definition: typeof.h:29
FT_Load_Glyph(FT_Face face, FT_UInt glyph_index, FT_Int32 load_flags)
Definition: ftobjs.c:760
#define FT_LOAD_IGNORE_TRANSFORM
Definition: freetype.h:3019
#define FT_LOCAL_DEF(x)
Definition: ftconfig.h:388
#define FT_TRACE3(varformat)
Definition: ftdebug.h:160
#define FT_TRACE4(varformat)
Definition: ftdebug.h:161
FT_BEGIN_HEADER typedef signed long FT_Pos
Definition: ftimage.h:58
#define FT_NEXT_USHORT(buffer)
Definition: ftstream.h:226
#define FT_NEXT_LONG(buffer)
Definition: ftstream.h:235
signed long FT_Fixed
Definition: fttypes.h:288
int FT_Error
Definition: fttypes.h:300
unsigned short FT_UShort
Definition: fttypes.h:209
const FT_Byte * FT_Bytes
Definition: fttypes.h:165
#define FT_INVALID_FORMAT
Definition: ftvalid.h:142
#define FT_INVALID_OFFSET
Definition: ftvalid.h:138
#define FT_INVALID_DATA
Definition: ftvalid.h:150
typedefFT_BEGIN_HEADER struct FT_ValidatorRec_ volatile * FT_Validator
Definition: ftvalid.h:42
#define FT_INVALID_GLYPH_ID
Definition: ftvalid.h:146
GLenum GLuint GLint GLenum face
Definition: glext.h:7025
GLint limit
Definition: glext.h:10326
GLfloat GLfloat p
Definition: glext.h:8902
GLintptr offset
Definition: glext.h:5920
gxv_LookupTable_validate(FT_Bytes table, FT_Bytes limit, GXV_Validator gxvalid)
Definition: gxvcommn.c:755
gxv_glyphid_validate(FT_UShort gid, GXV_Validator gxvalid)
Definition: gxvcommn.c:813
#define GXV_NAME_ENTER(name)
Definition: gxvcommn.h:301
@ GXV_LOOKUPVALUE_UNSIGNED
Definition: gxvcommn.h:100
#define GXV_TRACE(s)
Definition: gxvcommn.h:304
#define GXV_INIT
Definition: gxvcommn.h:300
#define GXV_EXIT
Definition: gxvcommn.h:302
#define GXV_LIMIT_CHECK(_count)
Definition: gxvcommn.h:272
struct GXV_prop_DataRec_ GXV_prop_DataRec
static void gxv_prop_property_validate(FT_UShort property, FT_UShort glyph, GXV_Validator gxvalid)
Definition: gxvprop.c:111
gxv_prop_validate(FT_Bytes table, FT_Face face, FT_Validator ftvalid)
Definition: gxvprop.c:257
static void gxv_prop_LookupValue_validate(FT_UShort glyph, GXV_LookupValueCPtr value_p, GXV_Validator gxvalid)
Definition: gxvprop.c:189
struct GXV_prop_DataRec_ * GXV_prop_Data
#define GXV_PROP_USE_COMPLEMENTARY_BRACKET
Definition: gxvprop.c:62
#define GXV_PROP_DATA(field)
Definition: gxvprop.c:59
#define GXV_PROP_DIRECTIONALITY_CLASS
Definition: gxvprop.c:66
#define GXV_PROP_RESERVED
Definition: gxvprop.c:65
static GXV_LookupValueDesc gxv_prop_LookupFmt4_transit(FT_UShort relative_gindex, GXV_LookupValueCPtr base_value_p, FT_Bytes lookuptbl_limit, GXV_Validator gxvalid)
Definition: gxvprop.c:225
static void gxv_prop_zero_advance_validate(FT_UShort gid, GXV_Validator gxvalid)
Definition: gxvprop.c:78
#define GXV_PROP_COMPLEMENTARY_BRACKET_OFFSET
Definition: gxvprop.c:63
#define GXV_PROP_FLOATER
Definition: gxvprop.c:61
#define GXV_PROP_ATTACHING_TO_RIGHT
Definition: gxvprop.c:64
#define error(str)
Definition: mkdosfs.c:1605
static void Exit(void)
Definition: sock.c:1330
FT_Vector advance
Definition: freetype.h:1919
FT_Pos x
Definition: ftimage.h:76
FT_Pos y
Definition: ftimage.h:77
GXV_Lookup_Fmt4_Transit_Func lookupfmt4_trans
Definition: gxvcommn.h:248
FT_Validator root
Definition: gxvcommn.h:239
void * table_data
Definition: gxvcommn.h:242
FT_Bytes lookuptbl_head
Definition: gxvcommn.h:249
GXV_Lookup_Value_Validate_Func lookupval_func
Definition: gxvcommn.h:247
GXV_LookupValue_SignSpec lookupval_sign
Definition: gxvcommn.h:246
FT_Fixed version
Definition: gxvprop.c:55
Definition: format.c:58
Definition: pdh_main.c:94
ActualNumberDriverObjects * sizeof(PDRIVER_OBJECT)) PDRIVER_OBJECT *DriverObjectList