1 /***************************************************************************/
5 /* TrueTypeGX/AAT bsln 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_gxvbsln
41 /*************************************************************************/
42 /*************************************************************************/
44 /***** Data and Types *****/
46 /*************************************************************************/
47 /*************************************************************************/
49 #define GXV_BSLN_VALUE_COUNT 32
50 #define GXV_BSLN_VALUE_EMPTY 0xFFFFU
53 typedef struct GXV_bsln_DataRec_
56 FT_UShort defaultBaseline;
58 } GXV_bsln_DataRec, *GXV_bsln_Data;
61 #define GXV_BSLN_DATA( field ) GXV_TABLE_DATA( bsln, field )
64 /*************************************************************************/
65 /*************************************************************************/
67 /***** UTILITY FUNCTIONS *****/
69 /*************************************************************************/
70 /*************************************************************************/
73 gxv_bsln_LookupValue_validate( FT_UShort glyph,
74 GXV_LookupValueCPtr value_p,
75 GXV_Validator gxvalid )
77 FT_UShort v = value_p->u;
83 GXV_NAME_ENTER( "lookup value" );
85 if ( v >= GXV_BSLN_VALUE_COUNT )
88 ctlPoints = (FT_UShort*)GXV_BSLN_DATA( ctlPoints_p );
89 if ( ctlPoints && ctlPoints[v] == GXV_BSLN_VALUE_EMPTY )
97 +===============+ --------+
104 | firstGlyph[0] | | head of lookup table
105 +---------------+ | +
106 | offset[0] | -> | offset [byte]
107 +===============+ | +
108 | lastGlyph[1] | | (glyphID - firstGlyph) * 2 [byte]
123 static GXV_LookupValueDesc
124 gxv_bsln_LookupFmt4_transit( FT_UShort relative_gindex,
125 GXV_LookupValueCPtr base_value_p,
126 FT_Bytes lookuptbl_limit,
127 GXV_Validator gxvalid )
132 GXV_LookupValueDesc value;
134 /* XXX: check range ? */
135 offset = (FT_UShort)( base_value_p->u +
136 ( relative_gindex * sizeof ( FT_UShort ) ) );
138 p = gxvalid->lookuptbl_head + offset;
139 limit = lookuptbl_limit;
140 GXV_LIMIT_CHECK( 2 );
142 value.u = FT_NEXT_USHORT( p );
149 gxv_bsln_parts_fmt0_validate( FT_Bytes tables,
151 GXV_Validator gxvalid )
156 GXV_NAME_ENTER( "parts format 0" );
159 GXV_LIMIT_CHECK( 2 * GXV_BSLN_VALUE_COUNT );
161 gxvalid->table_data = NULL; /* No ctlPoints here. */
168 gxv_bsln_parts_fmt1_validate( FT_Bytes tables,
170 GXV_Validator gxvalid )
175 GXV_NAME_ENTER( "parts format 1" );
178 gxv_bsln_parts_fmt0_validate( p, limit, gxvalid );
181 gxvalid->lookupval_sign = GXV_LOOKUPVALUE_UNSIGNED;
182 gxvalid->lookupval_func = gxv_bsln_LookupValue_validate;
183 gxvalid->lookupfmt4_trans = gxv_bsln_LookupFmt4_transit;
184 gxv_LookupTable_validate( p + 2 * GXV_BSLN_VALUE_COUNT,
193 gxv_bsln_parts_fmt2_validate( FT_Bytes tables,
195 GXV_Validator gxvalid )
203 FT_UShort defaultBaseline = GXV_BSLN_DATA( defaultBaseline );
206 GXV_NAME_ENTER( "parts format 2" );
208 GXV_LIMIT_CHECK( 2 + ( 2 * GXV_BSLN_VALUE_COUNT ) );
211 stdGlyph = FT_NEXT_USHORT( p );
212 GXV_TRACE(( " (stdGlyph = %u)\n", stdGlyph ));
214 gxv_glyphid_validate( stdGlyph, gxvalid );
216 /* Record the position of ctlPoints */
217 GXV_BSLN_DATA( ctlPoints_p ) = p;
220 for ( i = 0; i < GXV_BSLN_VALUE_COUNT; i++ )
222 ctlPoint = FT_NEXT_USHORT( p );
223 if ( ctlPoint == GXV_BSLN_VALUE_EMPTY )
225 if ( i == defaultBaseline )
229 gxv_ctlPoint_validate( stdGlyph, (FT_Short)ctlPoint, gxvalid );
237 gxv_bsln_parts_fmt3_validate( FT_Bytes tables,
239 GXV_Validator gxvalid)
244 GXV_NAME_ENTER( "parts format 3" );
246 /* stdGlyph + ctlPoints */
247 gxv_bsln_parts_fmt2_validate( p, limit, gxvalid );
250 gxvalid->lookupval_sign = GXV_LOOKUPVALUE_UNSIGNED;
251 gxvalid->lookupval_func = gxv_bsln_LookupValue_validate;
252 gxvalid->lookupfmt4_trans = gxv_bsln_LookupFmt4_transit;
253 gxv_LookupTable_validate( p + ( 2 + 2 * GXV_BSLN_VALUE_COUNT ),
261 /*************************************************************************/
262 /*************************************************************************/
264 /***** bsln TABLE *****/
266 /*************************************************************************/
267 /*************************************************************************/
270 gxv_bsln_validate( FT_Bytes table,
272 FT_Validator ftvalid )
274 GXV_ValidatorRec gxvalidrec;
275 GXV_Validator gxvalid = &gxvalidrec;
277 GXV_bsln_DataRec bslnrec;
278 GXV_bsln_Data bsln = &bslnrec;
285 FT_UShort defaultBaseline;
287 GXV_Validate_Func fmt_funcs_table [] =
289 gxv_bsln_parts_fmt0_validate,
290 gxv_bsln_parts_fmt1_validate,
291 gxv_bsln_parts_fmt2_validate,
292 gxv_bsln_parts_fmt3_validate,
296 gxvalid->root = ftvalid;
297 gxvalid->table_data = bsln;
298 gxvalid->face = face;
300 FT_TRACE3(( "validating `bsln' table\n" ));
304 GXV_LIMIT_CHECK( 4 + 2 + 2 );
305 version = FT_NEXT_ULONG( p );
306 format = FT_NEXT_USHORT( p );
307 defaultBaseline = FT_NEXT_USHORT( p );
309 /* only version 1.0 is defined (1996) */
310 if ( version != 0x00010000UL )
313 /* only format 1, 2, 3 are defined (1996) */
314 GXV_TRACE(( " (format = %d)\n", format ));
318 if ( defaultBaseline > 31 )
321 bsln->defaultBaseline = defaultBaseline;
323 fmt_funcs_table[format]( p, limit, gxvalid );
329 /* arch-tag: ebe81143-fdaa-4c68-a4d1-b57227daa3bc
330 (do not change this comment) */