1 /***************************************************************************/
5 /* OpenType BASE table validation (body). */
7 /* Copyright 2004, 2007 by */
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 /***************************************************************************/
23 /*************************************************************************/
25 /* The macro FT_COMPONENT is used in trace mode. It is an implicit */
26 /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */
27 /* messages during execution. */
30 #define FT_COMPONENT trace_otvbase
34 otv_BaseCoord_validate( FT_Bytes table
,
38 FT_UInt BaseCoordFormat
;
41 OTV_NAME_ENTER( "BaseCoord" );
44 BaseCoordFormat
= FT_NEXT_USHORT( p
);
45 p
+= 2; /* skip Coordinate */
47 OTV_TRACE(( " (format %d)\n", BaseCoordFormat
));
49 switch ( BaseCoordFormat
)
51 case 1: /* BaseCoordFormat1 */
54 case 2: /* BaseCoordFormat2 */
55 OTV_LIMIT_CHECK( 4 ); /* ReferenceGlyph, BaseCoordPoint */
58 case 3: /* BaseCoordFormat3 */
61 otv_Device_validate( table
+ FT_NEXT_USHORT( p
), valid
);
73 otv_BaseTagList_validate( FT_Bytes table
,
80 OTV_NAME_ENTER( "BaseTagList" );
84 BaseTagCount
= FT_NEXT_USHORT( p
);
86 OTV_TRACE(( " (BaseTagCount = %d)\n", BaseTagCount
));
88 OTV_LIMIT_CHECK( BaseTagCount
* 4 ); /* BaselineTag */
95 otv_BaseValues_validate( FT_Bytes table
,
99 FT_UInt BaseCoordCount
;
102 OTV_NAME_ENTER( "BaseValues" );
104 OTV_LIMIT_CHECK( 4 );
106 p
+= 2; /* skip DefaultIndex */
107 BaseCoordCount
= FT_NEXT_USHORT( p
);
109 OTV_TRACE(( " (BaseCoordCount = %d)\n", BaseCoordCount
));
111 OTV_LIMIT_CHECK( BaseCoordCount
* 2 );
114 for ( ; BaseCoordCount
> 0; BaseCoordCount
-- )
115 otv_BaseCoord_validate( table
+ FT_NEXT_USHORT( p
), valid
);
122 otv_MinMax_validate( FT_Bytes table
,
123 OTV_Validator valid
)
127 FT_UInt FeatMinMaxCount
;
129 OTV_OPTIONAL_TABLE( MinCoord
);
130 OTV_OPTIONAL_TABLE( MaxCoord
);
133 OTV_NAME_ENTER( "MinMax" );
135 OTV_LIMIT_CHECK( 6 );
137 OTV_OPTIONAL_OFFSET( MinCoord
);
138 OTV_OPTIONAL_OFFSET( MaxCoord
);
139 FeatMinMaxCount
= FT_NEXT_USHORT( p
);
141 OTV_TRACE(( " (FeatMinMaxCount = %d)\n", FeatMinMaxCount
));
143 table_size
= FeatMinMaxCount
* 8 + 6;
145 OTV_SIZE_CHECK( MinCoord
);
147 otv_BaseCoord_validate( table
+ MinCoord
, valid
);
149 OTV_SIZE_CHECK( MaxCoord
);
151 otv_BaseCoord_validate( table
+ MaxCoord
, valid
);
153 OTV_LIMIT_CHECK( FeatMinMaxCount
* 8 );
155 /* FeatMinMaxRecord */
156 for ( ; FeatMinMaxCount
> 0; FeatMinMaxCount
-- )
158 p
+= 4; /* skip FeatureTableTag */
160 OTV_OPTIONAL_OFFSET( MinCoord
);
161 OTV_OPTIONAL_OFFSET( MaxCoord
);
163 OTV_SIZE_CHECK( MinCoord
);
165 otv_BaseCoord_validate( table
+ MinCoord
, valid
);
167 OTV_SIZE_CHECK( MaxCoord
);
169 otv_BaseCoord_validate( table
+ MaxCoord
, valid
);
177 otv_BaseScript_validate( FT_Bytes table
,
178 OTV_Validator valid
)
182 FT_UInt BaseLangSysCount
;
184 OTV_OPTIONAL_TABLE( BaseValues
);
185 OTV_OPTIONAL_TABLE( DefaultMinMax
);
188 OTV_NAME_ENTER( "BaseScript" );
190 OTV_LIMIT_CHECK( 6 );
191 OTV_OPTIONAL_OFFSET( BaseValues
);
192 OTV_OPTIONAL_OFFSET( DefaultMinMax
);
193 BaseLangSysCount
= FT_NEXT_USHORT( p
);
195 OTV_TRACE(( " (BaseLangSysCount = %d)\n", BaseLangSysCount
));
197 table_size
= BaseLangSysCount
* 6 + 6;
199 OTV_SIZE_CHECK( BaseValues
);
201 otv_BaseValues_validate( table
+ BaseValues
, valid
);
203 OTV_SIZE_CHECK( DefaultMinMax
);
205 otv_MinMax_validate( table
+ DefaultMinMax
, valid
);
207 OTV_LIMIT_CHECK( BaseLangSysCount
* 6 );
209 /* BaseLangSysRecord */
210 for ( ; BaseLangSysCount
> 0; BaseLangSysCount
-- )
212 p
+= 4; /* skip BaseLangSysTag */
214 otv_MinMax_validate( table
+ FT_NEXT_USHORT( p
), valid
);
222 otv_BaseScriptList_validate( FT_Bytes table
,
223 OTV_Validator valid
)
226 FT_UInt BaseScriptCount
;
229 OTV_NAME_ENTER( "BaseScriptList" );
231 OTV_LIMIT_CHECK( 2 );
232 BaseScriptCount
= FT_NEXT_USHORT( p
);
234 OTV_TRACE(( " (BaseScriptCount = %d)\n", BaseScriptCount
));
236 OTV_LIMIT_CHECK( BaseScriptCount
* 6 );
238 /* BaseScriptRecord */
239 for ( ; BaseScriptCount
> 0; BaseScriptCount
-- )
241 p
+= 4; /* skip BaseScriptTag */
244 otv_BaseScript_validate( table
+ FT_NEXT_USHORT( p
), valid
);
252 otv_Axis_validate( FT_Bytes table
,
253 OTV_Validator valid
)
258 OTV_OPTIONAL_TABLE( BaseTagList
);
261 OTV_NAME_ENTER( "Axis" );
263 OTV_LIMIT_CHECK( 4 );
264 OTV_OPTIONAL_OFFSET( BaseTagList
);
268 OTV_SIZE_CHECK( BaseTagList
);
270 otv_BaseTagList_validate( table
+ BaseTagList
, valid
);
273 otv_BaseScriptList_validate( table
+ FT_NEXT_USHORT( p
), valid
);
280 otv_BASE_validate( FT_Bytes table
,
281 FT_Validator ftvalid
)
283 OTV_ValidatorRec validrec
;
284 OTV_Validator valid
= &validrec
;
288 OTV_OPTIONAL_TABLE( HorizAxis
);
289 OTV_OPTIONAL_TABLE( VertAxis
);
292 valid
->root
= ftvalid
;
294 FT_TRACE3(( "validating BASE table\n" ));
297 OTV_LIMIT_CHECK( 6 );
299 if ( FT_NEXT_ULONG( p
) != 0x10000UL
) /* Version */
304 OTV_OPTIONAL_OFFSET( HorizAxis
);
305 OTV_SIZE_CHECK( HorizAxis
);
307 otv_Axis_validate( table
+ HorizAxis
, valid
);
309 OTV_OPTIONAL_OFFSET( VertAxis
);
310 OTV_SIZE_CHECK( VertAxis
);
312 otv_Axis_validate( table
+ VertAxis
, valid
);