Suzuki, Toshiya (鈴木俊哉) | a438621 | 2005-08-24 04:31:31 +0000 | [diff] [blame] | 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 | /***************************************************************************/ |
Werner Lemberg | 4a7f0b1 | 2005-09-01 07:33:03 +0000 | [diff] [blame] | 20 | /* */ |
Suzuki, Toshiya (鈴木俊哉) | a438621 | 2005-08-24 04:31:31 +0000 | [diff] [blame] | 21 | /* gxvalid is derived from both gxlayout module and otvalid module. */ |
Werner Lemberg | 4a7f0b1 | 2005-09-01 07:33:03 +0000 | [diff] [blame] | 22 | /* Development of gxlayout is supported by the Information-technology */ |
| 23 | /* Promotion Agency(IPA), Japan. */ |
| 24 | /* */ |
Suzuki, Toshiya (鈴木俊哉) | a438621 | 2005-08-24 04:31:31 +0000 | [diff] [blame] | 25 | /***************************************************************************/ |
| 26 | |
Werner Lemberg | 4a7f0b1 | 2005-09-01 07:33:03 +0000 | [diff] [blame] | 27 | |
Suzuki, Toshiya (鈴木俊哉) | a438621 | 2005-08-24 04:31:31 +0000 | [diff] [blame] | 28 | #include "gxvmorx.h" |
| 29 | |
Werner Lemberg | 4a7f0b1 | 2005-09-01 07:33:03 +0000 | [diff] [blame] | 30 | |
Suzuki, Toshiya (鈴木俊哉) | a438621 | 2005-08-24 04:31:31 +0000 | [diff] [blame] | 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 | |
| 50 | } GXV_morx_subtable_type2_StateOptRec, |
| 51 | *GXV_morx_subtable_type2_StateOptRecData; |
| 52 | |
Werner Lemberg | 4a7f0b1 | 2005-09-01 07:33:03 +0000 | [diff] [blame] | 53 | |
| 54 | #define GXV_MORX_SUBTABLE_TYPE2_HEADER_SIZE \ |
| 55 | ( GXV_XSTATETABLE_HEADER_SIZE + 4 + 4 + 4 ) |
| 56 | |
Suzuki, Toshiya (鈴木俊哉) | a438621 | 2005-08-24 04:31:31 +0000 | [diff] [blame] | 57 | |
| 58 | static void |
| 59 | gxv_morx_subtable_type2_opttable_load( FT_Bytes table, |
| 60 | FT_Bytes limit, |
| 61 | GXV_Validator valid ) |
| 62 | { |
Werner Lemberg | 4a7f0b1 | 2005-09-01 07:33:03 +0000 | [diff] [blame] | 63 | FT_Bytes p = table; |
| 64 | |
| 65 | GXV_morx_subtable_type2_StateOptRecData optdata = |
Werner Lemberg | 99aa14c | 2005-09-05 19:31:27 +0000 | [diff] [blame] | 66 | (GXV_morx_subtable_type2_StateOptRecData)valid->xstatetable.optdata; |
Werner Lemberg | 4a7f0b1 | 2005-09-01 07:33:03 +0000 | [diff] [blame] | 67 | |
Suzuki, Toshiya (鈴木俊哉) | a438621 | 2005-08-24 04:31:31 +0000 | [diff] [blame] | 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 | |
Werner Lemberg | 4a7f0b1 | 2005-09-01 07:33:03 +0000 | [diff] [blame] | 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 )); |
Suzuki, Toshiya (鈴木俊哉) | a438621 | 2005-08-24 04:31:31 +0000 | [diff] [blame] | 80 | } |
| 81 | |
Werner Lemberg | 4a7f0b1 | 2005-09-01 07:33:03 +0000 | [diff] [blame] | 82 | |
Suzuki, Toshiya (鈴木俊哉) | a438621 | 2005-08-24 04:31:31 +0000 | [diff] [blame] | 83 | static void |
| 84 | gxv_morx_subtable_type2_subtable_setup( FT_ULong table_size, |
| 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]; |
Werner Lemberg | 4a7f0b1 | 2005-09-01 07:33:03 +0000 | [diff] [blame] | 96 | |
| 97 | GXV_morx_subtable_type2_StateOptRecData optdata = |
Werner Lemberg | 99aa14c | 2005-09-05 19:31:27 +0000 | [diff] [blame] | 98 | (GXV_morx_subtable_type2_StateOptRecData)valid->xstatetable.optdata; |
Suzuki, Toshiya (鈴木俊哉) | a438621 | 2005-08-24 04:31:31 +0000 | [diff] [blame] | 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", |
Werner Lemberg | 4a7f0b1 | 2005-09-01 07:33:03 +0000 | [diff] [blame] | 119 | classTable, *classTable_length_p )); |
Suzuki, Toshiya (鈴木俊哉) | a438621 | 2005-08-24 04:31:31 +0000 | [diff] [blame] | 120 | GXV_TRACE(( "stateArray: offset=0x%08x length=0x%08x\n", |
Werner Lemberg | 4a7f0b1 | 2005-09-01 07:33:03 +0000 | [diff] [blame] | 121 | stateArray, *stateArray_length_p )); |
Suzuki, Toshiya (鈴木俊哉) | a438621 | 2005-08-24 04:31:31 +0000 | [diff] [blame] | 122 | GXV_TRACE(( "entryTable: offset=0x%08x length=0x%08x\n", |
Werner Lemberg | 4a7f0b1 | 2005-09-01 07:33:03 +0000 | [diff] [blame] | 123 | entryTable, *entryTable_length_p )); |
Suzuki, Toshiya (鈴木俊哉) | a438621 | 2005-08-24 04:31:31 +0000 | [diff] [blame] | 124 | GXV_TRACE(( "ligActionTable: offset=0x%08x length=0x%08x\n", |
Werner Lemberg | 4a7f0b1 | 2005-09-01 07:33:03 +0000 | [diff] [blame] | 125 | optdata->ligActionTable, |
| 126 | optdata->ligActionTable_length )); |
Suzuki, Toshiya (鈴木俊哉) | a438621 | 2005-08-24 04:31:31 +0000 | [diff] [blame] | 127 | GXV_TRACE(( "componentTable: offset=0x%08x length=0x%08x\n", |
Werner Lemberg | 4a7f0b1 | 2005-09-01 07:33:03 +0000 | [diff] [blame] | 128 | optdata->componentTable, |
| 129 | optdata->componentTable_length )); |
Suzuki, Toshiya (鈴木俊哉) | a438621 | 2005-08-24 04:31:31 +0000 | [diff] [blame] | 130 | GXV_TRACE(( "ligatureTable: offset=0x%08x length=0x%08x\n", |
Werner Lemberg | 4a7f0b1 | 2005-09-01 07:33:03 +0000 | [diff] [blame] | 131 | optdata->ligatureTable, |
| 132 | optdata->ligatureTable_length )); |
| 133 | |
Suzuki, Toshiya (鈴木俊哉) | a438621 | 2005-08-24 04:31:31 +0000 | [diff] [blame] | 134 | GXV_EXIT; |
| 135 | } |
| 136 | |
Werner Lemberg | 4a7f0b1 | 2005-09-01 07:33:03 +0000 | [diff] [blame] | 137 | |
| 138 | #define GXV_MORX_LIGACTION_ENTRY_SIZE 4 |
Suzuki, Toshiya (鈴木俊哉) | a438621 | 2005-08-24 04:31:31 +0000 | [diff] [blame] | 139 | |
| 140 | |
| 141 | static void |
Werner Lemberg | 4a7f0b1 | 2005-09-01 07:33:03 +0000 | [diff] [blame] | 142 | gxv_morx_subtable_type2_ligActionIndex_validate( |
| 143 | FT_Bytes table, |
| 144 | FT_UShort ligActionIndex, |
| 145 | GXV_Validator valid ) |
Suzuki, Toshiya (鈴木俊哉) | a438621 | 2005-08-24 04:31:31 +0000 | [diff] [blame] | 146 | { |
| 147 | /* access ligActionTable */ |
Werner Lemberg | 4a7f0b1 | 2005-09-01 07:33:03 +0000 | [diff] [blame] | 148 | GXV_morx_subtable_type2_StateOptRecData optdata = |
Werner Lemberg | 99aa14c | 2005-09-05 19:31:27 +0000 | [diff] [blame] | 149 | (GXV_morx_subtable_type2_StateOptRecData)valid->xstatetable.optdata; |
Werner Lemberg | 4a7f0b1 | 2005-09-01 07:33:03 +0000 | [diff] [blame] | 150 | |
Suzuki, Toshiya (鈴木俊哉) | a438621 | 2005-08-24 04:31:31 +0000 | [diff] [blame] | 151 | FT_Bytes lat_base = table + optdata->ligActionTable; |
Werner Lemberg | 4a7f0b1 | 2005-09-01 07:33:03 +0000 | [diff] [blame] | 152 | FT_Bytes p = lat_base + |
| 153 | ligActionIndex * GXV_MORX_LIGACTION_ENTRY_SIZE; |
Suzuki, Toshiya (鈴木俊哉) | a438621 | 2005-08-24 04:31:31 +0000 | [diff] [blame] | 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 )); |
| 160 | FT_INVALID_OFFSET; |
| 161 | } |
| 162 | else if ( lat_limit < p ) |
| 163 | { |
| 164 | GXV_TRACE(( "lat_limit < p (%d byte overrun)\n", p - lat_limit )); |
| 165 | FT_INVALID_OFFSET; |
| 166 | } |
| 167 | |
| 168 | { |
| 169 | /* validate entry in ligActionTable */ |
| 170 | FT_ULong lig_action; |
| 171 | FT_UShort last; |
| 172 | FT_UShort store; |
| 173 | FT_ULong offset; |
| 174 | |
| 175 | |
| 176 | lig_action = FT_NEXT_ULONG( p ); |
Werner Lemberg | 7c25946 | 2005-09-28 07:34:45 +0000 | [diff] [blame] | 177 | last = (FT_UShort)( ( lig_action >> 31 ) & 1 ); |
| 178 | store = (FT_UShort)( ( lig_action >> 30 ) & 1 ); |
| 179 | |
| 180 | offset = lig_action & 0x3FFFFFFFUL; |
Suzuki, Toshiya (鈴木俊哉) | a438621 | 2005-08-24 04:31:31 +0000 | [diff] [blame] | 181 | } |
| 182 | } |
| 183 | |
| 184 | |
| 185 | static void |
Werner Lemberg | 4a7f0b1 | 2005-09-01 07:33:03 +0000 | [diff] [blame] | 186 | gxv_morx_subtable_type2_entry_validate( |
| 187 | FT_UShort state, |
| 188 | FT_UShort flags, |
| 189 | GXV_StateTable_GlyphOffsetDesc glyphOffset, |
| 190 | FT_Bytes table, |
| 191 | FT_Bytes limit, |
| 192 | GXV_Validator valid ) |
Suzuki, Toshiya (鈴木俊哉) | a438621 | 2005-08-24 04:31:31 +0000 | [diff] [blame] | 193 | { |
Werner Lemberg | 4a7f0b1 | 2005-09-01 07:33:03 +0000 | [diff] [blame] | 194 | FT_UShort setComponent; |
| 195 | FT_UShort dontAdvance; |
| 196 | FT_UShort performAction; |
| 197 | FT_UShort reserved; |
| 198 | FT_UShort ligActionIndex; |
Suzuki, Toshiya (鈴木俊哉) | a438621 | 2005-08-24 04:31:31 +0000 | [diff] [blame] | 199 | |
Werner Lemberg | 4a7f0b1 | 2005-09-01 07:33:03 +0000 | [diff] [blame] | 200 | FT_UNUSED( state ); |
| 201 | FT_UNUSED( limit ); |
| 202 | |
| 203 | |
Werner Lemberg | 7c25946 | 2005-09-28 07:34:45 +0000 | [diff] [blame] | 204 | setComponent = (FT_UShort)( ( flags >> 15 ) & 1 ); |
| 205 | dontAdvance = (FT_UShort)( ( flags >> 14 ) & 1 ); |
| 206 | performAction = (FT_UShort)( ( flags >> 13 ) & 1 ); |
| 207 | |
| 208 | reserved = (FT_UShort)( flags & 0x1FFF ); |
Suzuki, Toshiya (鈴木俊哉) | a438621 | 2005-08-24 04:31:31 +0000 | [diff] [blame] | 209 | ligActionIndex = glyphOffset.u; |
| 210 | |
| 211 | if ( reserved > 0 ) |
| 212 | GXV_TRACE(( " reserved 14bit is non-zero\n" )); |
| 213 | |
| 214 | if ( 0 < ligActionIndex ) |
Werner Lemberg | 4a7f0b1 | 2005-09-01 07:33:03 +0000 | [diff] [blame] | 215 | gxv_morx_subtable_type2_ligActionIndex_validate( |
| 216 | table, ligActionIndex, valid ); |
Suzuki, Toshiya (鈴木俊哉) | a438621 | 2005-08-24 04:31:31 +0000 | [diff] [blame] | 217 | } |
| 218 | |
| 219 | |
| 220 | static void |
| 221 | gxv_morx_subtable_type2_ligatureTable_validate( FT_Bytes table, |
| 222 | GXV_Validator valid ) |
| 223 | { |
Werner Lemberg | 4a7f0b1 | 2005-09-01 07:33:03 +0000 | [diff] [blame] | 224 | GXV_morx_subtable_type2_StateOptRecData optdata = |
Werner Lemberg | 99aa14c | 2005-09-05 19:31:27 +0000 | [diff] [blame] | 225 | (GXV_morx_subtable_type2_StateOptRecData)valid->xstatetable.optdata; |
Werner Lemberg | 4a7f0b1 | 2005-09-01 07:33:03 +0000 | [diff] [blame] | 226 | |
Suzuki, Toshiya (鈴木俊哉) | a438621 | 2005-08-24 04:31:31 +0000 | [diff] [blame] | 227 | FT_Bytes p = table + optdata->ligatureTable; |
| 228 | FT_Bytes limit = table + optdata->ligatureTable |
| 229 | + optdata->ligatureTable_length; |
| 230 | |
Werner Lemberg | 4a7f0b1 | 2005-09-01 07:33:03 +0000 | [diff] [blame] | 231 | |
Suzuki, Toshiya (鈴木俊哉) | a438621 | 2005-08-24 04:31:31 +0000 | [diff] [blame] | 232 | GXV_NAME_ENTER( "morx chain subtable type2 - substitutionTable" ); |
Werner Lemberg | 4a7f0b1 | 2005-09-01 07:33:03 +0000 | [diff] [blame] | 233 | |
Suzuki, Toshiya (鈴木俊哉) | a438621 | 2005-08-24 04:31:31 +0000 | [diff] [blame] | 234 | if ( 0 != optdata->ligatureTable ) |
| 235 | { |
| 236 | /* Apple does not give specification of ligatureTable format */ |
| 237 | while ( p < limit ) |
| 238 | { |
Werner Lemberg | 4a7f0b1 | 2005-09-01 07:33:03 +0000 | [diff] [blame] | 239 | FT_UShort lig_gid; |
| 240 | |
Suzuki, Toshiya (鈴木俊哉) | a438621 | 2005-08-24 04:31:31 +0000 | [diff] [blame] | 241 | |
| 242 | GXV_LIMIT_CHECK( 2 ); |
| 243 | lig_gid = FT_NEXT_USHORT( p ); |
| 244 | } |
| 245 | } |
Werner Lemberg | 4a7f0b1 | 2005-09-01 07:33:03 +0000 | [diff] [blame] | 246 | |
Suzuki, Toshiya (鈴木俊哉) | a438621 | 2005-08-24 04:31:31 +0000 | [diff] [blame] | 247 | GXV_EXIT; |
| 248 | } |
| 249 | |
| 250 | |
Werner Lemberg | 99aa14c | 2005-09-05 19:31:27 +0000 | [diff] [blame] | 251 | FT_LOCAL_DEF( void ) |
Suzuki, Toshiya (鈴木俊哉) | a438621 | 2005-08-24 04:31:31 +0000 | [diff] [blame] | 252 | gxv_morx_subtable_type2_validate( FT_Bytes table, |
| 253 | FT_Bytes limit, |
| 254 | GXV_Validator valid ) |
| 255 | { |
| 256 | FT_Bytes p = table; |
Werner Lemberg | 4a7f0b1 | 2005-09-01 07:33:03 +0000 | [diff] [blame] | 257 | |
Suzuki, Toshiya (鈴木俊哉) | a438621 | 2005-08-24 04:31:31 +0000 | [diff] [blame] | 258 | GXV_morx_subtable_type2_StateOptRec lig_rec; |
| 259 | |
Werner Lemberg | 4a7f0b1 | 2005-09-01 07:33:03 +0000 | [diff] [blame] | 260 | |
Suzuki, Toshiya (鈴木俊哉) | a438621 | 2005-08-24 04:31:31 +0000 | [diff] [blame] | 261 | GXV_NAME_ENTER( "morx chain subtable type2 (Ligature Substitution)" ); |
| 262 | |
Werner Lemberg | 99aa14c | 2005-09-05 19:31:27 +0000 | [diff] [blame] | 263 | GXV_LIMIT_CHECK( GXV_MORX_SUBTABLE_TYPE2_HEADER_SIZE ); |
Suzuki, Toshiya (鈴木俊哉) | a438621 | 2005-08-24 04:31:31 +0000 | [diff] [blame] | 264 | |
Werner Lemberg | 4a7f0b1 | 2005-09-01 07:33:03 +0000 | [diff] [blame] | 265 | valid->xstatetable.optdata = |
| 266 | &lig_rec; |
| 267 | valid->xstatetable.optdata_load_func = |
| 268 | gxv_morx_subtable_type2_opttable_load; |
| 269 | valid->xstatetable.subtable_setup_func = |
| 270 | gxv_morx_subtable_type2_subtable_setup; |
| 271 | valid->xstatetable.entry_glyphoffset_fmt = |
| 272 | GXV_GLYPHOFFSET_USHORT; |
| 273 | valid->xstatetable.entry_validate_func = |
| 274 | gxv_morx_subtable_type2_entry_validate; |
| 275 | |
Suzuki, Toshiya (鈴木俊哉) | a438621 | 2005-08-24 04:31:31 +0000 | [diff] [blame] | 276 | gxv_XStateTable_validate( p, limit, valid ); |
Werner Lemberg | 4a7f0b1 | 2005-09-01 07:33:03 +0000 | [diff] [blame] | 277 | |
Suzuki, Toshiya (鈴木俊哉) | a438621 | 2005-08-24 04:31:31 +0000 | [diff] [blame] | 278 | p += valid->subtable_length; |
| 279 | gxv_morx_subtable_type2_ligatureTable_validate( table, valid ); |
Werner Lemberg | 4a7f0b1 | 2005-09-01 07:33:03 +0000 | [diff] [blame] | 280 | |
Suzuki, Toshiya (鈴木俊哉) | a438621 | 2005-08-24 04:31:31 +0000 | [diff] [blame] | 281 | GXV_EXIT; |
| 282 | } |
| 283 | |
| 284 | |
| 285 | /* END */ |