1 /****************************************************************************
5 * TrueTypeGX/AAT prop table validation (body).
7 * Copyright (C) 2004-2020 by
8 * suzuki toshiya, Masatake YAMATO, Red Hat K.K.,
9 * David Turner, Robert Wilhelm, and Werner Lemberg.
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.
19 /****************************************************************************
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.
32 /**************************************************************************
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.
39 #define FT_COMPONENT gxvprop
42 /*************************************************************************/
43 /*************************************************************************/
45 /***** Data and Types *****/
47 /*************************************************************************/
48 /*************************************************************************/
50 #define GXV_PROP_HEADER_SIZE ( 4 + 2 + 2 )
51 #define GXV_PROP_SIZE_MIN GXV_PROP_HEADER_SIZE
53 typedef struct GXV_prop_DataRec_
57 } GXV_prop_DataRec, *GXV_prop_Data;
59 #define GXV_PROP_DATA( field ) GXV_TABLE_DATA( prop, field )
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
69 /*************************************************************************/
70 /*************************************************************************/
72 /***** UTILITY FUNCTIONS *****/
74 /*************************************************************************/
75 /*************************************************************************/
78 gxv_prop_zero_advance_validate( FT_UShort gid,
79 GXV_Validator gxvalid )
86 GXV_NAME_ENTER( "zero advance" );
90 error = FT_Load_Glyph( face,
92 FT_LOAD_IGNORE_TRANSFORM );
98 if ( glyph->advance.x != (FT_Pos)0 ||
99 glyph->advance.y != (FT_Pos)0 )
101 GXV_TRACE(( " found non-zero advance in zero-advance glyph\n" ));
109 /* Pass 0 as GLYPH to check the default property */
111 gxv_prop_property_validate( FT_UShort property,
113 GXV_Validator gxvalid )
115 if ( glyph != 0 && ( property & GXV_PROP_FLOATER ) )
116 gxv_prop_zero_advance_validate( glyph, gxvalid );
118 if ( property & GXV_PROP_USE_COMPLEMENTARY_BRACKET )
124 offset = (FT_UShort)( property & GXV_PROP_COMPLEMENTARY_BRACKET_OFFSET );
127 GXV_TRACE(( " found zero offset to property\n" ));
131 complement = (char)( offset >> 8 );
132 if ( complement & 0x08 )
134 /* Top bit is set: negative */
136 /* Calculate the absolute offset */
137 complement = (char)( ( complement & 0x07 ) + 1 );
139 /* The gid for complement must be greater than 0 */
140 if ( glyph <= complement )
142 GXV_TRACE(( " found non-positive glyph complement\n" ));
148 /* The gid for complement must be the face. */
149 gxv_glyphid_validate( (FT_UShort)( glyph + complement ), gxvalid );
154 if ( property & GXV_PROP_COMPLEMENTARY_BRACKET_OFFSET )
155 GXV_TRACE(( "glyph %d cannot have complementary bracketing\n",
159 /* this is introduced in version 2.0 */
160 if ( property & GXV_PROP_ATTACHING_TO_RIGHT )
162 if ( GXV_PROP_DATA( version ) == 0x00010000UL )
164 GXV_TRACE(( " found older version (1.0) in new version table\n" ));
169 if ( property & GXV_PROP_RESERVED )
171 GXV_TRACE(( " found non-zero bits in reserved bits\n" ));
175 if ( ( property & GXV_PROP_DIRECTIONALITY_CLASS ) > 11 )
177 /* TODO: Too restricted. Use the validation level. */
178 if ( GXV_PROP_DATA( version ) == 0x00010000UL ||
179 GXV_PROP_DATA( version ) == 0x00020000UL )
181 GXV_TRACE(( " found too old version in directionality class\n" ));
189 gxv_prop_LookupValue_validate( FT_UShort glyph,
190 GXV_LookupValueCPtr value_p,
191 GXV_Validator gxvalid )
193 gxv_prop_property_validate( value_p->u, glyph, gxvalid );
198 +===============+ --------+
205 | firstGlyph[0] | | head of lookup table
206 +---------------+ | +
207 | offset[0] | -> | offset [byte]
208 +===============+ | +
209 | lastGlyph[1] | | (glyphID - firstGlyph) * 2 [byte]
224 static GXV_LookupValueDesc
225 gxv_prop_LookupFmt4_transit( FT_UShort relative_gindex,
226 GXV_LookupValueCPtr base_value_p,
227 FT_Bytes lookuptbl_limit,
228 GXV_Validator gxvalid )
233 GXV_LookupValueDesc value;
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;
241 GXV_LIMIT_CHECK ( 2 );
242 value.u = FT_NEXT_USHORT( p );
248 /*************************************************************************/
249 /*************************************************************************/
251 /***** prop TABLE *****/
253 /*************************************************************************/
254 /*************************************************************************/
257 gxv_prop_validate( FT_Bytes table,
259 FT_Validator ftvalid )
263 GXV_ValidatorRec gxvalidrec;
264 GXV_Validator gxvalid = &gxvalidrec;
266 GXV_prop_DataRec proprec;
267 GXV_prop_Data prop = &proprec;
271 FT_UShort defaultProp;
274 gxvalid->root = ftvalid;
275 gxvalid->table_data = prop;
276 gxvalid->face = face;
278 FT_TRACE3(( "validating `prop' table\n" ));
281 GXV_LIMIT_CHECK( 4 + 2 + 2 );
282 version = FT_NEXT_LONG( p );
283 format = FT_NEXT_USHORT( p );
284 defaultProp = FT_NEXT_USHORT( p );
286 GXV_TRACE(( " version 0x%08x\n", version ));
287 GXV_TRACE(( " format 0x%04x\n", format ));
288 GXV_TRACE(( " defaultProp 0x%04x\n", defaultProp ));
290 /* only versions 1.0, 2.0, 3.0 are defined (1996) */
291 if ( version != 0x00010000UL &&
292 version != 0x00020000UL &&
293 version != 0x00030000UL )
295 GXV_TRACE(( " found unknown version\n" ));
300 /* only formats 0x0000, 0x0001 are defined (1996) */
303 GXV_TRACE(( " found unknown format\n" ));
307 gxv_prop_property_validate( defaultProp, 0, gxvalid );
311 FT_TRACE3(( "(format 0, no per-glyph properties, "
312 "remaining %d bytes are skipped)", limit - p ));
317 GXV_PROP_DATA( version ) = version;
319 gxvalid->lookupval_sign = GXV_LOOKUPVALUE_UNSIGNED;
320 gxvalid->lookupval_func = gxv_prop_LookupValue_validate;
321 gxvalid->lookupfmt4_trans = gxv_prop_LookupFmt4_transit;
323 gxv_LookupTable_validate( p, limit, gxvalid );