1 /***************************************************************************/
5 /* TrueTypeGX/AAT prop table validation (body). */
7 /* Copyright 2004, 2005 by suzuki toshiya, Masatake YAMATO, Red Hat K.K., */
8 /* David Turner, Robert Wilhelm, and Werner Lemberg. */
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. */
16 /***************************************************************************/
18 /***************************************************************************/
20 /* gxvalid is derived from both gxlayout module and otvalid module. */
21 /* Development of gxlayout is supported by the Information-technology */
22 /* Promotion Agency(IPA), Japan. */
24 /***************************************************************************/
31 /*************************************************************************/
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. */
38 #define FT_COMPONENT trace_gxvprop
41 /*************************************************************************/
42 /*************************************************************************/
44 /***** Data and Types *****/
46 /*************************************************************************/
47 /*************************************************************************/
49 #define GXV_PROP_HEADER_SIZE ( 4 + 2 + 2 )
50 #define GXV_PROP_SIZE_MIN GXV_PROP_HEADER_SIZE
52 typedef struct GXV_prop_DataRec_
56 } GXV_prop_DataRec
, *GXV_prop_Data
;
58 #define GXV_PROP_DATA( field ) GXV_TABLE_DATA( prop, field )
60 #define GXV_PROP_FLOATER 0x8000U
61 #define GXV_PROP_USE_COMPLEMENTARY_BRACKET 0x1000U
62 #define GXV_PROP_COMPLEMENTARY_BRACKET_OFFSET 0x0F00U
63 #define GXV_PROP_ATTACHING_TO_RIGHT 0x0080U
64 #define GXV_PROP_RESERVED 0x0060U
65 #define GXV_PROP_DIRECTIONALITY_CLASS 0x001FU
68 /*************************************************************************/
69 /*************************************************************************/
71 /***** UTILITY FUNCTIONS *****/
73 /*************************************************************************/
74 /*************************************************************************/
77 gxv_prop_zero_advance_validate( FT_UShort gid
,
78 GXV_Validator gxvalid
)
85 GXV_NAME_ENTER( "zero advance" );
89 error
= FT_Load_Glyph( face
,
91 FT_LOAD_IGNORE_TRANSFORM
);
97 if ( glyph
->advance
.x
!= (FT_Pos
)0 ||
98 glyph
->advance
.y
!= (FT_Pos
)0 )
100 GXV_TRACE(( " found non-zero advance in zero-advance glyph\n" ));
108 /* Pass 0 as GLYPH to check the default property */
110 gxv_prop_property_validate( FT_UShort property
,
112 GXV_Validator gxvalid
)
114 if ( glyph
!= 0 && ( property
& GXV_PROP_FLOATER
) )
115 gxv_prop_zero_advance_validate( glyph
, gxvalid
);
117 if ( property
& GXV_PROP_USE_COMPLEMENTARY_BRACKET
)
123 offset
= (FT_UShort
)( property
& GXV_PROP_COMPLEMENTARY_BRACKET_OFFSET
);
126 GXV_TRACE(( " found zero offset to property\n" ));
130 complement
= (char)( offset
>> 8 );
131 if ( complement
& 0x08 )
133 /* Top bit is set: negative */
135 /* Calculate the absolute offset */
136 complement
= (char)( ( complement
& 0x07 ) + 1 );
138 /* The gid for complement must be greater than 0 */
139 if ( glyph
<= complement
)
141 GXV_TRACE(( " found non-positive glyph complement\n" ));
147 /* The gid for complement must be the face. */
148 gxv_glyphid_validate( (FT_UShort
)( glyph
+ complement
), gxvalid
);
153 if ( property
& GXV_PROP_COMPLEMENTARY_BRACKET_OFFSET
)
154 GXV_TRACE(( "glyph %d cannot have complementary bracketing\n",
158 /* this is introduced in version 2.0 */
159 if ( property
& GXV_PROP_ATTACHING_TO_RIGHT
)
161 if ( GXV_PROP_DATA( version
) == 0x00010000UL
)
163 GXV_TRACE(( " found older version (1.0) in new version table\n" ));
168 if ( property
& GXV_PROP_RESERVED
)
170 GXV_TRACE(( " found non-zero bits in reserved bits\n" ));
174 if ( ( property
& GXV_PROP_DIRECTIONALITY_CLASS
) > 11 )
176 /* TODO: Too restricted. Use the validation level. */
177 if ( GXV_PROP_DATA( version
) == 0x00010000UL
||
178 GXV_PROP_DATA( version
) == 0x00020000UL
)
180 GXV_TRACE(( " found too old version in directionality class\n" ));
188 gxv_prop_LookupValue_validate( FT_UShort glyph
,
189 GXV_LookupValueCPtr value_p
,
190 GXV_Validator gxvalid
)
192 gxv_prop_property_validate( value_p
->u
, glyph
, gxvalid
);
197 +===============+ --------+
204 | firstGlyph[0] | | head of lookup table
205 +---------------+ | +
206 | offset[0] | -> | offset [byte]
207 +===============+ | +
208 | lastGlyph[1] | | (glyphID - firstGlyph) * 2 [byte]
223 static GXV_LookupValueDesc
224 gxv_prop_LookupFmt4_transit( FT_UShort relative_gindex
,
225 GXV_LookupValueCPtr base_value_p
,
226 FT_Bytes lookuptbl_limit
,
227 GXV_Validator gxvalid
)
232 GXV_LookupValueDesc value
;
234 /* XXX: check range? */
235 offset
= (FT_UShort
)( base_value_p
->u
+
236 relative_gindex
* sizeof ( FT_UShort
) );
237 p
= gxvalid
->lookuptbl_head
+ offset
;
238 limit
= lookuptbl_limit
;
240 GXV_LIMIT_CHECK ( 2 );
241 value
.u
= FT_NEXT_USHORT( p
);
247 /*************************************************************************/
248 /*************************************************************************/
250 /***** prop TABLE *****/
252 /*************************************************************************/
253 /*************************************************************************/
256 gxv_prop_validate( FT_Bytes table
,
258 FT_Validator ftvalid
)
262 GXV_ValidatorRec gxvalidrec
;
263 GXV_Validator gxvalid
= &gxvalidrec
;
265 GXV_prop_DataRec proprec
;
266 GXV_prop_Data prop
= &proprec
;
270 FT_UShort defaultProp
;
273 gxvalid
->root
= ftvalid
;
274 gxvalid
->table_data
= prop
;
275 gxvalid
->face
= face
;
277 FT_TRACE3(( "validating `prop' table\n" ));
280 GXV_LIMIT_CHECK( 4 + 2 + 2 );
281 version
= FT_NEXT_ULONG( p
);
282 format
= FT_NEXT_USHORT( p
);
283 defaultProp
= FT_NEXT_USHORT( p
);
285 GXV_TRACE(( " version 0x%08x\n", version
));
286 GXV_TRACE(( " format 0x%04x\n", format
));
287 GXV_TRACE(( " defaultProp 0x%04x\n", defaultProp
));
289 /* only versions 1.0, 2.0, 3.0 are defined (1996) */
290 if ( version
!= 0x00010000UL
&&
291 version
!= 0x00020000UL
&&
292 version
!= 0x00030000UL
)
294 GXV_TRACE(( " found unknown version\n" ));
299 /* only formats 0x0000, 0x0001 are defined (1996) */
302 GXV_TRACE(( " found unknown format\n" ));
306 gxv_prop_property_validate( defaultProp
, 0, gxvalid
);
310 FT_TRACE3(( "(format 0, no per-glyph properties, "
311 "remaining %d bytes are skipped)", limit
- p
));
316 GXV_PROP_DATA( version
) = version
;
318 gxvalid
->lookupval_sign
= GXV_LOOKUPVALUE_UNSIGNED
;
319 gxvalid
->lookupval_func
= gxv_prop_LookupValue_validate
;
320 gxvalid
->lookupfmt4_trans
= gxv_prop_LookupFmt4_transit
;
322 gxv_LookupTable_validate( p
, limit
, gxvalid
);