1 /****************************************************************************
5 * TrueTypeGX/AAT opbd table validation (body).
7 * Copyright (C) 2004-2023 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 gxvopbd
42 /*************************************************************************/
43 /*************************************************************************/
45 /***** Data and Types *****/
47 /*************************************************************************/
48 /*************************************************************************/
50 typedef struct GXV_opbd_DataRec_
53 FT_UShort valueOffset_min;
55 } GXV_opbd_DataRec, *GXV_opbd_Data;
58 #define GXV_OPBD_DATA( FIELD ) GXV_TABLE_DATA( opbd, FIELD )
61 /*************************************************************************/
62 /*************************************************************************/
64 /***** UTILITY FUNCTIONS *****/
66 /*************************************************************************/
67 /*************************************************************************/
70 gxv_opbd_LookupValue_validate( FT_UShort glyph,
71 GXV_LookupValueCPtr value_p,
72 GXV_Validator gxvalid )
74 /* offset in LookupTable is measured from the head of opbd table */
75 FT_Bytes p = gxvalid->root->base + value_p->u;
76 FT_Bytes limit = gxvalid->root->limit;
81 if ( value_p->u < GXV_OPBD_DATA( valueOffset_min ) )
82 GXV_OPBD_DATA( valueOffset_min ) = value_p->u;
84 for ( i = 0; i < 4; i++ )
87 delta_value = FT_NEXT_SHORT( p );
89 if ( GXV_OPBD_DATA( format ) ) /* format 1, value is ctrl pt. */
91 if ( delta_value == -1 )
94 gxv_ctlPoint_validate( glyph, (FT_UShort)delta_value, gxvalid );
96 else /* format 0, value is distance */
103 opbd ---------------------+
112 | firstGlyph[0] | | head of opbd sfnt table
113 +---------------+ | +
114 | offset[0] | -> | offset [byte]
115 +===============+ | +
116 | lastGlyph[1] | | (glyphID - firstGlyph) * 4 * sizeof(FT_Short) [byte]
134 static GXV_LookupValueDesc
135 gxv_opbd_LookupFmt4_transit( FT_UShort relative_gindex,
136 GXV_LookupValueCPtr base_value_p,
137 FT_Bytes lookuptbl_limit,
138 GXV_Validator gxvalid )
140 GXV_LookupValueDesc value;
142 FT_UNUSED( lookuptbl_limit );
143 FT_UNUSED( gxvalid );
145 /* XXX: check range? */
146 value.u = (FT_UShort)( base_value_p->u +
147 relative_gindex * 4 * sizeof ( FT_Short ) );
153 /*************************************************************************/
154 /*************************************************************************/
156 /***** opbd TABLE *****/
158 /*************************************************************************/
159 /*************************************************************************/
162 gxv_opbd_validate( FT_Bytes table,
164 FT_Validator ftvalid )
166 GXV_ValidatorRec gxvalidrec;
167 GXV_Validator gxvalid = &gxvalidrec;
168 GXV_opbd_DataRec opbdrec;
169 GXV_opbd_Data opbd = &opbdrec;
176 gxvalid->root = ftvalid;
177 gxvalid->table_data = opbd;
178 gxvalid->face = face;
180 FT_TRACE3(( "validating `opbd' table\n" ));
182 GXV_OPBD_DATA( valueOffset_min ) = 0xFFFFU;
185 GXV_LIMIT_CHECK( 4 + 2 );
186 version = FT_NEXT_ULONG( p );
187 GXV_OPBD_DATA( format ) = FT_NEXT_USHORT( p );
190 /* only 0x00010000 is defined (1996) */
191 GXV_TRACE(( "(version=0x%08lx)\n", version ));
192 if ( 0x00010000UL != version )
195 /* only values 0 and 1 are defined (1996) */
196 GXV_TRACE(( "(format=0x%04x)\n", GXV_OPBD_DATA( format ) ));
197 if ( 0x0001 < GXV_OPBD_DATA( format ) )
200 gxvalid->lookupval_sign = GXV_LOOKUPVALUE_UNSIGNED;
201 gxvalid->lookupval_func = gxv_opbd_LookupValue_validate;
202 gxvalid->lookupfmt4_trans = gxv_opbd_LookupFmt4_transit;
204 gxv_LookupTable_validate( p, limit, gxvalid );
205 p += gxvalid->subtable_length;
207 if ( p > table + GXV_OPBD_DATA( valueOffset_min ) )
210 "found overlap between LookupTable and opbd_value array\n" ));