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
,
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 )
105 /* Pass 0 as GLYPH to check the default property */
107 gxv_prop_property_validate( FT_UShort property
,
109 GXV_Validator valid
)
111 if ( glyph
!= 0 && ( property
& GXV_PROP_FLOATER
) )
112 gxv_prop_zero_advance_validate( glyph
, valid
);
114 if ( property
& GXV_PROP_USE_COMPLEMENTARY_BRACKET
)
120 offset
= (FT_UShort
)( property
& GXV_PROP_COMPLEMENTARY_BRACKET_OFFSET
);
124 complement
= (char)( offset
>> 8 );
125 if ( complement
& 0x08 )
127 /* Top bit is set: negative */
129 /* Calculate the absolute offset */
130 complement
= (char)( ( complement
& 0x07 ) + 1 );
132 /* The gid for complement must be greater than 0 */
133 if ( glyph
<= complement
)
138 /* The gid for complement must be the face. */
139 gxv_glyphid_validate( (FT_UShort
)( glyph
+ complement
), valid
);
144 if ( property
& GXV_PROP_COMPLEMENTARY_BRACKET_OFFSET
)
145 GXV_TRACE(( "glyph %d cannot have complementary bracketing\n",
149 /* this is introduced in version 2.0 */
150 if ( property
& GXV_PROP_ATTACHING_TO_RIGHT
)
152 if ( GXV_PROP_DATA( version
) == 0x00010000UL
)
156 if ( property
& GXV_PROP_RESERVED
)
159 if ( ( property
& GXV_PROP_DIRECTIONALITY_CLASS
) > 11 )
161 /* TODO: Too restricted. Use the validation level. */
162 if ( GXV_PROP_DATA( version
) == 0x00010000UL
||
163 GXV_PROP_DATA( version
) == 0x00020000UL
)
170 gxv_prop_LookupValue_validate( FT_UShort glyph
,
171 GXV_LookupValueCPtr value_p
,
172 GXV_Validator valid
)
174 gxv_prop_property_validate( value_p
->u
, glyph
, valid
);
179 +===============+ --------+
186 | firstGlyph[0] | | head of lookup table
187 +---------------+ | +
188 | offset[0] | -> | offset [byte]
189 +===============+ | +
190 | lastGlyph[1] | | (glyphID - firstGlyph) * 2 [byte]
205 static GXV_LookupValueDesc
206 gxv_prop_LookupFmt4_transit( FT_UShort relative_gindex
,
207 GXV_LookupValueCPtr base_value_p
,
208 FT_Bytes lookuptbl_limit
,
209 GXV_Validator valid
)
214 GXV_LookupValueDesc value
;
216 /* XXX: check range? */
217 offset
= (FT_UShort
)( base_value_p
->u
+
218 relative_gindex
* sizeof( FT_UShort
) );
219 p
= valid
->lookuptbl_head
+ offset
;
220 limit
= lookuptbl_limit
;
222 GXV_LIMIT_CHECK ( 2 );
223 value
.u
= FT_NEXT_USHORT( p
);
229 /*************************************************************************/
230 /*************************************************************************/
232 /***** prop TABLE *****/
234 /*************************************************************************/
235 /*************************************************************************/
238 gxv_prop_validate( FT_Bytes table
,
240 FT_Validator ftvalid
)
244 GXV_ValidatorRec validrec
;
245 GXV_Validator valid
= &validrec
;
247 GXV_prop_DataRec proprec
;
248 GXV_prop_Data prop
= &proprec
;
252 FT_UShort defaultProp
;
255 valid
->root
= ftvalid
;
256 valid
->table_data
= prop
;
259 FT_TRACE3(( "validating `prop' table\n" ));
262 GXV_LIMIT_CHECK( 4 + 2 + 2 );
263 version
= FT_NEXT_ULONG( p
);
264 format
= FT_NEXT_USHORT( p
);
265 defaultProp
= FT_NEXT_USHORT( p
);
267 /* only versions 1.0, 2.0, 3.0 are defined (1996) */
268 if ( version
!= 0x00010000UL
&&
269 version
!= 0x00020000UL
&&
270 version
!= 0x00030000UL
)
274 /* only formats 0x0000, 0x0001 are defined (1996) */
278 gxv_prop_property_validate( defaultProp
, 0, valid
);
282 FT_TRACE3(( "(format 0, no per-glyph properties, "
283 "remaining %d bytes are skipped)", limit
- p
));
288 GXV_PROP_DATA( version
) = version
;
290 valid
->lookupval_sign
= GXV_LOOKUPVALUE_UNSIGNED
;
291 valid
->lookupval_func
= gxv_prop_LookupValue_validate
;
292 valid
->lookupfmt4_trans
= gxv_prop_LookupFmt4_transit
;
294 gxv_LookupTable_validate( p
, limit
, valid
);