Suzuki, Toshiya (鈴木俊哉) | a438621 | 2005-08-24 04:31:31 +0000 | [diff] [blame] | 1 | /***************************************************************************/ |
| 2 | /* */ |
| 3 | /* gxvlcar.c */ |
| 4 | /* */ |
| 5 | /* TrueTypeGX/AAT lcar table validation (body). */ |
| 6 | /* */ |
Werner Lemberg | a4aa1c5 | 2005-08-31 22:39:23 +0000 | [diff] [blame] | 7 | /* Copyright 2004, 2005 by suzuki toshiya, Masatake YAMATO, Red Hat K.K., */ |
Suzuki, Toshiya (鈴木俊哉) | a438621 | 2005-08-24 04:31:31 +0000 | [diff] [blame] | 8 | /* David Turner, Robert Wilhelm, and Werner Lemberg. */ |
| 9 | /* */ |
| 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. */ |
| 15 | /* */ |
| 16 | /***************************************************************************/ |
| 17 | |
| 18 | /***************************************************************************/ |
Werner Lemberg | a4aa1c5 | 2005-08-31 22:39:23 +0000 | [diff] [blame] | 19 | /* */ |
Suzuki, Toshiya (鈴木俊哉) | a438621 | 2005-08-24 04:31:31 +0000 | [diff] [blame] | 20 | /* gxvalid is derived from both gxlayout module and otvalid module. */ |
Werner Lemberg | a4aa1c5 | 2005-08-31 22:39:23 +0000 | [diff] [blame] | 21 | /* Development of gxlayout is supported by the Information-technology */ |
| 22 | /* Promotion Agency(IPA), Japan. */ |
| 23 | /* */ |
Suzuki, Toshiya (鈴木俊哉) | a438621 | 2005-08-24 04:31:31 +0000 | [diff] [blame] | 24 | /***************************************************************************/ |
| 25 | |
| 26 | |
| 27 | #include "gxvalid.h" |
| 28 | #include "gxvcommn.h" |
| 29 | |
Werner Lemberg | a4aa1c5 | 2005-08-31 22:39:23 +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_gxvlcar |
| 39 | |
| 40 | |
Suzuki, Toshiya (鈴木俊哉) | a438621 | 2005-08-24 04:31:31 +0000 | [diff] [blame] | 41 | /*************************************************************************/ |
| 42 | /*************************************************************************/ |
| 43 | /***** *****/ |
| 44 | /***** Data and Types *****/ |
| 45 | /***** *****/ |
| 46 | /*************************************************************************/ |
| 47 | /*************************************************************************/ |
| 48 | |
| 49 | typedef struct GXV_lcar_DataRec_ |
| 50 | { |
| 51 | FT_UShort format; |
| 52 | |
| 53 | } GXV_lcar_DataRec, *GXV_lcar_Data; |
| 54 | |
Werner Lemberg | 4a7f0b1 | 2005-09-01 07:33:03 +0000 | [diff] [blame] | 55 | |
| 56 | #define GXV_LCAR_DATA( FIELD ) GXV_TABLE_DATA( lcar, FIELD ) |
Suzuki, Toshiya (鈴木俊哉) | a438621 | 2005-08-24 04:31:31 +0000 | [diff] [blame] | 57 | |
| 58 | |
| 59 | /*************************************************************************/ |
| 60 | /*************************************************************************/ |
| 61 | /***** *****/ |
| 62 | /***** UTILITY FUNCTIONS *****/ |
| 63 | /***** *****/ |
| 64 | /*************************************************************************/ |
| 65 | /*************************************************************************/ |
| 66 | |
| 67 | static void |
| 68 | gxv_lcar_partial_validate( FT_UShort partial, |
| 69 | FT_UShort glyph, |
| 70 | GXV_Validator valid ) |
| 71 | { |
| 72 | GXV_NAME_ENTER( "partial" ); |
| 73 | |
| 74 | if ( GXV_LCAR_DATA( format ) != 1 ) |
| 75 | goto Exit; |
| 76 | |
| 77 | gxv_ctlPoint_validate( glyph, partial, valid ); |
| 78 | |
| 79 | Exit: |
| 80 | GXV_EXIT; |
| 81 | } |
| 82 | |
| 83 | |
| 84 | static void |
| 85 | gxv_lcar_LookupValue_validate( FT_UShort glyph, |
| 86 | GXV_LookupValueDesc value, |
| 87 | GXV_Validator valid ) |
| 88 | { |
Werner Lemberg | a4aa1c5 | 2005-08-31 22:39:23 +0000 | [diff] [blame] | 89 | FT_Bytes p = valid->root->base + value.u; |
| 90 | FT_Bytes limit = valid->root->limit; |
| 91 | FT_UShort count; |
| 92 | FT_Short partial; |
| 93 | FT_UShort i; |
Suzuki, Toshiya (鈴木俊哉) | a438621 | 2005-08-24 04:31:31 +0000 | [diff] [blame] | 94 | |
| 95 | |
| 96 | GXV_NAME_ENTER( "element in lookupTable" ); |
| 97 | |
Suzuki, Toshiya (鈴木俊哉) | a438621 | 2005-08-24 04:31:31 +0000 | [diff] [blame] | 98 | GXV_LIMIT_CHECK( 2 ); |
| 99 | count = FT_NEXT_USHORT( p ); |
| 100 | |
| 101 | GXV_LIMIT_CHECK( 2 * count ); |
| 102 | for ( i = 0; i < count; i++ ) |
| 103 | { |
| 104 | partial = FT_NEXT_SHORT( p ); |
| 105 | gxv_lcar_partial_validate( partial, glyph, valid ); |
| 106 | } |
| 107 | |
| 108 | GXV_EXIT; |
| 109 | } |
| 110 | |
Werner Lemberg | a4aa1c5 | 2005-08-31 22:39:23 +0000 | [diff] [blame] | 111 | |
Suzuki, Toshiya (鈴木俊哉) | a438621 | 2005-08-24 04:31:31 +0000 | [diff] [blame] | 112 | /* |
| 113 | +------ lcar --------------------+ |
| 114 | | | |
| 115 | | +===============+ | |
| 116 | | | looup header | | |
| 117 | | +===============+ | |
| 118 | | | BinSrchHeader | | |
| 119 | | +===============+ | |
| 120 | | | lastGlyph[0] | | |
| 121 | | +---------------+ | |
| 122 | | | firstGlyph[0] | | head of lcar sfnt table |
| 123 | | +---------------+ | + |
| 124 | | | offset[0] | -> | offset [byte] |
| 125 | | +===============+ | + |
| 126 | | | lastGlyph[1] | | (glyphID - firstGlyph) * 2 [byte] |
| 127 | | +---------------+ | |
| 128 | | | firstGlyph[1] | | |
| 129 | | +---------------+ | |
| 130 | | | offset[1] | | |
| 131 | | +===============+ | |
| 132 | | | |
| 133 | | .... | |
| 134 | | | |
| 135 | | 16bit value array | |
| 136 | | +===============+ | |
| 137 | +------| value | <-------+ |
| 138 | | .... |
| 139 | | |
| 140 | | |
| 141 | | |
| 142 | | |
| 143 | | |
Werner Lemberg | a4aa1c5 | 2005-08-31 22:39:23 +0000 | [diff] [blame] | 144 | +----> lcar values...handled by lcar callback function |
| 145 | */ |
Suzuki, Toshiya (鈴木俊哉) | a438621 | 2005-08-24 04:31:31 +0000 | [diff] [blame] | 146 | |
| 147 | static GXV_LookupValueDesc |
| 148 | gxv_lcar_LookupFmt4_transit( FT_UShort relative_gindex, |
| 149 | GXV_LookupValueDesc base_value, |
| 150 | FT_Bytes lookuptbl_limit, |
| 151 | GXV_Validator valid ) |
| 152 | { |
| 153 | FT_Bytes p; |
| 154 | FT_Bytes limit; |
| 155 | FT_UShort offset; |
| 156 | GXV_LookupValueDesc value; |
| 157 | |
Werner Lemberg | a4aa1c5 | 2005-08-31 22:39:23 +0000 | [diff] [blame] | 158 | FT_UNUSED( lookuptbl_limit ); |
Suzuki, Toshiya (鈴木俊哉) | a438621 | 2005-08-24 04:31:31 +0000 | [diff] [blame] | 159 | |
Werner Lemberg | 7c25946 | 2005-09-28 07:34:45 +0000 | [diff] [blame] | 160 | /* XXX: check range? */ |
| 161 | offset = (FT_UShort)( base_value.u + |
| 162 | relative_gindex * sizeof ( FT_UShort ) ); |
Suzuki, Toshiya (鈴木俊哉) | a438621 | 2005-08-24 04:31:31 +0000 | [diff] [blame] | 163 | p = valid->root->base + offset; |
| 164 | limit = valid->root->limit; |
| 165 | |
| 166 | GXV_LIMIT_CHECK ( 2 ); |
| 167 | value.u = FT_NEXT_USHORT( p ); |
| 168 | |
| 169 | return value; |
| 170 | } |
| 171 | |
| 172 | |
| 173 | /*************************************************************************/ |
| 174 | /*************************************************************************/ |
| 175 | /***** *****/ |
| 176 | /***** lcar TABLE *****/ |
| 177 | /***** *****/ |
| 178 | /*************************************************************************/ |
| 179 | /*************************************************************************/ |
| 180 | |
| 181 | FT_LOCAL_DEF( void ) |
| 182 | gxv_lcar_validate( FT_Bytes table, |
| 183 | FT_Face face, |
| 184 | FT_Validator ftvalid ) |
| 185 | { |
| 186 | FT_Bytes p = table; |
| 187 | FT_Bytes limit = 0; |
| 188 | GXV_ValidatorRec validrec; |
| 189 | GXV_Validator valid = &validrec; |
| 190 | |
| 191 | GXV_lcar_DataRec lcarrec; |
| 192 | GXV_lcar_Data lcar = &lcarrec; |
| 193 | |
| 194 | FT_Fixed version; |
| 195 | |
| 196 | |
| 197 | valid->root = ftvalid; |
| 198 | valid->table_data = lcar; |
| 199 | valid->face = face; |
| 200 | |
Werner Lemberg | a4aa1c5 | 2005-08-31 22:39:23 +0000 | [diff] [blame] | 201 | FT_TRACE3(( "validating `lcar' table\n" )); |
Suzuki, Toshiya (鈴木俊哉) | a438621 | 2005-08-24 04:31:31 +0000 | [diff] [blame] | 202 | GXV_INIT; |
| 203 | |
| 204 | GXV_LIMIT_CHECK( 4 + 2 ); |
| 205 | version = FT_NEXT_ULONG( p ); |
| 206 | GXV_LCAR_DATA( format ) = FT_NEXT_USHORT( p ); |
| 207 | |
Werner Lemberg | a4aa1c5 | 2005-08-31 22:39:23 +0000 | [diff] [blame] | 208 | if ( version != 0x00010000UL) |
Suzuki, Toshiya (鈴木俊哉) | a438621 | 2005-08-24 04:31:31 +0000 | [diff] [blame] | 209 | FT_INVALID_FORMAT; |
| 210 | |
| 211 | if ( GXV_LCAR_DATA( format ) > 1 ) |
| 212 | FT_INVALID_FORMAT; |
| 213 | |
Suzuki, Toshiya (鈴木俊哉) | a438621 | 2005-08-24 04:31:31 +0000 | [diff] [blame] | 214 | valid->lookupval_sign = GXV_LOOKUPVALUE_UNSIGNED; |
| 215 | valid->lookupval_func = gxv_lcar_LookupValue_validate; |
| 216 | valid->lookupfmt4_trans = gxv_lcar_LookupFmt4_transit; |
| 217 | gxv_LookupTable_validate( p, limit, valid ); |
| 218 | |
| 219 | FT_TRACE4(( "\n" )); |
| 220 | } |
| 221 | |
| 222 | |
| 223 | /* END */ |