zenilib  0.5.3.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
gxvmorx2.c
Go to the documentation of this file.
1 /***************************************************************************/
2 /* */
3 /* gxvmorx2.c */
4 /* */
5 /* TrueTypeGX/AAT morx table validation */
6 /* body for type2 (Ligature Substitution) subtable. */
7 /* */
8 /* Copyright 2005 by suzuki toshiya, Masatake YAMATO, Red Hat K.K., */
9 /* David Turner, Robert Wilhelm, and Werner Lemberg. */
10 /* */
11 /* This file is part of the FreeType project, and may only be used, */
12 /* modified, and distributed under the terms of the FreeType project */
13 /* license, LICENSE.TXT. By continuing to use, modify, or distribute */
14 /* this file you indicate that you have read the license and */
15 /* understand and accept it fully. */
16 /* */
17 /***************************************************************************/
18 
19 /***************************************************************************/
20 /* */
21 /* gxvalid is derived from both gxlayout module and otvalid module. */
22 /* Development of gxlayout is supported by the Information-technology */
23 /* Promotion Agency(IPA), Japan. */
24 /* */
25 /***************************************************************************/
26 
27 
28 #include "gxvmorx.h"
29 
30 
31  /*************************************************************************/
32  /* */
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. */
36  /* */
37 #undef FT_COMPONENT
38 #define FT_COMPONENT trace_gxvmorx
39 
40 
41  typedef struct GXV_morx_subtable_type2_StateOptRec_
42  {
43  FT_ULong ligActionTable;
44  FT_ULong componentTable;
45  FT_ULong ligatureTable;
46  FT_ULong ligActionTable_length;
47  FT_ULong componentTable_length;
48  FT_ULong ligatureTable_length;
49 
52 
53 
54 #define GXV_MORX_SUBTABLE_TYPE2_HEADER_SIZE \
55  ( GXV_XSTATETABLE_HEADER_SIZE + 4 + 4 + 4 )
56 
57 
58  static void
61  GXV_Validator valid )
62  {
63  FT_Bytes p = table;
64 
67 
68 
69  GXV_LIMIT_CHECK( 4 + 4 + 4 );
70  optdata->ligActionTable = FT_NEXT_ULONG( p );
71  optdata->componentTable = FT_NEXT_ULONG( p );
72  optdata->ligatureTable = FT_NEXT_ULONG( p );
73 
74  GXV_TRACE(( "offset to ligActionTable=0x%08x\n",
75  optdata->ligActionTable ));
76  GXV_TRACE(( "offset to componentTable=0x%08x\n",
77  optdata->componentTable ));
78  GXV_TRACE(( "offset to ligatureTable=0x%08x\n",
79  optdata->ligatureTable ));
80  }
81 
82 
83  static void
85  FT_ULong classTable,
86  FT_ULong stateArray,
87  FT_ULong entryTable,
88  FT_ULong* classTable_length_p,
89  FT_ULong* stateArray_length_p,
90  FT_ULong* entryTable_length_p,
91  GXV_Validator valid )
92  {
93  FT_ULong o[6];
94  FT_ULong* l[6];
95  FT_ULong buff[7];
96 
99 
100 
101  GXV_NAME_ENTER( "subtable boundaries setup" );
102 
103  o[0] = classTable;
104  o[1] = stateArray;
105  o[2] = entryTable;
106  o[3] = optdata->ligActionTable;
107  o[4] = optdata->componentTable;
108  o[5] = optdata->ligatureTable;
109  l[0] = classTable_length_p;
110  l[1] = stateArray_length_p;
111  l[2] = entryTable_length_p;
112  l[3] = &(optdata->ligActionTable_length);
113  l[4] = &(optdata->componentTable_length);
114  l[5] = &(optdata->ligatureTable_length);
115 
116  gxv_set_length_by_ulong_offset( o, l, buff, 6, table_size, valid );
117 
118  GXV_TRACE(( "classTable: offset=0x%08x length=0x%08x\n",
119  classTable, *classTable_length_p ));
120  GXV_TRACE(( "stateArray: offset=0x%08x length=0x%08x\n",
121  stateArray, *stateArray_length_p ));
122  GXV_TRACE(( "entryTable: offset=0x%08x length=0x%08x\n",
123  entryTable, *entryTable_length_p ));
124  GXV_TRACE(( "ligActionTable: offset=0x%08x length=0x%08x\n",
125  optdata->ligActionTable,
126  optdata->ligActionTable_length ));
127  GXV_TRACE(( "componentTable: offset=0x%08x length=0x%08x\n",
128  optdata->componentTable,
129  optdata->componentTable_length ));
130  GXV_TRACE(( "ligatureTable: offset=0x%08x length=0x%08x\n",
131  optdata->ligatureTable,
132  optdata->ligatureTable_length ));
133 
134  GXV_EXIT;
135  }
136 
137 
138 #define GXV_MORX_LIGACTION_ENTRY_SIZE 4
139 
140 
141  static void
143  FT_Bytes table,
144  FT_UShort ligActionIndex,
145  GXV_Validator valid )
146  {
147  /* access ligActionTable */
150 
151  FT_Bytes lat_base = table + optdata->ligActionTable;
152  FT_Bytes p = lat_base +
153  ligActionIndex * GXV_MORX_LIGACTION_ENTRY_SIZE;
154  FT_Bytes lat_limit = lat_base + optdata->ligActionTable;
155 
156 
157  if ( p < lat_base )
158  {
159  GXV_TRACE(( "p < lat_base (%d byte rewind)\n", lat_base - p ));
161  }
162  else if ( lat_limit < p )
163  {
164  GXV_TRACE(( "lat_limit < p (%d byte overrun)\n", p - lat_limit ));
166  }
167 
168  {
169  /* validate entry in ligActionTable */
170  FT_ULong lig_action;
171 #ifdef GXV_LOAD_UNUSED_VARS
172  FT_UShort last;
173  FT_UShort store;
174 #endif
176  FT_Long gid_limit;
177 
178 
179  lig_action = FT_NEXT_ULONG( p );
180 #ifdef GXV_LOAD_UNUSED_VARS
181  last = (FT_UShort)( ( lig_action >> 31 ) & 1 );
182  store = (FT_UShort)( ( lig_action >> 30 ) & 1 );
183 #endif
184 
185  offset = lig_action & 0x3FFFFFFFUL;
186 
187  /* this offset is 30-bit signed value to add to GID */
188  /* it is different from the location offset in mort */
189  if ( ( offset & 0x3FFF0000UL ) == 0x3FFF0000UL )
190  { /* negative offset */
191  gid_limit = valid->face->num_glyphs - ( offset & 0x0000FFFFUL );
192  if ( gid_limit > 0 )
193  return;
194 
195  GXV_TRACE(( "ligature action table includes"
196  " too negative offset moving all GID"
197  " below defined range: 0x%04x\n",
198  offset & 0xFFFFU ));
200  }
201  else if ( ( offset & 0x3FFF0000UL ) == 0x0000000UL )
202  { /* positive offset */
203  if ( (FT_Long)offset < valid->face->num_glyphs )
204  return;
205 
206  GXV_TRACE(( "ligature action table includes"
207  " too large offset moving all GID"
208  " over defined range: 0x%04x\n",
209  offset & 0xFFFFU ));
211  }
212 
213  GXV_TRACE(( "ligature action table includes"
214  " invalid offset to add to 16-bit GID:"
215  " 0x%08x\n", offset ));
217  }
218  }
219 
220 
221  static void
223  FT_UShort state,
225  GXV_StateTable_GlyphOffsetCPtr glyphOffset_p,
226  FT_Bytes table,
227  FT_Bytes limit,
228  GXV_Validator valid )
229  {
230 #ifdef GXV_LOAD_UNUSED_VARS
231  FT_UShort setComponent;
232  FT_UShort dontAdvance;
233  FT_UShort performAction;
234 #endif
235  FT_UShort reserved;
236  FT_UShort ligActionIndex;
237 
238  FT_UNUSED( state );
239  FT_UNUSED( limit );
240 
241 
242 #ifdef GXV_LOAD_UNUSED_VARS
243  setComponent = (FT_UShort)( ( flags >> 15 ) & 1 );
244  dontAdvance = (FT_UShort)( ( flags >> 14 ) & 1 );
245  performAction = (FT_UShort)( ( flags >> 13 ) & 1 );
246 #endif
247 
248  reserved = (FT_UShort)( flags & 0x1FFF );
249  ligActionIndex = glyphOffset_p->u;
250 
251  if ( reserved > 0 )
252  GXV_TRACE(( " reserved 14bit is non-zero\n" ));
253 
254  if ( 0 < ligActionIndex )
256  table, ligActionIndex, valid );
257  }
258 
259 
260  static void
262  GXV_Validator valid )
263  {
266 
267  FT_Bytes p = table + optdata->ligatureTable;
268  FT_Bytes limit = table + optdata->ligatureTable
269  + optdata->ligatureTable_length;
270 
271 
272  GXV_NAME_ENTER( "morx chain subtable type2 - substitutionTable" );
273 
274  if ( 0 != optdata->ligatureTable )
275  {
276  /* Apple does not give specification of ligatureTable format */
277  while ( p < limit )
278  {
279  FT_UShort lig_gid;
280 
281 
282  GXV_LIMIT_CHECK( 2 );
283  lig_gid = FT_NEXT_USHORT( p );
284  if ( lig_gid < valid->face->num_glyphs )
286  }
287  }
288 
289  GXV_EXIT;
290  }
291 
292 
293  FT_LOCAL_DEF( void )
295  FT_Bytes limit,
296  GXV_Validator valid )
297  {
298  FT_Bytes p = table;
299 
301 
302 
303  GXV_NAME_ENTER( "morx chain subtable type2 (Ligature Substitution)" );
304 
306 
307  valid->xstatetable.optdata =
308  &lig_rec;
309  valid->xstatetable.optdata_load_func =
311  valid->xstatetable.subtable_setup_func =
313  valid->xstatetable.entry_glyphoffset_fmt =
315  valid->xstatetable.entry_validate_func =
317 
318  gxv_XStateTable_validate( p, limit, valid );
319 
320  p += valid->subtable_length;
322 
323  GXV_EXIT;
324  }
325 
326 
327 /* END */
GLenum GLsizei GLenum GLenum const GLvoid * table
Definition: glew.h:4422
signed long FT_Long
Definition: fttypes.h:238
unsigned long FT_ULong
Definition: fttypes.h:249
#define GXV_NAME_ENTER(name)
Definition: gxvcommn.h:301
#define GXV_TRACE(s)
Definition: gxvcommn.h:304
gxv_XStateTable_validate(FT_Bytes table, FT_Bytes limit, GXV_Validator valid)
Definition: gxvcommn.c:1558
struct GXV_morx_subtable_type2_StateOptRec_ * GXV_morx_subtable_type2_StateOptRecData
if(!yyg->yy_init)
#define GXV_SET_ERR_IF_PARANOID(err)
Definition: gxvcommn.h:66
#define GXV_MORX_LIGACTION_ENTRY_SIZE
Definition: gxvmorx2.c:138
#define GXV_MORX_SUBTABLE_TYPE2_HEADER_SIZE
Definition: gxvmorx2.c:54
static void gxv_morx_subtable_type2_subtable_setup(FT_ULong table_size, FT_ULong classTable, FT_ULong stateArray, FT_ULong entryTable, FT_ULong *classTable_length_p, FT_ULong *stateArray_length_p, FT_ULong *entryTable_length_p, GXV_Validator valid)
Definition: gxvmorx2.c:84
#define GXV_EXIT
Definition: gxvcommn.h:302
#define FT_LOCAL_DEF(x)
Definition: ftconfig.h:467
GLenum face
Definition: gl2ext.h:1490
GLfloat GLfloat p
Definition: glew.h:14938
GLint limit
Definition: glew.h:11829
GXV_XStateTable_ValidatorRec xstatetable
Definition: gxvcommn.h:255
const FT_Byte * FT_Bytes
Definition: fttypes.h:161
#define FT_NEXT_USHORT(buffer)
Definition: ftstream.h:233
GLdouble l
Definition: glew.h:8383
#define FT_INVALID_OFFSET
Definition: ftvalid.h:129
struct GXV_morx_subtable_type2_StateOptRec_ GXV_morx_subtable_type2_StateOptRec
GLintptr offset
Definition: glew.h:1668
GLenum GLsizei GLsizei GLsizei GLsizei GLbitfield flags
Definition: glew.h:2767
FT_Long num_glyphs
Definition: freetype.h:920
static void gxv_morx_subtable_type2_ligActionIndex_validate(FT_Bytes table, FT_UShort ligActionIndex, GXV_Validator valid)
Definition: gxvmorx2.c:142
#define FT_NEXT_ULONG(buffer)
Definition: ftstream.h:245
static void gxv_morx_subtable_type2_opttable_load(FT_Bytes table, FT_Bytes limit, GXV_Validator valid)
Definition: gxvmorx2.c:59
static void gxv_morx_subtable_type2_ligatureTable_validate(FT_Bytes table, GXV_Validator valid)
Definition: gxvmorx2.c:261
#define FT_INVALID_GLYPH_ID
Definition: ftvalid.h:137
unsigned short FT_UShort
Definition: fttypes.h:205
static void gxv_morx_subtable_type2_entry_validate(FT_UShort state, FT_UShort flags, GXV_StateTable_GlyphOffsetCPtr glyphOffset_p, FT_Bytes table, FT_Bytes limit, GXV_Validator valid)
Definition: gxvmorx2.c:222
#define FT_UNUSED(arg)
Definition: ftconfig.h:101
gxv_set_length_by_ulong_offset(FT_ULong *offset, FT_ULong **length, FT_ULong *buff, FT_UInt nmemb, FT_ULong limit, GXV_Validator valid)
Definition: gxvcommn.c:128
#define GXV_LIMIT_CHECK(_count)
Definition: gxvcommn.h:272
gxv_morx_subtable_type2_validate(FT_Bytes table, FT_Bytes limit, GXV_Validator valid)
Definition: gxvmorx2.c:294