1 /***************************************************************************/
5 /* TrueTypeGX/AAT opbd 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_gxvopbd
41 /*************************************************************************/
42 /*************************************************************************/
44 /***** Data and Types *****/
46 /*************************************************************************/
47 /*************************************************************************/
49 typedef struct GXV_opbd_DataRec_
52 FT_UShort valueOffset_min
;
54 } GXV_opbd_DataRec
, *GXV_opbd_Data
;
57 #define GXV_OPBD_DATA( FIELD ) GXV_TABLE_DATA( opbd, FIELD )
60 /*************************************************************************/
61 /*************************************************************************/
63 /***** UTILITY FUNCTIONS *****/
65 /*************************************************************************/
66 /*************************************************************************/
69 gxv_opbd_LookupValue_validate( FT_UShort glyph
,
70 GXV_LookupValueCPtr value_p
,
73 /* offset in LookupTable is measured from the head of opbd table */
74 FT_Bytes p
= valid
->root
->base
+ value_p
->u
;
75 FT_Bytes limit
= valid
->root
->limit
;
80 if ( value_p
->u
< GXV_OPBD_DATA( valueOffset_min
) )
81 GXV_OPBD_DATA( valueOffset_min
) = value_p
->u
;
83 for ( i
= 0; i
< 4; i
++ )
86 delta_value
= FT_NEXT_SHORT( p
);
88 if ( GXV_OPBD_DATA( format
) ) /* format 1, value is ctrl pt. */
90 if ( delta_value
== -1 )
93 gxv_ctlPoint_validate( glyph
, delta_value
, valid
);
95 else /* format 0, value is distance */
102 opbd ---------------------+
111 | firstGlyph[0] | | head of opbd sfnt table
112 +---------------+ | +
113 | offset[0] | -> | offset [byte]
114 +===============+ | +
115 | lastGlyph[1] | | (glyphID - firstGlyph) * 4 * sizeof(FT_Short) [byte]
133 static GXV_LookupValueDesc
134 gxv_opbd_LookupFmt4_transit( FT_UShort relative_gindex
,
135 GXV_LookupValueCPtr base_value_p
,
136 FT_Bytes lookuptbl_limit
,
137 GXV_Validator valid
)
139 GXV_LookupValueDesc value
;
141 FT_UNUSED( lookuptbl_limit
);
144 /* XXX: check range? */
145 value
.u
= (FT_UShort
)( base_value_p
->u
+
146 relative_gindex
* 4 * sizeof ( FT_Short
) );
152 /*************************************************************************/
153 /*************************************************************************/
155 /***** opbd TABLE *****/
157 /*************************************************************************/
158 /*************************************************************************/
161 gxv_opbd_validate( FT_Bytes table
,
163 FT_Validator ftvalid
)
165 GXV_ValidatorRec validrec
;
166 GXV_Validator valid
= &validrec
;
167 GXV_opbd_DataRec opbdrec
;
168 GXV_opbd_Data opbd
= &opbdrec
;
175 valid
->root
= ftvalid
;
176 valid
->table_data
= opbd
;
179 FT_TRACE3(( "validating `opbd' table\n" ));
181 GXV_OPBD_DATA( valueOffset_min
) = 0xFFFFU
;
184 GXV_LIMIT_CHECK( 4 + 2 );
185 version
= FT_NEXT_ULONG( p
);
186 GXV_OPBD_DATA( format
) = FT_NEXT_USHORT( p
);
189 /* only 0x00010000 is defined (1996) */
190 GXV_TRACE(( "(version=0x%08x)\n", version
));
191 if ( 0x00010000UL
!= version
)
194 /* only values 0 and 1 are defined (1996) */
195 GXV_TRACE(( "(format=0x%04x)\n", GXV_OPBD_DATA( format
) ));
196 if ( 0x0001 < GXV_OPBD_DATA( format
) )
199 valid
->lookupval_sign
= GXV_LOOKUPVALUE_UNSIGNED
;
200 valid
->lookupval_func
= gxv_opbd_LookupValue_validate
;
201 valid
->lookupfmt4_trans
= gxv_opbd_LookupFmt4_transit
;
203 gxv_LookupTable_validate( p
, limit
, valid
);
204 p
+= valid
->subtable_length
;
206 if ( p
> table
+ GXV_OPBD_DATA( valueOffset_min
) )
209 "found overlap between LookupTable and opbd_value array\n" ));