1 /****************************************************************************
5 * TrueTypeGX/AAT morx table validation
6 * body for type2 (Ligature Substitution) subtable.
8 * Copyright (C) 2005-2020 by
9 * suzuki toshiya, Masatake YAMATO, Red Hat K.K.,
10 * David Turner, Robert Wilhelm, and Werner Lemberg.
12 * This file is part of the FreeType project, and may only be used,
13 * modified, and distributed under the terms of the FreeType project
14 * license, LICENSE.TXT. By continuing to use, modify, or distribute
15 * this file you indicate that you have read the license and
16 * understand and accept it fully.
20 /****************************************************************************
22 * gxvalid is derived from both gxlayout module and otvalid module.
23 * Development of gxlayout is supported by the Information-technology
24 * 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 gxvmorx
42 typedef struct GXV_morx_subtable_type2_StateOptRec_
44 FT_ULong ligActionTable;
45 FT_ULong componentTable;
46 FT_ULong ligatureTable;
47 FT_ULong ligActionTable_length;
48 FT_ULong componentTable_length;
49 FT_ULong ligatureTable_length;
51 } GXV_morx_subtable_type2_StateOptRec,
52 *GXV_morx_subtable_type2_StateOptRecData;
55 #define GXV_MORX_SUBTABLE_TYPE2_HEADER_SIZE \
56 ( GXV_XSTATETABLE_HEADER_SIZE + 4 + 4 + 4 )
60 gxv_morx_subtable_type2_opttable_load( FT_Bytes table,
62 GXV_Validator gxvalid )
66 GXV_morx_subtable_type2_StateOptRecData optdata =
67 (GXV_morx_subtable_type2_StateOptRecData)gxvalid->xstatetable.optdata;
70 GXV_LIMIT_CHECK( 4 + 4 + 4 );
71 optdata->ligActionTable = FT_NEXT_ULONG( p );
72 optdata->componentTable = FT_NEXT_ULONG( p );
73 optdata->ligatureTable = FT_NEXT_ULONG( p );
75 GXV_TRACE(( "offset to ligActionTable=0x%08x\n",
76 optdata->ligActionTable ));
77 GXV_TRACE(( "offset to componentTable=0x%08x\n",
78 optdata->componentTable ));
79 GXV_TRACE(( "offset to ligatureTable=0x%08x\n",
80 optdata->ligatureTable ));
85 gxv_morx_subtable_type2_subtable_setup( FT_ULong table_size,
89 FT_ULong* classTable_length_p,
90 FT_ULong* stateArray_length_p,
91 FT_ULong* entryTable_length_p,
92 GXV_Validator gxvalid )
98 GXV_morx_subtable_type2_StateOptRecData optdata =
99 (GXV_morx_subtable_type2_StateOptRecData)gxvalid->xstatetable.optdata;
102 GXV_NAME_ENTER( "subtable boundaries setup" );
107 o[3] = optdata->ligActionTable;
108 o[4] = optdata->componentTable;
109 o[5] = optdata->ligatureTable;
110 l[0] = classTable_length_p;
111 l[1] = stateArray_length_p;
112 l[2] = entryTable_length_p;
113 l[3] = &(optdata->ligActionTable_length);
114 l[4] = &(optdata->componentTable_length);
115 l[5] = &(optdata->ligatureTable_length);
117 gxv_set_length_by_ulong_offset( o, l, buff, 6, table_size, gxvalid );
119 GXV_TRACE(( "classTable: offset=0x%08x length=0x%08x\n",
120 classTable, *classTable_length_p ));
121 GXV_TRACE(( "stateArray: offset=0x%08x length=0x%08x\n",
122 stateArray, *stateArray_length_p ));
123 GXV_TRACE(( "entryTable: offset=0x%08x length=0x%08x\n",
124 entryTable, *entryTable_length_p ));
125 GXV_TRACE(( "ligActionTable: offset=0x%08x length=0x%08x\n",
126 optdata->ligActionTable,
127 optdata->ligActionTable_length ));
128 GXV_TRACE(( "componentTable: offset=0x%08x length=0x%08x\n",
129 optdata->componentTable,
130 optdata->componentTable_length ));
131 GXV_TRACE(( "ligatureTable: offset=0x%08x length=0x%08x\n",
132 optdata->ligatureTable,
133 optdata->ligatureTable_length ));
139 #define GXV_MORX_LIGACTION_ENTRY_SIZE 4
143 gxv_morx_subtable_type2_ligActionIndex_validate(
145 FT_UShort ligActionIndex,
146 GXV_Validator gxvalid )
148 /* access ligActionTable */
149 GXV_morx_subtable_type2_StateOptRecData optdata =
150 (GXV_morx_subtable_type2_StateOptRecData)gxvalid->xstatetable.optdata;
152 FT_Bytes lat_base = table + optdata->ligActionTable;
153 FT_Bytes p = lat_base +
154 ligActionIndex * GXV_MORX_LIGACTION_ENTRY_SIZE;
155 FT_Bytes lat_limit = lat_base + optdata->ligActionTable;
160 GXV_TRACE(( "p < lat_base (%d byte rewind)\n", lat_base - p ));
163 else if ( lat_limit < p )
165 GXV_TRACE(( "lat_limit < p (%d byte overrun)\n", p - lat_limit ));
170 /* validate entry in ligActionTable */
172 #ifdef GXV_LOAD_UNUSED_VARS
180 lig_action = FT_NEXT_ULONG( p );
181 #ifdef GXV_LOAD_UNUSED_VARS
182 last = (FT_UShort)( ( lig_action >> 31 ) & 1 );
183 store = (FT_UShort)( ( lig_action >> 30 ) & 1 );
186 offset = lig_action & 0x3FFFFFFFUL;
188 /* this offset is 30-bit signed value to add to GID */
189 /* it is different from the location offset in mort */
190 if ( ( offset & 0x3FFF0000UL ) == 0x3FFF0000UL )
191 { /* negative offset */
192 gid_limit = gxvalid->face->num_glyphs -
193 (FT_Long)( offset & 0x0000FFFFUL );
197 GXV_TRACE(( "ligature action table includes"
198 " too negative offset moving all GID"
199 " below defined range: 0x%04x\n",
201 GXV_SET_ERR_IF_PARANOID( FT_INVALID_OFFSET );
203 else if ( ( offset & 0x3FFF0000UL ) == 0x00000000UL )
204 { /* positive offset */
205 if ( (FT_Long)offset < gxvalid->face->num_glyphs )
208 GXV_TRACE(( "ligature action table includes"
209 " too large offset moving all GID"
210 " over defined range: 0x%04x\n",
212 GXV_SET_ERR_IF_PARANOID( FT_INVALID_OFFSET );
215 GXV_TRACE(( "ligature action table includes"
216 " invalid offset to add to 16-bit GID:"
217 " 0x%08x\n", offset ));
218 GXV_SET_ERR_IF_PARANOID( FT_INVALID_OFFSET );
224 gxv_morx_subtable_type2_entry_validate(
227 GXV_StateTable_GlyphOffsetCPtr glyphOffset_p,
230 GXV_Validator gxvalid )
232 #ifdef GXV_LOAD_UNUSED_VARS
233 FT_UShort setComponent;
234 FT_UShort dontAdvance;
235 FT_UShort performAction;
238 FT_UShort ligActionIndex;
244 #ifdef GXV_LOAD_UNUSED_VARS
245 setComponent = (FT_UShort)( ( flags >> 15 ) & 1 );
246 dontAdvance = (FT_UShort)( ( flags >> 14 ) & 1 );
247 performAction = (FT_UShort)( ( flags >> 13 ) & 1 );
250 reserved = (FT_UShort)( flags & 0x1FFF );
251 ligActionIndex = glyphOffset_p->u;
254 GXV_TRACE(( " reserved 14bit is non-zero\n" ));
256 if ( 0 < ligActionIndex )
257 gxv_morx_subtable_type2_ligActionIndex_validate(
258 table, ligActionIndex, gxvalid );
263 gxv_morx_subtable_type2_ligatureTable_validate( FT_Bytes table,
264 GXV_Validator gxvalid )
266 GXV_morx_subtable_type2_StateOptRecData optdata =
267 (GXV_morx_subtable_type2_StateOptRecData)gxvalid->xstatetable.optdata;
269 FT_Bytes p = table + optdata->ligatureTable;
270 FT_Bytes limit = table + optdata->ligatureTable
271 + optdata->ligatureTable_length;
274 GXV_NAME_ENTER( "morx chain subtable type2 - substitutionTable" );
276 if ( 0 != optdata->ligatureTable )
278 /* Apple does not give specification of ligatureTable format */
284 GXV_LIMIT_CHECK( 2 );
285 lig_gid = FT_NEXT_USHORT( p );
286 if ( lig_gid < gxvalid->face->num_glyphs )
287 GXV_SET_ERR_IF_PARANOID( FT_INVALID_GLYPH_ID );
296 gxv_morx_subtable_type2_validate( FT_Bytes table,
298 GXV_Validator gxvalid )
302 GXV_morx_subtable_type2_StateOptRec lig_rec;
305 GXV_NAME_ENTER( "morx chain subtable type2 (Ligature Substitution)" );
307 GXV_LIMIT_CHECK( GXV_MORX_SUBTABLE_TYPE2_HEADER_SIZE );
309 gxvalid->xstatetable.optdata =
311 gxvalid->xstatetable.optdata_load_func =
312 gxv_morx_subtable_type2_opttable_load;
313 gxvalid->xstatetable.subtable_setup_func =
314 gxv_morx_subtable_type2_subtable_setup;
315 gxvalid->xstatetable.entry_glyphoffset_fmt =
316 GXV_GLYPHOFFSET_USHORT;
317 gxvalid->xstatetable.entry_validate_func =
318 gxv_morx_subtable_type2_entry_validate;
320 gxv_XStateTable_validate( p, limit, gxvalid );
323 p += gxvalid->subtable_length;
325 gxv_morx_subtable_type2_ligatureTable_validate( table, gxvalid );