[FREETYPE]
[reactos.git] / reactos / lib / 3rdparty / freetype / src / gxvalid / gxvmorx5.c
1 /***************************************************************************/
2 /* */
3 /* gxvmorx5.c */
4 /* */
5 /* TrueTypeGX/AAT morx table validation */
6 /* body for type5 (Contextual Glyph Insertion) subtable. */
7 /* */
8 /* Copyright 2005, 2007 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 /*
42 * `morx' subtable type5 (Contextual Glyph Insertion)
43 * has format of a StateTable with insertion-glyph-list
44 * without name. However, the 32bit offset from the head
45 * of subtable to the i-g-l is given after `entryTable',
46 * without variable name specification (the existence of
47 * this offset to the table is different from mort type5).
48 */
49
50
51 typedef struct GXV_morx_subtable_type5_StateOptRec_
52 {
53 FT_ULong insertionGlyphList;
54 FT_ULong insertionGlyphList_length;
55
56 } GXV_morx_subtable_type5_StateOptRec,
57 *GXV_morx_subtable_type5_StateOptRecData;
58
59
60 #define GXV_MORX_SUBTABLE_TYPE5_HEADER_SIZE \
61 ( GXV_STATETABLE_HEADER_SIZE + 4 )
62
63
64 static void
65 gxv_morx_subtable_type5_insertionGlyphList_load( FT_Bytes table,
66 FT_Bytes limit,
67 GXV_Validator valid )
68 {
69 FT_Bytes p = table;
70
71 GXV_morx_subtable_type5_StateOptRecData optdata =
72 (GXV_morx_subtable_type5_StateOptRecData)valid->xstatetable.optdata;
73
74
75 GXV_LIMIT_CHECK( 4 );
76 optdata->insertionGlyphList = FT_NEXT_ULONG( p );
77 }
78
79
80 static void
81 gxv_morx_subtable_type5_subtable_setup( FT_ULong table_size,
82 FT_ULong classTable,
83 FT_ULong stateArray,
84 FT_ULong entryTable,
85 FT_ULong* classTable_length_p,
86 FT_ULong* stateArray_length_p,
87 FT_ULong* entryTable_length_p,
88 GXV_Validator valid )
89 {
90 FT_ULong o[4];
91 FT_ULong* l[4];
92 FT_ULong buff[5];
93
94 GXV_morx_subtable_type5_StateOptRecData optdata =
95 (GXV_morx_subtable_type5_StateOptRecData)valid->xstatetable.optdata;
96
97
98 o[0] = classTable;
99 o[1] = stateArray;
100 o[2] = entryTable;
101 o[3] = optdata->insertionGlyphList;
102 l[0] = classTable_length_p;
103 l[1] = stateArray_length_p;
104 l[2] = entryTable_length_p;
105 l[3] = &(optdata->insertionGlyphList_length);
106
107 gxv_set_length_by_ulong_offset( o, l, buff, 4, table_size, valid );
108 }
109
110
111 static void
112 gxv_morx_subtable_type5_InsertList_validate( FT_UShort table_index,
113 FT_UShort count,
114 FT_Bytes table,
115 FT_Bytes limit,
116 GXV_Validator valid )
117 {
118 FT_Bytes p = table + table_index * 2;
119
120
121 #ifndef GXV_LOAD_TRACE_VARS
122 GXV_LIMIT_CHECK( count * 2 );
123 #else
124 while ( p < table + count * 2 + table_index * 2 )
125 {
126 FT_UShort insert_glyphID;
127
128
129 GXV_LIMIT_CHECK( 2 );
130 insert_glyphID = FT_NEXT_USHORT( p );
131 GXV_TRACE(( " 0x%04x", insert_glyphID ));
132 }
133
134 GXV_TRACE(( "\n" ));
135 #endif
136 }
137
138
139 static void
140 gxv_morx_subtable_type5_entry_validate(
141 FT_UShort state,
142 FT_UShort flags,
143 GXV_StateTable_GlyphOffsetCPtr glyphOffset_p,
144 FT_Bytes table,
145 FT_Bytes limit,
146 GXV_Validator valid )
147 {
148 #ifdef GXV_LOAD_UNUSED_VARS
149 FT_Bool setMark;
150 FT_Bool dontAdvance;
151 FT_Bool currentIsKashidaLike;
152 FT_Bool markedIsKashidaLike;
153 FT_Bool currentInsertBefore;
154 FT_Bool markedInsertBefore;
155 #endif
156 FT_Byte currentInsertCount;
157 FT_Byte markedInsertCount;
158 FT_Byte currentInsertList;
159 FT_UShort markedInsertList;
160
161 FT_UNUSED( state );
162
163
164 #ifdef GXV_LOAD_UNUSED_VARS
165 setMark = FT_BOOL( ( flags >> 15 ) & 1 );
166 dontAdvance = FT_BOOL( ( flags >> 14 ) & 1 );
167 currentIsKashidaLike = FT_BOOL( ( flags >> 13 ) & 1 );
168 markedIsKashidaLike = FT_BOOL( ( flags >> 12 ) & 1 );
169 currentInsertBefore = FT_BOOL( ( flags >> 11 ) & 1 );
170 markedInsertBefore = FT_BOOL( ( flags >> 10 ) & 1 );
171 #endif
172
173 currentInsertCount = (FT_Byte)( ( flags >> 5 ) & 0x1F );
174 markedInsertCount = (FT_Byte)( flags & 0x001F );
175
176 currentInsertList = (FT_Byte) ( glyphOffset_p->ul >> 16 );
177 markedInsertList = (FT_UShort)( glyphOffset_p->ul );
178
179 if ( currentInsertList && 0 != currentInsertCount )
180 gxv_morx_subtable_type5_InsertList_validate( currentInsertList,
181 currentInsertCount,
182 table, limit,
183 valid );
184
185 if ( markedInsertList && 0 != markedInsertCount )
186 gxv_morx_subtable_type5_InsertList_validate( markedInsertList,
187 markedInsertCount,
188 table, limit,
189 valid );
190 }
191
192
193 FT_LOCAL_DEF( void )
194 gxv_morx_subtable_type5_validate( FT_Bytes table,
195 FT_Bytes limit,
196 GXV_Validator valid )
197 {
198 FT_Bytes p = table;
199
200 GXV_morx_subtable_type5_StateOptRec et_rec;
201 GXV_morx_subtable_type5_StateOptRecData et = &et_rec;
202
203
204 GXV_NAME_ENTER( "morx chain subtable type5 (Glyph Insertion)" );
205
206 GXV_LIMIT_CHECK( GXV_MORX_SUBTABLE_TYPE5_HEADER_SIZE );
207
208 valid->xstatetable.optdata =
209 et;
210 valid->xstatetable.optdata_load_func =
211 gxv_morx_subtable_type5_insertionGlyphList_load;
212 valid->xstatetable.subtable_setup_func =
213 gxv_morx_subtable_type5_subtable_setup;
214 valid->xstatetable.entry_glyphoffset_fmt =
215 GXV_GLYPHOFFSET_ULONG;
216 valid->xstatetable.entry_validate_func =
217 gxv_morx_subtable_type5_entry_validate;
218
219 gxv_XStateTable_validate( p, limit, valid );
220
221 GXV_EXIT;
222 }
223
224
225 /* END */