1 /***************************************************************************/
5 /* TrueTypeGX/AAT mort table validation (body). */
7 /* Copyright 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_gxvmort
42 gxv_mort_feature_validate( GXV_mort_feature f,
45 if ( f->featureType >= gxv_feat_registry_length )
47 GXV_TRACE(( "featureType %d is out of registered range, "
48 "setting %d is unchecked\n",
49 f->featureType, f->featureSetting ));
50 GXV_SET_ERR_IF_PARANOID( FT_INVALID_DATA );
52 else if ( !gxv_feat_registry[f->featureType].existence )
54 GXV_TRACE(( "featureType %d is within registered area "
55 "but undefined, setting %d is unchecked\n",
56 f->featureType, f->featureSetting ));
57 GXV_SET_ERR_IF_PARANOID( FT_INVALID_DATA );
61 FT_Byte nSettings_max;
64 /* nSettings in gxvfeat.c is halved for exclusive on/off settings */
65 nSettings_max = gxv_feat_registry[f->featureType].nSettings;
66 if ( gxv_feat_registry[f->featureType].exclusive )
67 nSettings_max = (FT_Byte)( 2 * nSettings_max );
69 GXV_TRACE(( "featureType %d is registered", f->featureType ));
70 GXV_TRACE(( "setting %d", f->featureSetting ));
72 if ( f->featureSetting > nSettings_max )
74 GXV_TRACE(( "out of defined range %d", nSettings_max ));
75 GXV_SET_ERR_IF_PARANOID( FT_INVALID_DATA );
80 /* TODO: enableFlags must be unique value in specified chain? */
85 * nFeatureFlags is typed to FT_ULong to accept that in
86 * mort (typed FT_UShort) and morx (typed FT_ULong).
89 gxv_mort_featurearray_validate( FT_Bytes table,
91 FT_ULong nFeatureFlags,
97 GXV_mort_featureRec f = GXV_MORT_FEATURE_OFF;
100 GXV_NAME_ENTER( "mort feature list" );
101 for ( i = 0; i < nFeatureFlags; i++ )
103 GXV_LIMIT_CHECK( 2 + 2 + 4 + 4 );
104 f.featureType = FT_NEXT_USHORT( p );
105 f.featureSetting = FT_NEXT_USHORT( p );
106 f.enableFlags = FT_NEXT_ULONG( p );
107 f.disableFlags = FT_NEXT_ULONG( p );
109 gxv_mort_feature_validate( &f, valid );
112 if ( !IS_GXV_MORT_FEATURE_OFF( f ) )
115 valid->subtable_length = p - table;
121 gxv_mort_coverage_validate( FT_UShort coverage,
122 GXV_Validator valid )
126 if ( coverage & 0x8000U )
127 GXV_TRACE(( " this subtable is for vertical text only\n" ));
129 GXV_TRACE(( " this subtable is for horizontal text only\n" ));
131 if ( coverage & 0x4000 )
132 GXV_TRACE(( " this subtable is applied to glyph array "
133 "in descending order\n" ));
135 GXV_TRACE(( " this subtable is applied to glyph array "
136 "in ascending order\n" ));
138 if ( coverage & 0x2000 )
139 GXV_TRACE(( " this subtable is forcibly applied to "
140 "vertical/horizontal text\n" ));
142 if ( coverage & 0x1FF8 )
143 GXV_TRACE(( " coverage has non-zero bits in reserved area\n" ));
148 gxv_mort_subtables_validate( FT_Bytes table,
150 FT_UShort nSubtables,
151 GXV_Validator valid )
155 GXV_Validate_Func fmt_funcs_table[] =
157 gxv_mort_subtable_type0_validate, /* 0 */
158 gxv_mort_subtable_type1_validate, /* 1 */
159 gxv_mort_subtable_type2_validate, /* 2 */
161 gxv_mort_subtable_type4_validate, /* 4 */
162 gxv_mort_subtable_type5_validate, /* 5 */
166 GXV_Validate_Func func;
170 GXV_NAME_ENTER( "subtables in a chain" );
172 for ( i = 0; i < nSubtables; i++ )
176 #ifdef GXV_LOAD_UNUSED_VARS
177 FT_ULong subFeatureFlags;
183 GXV_LIMIT_CHECK( 2 + 2 + 4 );
184 length = FT_NEXT_USHORT( p );
185 coverage = FT_NEXT_USHORT( p );
186 #ifdef GXV_LOAD_UNUSED_VARS
187 subFeatureFlags = FT_NEXT_ULONG( p );
192 GXV_TRACE(( "validating chain subtable %d/%d (%d bytes)\n",
193 i + 1, nSubtables, length ));
194 type = coverage & 0x0007;
195 rest = length - ( 2 + 2 + 4 );
197 GXV_LIMIT_CHECK( rest );
198 gxv_mort_coverage_validate( coverage, valid );
203 func = fmt_funcs_table[type];
205 GXV_TRACE(( "morx type %d is reserved\n", type ));
207 func( p, p + rest, valid );
210 /* TODO: validate subFeatureFlags */
213 valid->subtable_length = p - table;
220 gxv_mort_chain_validate( FT_Bytes table,
222 GXV_Validator valid )
225 #ifdef GXV_LOAD_UNUSED_VARS
226 FT_ULong defaultFlags;
228 FT_ULong chainLength;
229 FT_UShort nFeatureFlags;
230 FT_UShort nSubtables;
233 GXV_NAME_ENTER( "mort chain header" );
235 GXV_LIMIT_CHECK( 4 + 4 + 2 + 2 );
236 #ifdef GXV_LOAD_UNUSED_VARS
237 defaultFlags = FT_NEXT_ULONG( p );
241 chainLength = FT_NEXT_ULONG( p );
242 nFeatureFlags = FT_NEXT_USHORT( p );
243 nSubtables = FT_NEXT_USHORT( p );
245 gxv_mort_featurearray_validate( p, table + chainLength,
246 nFeatureFlags, valid );
247 p += valid->subtable_length;
248 gxv_mort_subtables_validate( p, table + chainLength, nSubtables, valid );
249 valid->subtable_length = chainLength;
251 /* TODO: validate defaultFlags */
257 gxv_mort_validate( FT_Bytes table,
259 FT_Validator ftvalid )
261 GXV_ValidatorRec validrec;
262 GXV_Validator valid = &validrec;
270 valid->root = ftvalid;
272 limit = valid->root->limit;
274 FT_TRACE3(( "validating `mort' table\n" ));
277 GXV_LIMIT_CHECK( 4 + 4 );
278 version = FT_NEXT_ULONG( p );
279 nChains = FT_NEXT_ULONG( p );
281 if (version != 0x00010000UL)
284 for ( i = 0; i < nChains; i++ )
286 GXV_TRACE(( "validating chain %d/%d\n", i + 1, nChains ));
287 GXV_32BIT_ALIGNMENT_VALIDATE( p - table );
288 gxv_mort_chain_validate( p, limit, valid );
289 p += valid->subtable_length;