Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 1 | /***************************************************************************/ |
| 2 | /* */ |
Werner Lemberg | b5084e1 | 2000-10-28 17:10:06 +0000 | [diff] [blame] | 3 | /* t1load.c */ |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 4 | /* */ |
Werner Lemberg | b5084e1 | 2000-10-28 17:10:06 +0000 | [diff] [blame] | 5 | /* Type 1 font loader (body). */ |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 6 | /* */ |
Werner Lemberg | 415235d | 2001-06-28 17:49:10 +0000 | [diff] [blame] | 7 | /* Copyright 1996-2001 by */ |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +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 | |
| 19 | /*************************************************************************/ |
| 20 | /* */ |
| 21 | /* This is the new and improved Type 1 data loader for FreeType 2. The */ |
| 22 | /* old loader has several problems: it is slow, complex, difficult to */ |
| 23 | /* maintain, and contains incredible hacks to make it accept some */ |
| 24 | /* ill-formed Type 1 fonts without hiccup-ing. Moreover, about 5% of */ |
| 25 | /* the Type 1 fonts on my machine still aren't loaded correctly by it. */ |
| 26 | /* */ |
| 27 | /* This version is much simpler, much faster and also easier to read and */ |
| 28 | /* maintain by a great order of magnitude. The idea behind it is to */ |
| 29 | /* _not_ try to read the Type 1 token stream with a state machine (i.e. */ |
| 30 | /* a Postscript-like interpreter) but rather to perform simple pattern */ |
| 31 | /* matching. */ |
| 32 | /* */ |
| 33 | /* Indeed, nearly all data definitions follow a simple pattern like */ |
| 34 | /* */ |
| 35 | /* ... /Field <data> ... */ |
| 36 | /* */ |
| 37 | /* where <data> can be a number, a boolean, a string, or an array of */ |
| 38 | /* numbers. There are a few exceptions, namely the encoding, font name, */ |
| 39 | /* charstrings, and subrs; they are handled with a special pattern */ |
| 40 | /* matching routine. */ |
| 41 | /* */ |
| 42 | /* All other common cases are handled very simply. The matching rules */ |
| 43 | /* are defined in the file `t1tokens.h' through the use of several */ |
| 44 | /* macros calls PARSE_XXX. */ |
| 45 | /* */ |
| 46 | /* This file is included twice here; the first time to generate parsing */ |
| 47 | /* callback functions, the second to generate a table of keywords (with */ |
| 48 | /* pointers to the associated callback). */ |
| 49 | /* */ |
| 50 | /* The function `parse_dict' simply scans *linearly* a given dictionary */ |
| 51 | /* (either the top-level or private one) and calls the appropriate */ |
| 52 | /* callback when it encounters an immediate keyword. */ |
| 53 | /* */ |
| 54 | /* This is by far the fastest way one can find to parse and read all */ |
| 55 | /* data. */ |
| 56 | /* */ |
| 57 | /* This led to tremendous code size reduction. Note that later, the */ |
| 58 | /* glyph loader will also be _greatly_ simplified, and the automatic */ |
| 59 | /* hinter will replace the clumsy `t1hinter'. */ |
| 60 | /* */ |
| 61 | /*************************************************************************/ |
| 62 | |
Werner Lemberg | cc069be | 2000-12-08 16:17:16 +0000 | [diff] [blame] | 63 | |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 64 | #include <ft2build.h> |
| 65 | #include FT_INTERNAL_DEBUG_H |
| 66 | #include FT_CONFIG_CONFIG_H |
| 67 | #include FT_MULTIPLE_MASTERS_H |
| 68 | #include FT_INTERNAL_TYPE1_TYPES_H |
David Turner | 2dfb5ac | 2000-01-27 14:02:04 +0000 | [diff] [blame] | 69 | |
David Turner | 8d3a401 | 2001-03-20 11:14:24 +0000 | [diff] [blame] | 70 | #include "t1load.h" |
Werner Lemberg | cc069be | 2000-12-08 16:17:16 +0000 | [diff] [blame] | 71 | |
Werner Lemberg | 1f7f0e8 | 2001-06-06 17:30:41 +0000 | [diff] [blame] | 72 | #include "t1errors.h" |
| 73 | |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 74 | #include <string.h> /* for strncmp(), strcmp() */ |
| 75 | #include <ctype.h> /* for isalnum() */ |
| 76 | |
| 77 | |
| 78 | /*************************************************************************/ |
| 79 | /* */ |
| 80 | /* The macro FT_COMPONENT is used in trace mode. It is an implicit */ |
| 81 | /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */ |
| 82 | /* messages during execution. */ |
| 83 | /* */ |
David Turner | 2dfb5ac | 2000-01-27 14:02:04 +0000 | [diff] [blame] | 84 | #undef FT_COMPONENT |
Werner Lemberg | b5084e1 | 2000-10-28 17:10:06 +0000 | [diff] [blame] | 85 | #define FT_COMPONENT trace_t1load |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 86 | |
David Turner | 2dfb5ac | 2000-01-27 14:02:04 +0000 | [diff] [blame] | 87 | |
Werner Lemberg | b5084e1 | 2000-10-28 17:10:06 +0000 | [diff] [blame] | 88 | #ifndef T1_CONFIG_OPTION_NO_MM_SUPPORT |
David Turner | 1c9a1ca | 2000-05-24 21:12:02 +0000 | [diff] [blame] | 89 | |
David Turner | 1118720 | 2000-05-26 17:13:23 +0000 | [diff] [blame] | 90 | |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 91 | /*************************************************************************/ |
| 92 | /*************************************************************************/ |
| 93 | /***** *****/ |
| 94 | /***** MULTIPLE MASTERS SUPPORT *****/ |
| 95 | /***** *****/ |
| 96 | /*************************************************************************/ |
| 97 | /*************************************************************************/ |
Werner Lemberg | b48a609 | 2000-07-09 19:15:30 +0000 | [diff] [blame] | 98 | |
Werner Lemberg | 4a2305c | 2001-06-28 07:17:51 +0000 | [diff] [blame] | 99 | static FT_Error |
| 100 | t1_allocate_blend( T1_Face face, |
| 101 | FT_UInt num_designs, |
| 102 | FT_UInt num_axis ) |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 103 | { |
David Turner | 2964417 | 2002-02-28 18:59:37 +0000 | [diff] [blame] | 104 | PS_Blend blend; |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 105 | FT_Memory memory = face->root.memory; |
| 106 | FT_Error error = 0; |
Werner Lemberg | b48a609 | 2000-07-09 19:15:30 +0000 | [diff] [blame] | 107 | |
| 108 | |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 109 | blend = face->blend; |
| 110 | if ( !blend ) |
| 111 | { |
David Turner | e459d74 | 2002-03-22 13:52:37 +0000 | [diff] [blame^] | 112 | if ( FT_NEW( blend ) ) |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 113 | goto Exit; |
Werner Lemberg | b48a609 | 2000-07-09 19:15:30 +0000 | [diff] [blame] | 114 | |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 115 | face->blend = blend; |
| 116 | } |
Werner Lemberg | b48a609 | 2000-07-09 19:15:30 +0000 | [diff] [blame] | 117 | |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 118 | /* allocate design data if needed */ |
| 119 | if ( num_designs > 0 ) |
| 120 | { |
| 121 | if ( blend->num_designs == 0 ) |
| 122 | { |
David Turner | e208f4e | 2000-07-10 20:30:59 +0000 | [diff] [blame] | 123 | FT_UInt nn; |
Werner Lemberg | e4b32a5 | 2000-10-31 20:42:18 +0000 | [diff] [blame] | 124 | |
Werner Lemberg | 93ac3e3 | 2000-07-10 21:41:32 +0000 | [diff] [blame] | 125 | |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 126 | /* allocate the blend `private' and `font_info' dictionaries */ |
David Turner | e459d74 | 2002-03-22 13:52:37 +0000 | [diff] [blame^] | 127 | if ( FT_NEW_ARRAY( blend->font_infos[1], num_designs ) || |
| 128 | FT_NEW_ARRAY( blend->privates[1], num_designs ) || |
| 129 | FT_NEW_ARRAY( blend->weight_vector, num_designs * 2 ) ) |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 130 | goto Exit; |
Werner Lemberg | b48a609 | 2000-07-09 19:15:30 +0000 | [diff] [blame] | 131 | |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 132 | blend->default_weight_vector = blend->weight_vector + num_designs; |
Werner Lemberg | b48a609 | 2000-07-09 19:15:30 +0000 | [diff] [blame] | 133 | |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 134 | blend->font_infos[0] = &face->type1.font_info; |
| 135 | blend->privates [0] = &face->type1.private_dict; |
Werner Lemberg | e4b32a5 | 2000-10-31 20:42:18 +0000 | [diff] [blame] | 136 | |
David Turner | e208f4e | 2000-07-10 20:30:59 +0000 | [diff] [blame] | 137 | for ( nn = 2; nn <= num_designs; nn++ ) |
| 138 | { |
Werner Lemberg | 93ac3e3 | 2000-07-10 21:41:32 +0000 | [diff] [blame] | 139 | blend->privates[nn] = blend->privates [nn - 1] + 1; |
| 140 | blend->font_infos[nn] = blend->font_infos[nn - 1] + 1; |
David Turner | e208f4e | 2000-07-10 20:30:59 +0000 | [diff] [blame] | 141 | } |
Werner Lemberg | e4b32a5 | 2000-10-31 20:42:18 +0000 | [diff] [blame] | 142 | |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 143 | blend->num_designs = num_designs; |
| 144 | } |
| 145 | else if ( blend->num_designs != num_designs ) |
| 146 | goto Fail; |
| 147 | } |
Werner Lemberg | b48a609 | 2000-07-09 19:15:30 +0000 | [diff] [blame] | 148 | |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 149 | /* allocate axis data if needed */ |
| 150 | if ( num_axis > 0 ) |
| 151 | { |
| 152 | if ( blend->num_axis != 0 && blend->num_axis != num_axis ) |
| 153 | goto Fail; |
Werner Lemberg | b48a609 | 2000-07-09 19:15:30 +0000 | [diff] [blame] | 154 | |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 155 | blend->num_axis = num_axis; |
| 156 | } |
Werner Lemberg | b48a609 | 2000-07-09 19:15:30 +0000 | [diff] [blame] | 157 | |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 158 | /* allocate the blend design pos table if needed */ |
| 159 | num_designs = blend->num_designs; |
| 160 | num_axis = blend->num_axis; |
| 161 | if ( num_designs && num_axis && blend->design_pos[0] == 0 ) |
| 162 | { |
| 163 | FT_UInt n; |
Werner Lemberg | b48a609 | 2000-07-09 19:15:30 +0000 | [diff] [blame] | 164 | |
| 165 | |
David Turner | e459d74 | 2002-03-22 13:52:37 +0000 | [diff] [blame^] | 166 | if ( FT_NEW_ARRAY( blend->design_pos[0], num_designs * num_axis ) ) |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 167 | goto Exit; |
Werner Lemberg | b48a609 | 2000-07-09 19:15:30 +0000 | [diff] [blame] | 168 | |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 169 | for ( n = 1; n < num_designs; n++ ) |
| 170 | blend->design_pos[n] = blend->design_pos[0] + num_axis * n; |
| 171 | } |
Werner Lemberg | b48a609 | 2000-07-09 19:15:30 +0000 | [diff] [blame] | 172 | |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 173 | Exit: |
| 174 | return error; |
Werner Lemberg | b48a609 | 2000-07-09 19:15:30 +0000 | [diff] [blame] | 175 | |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 176 | Fail: |
| 177 | error = -1; |
| 178 | goto Exit; |
Werner Lemberg | b48a609 | 2000-07-09 19:15:30 +0000 | [diff] [blame] | 179 | } |
| 180 | |
| 181 | |
David Turner | bc82f1b | 2002-03-01 02:26:22 +0000 | [diff] [blame] | 182 | FT_LOCAL_DEF( FT_Error ) |
Werner Lemberg | 4a2305c | 2001-06-28 07:17:51 +0000 | [diff] [blame] | 183 | T1_Get_Multi_Master( T1_Face face, |
| 184 | FT_Multi_Master* master ) |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 185 | { |
David Turner | 2964417 | 2002-02-28 18:59:37 +0000 | [diff] [blame] | 186 | PS_Blend blend = face->blend; |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 187 | FT_UInt n; |
| 188 | FT_Error error; |
Werner Lemberg | b48a609 | 2000-07-09 19:15:30 +0000 | [diff] [blame] | 189 | |
| 190 | |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 191 | error = T1_Err_Invalid_Argument; |
Werner Lemberg | b48a609 | 2000-07-09 19:15:30 +0000 | [diff] [blame] | 192 | |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 193 | if ( blend ) |
| 194 | { |
| 195 | master->num_axis = blend->num_axis; |
| 196 | master->num_designs = blend->num_designs; |
Werner Lemberg | b48a609 | 2000-07-09 19:15:30 +0000 | [diff] [blame] | 197 | |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 198 | for ( n = 0; n < blend->num_axis; n++ ) |
| 199 | { |
David Turner | 2964417 | 2002-02-28 18:59:37 +0000 | [diff] [blame] | 200 | FT_MM_Axis* axis = master->axis + n; |
| 201 | PS_DesignMap map = blend->design_map + n; |
Werner Lemberg | b48a609 | 2000-07-09 19:15:30 +0000 | [diff] [blame] | 202 | |
| 203 | |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 204 | axis->name = blend->axis_names[n]; |
| 205 | axis->minimum = map->design_points[0]; |
| 206 | axis->maximum = map->design_points[map->num_points - 1]; |
| 207 | } |
| 208 | error = 0; |
| 209 | } |
| 210 | return error; |
Werner Lemberg | b48a609 | 2000-07-09 19:15:30 +0000 | [diff] [blame] | 211 | } |
| 212 | |
| 213 | |
David Turner | bc82f1b | 2002-03-01 02:26:22 +0000 | [diff] [blame] | 214 | FT_LOCAL_DEF( FT_Error ) |
Werner Lemberg | 4a2305c | 2001-06-28 07:17:51 +0000 | [diff] [blame] | 215 | T1_Set_MM_Blend( T1_Face face, |
| 216 | FT_UInt num_coords, |
| 217 | FT_Fixed* coords ) |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 218 | { |
David Turner | 2964417 | 2002-02-28 18:59:37 +0000 | [diff] [blame] | 219 | PS_Blend blend = face->blend; |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 220 | FT_Error error; |
| 221 | FT_UInt n, m; |
Werner Lemberg | b48a609 | 2000-07-09 19:15:30 +0000 | [diff] [blame] | 222 | |
David Turner | 1118720 | 2000-05-26 17:13:23 +0000 | [diff] [blame] | 223 | |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 224 | error = T1_Err_Invalid_Argument; |
| 225 | |
| 226 | if ( blend && blend->num_axis == num_coords ) |
| 227 | { |
| 228 | /* recompute the weight vector from the blend coordinates */ |
Werner Lemberg | 1429db6 | 2001-04-02 23:54:01 +0000 | [diff] [blame] | 229 | error = T1_Err_Ok; |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 230 | |
| 231 | for ( n = 0; n < blend->num_designs; n++ ) |
| 232 | { |
| 233 | FT_Fixed result = 0x10000L; /* 1.0 fixed */ |
| 234 | |
| 235 | |
| 236 | for ( m = 0; m < blend->num_axis; m++ ) |
| 237 | { |
| 238 | FT_Fixed factor; |
Werner Lemberg | b48a609 | 2000-07-09 19:15:30 +0000 | [diff] [blame] | 239 | |
David Turner | 1118720 | 2000-05-26 17:13:23 +0000 | [diff] [blame] | 240 | |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 241 | /* get current blend axis position */ |
| 242 | factor = coords[m]; |
| 243 | if ( factor < 0 ) factor = 0; |
| 244 | if ( factor > 0x10000L ) factor = 0x10000L; |
Werner Lemberg | b48a609 | 2000-07-09 19:15:30 +0000 | [diff] [blame] | 245 | |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 246 | if ( ( n & ( 1 << m ) ) == 0 ) |
| 247 | factor = 0x10000L - factor; |
Werner Lemberg | b48a609 | 2000-07-09 19:15:30 +0000 | [diff] [blame] | 248 | |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 249 | result = FT_MulFix( result, factor ); |
| 250 | } |
| 251 | blend->weight_vector[n] = result; |
| 252 | } |
David Turner | 1c9a1ca | 2000-05-24 21:12:02 +0000 | [diff] [blame] | 253 | |
Werner Lemberg | 1429db6 | 2001-04-02 23:54:01 +0000 | [diff] [blame] | 254 | error = T1_Err_Ok; |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 255 | } |
| 256 | return error; |
| 257 | } |
Werner Lemberg | b48a609 | 2000-07-09 19:15:30 +0000 | [diff] [blame] | 258 | |
| 259 | |
David Turner | bc82f1b | 2002-03-01 02:26:22 +0000 | [diff] [blame] | 260 | FT_LOCAL_DEF( FT_Error ) |
Werner Lemberg | 4a2305c | 2001-06-28 07:17:51 +0000 | [diff] [blame] | 261 | T1_Set_MM_Design( T1_Face face, |
| 262 | FT_UInt num_coords, |
| 263 | FT_Long* coords ) |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 264 | { |
David Turner | 2964417 | 2002-02-28 18:59:37 +0000 | [diff] [blame] | 265 | PS_Blend blend = face->blend; |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 266 | FT_Error error; |
| 267 | FT_UInt n, p; |
David Turner | 1c9a1ca | 2000-05-24 21:12:02 +0000 | [diff] [blame] | 268 | |
Werner Lemberg | b48a609 | 2000-07-09 19:15:30 +0000 | [diff] [blame] | 269 | |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 270 | error = T1_Err_Invalid_Argument; |
| 271 | if ( blend && blend->num_axis == num_coords ) |
| 272 | { |
| 273 | /* compute the blend coordinates through the blend design map */ |
| 274 | FT_Fixed final_blends[T1_MAX_MM_DESIGNS]; |
Werner Lemberg | b48a609 | 2000-07-09 19:15:30 +0000 | [diff] [blame] | 275 | |
David Turner | 7c388ba | 2000-05-26 02:07:40 +0000 | [diff] [blame] | 276 | |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 277 | for ( n = 0; n < blend->num_axis; n++ ) |
| 278 | { |
| 279 | FT_Long design = coords[n]; |
| 280 | FT_Fixed the_blend; |
David Turner | 2964417 | 2002-02-28 18:59:37 +0000 | [diff] [blame] | 281 | PS_DesignMap map = blend->design_map + n; |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 282 | FT_Fixed* designs = map->design_points; |
| 283 | FT_Fixed* blends = map->blend_points; |
| 284 | FT_Int before = -1, after = -1; |
Werner Lemberg | b48a609 | 2000-07-09 19:15:30 +0000 | [diff] [blame] | 285 | |
David Turner | efa80f2 | 2000-12-01 21:43:05 +0000 | [diff] [blame] | 286 | for ( p = 0; p < (FT_UInt)map->num_points; p++ ) |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 287 | { |
| 288 | FT_Fixed p_design = designs[p]; |
Werner Lemberg | b48a609 | 2000-07-09 19:15:30 +0000 | [diff] [blame] | 289 | |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 290 | |
| 291 | /* exact match ? */ |
| 292 | if ( design == p_design ) |
| 293 | { |
| 294 | the_blend = blends[p]; |
| 295 | goto Found; |
| 296 | } |
Werner Lemberg | b48a609 | 2000-07-09 19:15:30 +0000 | [diff] [blame] | 297 | |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 298 | if ( design < p_design ) |
| 299 | { |
| 300 | after = p; |
| 301 | break; |
| 302 | } |
Werner Lemberg | b48a609 | 2000-07-09 19:15:30 +0000 | [diff] [blame] | 303 | |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 304 | before = p; |
| 305 | } |
Werner Lemberg | b48a609 | 2000-07-09 19:15:30 +0000 | [diff] [blame] | 306 | |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 307 | /* now, interpolate if needed */ |
| 308 | if ( before < 0 ) |
| 309 | the_blend = blends[0]; |
Werner Lemberg | b48a609 | 2000-07-09 19:15:30 +0000 | [diff] [blame] | 310 | |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 311 | else if ( after < 0 ) |
| 312 | the_blend = blends[map->num_points - 1]; |
Werner Lemberg | b48a609 | 2000-07-09 19:15:30 +0000 | [diff] [blame] | 313 | |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 314 | else |
| 315 | the_blend = FT_MulDiv( design - designs[before], |
| 316 | blends [after] - blends [before], |
| 317 | designs[after] - designs[before] ); |
| 318 | |
| 319 | Found: |
| 320 | final_blends[n] = the_blend; |
| 321 | } |
Werner Lemberg | b48a609 | 2000-07-09 19:15:30 +0000 | [diff] [blame] | 322 | |
Werner Lemberg | b5084e1 | 2000-10-28 17:10:06 +0000 | [diff] [blame] | 323 | error = T1_Set_MM_Blend( face, num_coords, final_blends ); |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 324 | } |
| 325 | |
| 326 | return error; |
| 327 | } |
Werner Lemberg | b48a609 | 2000-07-09 19:15:30 +0000 | [diff] [blame] | 328 | |
| 329 | |
David Turner | bc82f1b | 2002-03-01 02:26:22 +0000 | [diff] [blame] | 330 | FT_LOCAL_DEF( void ) |
Werner Lemberg | 4a2305c | 2001-06-28 07:17:51 +0000 | [diff] [blame] | 331 | T1_Done_Blend( T1_Face face ) |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 332 | { |
| 333 | FT_Memory memory = face->root.memory; |
David Turner | 2964417 | 2002-02-28 18:59:37 +0000 | [diff] [blame] | 334 | PS_Blend blend = face->blend; |
Werner Lemberg | b48a609 | 2000-07-09 19:15:30 +0000 | [diff] [blame] | 335 | |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 336 | |
| 337 | if ( blend ) |
| 338 | { |
| 339 | FT_UInt num_designs = blend->num_designs; |
| 340 | FT_UInt num_axis = blend->num_axis; |
| 341 | FT_UInt n; |
Werner Lemberg | b48a609 | 2000-07-09 19:15:30 +0000 | [diff] [blame] | 342 | |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 343 | |
| 344 | /* release design pos table */ |
David Turner | e459d74 | 2002-03-22 13:52:37 +0000 | [diff] [blame^] | 345 | FT_FREE( blend->design_pos[0] ); |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 346 | for ( n = 1; n < num_designs; n++ ) |
| 347 | blend->design_pos[n] = 0; |
Werner Lemberg | b48a609 | 2000-07-09 19:15:30 +0000 | [diff] [blame] | 348 | |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 349 | /* release blend `private' and `font info' dictionaries */ |
David Turner | e459d74 | 2002-03-22 13:52:37 +0000 | [diff] [blame^] | 350 | FT_FREE( blend->privates[1] ); |
| 351 | FT_FREE( blend->font_infos[1] ); |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 352 | |
| 353 | for ( n = 0; n < num_designs; n++ ) |
| 354 | { |
| 355 | blend->privates [n] = 0; |
| 356 | blend->font_infos[n] = 0; |
| 357 | } |
Werner Lemberg | b48a609 | 2000-07-09 19:15:30 +0000 | [diff] [blame] | 358 | |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 359 | /* release weight vectors */ |
David Turner | e459d74 | 2002-03-22 13:52:37 +0000 | [diff] [blame^] | 360 | FT_FREE( blend->weight_vector ); |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 361 | blend->default_weight_vector = 0; |
Werner Lemberg | b48a609 | 2000-07-09 19:15:30 +0000 | [diff] [blame] | 362 | |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 363 | /* release axis names */ |
| 364 | for ( n = 0; n < num_axis; n++ ) |
David Turner | e459d74 | 2002-03-22 13:52:37 +0000 | [diff] [blame^] | 365 | FT_FREE( blend->axis_names[n] ); |
Werner Lemberg | b48a609 | 2000-07-09 19:15:30 +0000 | [diff] [blame] | 366 | |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 367 | /* release design map */ |
| 368 | for ( n = 0; n < num_axis; n++ ) |
| 369 | { |
David Turner | 2964417 | 2002-02-28 18:59:37 +0000 | [diff] [blame] | 370 | PS_DesignMap dmap = blend->design_map + n; |
David Turner | 1c9a1ca | 2000-05-24 21:12:02 +0000 | [diff] [blame] | 371 | |
David Turner | 7c388ba | 2000-05-26 02:07:40 +0000 | [diff] [blame] | 372 | |
David Turner | e459d74 | 2002-03-22 13:52:37 +0000 | [diff] [blame^] | 373 | FT_FREE( dmap->design_points ); |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 374 | dmap->num_points = 0; |
| 375 | } |
Werner Lemberg | b48a609 | 2000-07-09 19:15:30 +0000 | [diff] [blame] | 376 | |
David Turner | e459d74 | 2002-03-22 13:52:37 +0000 | [diff] [blame^] | 377 | FT_FREE( face->blend ); |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 378 | } |
| 379 | } |
Werner Lemberg | b48a609 | 2000-07-09 19:15:30 +0000 | [diff] [blame] | 380 | |
| 381 | |
Werner Lemberg | 4a2305c | 2001-06-28 07:17:51 +0000 | [diff] [blame] | 382 | static void |
| 383 | parse_blend_axis_types( T1_Face face, |
| 384 | T1_Loader* loader ) |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 385 | { |
David Turner | 4e7eeee | 2002-02-28 16:10:29 +0000 | [diff] [blame] | 386 | T1_TokenRec axis_tokens[ T1_MAX_MM_AXIS ]; |
| 387 | FT_Int n, num_axis; |
| 388 | FT_Error error = 0; |
David Turner | 2964417 | 2002-02-28 18:59:37 +0000 | [diff] [blame] | 389 | PS_Blend blend; |
David Turner | 4e7eeee | 2002-02-28 16:10:29 +0000 | [diff] [blame] | 390 | FT_Memory memory; |
Werner Lemberg | b48a609 | 2000-07-09 19:15:30 +0000 | [diff] [blame] | 391 | |
David Turner | 1c9a1ca | 2000-05-24 21:12:02 +0000 | [diff] [blame] | 392 | |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 393 | /* take an array of objects */ |
Werner Lemberg | b5084e1 | 2000-10-28 17:10:06 +0000 | [diff] [blame] | 394 | T1_ToTokenArray( &loader->parser, axis_tokens, |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 395 | T1_MAX_MM_AXIS, &num_axis ); |
| 396 | if ( num_axis <= 0 || num_axis > T1_MAX_MM_AXIS ) |
| 397 | { |
| 398 | FT_ERROR(( "parse_blend_axis_types: incorrect number of axes: %d\n", |
| 399 | num_axis )); |
| 400 | error = T1_Err_Invalid_File_Format; |
| 401 | goto Exit; |
| 402 | } |
Werner Lemberg | b48a609 | 2000-07-09 19:15:30 +0000 | [diff] [blame] | 403 | |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 404 | /* allocate blend if necessary */ |
| 405 | error = t1_allocate_blend( face, 0, (FT_UInt)num_axis ); |
| 406 | if ( error ) |
| 407 | goto Exit; |
Werner Lemberg | b48a609 | 2000-07-09 19:15:30 +0000 | [diff] [blame] | 408 | |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 409 | blend = face->blend; |
| 410 | memory = face->root.memory; |
Werner Lemberg | b48a609 | 2000-07-09 19:15:30 +0000 | [diff] [blame] | 411 | |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 412 | /* each token is an immediate containing the name of the axis */ |
| 413 | for ( n = 0; n < num_axis; n++ ) |
| 414 | { |
David Turner | 4e7eeee | 2002-02-28 16:10:29 +0000 | [diff] [blame] | 415 | T1_Token token = axis_tokens + n; |
Werner Lemberg | 8728f29 | 2000-08-23 17:32:42 +0000 | [diff] [blame] | 416 | FT_Byte* name; |
| 417 | FT_Int len; |
Werner Lemberg | b48a609 | 2000-07-09 19:15:30 +0000 | [diff] [blame] | 418 | |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 419 | /* skip first slash, if any */ |
| 420 | if (token->start[0] == '/') |
| 421 | token->start++; |
Werner Lemberg | b48a609 | 2000-07-09 19:15:30 +0000 | [diff] [blame] | 422 | |
Werner Lemberg | 914b289 | 2001-03-10 17:07:42 +0000 | [diff] [blame] | 423 | len = (FT_Int)( token->limit - token->start ); |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 424 | if ( len <= 0 ) |
| 425 | { |
| 426 | error = T1_Err_Invalid_File_Format; |
| 427 | goto Exit; |
| 428 | } |
Werner Lemberg | b48a609 | 2000-07-09 19:15:30 +0000 | [diff] [blame] | 429 | |
David Turner | e459d74 | 2002-03-22 13:52:37 +0000 | [diff] [blame^] | 430 | if ( FT_ALLOC( blend->axis_names[n], len + 1 ) ) |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 431 | goto Exit; |
Werner Lemberg | b48a609 | 2000-07-09 19:15:30 +0000 | [diff] [blame] | 432 | |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 433 | name = (FT_Byte*)blend->axis_names[n]; |
David Turner | e459d74 | 2002-03-22 13:52:37 +0000 | [diff] [blame^] | 434 | FT_MEM_COPY( name, token->start, len ); |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 435 | name[len] = 0; |
| 436 | } |
Werner Lemberg | b48a609 | 2000-07-09 19:15:30 +0000 | [diff] [blame] | 437 | |
| 438 | Exit: |
David Turner | a39acf5 | 2000-08-23 02:47:57 +0000 | [diff] [blame] | 439 | loader->parser.root.error = error; |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 440 | } |
Werner Lemberg | b48a609 | 2000-07-09 19:15:30 +0000 | [diff] [blame] | 441 | |
| 442 | |
Werner Lemberg | 4a2305c | 2001-06-28 07:17:51 +0000 | [diff] [blame] | 443 | static void |
| 444 | parse_blend_design_positions( T1_Face face, |
| 445 | T1_Loader* loader ) |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 446 | { |
David Turner | 4e7eeee | 2002-02-28 16:10:29 +0000 | [diff] [blame] | 447 | T1_TokenRec design_tokens[ T1_MAX_MM_DESIGNS ]; |
Werner Lemberg | b5084e1 | 2000-10-28 17:10:06 +0000 | [diff] [blame] | 448 | FT_Int num_designs; |
| 449 | FT_Int num_axis; |
David Turner | 4e7eeee | 2002-02-28 16:10:29 +0000 | [diff] [blame] | 450 | T1_Parser parser = &loader->parser; |
Werner Lemberg | b48a609 | 2000-07-09 19:15:30 +0000 | [diff] [blame] | 451 | |
Werner Lemberg | b5084e1 | 2000-10-28 17:10:06 +0000 | [diff] [blame] | 452 | FT_Error error = 0; |
David Turner | 2964417 | 2002-02-28 18:59:37 +0000 | [diff] [blame] | 453 | PS_Blend blend; |
David Turner | 1c9a1ca | 2000-05-24 21:12:02 +0000 | [diff] [blame] | 454 | |
Werner Lemberg | b48a609 | 2000-07-09 19:15:30 +0000 | [diff] [blame] | 455 | |
| 456 | /* get the array of design tokens - compute number of designs */ |
Werner Lemberg | b5084e1 | 2000-10-28 17:10:06 +0000 | [diff] [blame] | 457 | T1_ToTokenArray( parser, design_tokens, T1_MAX_MM_DESIGNS, &num_designs ); |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 458 | if ( num_designs <= 0 || num_designs > T1_MAX_MM_DESIGNS ) |
| 459 | { |
| 460 | FT_ERROR(( "parse_blend_design_positions:" )); |
| 461 | FT_ERROR(( " incorrect number of designs: %d\n", |
| 462 | num_designs )); |
| 463 | error = T1_Err_Invalid_File_Format; |
| 464 | goto Exit; |
| 465 | } |
Werner Lemberg | b48a609 | 2000-07-09 19:15:30 +0000 | [diff] [blame] | 466 | |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 467 | { |
David Turner | a39acf5 | 2000-08-23 02:47:57 +0000 | [diff] [blame] | 468 | FT_Byte* old_cursor = parser->root.cursor; |
| 469 | FT_Byte* old_limit = parser->root.limit; |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 470 | FT_UInt n; |
Werner Lemberg | b48a609 | 2000-07-09 19:15:30 +0000 | [diff] [blame] | 471 | |
David Turner | 1c9a1ca | 2000-05-24 21:12:02 +0000 | [diff] [blame] | 472 | |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 473 | blend = face->blend; |
| 474 | num_axis = 0; /* make compiler happy */ |
| 475 | |
| 476 | for ( n = 0; n < (FT_UInt)num_designs; n++ ) |
| 477 | { |
David Turner | 4e7eeee | 2002-02-28 16:10:29 +0000 | [diff] [blame] | 478 | T1_TokenRec axis_tokens[ T1_MAX_MM_DESIGNS ]; |
| 479 | T1_Token token; |
David Turner | a39acf5 | 2000-08-23 02:47:57 +0000 | [diff] [blame] | 480 | FT_Int axis, n_axis; |
Werner Lemberg | b48a609 | 2000-07-09 19:15:30 +0000 | [diff] [blame] | 481 | |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 482 | |
| 483 | /* read axis/coordinates tokens */ |
| 484 | token = design_tokens + n; |
David Turner | a39acf5 | 2000-08-23 02:47:57 +0000 | [diff] [blame] | 485 | parser->root.cursor = token->start - 1; |
| 486 | parser->root.limit = token->limit + 1; |
Werner Lemberg | b5084e1 | 2000-10-28 17:10:06 +0000 | [diff] [blame] | 487 | T1_ToTokenArray( parser, axis_tokens, T1_MAX_MM_AXIS, &n_axis ); |
Werner Lemberg | b48a609 | 2000-07-09 19:15:30 +0000 | [diff] [blame] | 488 | |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 489 | if ( n == 0 ) |
| 490 | { |
| 491 | num_axis = n_axis; |
| 492 | error = t1_allocate_blend( face, num_designs, num_axis ); |
| 493 | if ( error ) |
| 494 | goto Exit; |
| 495 | blend = face->blend; |
| 496 | } |
| 497 | else if ( n_axis != num_axis ) |
| 498 | { |
| 499 | FT_ERROR(( "parse_blend_design_positions: incorrect table\n" )); |
| 500 | error = T1_Err_Invalid_File_Format; |
| 501 | goto Exit; |
| 502 | } |
Werner Lemberg | b48a609 | 2000-07-09 19:15:30 +0000 | [diff] [blame] | 503 | |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 504 | /* now, read each axis token into the design position */ |
| 505 | for ( axis = 0; axis < n_axis; axis++ ) |
| 506 | { |
David Turner | 4e7eeee | 2002-02-28 16:10:29 +0000 | [diff] [blame] | 507 | T1_Token token2 = axis_tokens + axis; |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 508 | |
| 509 | |
David Turner | a39acf5 | 2000-08-23 02:47:57 +0000 | [diff] [blame] | 510 | parser->root.cursor = token2->start; |
| 511 | parser->root.limit = token2->limit; |
Werner Lemberg | b5084e1 | 2000-10-28 17:10:06 +0000 | [diff] [blame] | 512 | blend->design_pos[n][axis] = T1_ToFixed( parser, 0 ); |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 513 | } |
| 514 | } |
Werner Lemberg | b48a609 | 2000-07-09 19:15:30 +0000 | [diff] [blame] | 515 | |
David Turner | a39acf5 | 2000-08-23 02:47:57 +0000 | [diff] [blame] | 516 | loader->parser.root.cursor = old_cursor; |
| 517 | loader->parser.root.limit = old_limit; |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 518 | } |
Werner Lemberg | b48a609 | 2000-07-09 19:15:30 +0000 | [diff] [blame] | 519 | |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 520 | Exit: |
David Turner | a39acf5 | 2000-08-23 02:47:57 +0000 | [diff] [blame] | 521 | loader->parser.root.error = error; |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 522 | } |
Werner Lemberg | b48a609 | 2000-07-09 19:15:30 +0000 | [diff] [blame] | 523 | |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 524 | |
Werner Lemberg | 4a2305c | 2001-06-28 07:17:51 +0000 | [diff] [blame] | 525 | static void |
| 526 | parse_blend_design_map( T1_Face face, |
| 527 | T1_Loader* loader ) |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 528 | { |
Werner Lemberg | b5084e1 | 2000-10-28 17:10:06 +0000 | [diff] [blame] | 529 | FT_Error error = 0; |
David Turner | 4e7eeee | 2002-02-28 16:10:29 +0000 | [diff] [blame] | 530 | T1_Parser parser = &loader->parser; |
David Turner | 2964417 | 2002-02-28 18:59:37 +0000 | [diff] [blame] | 531 | PS_Blend blend; |
David Turner | 4e7eeee | 2002-02-28 16:10:29 +0000 | [diff] [blame] | 532 | T1_TokenRec axis_tokens[ T1_MAX_MM_AXIS ]; |
Werner Lemberg | b5084e1 | 2000-10-28 17:10:06 +0000 | [diff] [blame] | 533 | FT_Int n, num_axis; |
| 534 | FT_Byte* old_cursor; |
| 535 | FT_Byte* old_limit; |
| 536 | FT_Memory memory = face->root.memory; |
Werner Lemberg | b48a609 | 2000-07-09 19:15:30 +0000 | [diff] [blame] | 537 | |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 538 | |
Werner Lemberg | b5084e1 | 2000-10-28 17:10:06 +0000 | [diff] [blame] | 539 | T1_ToTokenArray( parser, axis_tokens, T1_MAX_MM_AXIS, &num_axis ); |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 540 | if ( num_axis <= 0 || num_axis > T1_MAX_MM_AXIS ) |
| 541 | { |
| 542 | FT_ERROR(( "parse_blend_design_map: incorrect number of axes: %d\n", |
| 543 | num_axis )); |
| 544 | error = T1_Err_Invalid_File_Format; |
| 545 | goto Exit; |
| 546 | } |
David Turner | a39acf5 | 2000-08-23 02:47:57 +0000 | [diff] [blame] | 547 | old_cursor = parser->root.cursor; |
| 548 | old_limit = parser->root.limit; |
Werner Lemberg | b48a609 | 2000-07-09 19:15:30 +0000 | [diff] [blame] | 549 | |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 550 | error = t1_allocate_blend( face, 0, num_axis ); |
| 551 | if ( error ) |
| 552 | goto Exit; |
| 553 | blend = face->blend; |
Werner Lemberg | b48a609 | 2000-07-09 19:15:30 +0000 | [diff] [blame] | 554 | |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 555 | /* now, read each axis design map */ |
| 556 | for ( n = 0; n < num_axis; n++ ) |
| 557 | { |
David Turner | 2964417 | 2002-02-28 18:59:37 +0000 | [diff] [blame] | 558 | PS_DesignMap map = blend->design_map + n; |
David Turner | 4e7eeee | 2002-02-28 16:10:29 +0000 | [diff] [blame] | 559 | T1_Token token; |
Werner Lemberg | 8728f29 | 2000-08-23 17:32:42 +0000 | [diff] [blame] | 560 | FT_Int p, num_points; |
Werner Lemberg | b48a609 | 2000-07-09 19:15:30 +0000 | [diff] [blame] | 561 | |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 562 | |
| 563 | token = axis_tokens + n; |
David Turner | a39acf5 | 2000-08-23 02:47:57 +0000 | [diff] [blame] | 564 | parser->root.cursor = token->start; |
| 565 | parser->root.limit = token->limit; |
Werner Lemberg | b48a609 | 2000-07-09 19:15:30 +0000 | [diff] [blame] | 566 | |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 567 | /* count the number of map points */ |
| 568 | { |
Werner Lemberg | b1dd353 | 2000-07-31 22:51:00 +0000 | [diff] [blame] | 569 | FT_Byte* ptr = token->start; |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 570 | FT_Byte* limit = token->limit; |
Werner Lemberg | b48a609 | 2000-07-09 19:15:30 +0000 | [diff] [blame] | 571 | |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 572 | |
| 573 | num_points = 0; |
Werner Lemberg | b1dd353 | 2000-07-31 22:51:00 +0000 | [diff] [blame] | 574 | for ( ; ptr < limit; ptr++ ) |
| 575 | if ( ptr[0] == '[' ) |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 576 | num_points++; |
| 577 | } |
| 578 | if ( num_points <= 0 || num_points > T1_MAX_MM_MAP_POINTS ) |
| 579 | { |
| 580 | FT_ERROR(( "parse_blend_design_map: incorrect table\n" )); |
| 581 | error = T1_Err_Invalid_File_Format; |
| 582 | goto Exit; |
| 583 | } |
Werner Lemberg | b48a609 | 2000-07-09 19:15:30 +0000 | [diff] [blame] | 584 | |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 585 | /* allocate design map data */ |
David Turner | e459d74 | 2002-03-22 13:52:37 +0000 | [diff] [blame^] | 586 | if ( FT_NEW_ARRAY( map->design_points, num_points * 2 ) ) |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 587 | goto Exit; |
| 588 | map->blend_points = map->design_points + num_points; |
| 589 | map->num_points = (FT_Byte)num_points; |
Werner Lemberg | b48a609 | 2000-07-09 19:15:30 +0000 | [diff] [blame] | 590 | |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 591 | for ( p = 0; p < num_points; p++ ) |
| 592 | { |
Werner Lemberg | b5084e1 | 2000-10-28 17:10:06 +0000 | [diff] [blame] | 593 | map->design_points[p] = T1_ToInt( parser ); |
| 594 | map->blend_points [p] = T1_ToFixed( parser, 0 ); |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 595 | } |
Werner Lemberg | b48a609 | 2000-07-09 19:15:30 +0000 | [diff] [blame] | 596 | } |
| 597 | |
David Turner | a39acf5 | 2000-08-23 02:47:57 +0000 | [diff] [blame] | 598 | parser->root.cursor = old_cursor; |
| 599 | parser->root.limit = old_limit; |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 600 | |
| 601 | Exit: |
David Turner | a39acf5 | 2000-08-23 02:47:57 +0000 | [diff] [blame] | 602 | parser->root.error = error; |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 603 | } |
Werner Lemberg | b48a609 | 2000-07-09 19:15:30 +0000 | [diff] [blame] | 604 | |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 605 | |
Werner Lemberg | 4a2305c | 2001-06-28 07:17:51 +0000 | [diff] [blame] | 606 | static void |
| 607 | parse_weight_vector( T1_Face face, |
| 608 | T1_Loader* loader ) |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 609 | { |
Werner Lemberg | b5084e1 | 2000-10-28 17:10:06 +0000 | [diff] [blame] | 610 | FT_Error error = 0; |
David Turner | 4e7eeee | 2002-02-28 16:10:29 +0000 | [diff] [blame] | 611 | T1_Parser parser = &loader->parser; |
David Turner | 2964417 | 2002-02-28 18:59:37 +0000 | [diff] [blame] | 612 | PS_Blend blend = face->blend; |
David Turner | 4e7eeee | 2002-02-28 16:10:29 +0000 | [diff] [blame] | 613 | T1_TokenRec master; |
Werner Lemberg | b5084e1 | 2000-10-28 17:10:06 +0000 | [diff] [blame] | 614 | FT_UInt n; |
| 615 | FT_Byte* old_cursor; |
| 616 | FT_Byte* old_limit; |
Werner Lemberg | b48a609 | 2000-07-09 19:15:30 +0000 | [diff] [blame] | 617 | |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 618 | |
| 619 | if ( !blend || blend->num_designs == 0 ) |
| 620 | { |
| 621 | FT_ERROR(( "parse_weight_vector: too early!\n" )); |
| 622 | error = T1_Err_Invalid_File_Format; |
| 623 | goto Exit; |
| 624 | } |
Werner Lemberg | b48a609 | 2000-07-09 19:15:30 +0000 | [diff] [blame] | 625 | |
Werner Lemberg | b5084e1 | 2000-10-28 17:10:06 +0000 | [diff] [blame] | 626 | T1_ToToken( parser, &master ); |
David Turner | 4e7eeee | 2002-02-28 16:10:29 +0000 | [diff] [blame] | 627 | if ( master.type != T1_TOKEN_TYPE_ARRAY ) |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 628 | { |
| 629 | FT_ERROR(( "parse_weight_vector: incorrect format!\n" )); |
| 630 | error = T1_Err_Invalid_File_Format; |
| 631 | goto Exit; |
| 632 | } |
Werner Lemberg | b48a609 | 2000-07-09 19:15:30 +0000 | [diff] [blame] | 633 | |
David Turner | a39acf5 | 2000-08-23 02:47:57 +0000 | [diff] [blame] | 634 | old_cursor = parser->root.cursor; |
| 635 | old_limit = parser->root.limit; |
Werner Lemberg | b48a609 | 2000-07-09 19:15:30 +0000 | [diff] [blame] | 636 | |
David Turner | a39acf5 | 2000-08-23 02:47:57 +0000 | [diff] [blame] | 637 | parser->root.cursor = master.start; |
| 638 | parser->root.limit = master.limit; |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 639 | |
| 640 | for ( n = 0; n < blend->num_designs; n++ ) |
| 641 | { |
| 642 | blend->default_weight_vector[n] = |
Werner Lemberg | b5084e1 | 2000-10-28 17:10:06 +0000 | [diff] [blame] | 643 | blend->weight_vector[n] = T1_ToFixed( parser, 0 ); |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 644 | } |
Werner Lemberg | b48a609 | 2000-07-09 19:15:30 +0000 | [diff] [blame] | 645 | |
David Turner | a39acf5 | 2000-08-23 02:47:57 +0000 | [diff] [blame] | 646 | parser->root.cursor = old_cursor; |
| 647 | parser->root.limit = old_limit; |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 648 | |
| 649 | Exit: |
David Turner | a39acf5 | 2000-08-23 02:47:57 +0000 | [diff] [blame] | 650 | parser->root.error = error; |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 651 | } |
Werner Lemberg | b48a609 | 2000-07-09 19:15:30 +0000 | [diff] [blame] | 652 | |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 653 | |
| 654 | /* the keyword `/shareddict' appears in some multiple master fonts */ |
| 655 | /* with a lot of Postscript garbage behind it (that's completely out */ |
| 656 | /* of spec!); we detect it and terminate the parsing */ |
| 657 | /* */ |
Werner Lemberg | 4a2305c | 2001-06-28 07:17:51 +0000 | [diff] [blame] | 658 | static void |
| 659 | parse_shared_dict( T1_Face face, |
| 660 | T1_Loader* loader ) |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 661 | { |
David Turner | 4e7eeee | 2002-02-28 16:10:29 +0000 | [diff] [blame] | 662 | T1_Parser parser = &loader->parser; |
Werner Lemberg | b48a609 | 2000-07-09 19:15:30 +0000 | [diff] [blame] | 663 | |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 664 | FT_UNUSED( face ); |
Werner Lemberg | b48a609 | 2000-07-09 19:15:30 +0000 | [diff] [blame] | 665 | |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 666 | |
David Turner | a39acf5 | 2000-08-23 02:47:57 +0000 | [diff] [blame] | 667 | parser->root.cursor = parser->root.limit; |
| 668 | parser->root.error = 0; |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 669 | } |
| 670 | |
Werner Lemberg | b5084e1 | 2000-10-28 17:10:06 +0000 | [diff] [blame] | 671 | #endif /* T1_CONFIG_OPTION_NO_MM_SUPPORT */ |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 672 | |
Werner Lemberg | b48a609 | 2000-07-09 19:15:30 +0000 | [diff] [blame] | 673 | |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 674 | /*************************************************************************/ |
| 675 | /*************************************************************************/ |
| 676 | /***** *****/ |
| 677 | /***** TYPE 1 SYMBOL PARSING *****/ |
| 678 | /***** *****/ |
| 679 | /*************************************************************************/ |
| 680 | /*************************************************************************/ |
| 681 | |
| 682 | |
| 683 | /*************************************************************************/ |
| 684 | /* */ |
| 685 | /* First of all, define the token field static variables. This is a set */ |
David Turner | 4e7eeee | 2002-02-28 16:10:29 +0000 | [diff] [blame] | 686 | /* of T1_FieldRec variables used later. */ |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 687 | /* */ |
| 688 | /*************************************************************************/ |
| 689 | |
David Turner | 1c9a1ca | 2000-05-24 21:12:02 +0000 | [diff] [blame] | 690 | |
Werner Lemberg | 4a2305c | 2001-06-28 07:17:51 +0000 | [diff] [blame] | 691 | static FT_Error |
| 692 | t1_load_keyword( T1_Face face, |
| 693 | T1_Loader* loader, |
David Turner | 4e7eeee | 2002-02-28 16:10:29 +0000 | [diff] [blame] | 694 | T1_Field field ) |
David Turner | 1c9a1ca | 2000-05-24 21:12:02 +0000 | [diff] [blame] | 695 | { |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 696 | FT_Error error; |
| 697 | void* dummy_object; |
| 698 | void** objects; |
| 699 | FT_UInt max_objects; |
David Turner | 2964417 | 2002-02-28 18:59:37 +0000 | [diff] [blame] | 700 | PS_Blend blend = face->blend; |
Werner Lemberg | b48a609 | 2000-07-09 19:15:30 +0000 | [diff] [blame] | 701 | |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 702 | |
David Turner | 1c9a1ca | 2000-05-24 21:12:02 +0000 | [diff] [blame] | 703 | /* if the keyword has a dedicated callback, call it */ |
David Turner | 4e7eeee | 2002-02-28 16:10:29 +0000 | [diff] [blame] | 704 | if ( field->type == T1_FIELD_TYPE_CALLBACK ) |
David Turner | 1c9a1ca | 2000-05-24 21:12:02 +0000 | [diff] [blame] | 705 | { |
David Turner | 34f1c2f | 2000-08-23 22:47:44 +0000 | [diff] [blame] | 706 | field->reader( (FT_Face)face, loader ); |
David Turner | a39acf5 | 2000-08-23 02:47:57 +0000 | [diff] [blame] | 707 | error = loader->parser.root.error; |
David Turner | 1c9a1ca | 2000-05-24 21:12:02 +0000 | [diff] [blame] | 708 | goto Exit; |
| 709 | } |
Werner Lemberg | b48a609 | 2000-07-09 19:15:30 +0000 | [diff] [blame] | 710 | |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 711 | /* now, the keyword is either a simple field, or a table of fields; */ |
| 712 | /* we are now going to take care of it */ |
David Turner | 34f1c2f | 2000-08-23 22:47:44 +0000 | [diff] [blame] | 713 | switch ( field->location ) |
David Turner | 1c9a1ca | 2000-05-24 21:12:02 +0000 | [diff] [blame] | 714 | { |
David Turner | 429978b | 2002-03-14 10:09:35 +0000 | [diff] [blame] | 715 | case T1_FIELD_LOCATION_FONT_INFO: |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 716 | dummy_object = &face->type1.font_info; |
| 717 | objects = &dummy_object; |
| 718 | max_objects = 0; |
| 719 | |
| 720 | if ( blend ) |
| 721 | { |
| 722 | objects = (void**)blend->font_infos; |
| 723 | max_objects = blend->num_designs; |
| 724 | } |
| 725 | break; |
Werner Lemberg | b48a609 | 2000-07-09 19:15:30 +0000 | [diff] [blame] | 726 | |
David Turner | 429978b | 2002-03-14 10:09:35 +0000 | [diff] [blame] | 727 | case T1_FIELD_LOCATION_PRIVATE: |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 728 | dummy_object = &face->type1.private_dict; |
| 729 | objects = &dummy_object; |
| 730 | max_objects = 0; |
| 731 | |
| 732 | if ( blend ) |
| 733 | { |
| 734 | objects = (void**)blend->privates; |
| 735 | max_objects = blend->num_designs; |
| 736 | } |
| 737 | break; |
Werner Lemberg | b48a609 | 2000-07-09 19:15:30 +0000 | [diff] [blame] | 738 | |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 739 | default: |
| 740 | dummy_object = &face->type1; |
| 741 | objects = &dummy_object; |
| 742 | max_objects = 0; |
David Turner | 1c9a1ca | 2000-05-24 21:12:02 +0000 | [diff] [blame] | 743 | } |
Werner Lemberg | b48a609 | 2000-07-09 19:15:30 +0000 | [diff] [blame] | 744 | |
David Turner | 4e7eeee | 2002-02-28 16:10:29 +0000 | [diff] [blame] | 745 | if ( field->type == T1_FIELD_TYPE_INTEGER_ARRAY || |
| 746 | field->type == T1_FIELD_TYPE_FIXED_ARRAY ) |
Werner Lemberg | b5084e1 | 2000-10-28 17:10:06 +0000 | [diff] [blame] | 747 | error = T1_Load_Field_Table( &loader->parser, field, |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 748 | objects, max_objects, 0 ); |
David Turner | 1c9a1ca | 2000-05-24 21:12:02 +0000 | [diff] [blame] | 749 | else |
Werner Lemberg | b5084e1 | 2000-10-28 17:10:06 +0000 | [diff] [blame] | 750 | error = T1_Load_Field( &loader->parser, field, |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 751 | objects, max_objects, 0 ); |
Werner Lemberg | b48a609 | 2000-07-09 19:15:30 +0000 | [diff] [blame] | 752 | |
David Turner | 1c9a1ca | 2000-05-24 21:12:02 +0000 | [diff] [blame] | 753 | Exit: |
| 754 | return error; |
Werner Lemberg | b48a609 | 2000-07-09 19:15:30 +0000 | [diff] [blame] | 755 | } |
David Turner | 2dfb5ac | 2000-01-27 14:02:04 +0000 | [diff] [blame] | 756 | |
| 757 | |
Werner Lemberg | 4a2305c | 2001-06-28 07:17:51 +0000 | [diff] [blame] | 758 | static int |
| 759 | is_space( FT_Byte c ) |
David Turner | 2dfb5ac | 2000-01-27 14:02:04 +0000 | [diff] [blame] | 760 | { |
Werner Lemberg | 8728f29 | 2000-08-23 17:32:42 +0000 | [diff] [blame] | 761 | return ( c == ' ' || c == '\t' || c == '\r' || c == '\n' ); |
David Turner | 2dfb5ac | 2000-01-27 14:02:04 +0000 | [diff] [blame] | 762 | } |
| 763 | |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 764 | |
Werner Lemberg | 4a2305c | 2001-06-28 07:17:51 +0000 | [diff] [blame] | 765 | static int |
| 766 | is_alpha( FT_Byte c ) |
David Turner | 2dfb5ac | 2000-01-27 14:02:04 +0000 | [diff] [blame] | 767 | { |
David Turner | 8ab0add | 2001-08-30 07:59:28 +0000 | [diff] [blame] | 768 | /* Note: we must accept "+" as a valid character, as it is used in */ |
Werner Lemberg | ec34290 | 2001-09-10 06:55:43 +0000 | [diff] [blame] | 769 | /* embedded type1 fonts in PDF documents. */ |
David Turner | 8ab0add | 2001-08-30 07:59:28 +0000 | [diff] [blame] | 770 | /* */ |
| 771 | return ( isalnum( c ) || c == '.' || c == '_' || c == '-' || c == '+' ); |
David Turner | 2dfb5ac | 2000-01-27 14:02:04 +0000 | [diff] [blame] | 772 | } |
| 773 | |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 774 | |
Werner Lemberg | 4a2305c | 2001-06-28 07:17:51 +0000 | [diff] [blame] | 775 | static int |
David Turner | 4e7eeee | 2002-02-28 16:10:29 +0000 | [diff] [blame] | 776 | read_binary_data( T1_Parser parser, |
Werner Lemberg | 4a2305c | 2001-06-28 07:17:51 +0000 | [diff] [blame] | 777 | FT_Int* size, |
| 778 | FT_Byte** base ) |
David Turner | 2dfb5ac | 2000-01-27 14:02:04 +0000 | [diff] [blame] | 779 | { |
David Turner | f9b8dec | 2000-06-16 19:34:52 +0000 | [diff] [blame] | 780 | FT_Byte* cur; |
David Turner | a39acf5 | 2000-08-23 02:47:57 +0000 | [diff] [blame] | 781 | FT_Byte* limit = parser->root.limit; |
David Turner | e49ab25 | 2000-05-16 23:44:38 +0000 | [diff] [blame] | 782 | |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 783 | |
David Turner | 2dfb5ac | 2000-01-27 14:02:04 +0000 | [diff] [blame] | 784 | /* the binary data has the following format */ |
| 785 | /* */ |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 786 | /* `size' [white*] RD white ....... ND */ |
David Turner | 2dfb5ac | 2000-01-27 14:02:04 +0000 | [diff] [blame] | 787 | /* */ |
David Turner | e49ab25 | 2000-05-16 23:44:38 +0000 | [diff] [blame] | 788 | |
Werner Lemberg | b5084e1 | 2000-10-28 17:10:06 +0000 | [diff] [blame] | 789 | T1_Skip_Spaces( parser ); |
David Turner | a39acf5 | 2000-08-23 02:47:57 +0000 | [diff] [blame] | 790 | cur = parser->root.cursor; |
David Turner | e49ab25 | 2000-05-16 23:44:38 +0000 | [diff] [blame] | 791 | |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 792 | if ( cur < limit && (FT_Byte)( *cur - '0' ) < 10 ) |
David Turner | 2dfb5ac | 2000-01-27 14:02:04 +0000 | [diff] [blame] | 793 | { |
Werner Lemberg | b5084e1 | 2000-10-28 17:10:06 +0000 | [diff] [blame] | 794 | *size = T1_ToInt( parser ); |
David Turner | e49ab25 | 2000-05-16 23:44:38 +0000 | [diff] [blame] | 795 | |
Werner Lemberg | b5084e1 | 2000-10-28 17:10:06 +0000 | [diff] [blame] | 796 | T1_Skip_Spaces( parser ); |
| 797 | T1_Skip_Alpha ( parser ); /* `RD' or `-|' or something else */ |
David Turner | e49ab25 | 2000-05-16 23:44:38 +0000 | [diff] [blame] | 798 | |
David Turner | 2dfb5ac | 2000-01-27 14:02:04 +0000 | [diff] [blame] | 799 | /* there is only one whitespace char after the */ |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 800 | /* `RD' or `-|' token */ |
David Turner | a39acf5 | 2000-08-23 02:47:57 +0000 | [diff] [blame] | 801 | *base = parser->root.cursor + 1; |
David Turner | e49ab25 | 2000-05-16 23:44:38 +0000 | [diff] [blame] | 802 | |
Werner Lemberg | 8728f29 | 2000-08-23 17:32:42 +0000 | [diff] [blame] | 803 | parser->root.cursor += *size + 1; |
David Turner | 2dfb5ac | 2000-01-27 14:02:04 +0000 | [diff] [blame] | 804 | return 1; |
| 805 | } |
| 806 | |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 807 | FT_ERROR(( "read_binary_data: invalid size field\n" )); |
David Turner | a39acf5 | 2000-08-23 02:47:57 +0000 | [diff] [blame] | 808 | parser->root.error = T1_Err_Invalid_File_Format; |
David Turner | 2dfb5ac | 2000-01-27 14:02:04 +0000 | [diff] [blame] | 809 | return 0; |
| 810 | } |
| 811 | |
| 812 | |
| 813 | /* we will now define the routines used to handle */ |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 814 | /* the `/Encoding', `/Subrs', and `/CharStrings' */ |
| 815 | /* dictionaries */ |
David Turner | 2dfb5ac | 2000-01-27 14:02:04 +0000 | [diff] [blame] | 816 | |
Werner Lemberg | 4a2305c | 2001-06-28 07:17:51 +0000 | [diff] [blame] | 817 | static void |
| 818 | parse_font_name( T1_Face face, |
| 819 | T1_Loader* loader ) |
David Turner | 2dfb5ac | 2000-01-27 14:02:04 +0000 | [diff] [blame] | 820 | { |
David Turner | 4e7eeee | 2002-02-28 16:10:29 +0000 | [diff] [blame] | 821 | T1_Parser parser = &loader->parser; |
Werner Lemberg | b5084e1 | 2000-10-28 17:10:06 +0000 | [diff] [blame] | 822 | FT_Error error; |
| 823 | FT_Memory memory = parser->root.memory; |
| 824 | FT_Int len; |
| 825 | FT_Byte* cur; |
| 826 | FT_Byte* cur2; |
| 827 | FT_Byte* limit; |
David Turner | e49ab25 | 2000-05-16 23:44:38 +0000 | [diff] [blame] | 828 | |
Werner Lemberg | c3b2160 | 2001-12-05 01:22:05 +0000 | [diff] [blame] | 829 | |
Tom Kacvinsky | 48f26bc | 2001-10-20 17:44:48 +0000 | [diff] [blame] | 830 | if ( face->type1.font_name ) |
| 831 | /* with synthetic fonts, it's possible we get here twice */ |
| 832 | return; |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 833 | |
Werner Lemberg | b5084e1 | 2000-10-28 17:10:06 +0000 | [diff] [blame] | 834 | T1_Skip_Spaces( parser ); |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 835 | |
David Turner | a39acf5 | 2000-08-23 02:47:57 +0000 | [diff] [blame] | 836 | cur = parser->root.cursor; |
| 837 | limit = parser->root.limit; |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 838 | |
| 839 | if ( cur >= limit - 1 || *cur != '/' ) |
| 840 | return; |
David Turner | e49ab25 | 2000-05-16 23:44:38 +0000 | [diff] [blame] | 841 | |
David Turner | 2dfb5ac | 2000-01-27 14:02:04 +0000 | [diff] [blame] | 842 | cur++; |
| 843 | cur2 = cur; |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 844 | while ( cur2 < limit && is_alpha( *cur2 ) ) |
| 845 | cur2++; |
| 846 | |
Werner Lemberg | 914b289 | 2001-03-10 17:07:42 +0000 | [diff] [blame] | 847 | len = (FT_Int)( cur2 - cur ); |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 848 | if ( len > 0 ) |
David Turner | 2dfb5ac | 2000-01-27 14:02:04 +0000 | [diff] [blame] | 849 | { |
David Turner | e459d74 | 2002-03-22 13:52:37 +0000 | [diff] [blame^] | 850 | if ( FT_ALLOC( face->type1.font_name, len + 1 ) ) |
David Turner | 2dfb5ac | 2000-01-27 14:02:04 +0000 | [diff] [blame] | 851 | { |
David Turner | a39acf5 | 2000-08-23 02:47:57 +0000 | [diff] [blame] | 852 | parser->root.error = error; |
David Turner | 2dfb5ac | 2000-01-27 14:02:04 +0000 | [diff] [blame] | 853 | return; |
| 854 | } |
David Turner | e49ab25 | 2000-05-16 23:44:38 +0000 | [diff] [blame] | 855 | |
David Turner | e459d74 | 2002-03-22 13:52:37 +0000 | [diff] [blame^] | 856 | FT_MEM_COPY( face->type1.font_name, cur, len ); |
David Turner | 2dfb5ac | 2000-01-27 14:02:04 +0000 | [diff] [blame] | 857 | face->type1.font_name[len] = '\0'; |
| 858 | } |
David Turner | a39acf5 | 2000-08-23 02:47:57 +0000 | [diff] [blame] | 859 | parser->root.cursor = cur2; |
David Turner | 2dfb5ac | 2000-01-27 14:02:04 +0000 | [diff] [blame] | 860 | } |
| 861 | |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 862 | |
Werner Lemberg | 4a2305c | 2001-06-28 07:17:51 +0000 | [diff] [blame] | 863 | static void |
| 864 | parse_font_bbox( T1_Face face, |
| 865 | T1_Loader* loader ) |
David Turner | 2dfb5ac | 2000-01-27 14:02:04 +0000 | [diff] [blame] | 866 | { |
David Turner | 4e7eeee | 2002-02-28 16:10:29 +0000 | [diff] [blame] | 867 | T1_Parser parser = &loader->parser; |
Tom Kacvinsky | 5d362b6 | 2001-03-10 19:08:44 +0000 | [diff] [blame] | 868 | FT_Fixed temp[4]; |
Werner Lemberg | b5084e1 | 2000-10-28 17:10:06 +0000 | [diff] [blame] | 869 | FT_BBox* bbox = &face->type1.font_bbox; |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 870 | |
David Turner | e49ab25 | 2000-05-16 23:44:38 +0000 | [diff] [blame] | 871 | |
Tom Kacvinsky | 5d362b6 | 2001-03-10 19:08:44 +0000 | [diff] [blame] | 872 | (void)T1_ToFixedArray( parser, 4, temp, 0 ); |
| 873 | bbox->xMin = FT_RoundFix( temp[0] ); |
| 874 | bbox->yMin = FT_RoundFix( temp[1] ); |
| 875 | bbox->xMax = FT_RoundFix( temp[2] ); |
| 876 | bbox->yMax = FT_RoundFix( temp[3] ); |
David Turner | 2dfb5ac | 2000-01-27 14:02:04 +0000 | [diff] [blame] | 877 | } |
| 878 | |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 879 | |
Werner Lemberg | 4a2305c | 2001-06-28 07:17:51 +0000 | [diff] [blame] | 880 | static void |
| 881 | parse_font_matrix( T1_Face face, |
| 882 | T1_Loader* loader ) |
David Turner | 1c9a1ca | 2000-05-24 21:12:02 +0000 | [diff] [blame] | 883 | { |
David Turner | 4e7eeee | 2002-02-28 16:10:29 +0000 | [diff] [blame] | 884 | T1_Parser parser = &loader->parser; |
Werner Lemberg | b5084e1 | 2000-10-28 17:10:06 +0000 | [diff] [blame] | 885 | FT_Matrix* matrix = &face->type1.font_matrix; |
| 886 | FT_Vector* offset = &face->type1.font_offset; |
Tom Kacvinsky | b2d5fef | 2001-01-24 22:41:20 +0000 | [diff] [blame] | 887 | FT_Face root = (FT_Face)&face->root; |
Werner Lemberg | b5084e1 | 2000-10-28 17:10:06 +0000 | [diff] [blame] | 888 | FT_Fixed temp[6]; |
Tom Kacvinsky | b2d5fef | 2001-01-24 22:41:20 +0000 | [diff] [blame] | 889 | FT_Fixed temp_scale; |
David Turner | 1c9a1ca | 2000-05-24 21:12:02 +0000 | [diff] [blame] | 890 | |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 891 | |
Just van Rossum | 7c64409 | 2000-08-01 04:29:25 +0000 | [diff] [blame] | 892 | if ( matrix->xx || matrix->yx ) |
| 893 | /* with synthetic fonts, it's possible we get here twice */ |
| 894 | return; |
| 895 | |
Werner Lemberg | b5084e1 | 2000-10-28 17:10:06 +0000 | [diff] [blame] | 896 | (void)T1_ToFixedArray( parser, 6, temp, 3 ); |
David Turner | 24d7024 | 2000-08-17 01:09:06 +0000 | [diff] [blame] | 897 | |
Tom Kacvinsky | b2d5fef | 2001-01-24 22:41:20 +0000 | [diff] [blame] | 898 | temp_scale = ABS( temp[3] ); |
| 899 | |
Werner Lemberg | ec34290 | 2001-09-10 06:55:43 +0000 | [diff] [blame] | 900 | /* Set Units per EM based on FontMatrix values. We set the value to */ |
| 901 | /* 1000 / temp_scale, because temp_scale was already multiplied by */ |
| 902 | /* 1000 (in t1_tofixed, from psobjs.c). */ |
Tom Kacvinsky | f3dad68 | 2001-03-19 13:52:31 +0000 | [diff] [blame] | 903 | |
Werner Lemberg | ec34290 | 2001-09-10 06:55:43 +0000 | [diff] [blame] | 904 | root->units_per_EM = (FT_UShort)( FT_DivFix( 1000 * 0x10000L, |
| 905 | temp_scale ) >> 16 ); |
Tom Kacvinsky | b2d5fef | 2001-01-24 22:41:20 +0000 | [diff] [blame] | 906 | |
| 907 | /* we need to scale the values by 1.0/temp_scale */ |
| 908 | if ( temp_scale != 0x10000L ) |
David Turner | 24d7024 | 2000-08-17 01:09:06 +0000 | [diff] [blame] | 909 | { |
Tom Kacvinsky | b2d5fef | 2001-01-24 22:41:20 +0000 | [diff] [blame] | 910 | temp[0] = FT_DivFix( temp[0], temp_scale ); |
| 911 | temp[1] = FT_DivFix( temp[1], temp_scale ); |
| 912 | temp[2] = FT_DivFix( temp[2], temp_scale ); |
| 913 | temp[4] = FT_DivFix( temp[4], temp_scale ); |
| 914 | temp[5] = FT_DivFix( temp[5], temp_scale ); |
Werner Lemberg | b1c8bf0 | 2000-08-17 07:18:04 +0000 | [diff] [blame] | 915 | temp[3] = 0x10000L; |
David Turner | 24d7024 | 2000-08-17 01:09:06 +0000 | [diff] [blame] | 916 | } |
| 917 | |
David Turner | 1c9a1ca | 2000-05-24 21:12:02 +0000 | [diff] [blame] | 918 | matrix->xx = temp[0]; |
| 919 | matrix->yx = temp[1]; |
| 920 | matrix->xy = temp[2]; |
| 921 | matrix->yy = temp[3]; |
Werner Lemberg | e4b32a5 | 2000-10-31 20:42:18 +0000 | [diff] [blame] | 922 | |
Werner Lemberg | 6fbe4db | 2000-10-05 04:53:31 +0000 | [diff] [blame] | 923 | /* note that the offsets must be expressed in integer font units */ |
David Turner | f00a4de | 2000-10-03 22:03:09 +0000 | [diff] [blame] | 924 | offset->x = temp[4] >> 16; |
| 925 | offset->y = temp[5] >> 16; |
David Turner | 1c9a1ca | 2000-05-24 21:12:02 +0000 | [diff] [blame] | 926 | } |
| 927 | |
| 928 | |
Werner Lemberg | 4a2305c | 2001-06-28 07:17:51 +0000 | [diff] [blame] | 929 | static void |
| 930 | parse_encoding( T1_Face face, |
| 931 | T1_Loader* loader ) |
David Turner | 2dfb5ac | 2000-01-27 14:02:04 +0000 | [diff] [blame] | 932 | { |
David Turner | 4e7eeee | 2002-02-28 16:10:29 +0000 | [diff] [blame] | 933 | T1_Parser parser = &loader->parser; |
Werner Lemberg | b5084e1 | 2000-10-28 17:10:06 +0000 | [diff] [blame] | 934 | FT_Byte* cur = parser->root.cursor; |
| 935 | FT_Byte* limit = parser->root.limit; |
Werner Lemberg | e4b32a5 | 2000-10-31 20:42:18 +0000 | [diff] [blame] | 936 | |
David Turner | 4e7eeee | 2002-02-28 16:10:29 +0000 | [diff] [blame] | 937 | PSAux_Service psaux = (PSAux_Service)face->psaux; |
David Turner | e49ab25 | 2000-05-16 23:44:38 +0000 | [diff] [blame] | 938 | |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 939 | |
David Turner | 2dfb5ac | 2000-01-27 14:02:04 +0000 | [diff] [blame] | 940 | /* skip whitespace */ |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 941 | while ( is_space( *cur ) ) |
David Turner | 2dfb5ac | 2000-01-27 14:02:04 +0000 | [diff] [blame] | 942 | { |
| 943 | cur++; |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 944 | if ( cur >= limit ) |
David Turner | 2dfb5ac | 2000-01-27 14:02:04 +0000 | [diff] [blame] | 945 | { |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 946 | FT_ERROR(( "parse_encoding: out of bounds!\n" )); |
David Turner | a39acf5 | 2000-08-23 02:47:57 +0000 | [diff] [blame] | 947 | parser->root.error = T1_Err_Invalid_File_Format; |
David Turner | 2dfb5ac | 2000-01-27 14:02:04 +0000 | [diff] [blame] | 948 | return; |
| 949 | } |
| 950 | } |
David Turner | e49ab25 | 2000-05-16 23:44:38 +0000 | [diff] [blame] | 951 | |
David Turner | 2dfb5ac | 2000-01-27 14:02:04 +0000 | [diff] [blame] | 952 | /* if we have a number, then the encoding is an array, */ |
| 953 | /* and we must load it now */ |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 954 | if ( (FT_Byte)( *cur - '0' ) < 10 ) |
David Turner | 2dfb5ac | 2000-01-27 14:02:04 +0000 | [diff] [blame] | 955 | { |
David Turner | 2964417 | 2002-02-28 18:59:37 +0000 | [diff] [blame] | 956 | T1_Encoding encode = &face->type1.encoding; |
David Turner | f9b8dec | 2000-06-16 19:34:52 +0000 | [diff] [blame] | 957 | FT_Int count, n; |
David Turner | 4e7eeee | 2002-02-28 16:10:29 +0000 | [diff] [blame] | 958 | PS_Table char_table = &loader->encoding_table; |
David Turner | a39acf5 | 2000-08-23 02:47:57 +0000 | [diff] [blame] | 959 | FT_Memory memory = parser->root.memory; |
David Turner | f9b8dec | 2000-06-16 19:34:52 +0000 | [diff] [blame] | 960 | FT_Error error; |
David Turner | e49ab25 | 2000-05-16 23:44:38 +0000 | [diff] [blame] | 961 | |
Werner Lemberg | c3b2160 | 2001-12-05 01:22:05 +0000 | [diff] [blame] | 962 | |
Tom Kacvinsky | 629bf28 | 2001-10-20 20:46:36 +0000 | [diff] [blame] | 963 | if ( encode->char_index ) |
| 964 | /* with synthetic fonts, it's possible we get here twice */ |
| 965 | return; |
| 966 | |
David Turner | 2dfb5ac | 2000-01-27 14:02:04 +0000 | [diff] [blame] | 967 | /* read the number of entries in the encoding, should be 256 */ |
Werner Lemberg | b5084e1 | 2000-10-28 17:10:06 +0000 | [diff] [blame] | 968 | count = T1_ToInt( parser ); |
David Turner | a39acf5 | 2000-08-23 02:47:57 +0000 | [diff] [blame] | 969 | if ( parser->root.error ) |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 970 | return; |
David Turner | 2dfb5ac | 2000-01-27 14:02:04 +0000 | [diff] [blame] | 971 | |
Werner Lemberg | b5084e1 | 2000-10-28 17:10:06 +0000 | [diff] [blame] | 972 | /* we use a T1_Table to store our charnames */ |
Werner Lemberg | 556ad08 | 2002-01-28 13:34:52 +0000 | [diff] [blame] | 973 | loader->num_chars = encode->num_chars = count; |
David Turner | e459d74 | 2002-03-22 13:52:37 +0000 | [diff] [blame^] | 974 | if ( FT_NEW_ARRAY( encode->char_index, count ) || |
| 975 | FT_NEW_ARRAY( encode->char_name, count ) || |
| 976 | FT_SET_ERROR( psaux->ps_table_funcs->init( |
| 977 | char_table, count, memory ) ) ) |
David Turner | 2dfb5ac | 2000-01-27 14:02:04 +0000 | [diff] [blame] | 978 | { |
David Turner | a39acf5 | 2000-08-23 02:47:57 +0000 | [diff] [blame] | 979 | parser->root.error = error; |
David Turner | 2dfb5ac | 2000-01-27 14:02:04 +0000 | [diff] [blame] | 980 | return; |
| 981 | } |
David Turner | e49ab25 | 2000-05-16 23:44:38 +0000 | [diff] [blame] | 982 | |
Tom Kacvinsky | 4082200 | 2000-10-17 20:25:30 +0000 | [diff] [blame] | 983 | /* We need to `zero' out encoding_table.elements */ |
Werner Lemberg | 05f0ad0 | 2000-10-19 05:12:00 +0000 | [diff] [blame] | 984 | for ( n = 0; n < count; n++ ) |
Tom Kacvinsky | 4082200 | 2000-10-17 20:25:30 +0000 | [diff] [blame] | 985 | { |
Werner Lemberg | a13a473 | 2000-11-02 15:14:38 +0000 | [diff] [blame] | 986 | char* notdef = (char *)".notdef"; |
Werner Lemberg | 05f0ad0 | 2000-10-19 05:12:00 +0000 | [diff] [blame] | 987 | |
| 988 | |
Werner Lemberg | b5084e1 | 2000-10-28 17:10:06 +0000 | [diff] [blame] | 989 | T1_Add_Table( char_table, n, notdef, 8 ); |
Tom Kacvinsky | 4082200 | 2000-10-17 20:25:30 +0000 | [diff] [blame] | 990 | } |
| 991 | |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 992 | /* Now, we will need to read a record of the form */ |
David Turner | 2dfb5ac | 2000-01-27 14:02:04 +0000 | [diff] [blame] | 993 | /* ... charcode /charname ... for each entry in our table */ |
| 994 | /* */ |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 995 | /* We simply look for a number followed by an immediate */ |
| 996 | /* name. Note that this ignores correctly the sequence */ |
| 997 | /* that is often seen in type1 fonts: */ |
David Turner | 2dfb5ac | 2000-01-27 14:02:04 +0000 | [diff] [blame] | 998 | /* */ |
| 999 | /* 0 1 255 { 1 index exch /.notdef put } for dup */ |
| 1000 | /* */ |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 1001 | /* used to clean the encoding array before anything else. */ |
David Turner | 2dfb5ac | 2000-01-27 14:02:04 +0000 | [diff] [blame] | 1002 | /* */ |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 1003 | /* We stop when we encounter a `def'. */ |
David Turner | 2dfb5ac | 2000-01-27 14:02:04 +0000 | [diff] [blame] | 1004 | |
David Turner | a39acf5 | 2000-08-23 02:47:57 +0000 | [diff] [blame] | 1005 | cur = parser->root.cursor; |
| 1006 | limit = parser->root.limit; |
David Turner | 2dfb5ac | 2000-01-27 14:02:04 +0000 | [diff] [blame] | 1007 | n = 0; |
| 1008 | |
| 1009 | for ( ; cur < limit; ) |
| 1010 | { |
David Turner | f9b8dec | 2000-06-16 19:34:52 +0000 | [diff] [blame] | 1011 | FT_Byte c; |
David Turner | e49ab25 | 2000-05-16 23:44:38 +0000 | [diff] [blame] | 1012 | |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 1013 | |
David Turner | 2dfb5ac | 2000-01-27 14:02:04 +0000 | [diff] [blame] | 1014 | c = *cur; |
David Turner | e49ab25 | 2000-05-16 23:44:38 +0000 | [diff] [blame] | 1015 | |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 1016 | /* we stop when we encounter a `def' */ |
| 1017 | if ( c == 'd' && cur + 3 < limit ) |
David Turner | 2dfb5ac | 2000-01-27 14:02:04 +0000 | [diff] [blame] | 1018 | { |
| 1019 | if ( cur[1] == 'e' && |
| 1020 | cur[2] == 'f' && |
David Turner | 95bec28 | 2000-02-15 12:55:57 +0000 | [diff] [blame] | 1021 | is_space(cur[-1]) && |
David Turner | 2dfb5ac | 2000-01-27 14:02:04 +0000 | [diff] [blame] | 1022 | is_space(cur[3]) ) |
David Turner | 95bec28 | 2000-02-15 12:55:57 +0000 | [diff] [blame] | 1023 | { |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 1024 | FT_TRACE6(( "encoding end\n" )); |
| 1025 | break; |
David Turner | 95bec28 | 2000-02-15 12:55:57 +0000 | [diff] [blame] | 1026 | } |
David Turner | 2dfb5ac | 2000-01-27 14:02:04 +0000 | [diff] [blame] | 1027 | } |
David Turner | e49ab25 | 2000-05-16 23:44:38 +0000 | [diff] [blame] | 1028 | |
David Turner | 2dfb5ac | 2000-01-27 14:02:04 +0000 | [diff] [blame] | 1029 | /* otherwise, we must find a number before anything else */ |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 1030 | if ( (FT_Byte)( c - '0' ) < 10 ) |
David Turner | 2dfb5ac | 2000-01-27 14:02:04 +0000 | [diff] [blame] | 1031 | { |
David Turner | f9b8dec | 2000-06-16 19:34:52 +0000 | [diff] [blame] | 1032 | FT_Int charcode; |
David Turner | e49ab25 | 2000-05-16 23:44:38 +0000 | [diff] [blame] | 1033 | |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 1034 | |
David Turner | a39acf5 | 2000-08-23 02:47:57 +0000 | [diff] [blame] | 1035 | parser->root.cursor = cur; |
Werner Lemberg | b5084e1 | 2000-10-28 17:10:06 +0000 | [diff] [blame] | 1036 | charcode = T1_ToInt( parser ); |
David Turner | a39acf5 | 2000-08-23 02:47:57 +0000 | [diff] [blame] | 1037 | cur = parser->root.cursor; |
David Turner | e49ab25 | 2000-05-16 23:44:38 +0000 | [diff] [blame] | 1038 | |
David Turner | 2dfb5ac | 2000-01-27 14:02:04 +0000 | [diff] [blame] | 1039 | /* skip whitespace */ |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 1040 | while ( cur < limit && is_space( *cur ) ) |
| 1041 | cur++; |
David Turner | e49ab25 | 2000-05-16 23:44:38 +0000 | [diff] [blame] | 1042 | |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 1043 | if ( cur < limit && *cur == '/' ) |
David Turner | 2dfb5ac | 2000-01-27 14:02:04 +0000 | [diff] [blame] | 1044 | { |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 1045 | /* bingo, we have an immediate name -- it must be a */ |
| 1046 | /* character name */ |
| 1047 | FT_Byte* cur2 = cur + 1; |
David Turner | f9b8dec | 2000-06-16 19:34:52 +0000 | [diff] [blame] | 1048 | FT_Int len; |
David Turner | e49ab25 | 2000-05-16 23:44:38 +0000 | [diff] [blame] | 1049 | |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 1050 | |
| 1051 | while ( cur2 < limit && is_alpha( *cur2 ) ) |
| 1052 | cur2++; |
| 1053 | |
Werner Lemberg | 914b289 | 2001-03-10 17:07:42 +0000 | [diff] [blame] | 1054 | len = (FT_Int)( cur2 - cur - 1 ); |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 1055 | |
Werner Lemberg | b5084e1 | 2000-10-28 17:10:06 +0000 | [diff] [blame] | 1056 | parser->root.error = T1_Add_Table( char_table, charcode, |
Tom Kacvinsky | cad797e | 2001-04-10 18:15:17 +0000 | [diff] [blame] | 1057 | cur + 1, len + 1 ); |
David Turner | 2dfb5ac | 2000-01-27 14:02:04 +0000 | [diff] [blame] | 1058 | char_table->elements[charcode][len] = '\0'; |
David Turner | a39acf5 | 2000-08-23 02:47:57 +0000 | [diff] [blame] | 1059 | if ( parser->root.error ) |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 1060 | return; |
David Turner | e49ab25 | 2000-05-16 23:44:38 +0000 | [diff] [blame] | 1061 | |
David Turner | 2dfb5ac | 2000-01-27 14:02:04 +0000 | [diff] [blame] | 1062 | cur = cur2; |
| 1063 | } |
| 1064 | } |
| 1065 | else |
| 1066 | cur++; |
| 1067 | } |
David Turner | e49ab25 | 2000-05-16 23:44:38 +0000 | [diff] [blame] | 1068 | |
David Turner | 2964417 | 2002-02-28 18:59:37 +0000 | [diff] [blame] | 1069 | face->type1.encoding_type = T1_ENCODING_TYPE_ARRAY; |
Werner Lemberg | 8728f29 | 2000-08-23 17:32:42 +0000 | [diff] [blame] | 1070 | parser->root.cursor = cur; |
David Turner | 2dfb5ac | 2000-01-27 14:02:04 +0000 | [diff] [blame] | 1071 | } |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 1072 | /* Otherwise, we should have either `StandardEncoding' or */ |
| 1073 | /* `ExpertEncoding' */ |
David Turner | 2dfb5ac | 2000-01-27 14:02:04 +0000 | [diff] [blame] | 1074 | else |
| 1075 | { |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 1076 | if ( cur + 17 < limit && |
David Turner | 0dd3434 | 2000-02-02 12:20:53 +0000 | [diff] [blame] | 1077 | strncmp( (const char*)cur, "StandardEncoding", 16 ) == 0 ) |
David Turner | 2964417 | 2002-02-28 18:59:37 +0000 | [diff] [blame] | 1078 | face->type1.encoding_type = T1_ENCODING_TYPE_STANDARD; |
David Turner | e49ab25 | 2000-05-16 23:44:38 +0000 | [diff] [blame] | 1079 | |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 1080 | else if ( cur + 15 < limit && |
David Turner | 0dd3434 | 2000-02-02 12:20:53 +0000 | [diff] [blame] | 1081 | strncmp( (const char*)cur, "ExpertEncoding", 14 ) == 0 ) |
David Turner | 2964417 | 2002-02-28 18:59:37 +0000 | [diff] [blame] | 1082 | face->type1.encoding_type = T1_ENCODING_TYPE_EXPORT; |
David Turner | 2dfb5ac | 2000-01-27 14:02:04 +0000 | [diff] [blame] | 1083 | |
Werner Lemberg | 66b3509 | 2002-02-10 12:33:14 +0000 | [diff] [blame] | 1084 | else if ( cur + 18 < limit && |
| 1085 | strncmp( (const char*)cur, "ISOLatin1Encoding", 17 ) == 0 ) |
David Turner | 2964417 | 2002-02-28 18:59:37 +0000 | [diff] [blame] | 1086 | face->type1.encoding_type = T1_ENCODING_TYPE_ISOLATIN1; |
Werner Lemberg | 66b3509 | 2002-02-10 12:33:14 +0000 | [diff] [blame] | 1087 | |
David Turner | 2dfb5ac | 2000-01-27 14:02:04 +0000 | [diff] [blame] | 1088 | else |
| 1089 | { |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 1090 | FT_ERROR(( "parse_encoding: invalid token!\n" )); |
David Turner | a39acf5 | 2000-08-23 02:47:57 +0000 | [diff] [blame] | 1091 | parser->root.error = T1_Err_Invalid_File_Format; |
David Turner | e49ab25 | 2000-05-16 23:44:38 +0000 | [diff] [blame] | 1092 | } |
David Turner | 2dfb5ac | 2000-01-27 14:02:04 +0000 | [diff] [blame] | 1093 | } |
| 1094 | } |
| 1095 | |
| 1096 | |
Werner Lemberg | 4a2305c | 2001-06-28 07:17:51 +0000 | [diff] [blame] | 1097 | static void |
| 1098 | parse_subrs( T1_Face face, |
| 1099 | T1_Loader* loader ) |
David Turner | 2dfb5ac | 2000-01-27 14:02:04 +0000 | [diff] [blame] | 1100 | { |
David Turner | 9ddeee1 | 2002-03-06 12:36:22 +0000 | [diff] [blame] | 1101 | T1_Parser parser = &loader->parser; |
| 1102 | PS_Table table = &loader->subrs; |
Werner Lemberg | b5084e1 | 2000-10-28 17:10:06 +0000 | [diff] [blame] | 1103 | FT_Memory memory = parser->root.memory; |
| 1104 | FT_Error error; |
| 1105 | FT_Int n; |
David Turner | e49ab25 | 2000-05-16 23:44:38 +0000 | [diff] [blame] | 1106 | |
David Turner | 4e7eeee | 2002-02-28 16:10:29 +0000 | [diff] [blame] | 1107 | PSAux_Service psaux = (PSAux_Service)face->psaux; |
Werner Lemberg | 8728f29 | 2000-08-23 17:32:42 +0000 | [diff] [blame] | 1108 | |
Werner Lemberg | c3b2160 | 2001-12-05 01:22:05 +0000 | [diff] [blame] | 1109 | |
Tom Kacvinsky | 48f26bc | 2001-10-20 17:44:48 +0000 | [diff] [blame] | 1110 | if ( loader->num_subrs ) |
| 1111 | /* with synthetic fonts, it's possible we get here twice */ |
| 1112 | return; |
Werner Lemberg | e4b32a5 | 2000-10-31 20:42:18 +0000 | [diff] [blame] | 1113 | |
Werner Lemberg | b5084e1 | 2000-10-28 17:10:06 +0000 | [diff] [blame] | 1114 | loader->num_subrs = T1_ToInt( parser ); |
David Turner | a39acf5 | 2000-08-23 02:47:57 +0000 | [diff] [blame] | 1115 | if ( parser->root.error ) |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 1116 | return; |
David Turner | e49ab25 | 2000-05-16 23:44:38 +0000 | [diff] [blame] | 1117 | |
Werner Lemberg | d082cd6 | 2000-07-25 17:25:32 +0000 | [diff] [blame] | 1118 | /* position the parser right before the `dup' of the first subr */ |
Werner Lemberg | b5084e1 | 2000-10-28 17:10:06 +0000 | [diff] [blame] | 1119 | T1_Skip_Spaces( parser ); |
| 1120 | T1_Skip_Alpha( parser ); /* `array' */ |
| 1121 | T1_Skip_Spaces( parser ); |
Just van Rossum | 53fb1f5 | 2000-07-25 16:20:57 +0000 | [diff] [blame] | 1122 | |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 1123 | /* initialize subrs array */ |
David Turner | a39acf5 | 2000-08-23 02:47:57 +0000 | [diff] [blame] | 1124 | error = psaux->ps_table_funcs->init( table, loader->num_subrs, memory ); |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 1125 | if ( error ) |
| 1126 | goto Fail; |
David Turner | 2dfb5ac | 2000-01-27 14:02:04 +0000 | [diff] [blame] | 1127 | |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 1128 | /* the format is simple: */ |
David Turner | 2dfb5ac | 2000-01-27 14:02:04 +0000 | [diff] [blame] | 1129 | /* */ |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 1130 | /* `index' + binary data */ |
David Turner | 2dfb5ac | 2000-01-27 14:02:04 +0000 | [diff] [blame] | 1131 | /* */ |
David Turner | e49ab25 | 2000-05-16 23:44:38 +0000 | [diff] [blame] | 1132 | |
David Turner | 2dfb5ac | 2000-01-27 14:02:04 +0000 | [diff] [blame] | 1133 | for ( n = 0; n < loader->num_subrs; n++ ) |
| 1134 | { |
Werner Lemberg | 0d9165e | 2002-03-07 21:59:59 +0000 | [diff] [blame] | 1135 | FT_Int idx, size; |
David Turner | f9b8dec | 2000-06-16 19:34:52 +0000 | [diff] [blame] | 1136 | FT_Byte* base; |
David Turner | e49ab25 | 2000-05-16 23:44:38 +0000 | [diff] [blame] | 1137 | |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 1138 | |
Werner Lemberg | d082cd6 | 2000-07-25 17:25:32 +0000 | [diff] [blame] | 1139 | /* If the next token isn't `dup', we are also done. This */ |
| 1140 | /* happens when there are `holes' in the Subrs array. */ |
David Turner | a39acf5 | 2000-08-23 02:47:57 +0000 | [diff] [blame] | 1141 | if ( strncmp( (char*)parser->root.cursor, "dup", 3 ) != 0 ) |
Just van Rossum | 53fb1f5 | 2000-07-25 16:20:57 +0000 | [diff] [blame] | 1142 | break; |
| 1143 | |
Werner Lemberg | 0d9165e | 2002-03-07 21:59:59 +0000 | [diff] [blame] | 1144 | idx = T1_ToInt( parser ); |
Werner Lemberg | e4b32a5 | 2000-10-31 20:42:18 +0000 | [diff] [blame] | 1145 | |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 1146 | if ( !read_binary_data( parser, &size, &base ) ) |
| 1147 | return; |
David Turner | e49ab25 | 2000-05-16 23:44:38 +0000 | [diff] [blame] | 1148 | |
Werner Lemberg | d082cd6 | 2000-07-25 17:25:32 +0000 | [diff] [blame] | 1149 | /* The binary string is followed by one token, e.g. `NP' */ |
| 1150 | /* (bound to `noaccess put') or by two separate tokens: */ |
| 1151 | /* `noaccess' & `put'. We position the parser right */ |
| 1152 | /* before the next `dup', if any. */ |
Werner Lemberg | b5084e1 | 2000-10-28 17:10:06 +0000 | [diff] [blame] | 1153 | T1_Skip_Spaces( parser ); |
| 1154 | T1_Skip_Alpha( parser ); /* `NP' or `I' or `noaccess' */ |
| 1155 | T1_Skip_Spaces( parser ); |
Werner Lemberg | d082cd6 | 2000-07-25 17:25:32 +0000 | [diff] [blame] | 1156 | |
David Turner | a39acf5 | 2000-08-23 02:47:57 +0000 | [diff] [blame] | 1157 | if ( strncmp( (char*)parser->root.cursor, "put", 3 ) == 0 ) |
Just van Rossum | 53fb1f5 | 2000-07-25 16:20:57 +0000 | [diff] [blame] | 1158 | { |
Werner Lemberg | b5084e1 | 2000-10-28 17:10:06 +0000 | [diff] [blame] | 1159 | T1_Skip_Alpha( parser ); /* skip `put' */ |
| 1160 | T1_Skip_Spaces( parser ); |
Just van Rossum | 53fb1f5 | 2000-07-25 16:20:57 +0000 | [diff] [blame] | 1161 | } |
| 1162 | |
David Turner | d0079e6 | 2000-06-23 00:07:06 +0000 | [diff] [blame] | 1163 | /* some fonts use a value of -1 for lenIV to indicate that */ |
Werner Lemberg | d082cd6 | 2000-07-25 17:25:32 +0000 | [diff] [blame] | 1164 | /* the charstrings are unencoded */ |
David Turner | d0079e6 | 2000-06-23 00:07:06 +0000 | [diff] [blame] | 1165 | /* */ |
Werner Lemberg | d082cd6 | 2000-07-25 17:25:32 +0000 | [diff] [blame] | 1166 | /* thanks to Tom Kacvinsky for pointing this out */ |
David Turner | d0079e6 | 2000-06-23 00:07:06 +0000 | [diff] [blame] | 1167 | /* */ |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 1168 | if ( face->type1.private_dict.lenIV >= 0 ) |
David Turner | d0079e6 | 2000-06-23 00:07:06 +0000 | [diff] [blame] | 1169 | { |
Werner Lemberg | 556ad08 | 2002-01-28 13:34:52 +0000 | [diff] [blame] | 1170 | FT_Byte* temp; |
David Turner | 95bec28 | 2000-02-15 12:55:57 +0000 | [diff] [blame] | 1171 | |
Werner Lemberg | 556ad08 | 2002-01-28 13:34:52 +0000 | [diff] [blame] | 1172 | |
| 1173 | /* t1_decrypt() shouldn't write to base -- make temporary copy */ |
David Turner | e459d74 | 2002-03-22 13:52:37 +0000 | [diff] [blame^] | 1174 | if ( FT_ALLOC( temp, size ) ) |
Werner Lemberg | 556ad08 | 2002-01-28 13:34:52 +0000 | [diff] [blame] | 1175 | goto Fail; |
David Turner | e459d74 | 2002-03-22 13:52:37 +0000 | [diff] [blame^] | 1176 | FT_MEM_COPY( temp, base, size ); |
Werner Lemberg | 556ad08 | 2002-01-28 13:34:52 +0000 | [diff] [blame] | 1177 | psaux->t1_decrypt( temp, size, 4330 ); |
| 1178 | size -= face->type1.private_dict.lenIV; |
Werner Lemberg | 0d9165e | 2002-03-07 21:59:59 +0000 | [diff] [blame] | 1179 | error = T1_Add_Table( table, idx, |
Werner Lemberg | 556ad08 | 2002-01-28 13:34:52 +0000 | [diff] [blame] | 1180 | temp + face->type1.private_dict.lenIV, size ); |
David Turner | e459d74 | 2002-03-22 13:52:37 +0000 | [diff] [blame^] | 1181 | FT_FREE( temp ); |
Werner Lemberg | 556ad08 | 2002-01-28 13:34:52 +0000 | [diff] [blame] | 1182 | } |
| 1183 | else |
Werner Lemberg | 0d9165e | 2002-03-07 21:59:59 +0000 | [diff] [blame] | 1184 | error = T1_Add_Table( table, idx, base, size ); |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 1185 | if ( error ) |
| 1186 | goto Fail; |
David Turner | 2dfb5ac | 2000-01-27 14:02:04 +0000 | [diff] [blame] | 1187 | } |
| 1188 | return; |
| 1189 | |
| 1190 | Fail: |
David Turner | a39acf5 | 2000-08-23 02:47:57 +0000 | [diff] [blame] | 1191 | parser->root.error = error; |
David Turner | 2dfb5ac | 2000-01-27 14:02:04 +0000 | [diff] [blame] | 1192 | } |
| 1193 | |
| 1194 | |
Werner Lemberg | 4a2305c | 2001-06-28 07:17:51 +0000 | [diff] [blame] | 1195 | static void |
| 1196 | parse_charstrings( T1_Face face, |
| 1197 | T1_Loader* loader ) |
David Turner | 2dfb5ac | 2000-01-27 14:02:04 +0000 | [diff] [blame] | 1198 | { |
David Turner | 4e7eeee | 2002-02-28 16:10:29 +0000 | [diff] [blame] | 1199 | T1_Parser parser = &loader->parser; |
| 1200 | PS_Table code_table = &loader->charstrings; |
| 1201 | PS_Table name_table = &loader->glyph_names; |
| 1202 | PS_Table swap_table = &loader->swap_table; |
Werner Lemberg | b5084e1 | 2000-10-28 17:10:06 +0000 | [diff] [blame] | 1203 | FT_Memory memory = parser->root.memory; |
| 1204 | FT_Error error; |
David Turner | 2dfb5ac | 2000-01-27 14:02:04 +0000 | [diff] [blame] | 1205 | |
David Turner | 4e7eeee | 2002-02-28 16:10:29 +0000 | [diff] [blame] | 1206 | PSAux_Service psaux = (PSAux_Service)face->psaux; |
David Turner | a39acf5 | 2000-08-23 02:47:57 +0000 | [diff] [blame] | 1207 | |
David Turner | f9b8dec | 2000-06-16 19:34:52 +0000 | [diff] [blame] | 1208 | FT_Byte* cur; |
David Turner | a39acf5 | 2000-08-23 02:47:57 +0000 | [diff] [blame] | 1209 | FT_Byte* limit = parser->root.limit; |
David Turner | f9b8dec | 2000-06-16 19:34:52 +0000 | [diff] [blame] | 1210 | FT_Int n; |
Tom Kacvinsky | 4082200 | 2000-10-17 20:25:30 +0000 | [diff] [blame] | 1211 | FT_UInt notdef_index = 0; |
| 1212 | FT_Byte notdef_found = 0; |
David Turner | e49ab25 | 2000-05-16 23:44:38 +0000 | [diff] [blame] | 1213 | |
Werner Lemberg | 05f0ad0 | 2000-10-19 05:12:00 +0000 | [diff] [blame] | 1214 | |
Just van Rossum | 7c64409 | 2000-08-01 04:29:25 +0000 | [diff] [blame] | 1215 | if ( loader->num_glyphs ) |
| 1216 | /* with synthetic fonts, it's possible we get here twice */ |
| 1217 | return; |
| 1218 | |
Werner Lemberg | b5084e1 | 2000-10-28 17:10:06 +0000 | [diff] [blame] | 1219 | loader->num_glyphs = T1_ToInt( parser ); |
David Turner | a39acf5 | 2000-08-23 02:47:57 +0000 | [diff] [blame] | 1220 | if ( parser->root.error ) |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 1221 | return; |
| 1222 | |
Tom Kacvinsky | cad797e | 2001-04-10 18:15:17 +0000 | [diff] [blame] | 1223 | /* initialize tables (leaving room for addition of .notdef, */ |
David Turner | 09d55ce | 2001-05-11 18:08:58 +0000 | [diff] [blame] | 1224 | /* if necessary). */ |
Tom Kacvinsky | cad797e | 2001-04-10 18:15:17 +0000 | [diff] [blame] | 1225 | |
Werner Lemberg | 8728f29 | 2000-08-23 17:32:42 +0000 | [diff] [blame] | 1226 | error = psaux->ps_table_funcs->init( code_table, |
Tom Kacvinsky | 4082200 | 2000-10-17 20:25:30 +0000 | [diff] [blame] | 1227 | loader->num_glyphs + 1, |
Werner Lemberg | 8728f29 | 2000-08-23 17:32:42 +0000 | [diff] [blame] | 1228 | memory ); |
| 1229 | if ( error ) |
David Turner | a39acf5 | 2000-08-23 02:47:57 +0000 | [diff] [blame] | 1230 | goto Fail; |
| 1231 | |
Werner Lemberg | 8728f29 | 2000-08-23 17:32:42 +0000 | [diff] [blame] | 1232 | error = psaux->ps_table_funcs->init( name_table, |
Tom Kacvinsky | 4082200 | 2000-10-17 20:25:30 +0000 | [diff] [blame] | 1233 | loader->num_glyphs + 1, |
Werner Lemberg | 8728f29 | 2000-08-23 17:32:42 +0000 | [diff] [blame] | 1234 | memory ); |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 1235 | if ( error ) |
| 1236 | goto Fail; |
David Turner | e49ab25 | 2000-05-16 23:44:38 +0000 | [diff] [blame] | 1237 | |
Tom Kacvinsky | cad797e | 2001-04-10 18:15:17 +0000 | [diff] [blame] | 1238 | /* Initialize table for swapping index notdef_index and */ |
| 1239 | /* index 0 names and codes (if necessary). */ |
| 1240 | |
| 1241 | error = psaux->ps_table_funcs->init( swap_table, 4, memory ); |
| 1242 | |
| 1243 | if ( error ) |
| 1244 | goto Fail; |
| 1245 | |
| 1246 | |
David Turner | 2dfb5ac | 2000-01-27 14:02:04 +0000 | [diff] [blame] | 1247 | n = 0; |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 1248 | for (;;) |
David Turner | 2dfb5ac | 2000-01-27 14:02:04 +0000 | [diff] [blame] | 1249 | { |
David Turner | f9b8dec | 2000-06-16 19:34:52 +0000 | [diff] [blame] | 1250 | FT_Int size; |
| 1251 | FT_Byte* base; |
David Turner | e49ab25 | 2000-05-16 23:44:38 +0000 | [diff] [blame] | 1252 | |
Werner Lemberg | 05f0ad0 | 2000-10-19 05:12:00 +0000 | [diff] [blame] | 1253 | |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 1254 | /* the format is simple: */ |
| 1255 | /* `/glyphname' + binary data */ |
David Turner | 2dfb5ac | 2000-01-27 14:02:04 +0000 | [diff] [blame] | 1256 | /* */ |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 1257 | /* note that we stop when we find a `def' */ |
David Turner | 2dfb5ac | 2000-01-27 14:02:04 +0000 | [diff] [blame] | 1258 | /* */ |
Werner Lemberg | b5084e1 | 2000-10-28 17:10:06 +0000 | [diff] [blame] | 1259 | T1_Skip_Spaces( parser ); |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 1260 | |
David Turner | a39acf5 | 2000-08-23 02:47:57 +0000 | [diff] [blame] | 1261 | cur = parser->root.cursor; |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 1262 | if ( cur >= limit ) |
David Turner | 2dfb5ac | 2000-01-27 14:02:04 +0000 | [diff] [blame] | 1263 | break; |
| 1264 | |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 1265 | /* we stop when we find a `def' or `end' keyword */ |
| 1266 | if ( *cur == 'd' && |
| 1267 | cur + 3 < limit && |
| 1268 | cur[1] == 'e' && |
| 1269 | cur[2] == 'f' ) |
David Turner | 95bec28 | 2000-02-15 12:55:57 +0000 | [diff] [blame] | 1270 | break; |
| 1271 | |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 1272 | if ( *cur == 'e' && |
| 1273 | cur + 3 < limit && |
| 1274 | cur[1] == 'n' && |
| 1275 | cur[2] == 'd' ) |
| 1276 | break; |
| 1277 | |
| 1278 | if ( *cur != '/' ) |
Werner Lemberg | b5084e1 | 2000-10-28 17:10:06 +0000 | [diff] [blame] | 1279 | T1_Skip_Alpha( parser ); |
David Turner | 2dfb5ac | 2000-01-27 14:02:04 +0000 | [diff] [blame] | 1280 | else |
| 1281 | { |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 1282 | FT_Byte* cur2 = cur + 1; |
David Turner | f9b8dec | 2000-06-16 19:34:52 +0000 | [diff] [blame] | 1283 | FT_Int len; |
David Turner | e49ab25 | 2000-05-16 23:44:38 +0000 | [diff] [blame] | 1284 | |
David Turner | e49ab25 | 2000-05-16 23:44:38 +0000 | [diff] [blame] | 1285 | |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 1286 | while ( cur2 < limit && is_alpha( *cur2 ) ) |
| 1287 | cur2++; |
Werner Lemberg | 914b289 | 2001-03-10 17:07:42 +0000 | [diff] [blame] | 1288 | len = (FT_Int)( cur2 - cur - 1 ); |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 1289 | |
Werner Lemberg | b5084e1 | 2000-10-28 17:10:06 +0000 | [diff] [blame] | 1290 | error = T1_Add_Table( name_table, n, cur + 1, len + 1 ); |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 1291 | if ( error ) |
| 1292 | goto Fail; |
David Turner | e49ab25 | 2000-05-16 23:44:38 +0000 | [diff] [blame] | 1293 | |
David Turner | 2dfb5ac | 2000-01-27 14:02:04 +0000 | [diff] [blame] | 1294 | /* add a trailing zero to the name table */ |
| 1295 | name_table->elements[n][len] = '\0'; |
David Turner | e49ab25 | 2000-05-16 23:44:38 +0000 | [diff] [blame] | 1296 | |
Werner Lemberg | 05f0ad0 | 2000-10-19 05:12:00 +0000 | [diff] [blame] | 1297 | /* record index of /.notdef */ |
| 1298 | if ( strcmp( (const char*)".notdef", |
| 1299 | (const char*)(name_table->elements[n]) ) == 0 ) |
| 1300 | { |
| 1301 | notdef_index = n; |
| 1302 | notdef_found = 1; |
Tom Kacvinsky | 4082200 | 2000-10-17 20:25:30 +0000 | [diff] [blame] | 1303 | } |
| 1304 | |
David Turner | a39acf5 | 2000-08-23 02:47:57 +0000 | [diff] [blame] | 1305 | parser->root.cursor = cur2; |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 1306 | if ( !read_binary_data( parser, &size, &base ) ) |
| 1307 | return; |
David Turner | 95bec28 | 2000-02-15 12:55:57 +0000 | [diff] [blame] | 1308 | |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 1309 | if ( face->type1.private_dict.lenIV >= 0 ) |
David Turner | d0079e6 | 2000-06-23 00:07:06 +0000 | [diff] [blame] | 1310 | { |
Werner Lemberg | 556ad08 | 2002-01-28 13:34:52 +0000 | [diff] [blame] | 1311 | FT_Byte* temp; |
David Turner | 95bec28 | 2000-02-15 12:55:57 +0000 | [diff] [blame] | 1312 | |
Werner Lemberg | 556ad08 | 2002-01-28 13:34:52 +0000 | [diff] [blame] | 1313 | |
| 1314 | /* t1_decrypt() shouldn't write to base -- make temporary copy */ |
David Turner | e459d74 | 2002-03-22 13:52:37 +0000 | [diff] [blame^] | 1315 | if ( FT_ALLOC( temp, size ) ) |
Werner Lemberg | 556ad08 | 2002-01-28 13:34:52 +0000 | [diff] [blame] | 1316 | goto Fail; |
David Turner | e459d74 | 2002-03-22 13:52:37 +0000 | [diff] [blame^] | 1317 | FT_MEM_COPY( temp, base, size ); |
Werner Lemberg | 556ad08 | 2002-01-28 13:34:52 +0000 | [diff] [blame] | 1318 | psaux->t1_decrypt( temp, size, 4330 ); |
| 1319 | size -= face->type1.private_dict.lenIV; |
| 1320 | error = T1_Add_Table( code_table, n, |
| 1321 | temp + face->type1.private_dict.lenIV, size ); |
David Turner | e459d74 | 2002-03-22 13:52:37 +0000 | [diff] [blame^] | 1322 | FT_FREE( temp ); |
Werner Lemberg | 556ad08 | 2002-01-28 13:34:52 +0000 | [diff] [blame] | 1323 | } |
| 1324 | else |
| 1325 | error = T1_Add_Table( code_table, n, base, size ); |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 1326 | if ( error ) |
| 1327 | goto Fail; |
David Turner | e49ab25 | 2000-05-16 23:44:38 +0000 | [diff] [blame] | 1328 | |
David Turner | 2dfb5ac | 2000-01-27 14:02:04 +0000 | [diff] [blame] | 1329 | n++; |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 1330 | if ( n >= loader->num_glyphs ) |
David Turner | 2dfb5ac | 2000-01-27 14:02:04 +0000 | [diff] [blame] | 1331 | break; |
| 1332 | } |
| 1333 | } |
Tom Kacvinsky | 4082200 | 2000-10-17 20:25:30 +0000 | [diff] [blame] | 1334 | |
David Turner | 95bec28 | 2000-02-15 12:55:57 +0000 | [diff] [blame] | 1335 | loader->num_glyphs = n; |
Tom Kacvinsky | 4082200 | 2000-10-17 20:25:30 +0000 | [diff] [blame] | 1336 | |
| 1337 | /* if /.notdef is found but does not occupy index 0, do our magic. */ |
| 1338 | if ( strcmp( (const char*)".notdef", |
Werner Lemberg | 05f0ad0 | 2000-10-19 05:12:00 +0000 | [diff] [blame] | 1339 | (const char*)name_table->elements[0] ) && |
| 1340 | notdef_found ) |
Tom Kacvinsky | 4082200 | 2000-10-17 20:25:30 +0000 | [diff] [blame] | 1341 | { |
Werner Lemberg | ef6ebd6 | 2001-04-11 18:09:49 +0000 | [diff] [blame] | 1342 | /* Swap glyph in index 0 with /.notdef glyph. First, add index 0 */ |
Tom Kacvinsky | 9d770c9 | 2001-04-11 18:40:27 +0000 | [diff] [blame] | 1343 | /* name and code entries to swap_table. Then place notdef_index name */ |
| 1344 | /* and code entries into swap_table. Then swap name and code */ |
Werner Lemberg | ef6ebd6 | 2001-04-11 18:09:49 +0000 | [diff] [blame] | 1345 | /* entries at indices notdef_index and 0 using values stored in */ |
| 1346 | /* swap_table. */ |
Tom Kacvinsky | 4082200 | 2000-10-17 20:25:30 +0000 | [diff] [blame] | 1347 | |
Tom Kacvinsky | cad797e | 2001-04-10 18:15:17 +0000 | [diff] [blame] | 1348 | /* Index 0 name */ |
| 1349 | error = T1_Add_Table( swap_table, 0, |
Werner Lemberg | 05f0ad0 | 2000-10-19 05:12:00 +0000 | [diff] [blame] | 1350 | name_table->elements[0], |
| 1351 | name_table->lengths [0] ); |
Tom Kacvinsky | 4082200 | 2000-10-17 20:25:30 +0000 | [diff] [blame] | 1352 | if ( error ) |
Werner Lemberg | 05f0ad0 | 2000-10-19 05:12:00 +0000 | [diff] [blame] | 1353 | goto Fail; |
Tom Kacvinsky | cad797e | 2001-04-10 18:15:17 +0000 | [diff] [blame] | 1354 | |
| 1355 | /* Index 0 code */ |
| 1356 | error = T1_Add_Table( swap_table, 1, |
Werner Lemberg | 05f0ad0 | 2000-10-19 05:12:00 +0000 | [diff] [blame] | 1357 | code_table->elements[0], |
| 1358 | code_table->lengths [0] ); |
Tom Kacvinsky | 4082200 | 2000-10-17 20:25:30 +0000 | [diff] [blame] | 1359 | if ( error ) |
Werner Lemberg | 05f0ad0 | 2000-10-19 05:12:00 +0000 | [diff] [blame] | 1360 | goto Fail; |
Tom Kacvinsky | 4082200 | 2000-10-17 20:25:30 +0000 | [diff] [blame] | 1361 | |
Tom Kacvinsky | cad797e | 2001-04-10 18:15:17 +0000 | [diff] [blame] | 1362 | /* Index notdef_index name */ |
| 1363 | error = T1_Add_Table( swap_table, 2, |
Werner Lemberg | 05f0ad0 | 2000-10-19 05:12:00 +0000 | [diff] [blame] | 1364 | name_table->elements[notdef_index], |
| 1365 | name_table->lengths [notdef_index] ); |
Tom Kacvinsky | 4082200 | 2000-10-17 20:25:30 +0000 | [diff] [blame] | 1366 | if ( error ) |
Werner Lemberg | 05f0ad0 | 2000-10-19 05:12:00 +0000 | [diff] [blame] | 1367 | goto Fail; |
Tom Kacvinsky | 4082200 | 2000-10-17 20:25:30 +0000 | [diff] [blame] | 1368 | |
Tom Kacvinsky | cad797e | 2001-04-10 18:15:17 +0000 | [diff] [blame] | 1369 | /* Index notdef_index code */ |
| 1370 | error = T1_Add_Table( swap_table, 3, |
Werner Lemberg | 05f0ad0 | 2000-10-19 05:12:00 +0000 | [diff] [blame] | 1371 | code_table->elements[notdef_index], |
| 1372 | code_table->lengths [notdef_index] ); |
Tom Kacvinsky | 4082200 | 2000-10-17 20:25:30 +0000 | [diff] [blame] | 1373 | if ( error ) |
Werner Lemberg | 05f0ad0 | 2000-10-19 05:12:00 +0000 | [diff] [blame] | 1374 | goto Fail; |
Tom Kacvinsky | 4082200 | 2000-10-17 20:25:30 +0000 | [diff] [blame] | 1375 | |
Werner Lemberg | b5084e1 | 2000-10-28 17:10:06 +0000 | [diff] [blame] | 1376 | error = T1_Add_Table( name_table, notdef_index, |
Tom Kacvinsky | cad797e | 2001-04-10 18:15:17 +0000 | [diff] [blame] | 1377 | swap_table->elements[0], |
| 1378 | swap_table->lengths [0] ); |
Tom Kacvinsky | 4082200 | 2000-10-17 20:25:30 +0000 | [diff] [blame] | 1379 | if ( error ) |
Werner Lemberg | 05f0ad0 | 2000-10-19 05:12:00 +0000 | [diff] [blame] | 1380 | goto Fail; |
Tom Kacvinsky | 4082200 | 2000-10-17 20:25:30 +0000 | [diff] [blame] | 1381 | |
Werner Lemberg | b5084e1 | 2000-10-28 17:10:06 +0000 | [diff] [blame] | 1382 | error = T1_Add_Table( code_table, notdef_index, |
Tom Kacvinsky | cad797e | 2001-04-10 18:15:17 +0000 | [diff] [blame] | 1383 | swap_table->elements[1], |
| 1384 | swap_table->lengths [1] ); |
| 1385 | if ( error ) |
| 1386 | goto Fail; |
| 1387 | |
| 1388 | error = T1_Add_Table( name_table, 0, |
| 1389 | swap_table->elements[2], |
| 1390 | swap_table->lengths [2] ); |
| 1391 | if ( error ) |
| 1392 | goto Fail; |
| 1393 | |
| 1394 | error = T1_Add_Table( code_table, 0, |
| 1395 | swap_table->elements[3], |
| 1396 | swap_table->lengths [3] ); |
Tom Kacvinsky | 4082200 | 2000-10-17 20:25:30 +0000 | [diff] [blame] | 1397 | if ( error ) |
Werner Lemberg | 05f0ad0 | 2000-10-19 05:12:00 +0000 | [diff] [blame] | 1398 | goto Fail; |
Tom Kacvinsky | 4082200 | 2000-10-17 20:25:30 +0000 | [diff] [blame] | 1399 | |
| 1400 | } |
| 1401 | else if ( !notdef_found ) |
| 1402 | { |
| 1403 | |
| 1404 | /* notdef_index is already 0, or /.notdef is undefined in */ |
| 1405 | /* charstrings dictionary. Worry about /.notdef undefined. */ |
Tom Kacvinsky | cad797e | 2001-04-10 18:15:17 +0000 | [diff] [blame] | 1406 | /* We take index 0 and add it to the end of the table(s) */ |
Tom Kacvinsky | 4082200 | 2000-10-17 20:25:30 +0000 | [diff] [blame] | 1407 | /* and add our own /.notdef glyph to index 0. */ |
Werner Lemberg | e4b32a5 | 2000-10-31 20:42:18 +0000 | [diff] [blame] | 1408 | |
Tom Kacvinsky | 4082200 | 2000-10-17 20:25:30 +0000 | [diff] [blame] | 1409 | /* 0 333 hsbw endchar */ |
Werner Lemberg | 05f0ad0 | 2000-10-19 05:12:00 +0000 | [diff] [blame] | 1410 | FT_Byte notdef_glyph[] = {0x8B, 0xF7, 0xE1, 0x0D, 0x0E}; |
Werner Lemberg | a13a473 | 2000-11-02 15:14:38 +0000 | [diff] [blame] | 1411 | char* notdef_name = (char *)".notdef"; |
Werner Lemberg | 05f0ad0 | 2000-10-19 05:12:00 +0000 | [diff] [blame] | 1412 | |
Tom Kacvinsky | 4082200 | 2000-10-17 20:25:30 +0000 | [diff] [blame] | 1413 | |
Tom Kacvinsky | cad797e | 2001-04-10 18:15:17 +0000 | [diff] [blame] | 1414 | error = T1_Add_Table( swap_table, 0, |
Tom Kacvinsky | 4082200 | 2000-10-17 20:25:30 +0000 | [diff] [blame] | 1415 | name_table->elements[0], |
| 1416 | name_table->lengths [0] ); |
| 1417 | if ( error ) |
| 1418 | goto Fail; |
| 1419 | |
Tom Kacvinsky | cad797e | 2001-04-10 18:15:17 +0000 | [diff] [blame] | 1420 | error = T1_Add_Table( swap_table, 1, |
Tom Kacvinsky | 4082200 | 2000-10-17 20:25:30 +0000 | [diff] [blame] | 1421 | code_table->elements[0], |
| 1422 | code_table->lengths [0] ); |
| 1423 | if ( error ) |
| 1424 | goto Fail; |
| 1425 | |
Werner Lemberg | b5084e1 | 2000-10-28 17:10:06 +0000 | [diff] [blame] | 1426 | error = T1_Add_Table( name_table, 0, notdef_name, 8 ); |
Tom Kacvinsky | 4082200 | 2000-10-17 20:25:30 +0000 | [diff] [blame] | 1427 | if ( error ) |
| 1428 | goto Fail; |
| 1429 | |
Werner Lemberg | b5084e1 | 2000-10-28 17:10:06 +0000 | [diff] [blame] | 1430 | error = T1_Add_Table( code_table, 0, notdef_glyph, 5 ); |
Tom Kacvinsky | 4082200 | 2000-10-17 20:25:30 +0000 | [diff] [blame] | 1431 | |
| 1432 | if ( error ) |
| 1433 | goto Fail; |
| 1434 | |
Tom Kacvinsky | cad797e | 2001-04-10 18:15:17 +0000 | [diff] [blame] | 1435 | error = T1_Add_Table( name_table, n, |
| 1436 | swap_table->elements[0], |
| 1437 | swap_table->lengths [0] ); |
| 1438 | if ( error ) |
| 1439 | goto Fail; |
| 1440 | |
| 1441 | error = T1_Add_Table( code_table, n, |
| 1442 | swap_table->elements[1], |
| 1443 | swap_table->lengths [1] ); |
| 1444 | if ( error ) |
| 1445 | goto Fail; |
| 1446 | |
Tom Kacvinsky | 4082200 | 2000-10-17 20:25:30 +0000 | [diff] [blame] | 1447 | /* we added a glyph. */ |
| 1448 | loader->num_glyphs = n + 1; |
Tom Kacvinsky | 4082200 | 2000-10-17 20:25:30 +0000 | [diff] [blame] | 1449 | } |
| 1450 | |
David Turner | 2dfb5ac | 2000-01-27 14:02:04 +0000 | [diff] [blame] | 1451 | return; |
David Turner | e49ab25 | 2000-05-16 23:44:38 +0000 | [diff] [blame] | 1452 | |
David Turner | 2dfb5ac | 2000-01-27 14:02:04 +0000 | [diff] [blame] | 1453 | Fail: |
David Turner | a39acf5 | 2000-08-23 02:47:57 +0000 | [diff] [blame] | 1454 | parser->root.error = error; |
David Turner | 2dfb5ac | 2000-01-27 14:02:04 +0000 | [diff] [blame] | 1455 | } |
| 1456 | |
| 1457 | |
David Turner | 2dfb5ac | 2000-01-27 14:02:04 +0000 | [diff] [blame] | 1458 | static |
David Turner | 4e7eeee | 2002-02-28 16:10:29 +0000 | [diff] [blame] | 1459 | const T1_FieldRec t1_keywords[] = |
David Turner | 2dfb5ac | 2000-01-27 14:02:04 +0000 | [diff] [blame] | 1460 | { |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 1461 | |
David Turner | 8d3a401 | 2001-03-20 11:14:24 +0000 | [diff] [blame] | 1462 | #include "t1tokens.h" |
Werner Lemberg | b48a609 | 2000-07-09 19:15:30 +0000 | [diff] [blame] | 1463 | |
David Turner | 2dfb5ac | 2000-01-27 14:02:04 +0000 | [diff] [blame] | 1464 | /* now add the special functions... */ |
David Turner | 34f1c2f | 2000-08-23 22:47:44 +0000 | [diff] [blame] | 1465 | T1_FIELD_CALLBACK( "FontName", parse_font_name ) |
| 1466 | T1_FIELD_CALLBACK( "FontBBox", parse_font_bbox ) |
| 1467 | T1_FIELD_CALLBACK( "FontMatrix", parse_font_matrix ) |
| 1468 | T1_FIELD_CALLBACK( "Encoding", parse_encoding ) |
| 1469 | T1_FIELD_CALLBACK( "Subrs", parse_subrs ) |
| 1470 | T1_FIELD_CALLBACK( "CharStrings", parse_charstrings ) |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 1471 | |
Werner Lemberg | b5084e1 | 2000-10-28 17:10:06 +0000 | [diff] [blame] | 1472 | #ifndef T1_CONFIG_OPTION_NO_MM_SUPPORT |
David Turner | 34f1c2f | 2000-08-23 22:47:44 +0000 | [diff] [blame] | 1473 | T1_FIELD_CALLBACK( "BlendDesignPositions", parse_blend_design_positions ) |
| 1474 | T1_FIELD_CALLBACK( "BlendDesignMap", parse_blend_design_map ) |
| 1475 | T1_FIELD_CALLBACK( "BlendAxisTypes", parse_blend_axis_types ) |
| 1476 | T1_FIELD_CALLBACK( "WeightVector", parse_weight_vector ) |
| 1477 | T1_FIELD_CALLBACK( "shareddict", parse_shared_dict ) |
Werner Lemberg | b48a609 | 2000-07-09 19:15:30 +0000 | [diff] [blame] | 1478 | #endif |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 1479 | |
David Turner | 429978b | 2002-03-14 10:09:35 +0000 | [diff] [blame] | 1480 | { 0, T1_FIELD_LOCATION_CID_INFO, T1_FIELD_TYPE_NONE, 0, 0, 0, 0, 0 } |
David Turner | 2dfb5ac | 2000-01-27 14:02:04 +0000 | [diff] [blame] | 1481 | }; |
| 1482 | |
| 1483 | |
Werner Lemberg | 4a2305c | 2001-06-28 07:17:51 +0000 | [diff] [blame] | 1484 | static FT_Error |
| 1485 | parse_dict( T1_Face face, |
| 1486 | T1_Loader* loader, |
| 1487 | FT_Byte* base, |
| 1488 | FT_Long size ) |
David Turner | 2dfb5ac | 2000-01-27 14:02:04 +0000 | [diff] [blame] | 1489 | { |
David Turner | 4e7eeee | 2002-02-28 16:10:29 +0000 | [diff] [blame] | 1490 | T1_Parser parser = &loader->parser; |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 1491 | |
David Turner | e49ab25 | 2000-05-16 23:44:38 +0000 | [diff] [blame] | 1492 | |
David Turner | a39acf5 | 2000-08-23 02:47:57 +0000 | [diff] [blame] | 1493 | parser->root.cursor = base; |
| 1494 | parser->root.limit = base + size; |
| 1495 | parser->root.error = 0; |
David Turner | e49ab25 | 2000-05-16 23:44:38 +0000 | [diff] [blame] | 1496 | |
David Turner | 2dfb5ac | 2000-01-27 14:02:04 +0000 | [diff] [blame] | 1497 | { |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 1498 | FT_Byte* cur = base; |
| 1499 | FT_Byte* limit = cur + size; |
David Turner | e49ab25 | 2000-05-16 23:44:38 +0000 | [diff] [blame] | 1500 | |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 1501 | |
| 1502 | for ( ; cur < limit; cur++ ) |
David Turner | 2dfb5ac | 2000-01-27 14:02:04 +0000 | [diff] [blame] | 1503 | { |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 1504 | /* look for `FontDirectory', which causes problems on some fonts */ |
| 1505 | if ( *cur == 'F' && cur + 25 < limit && |
David Turner | 1c9a1ca | 2000-05-24 21:12:02 +0000 | [diff] [blame] | 1506 | strncmp( (char*)cur, "FontDirectory", 13 ) == 0 ) |
| 1507 | { |
David Turner | f9b8dec | 2000-06-16 19:34:52 +0000 | [diff] [blame] | 1508 | FT_Byte* cur2; |
Werner Lemberg | b48a609 | 2000-07-09 19:15:30 +0000 | [diff] [blame] | 1509 | |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 1510 | |
| 1511 | /* skip the `FontDirectory' keyword */ |
David Turner | 1c9a1ca | 2000-05-24 21:12:02 +0000 | [diff] [blame] | 1512 | cur += 13; |
| 1513 | cur2 = cur; |
Werner Lemberg | b48a609 | 2000-07-09 19:15:30 +0000 | [diff] [blame] | 1514 | |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 1515 | /* lookup the `known' keyword */ |
| 1516 | while ( cur < limit && *cur != 'k' && |
| 1517 | strncmp( (char*)cur, "known", 5 ) ) |
David Turner | 1c9a1ca | 2000-05-24 21:12:02 +0000 | [diff] [blame] | 1518 | cur++; |
Werner Lemberg | b48a609 | 2000-07-09 19:15:30 +0000 | [diff] [blame] | 1519 | |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 1520 | if ( cur < limit ) |
David Turner | 1c9a1ca | 2000-05-24 21:12:02 +0000 | [diff] [blame] | 1521 | { |
David Turner | 4e7eeee | 2002-02-28 16:10:29 +0000 | [diff] [blame] | 1522 | T1_TokenRec token; |
Werner Lemberg | b48a609 | 2000-07-09 19:15:30 +0000 | [diff] [blame] | 1523 | |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 1524 | |
| 1525 | /* skip the `known' keyword and the token following it */ |
David Turner | 1c9a1ca | 2000-05-24 21:12:02 +0000 | [diff] [blame] | 1526 | cur += 5; |
David Turner | a39acf5 | 2000-08-23 02:47:57 +0000 | [diff] [blame] | 1527 | loader->parser.root.cursor = cur; |
Werner Lemberg | b5084e1 | 2000-10-28 17:10:06 +0000 | [diff] [blame] | 1528 | T1_ToToken( &loader->parser, &token ); |
Werner Lemberg | b48a609 | 2000-07-09 19:15:30 +0000 | [diff] [blame] | 1529 | |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 1530 | /* if the last token was an array, skip it! */ |
David Turner | 4e7eeee | 2002-02-28 16:10:29 +0000 | [diff] [blame] | 1531 | if ( token.type == T1_TOKEN_TYPE_ARRAY ) |
David Turner | a39acf5 | 2000-08-23 02:47:57 +0000 | [diff] [blame] | 1532 | cur2 = parser->root.cursor; |
David Turner | 1c9a1ca | 2000-05-24 21:12:02 +0000 | [diff] [blame] | 1533 | } |
| 1534 | cur = cur2; |
| 1535 | } |
David Turner | 2dfb5ac | 2000-01-27 14:02:04 +0000 | [diff] [blame] | 1536 | /* look for immediates */ |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 1537 | else if ( *cur == '/' && cur + 2 < limit ) |
David Turner | 2dfb5ac | 2000-01-27 14:02:04 +0000 | [diff] [blame] | 1538 | { |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 1539 | FT_Byte* cur2; |
| 1540 | FT_Int len; |
David Turner | e49ab25 | 2000-05-16 23:44:38 +0000 | [diff] [blame] | 1541 | |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 1542 | |
| 1543 | cur++; |
David Turner | 2dfb5ac | 2000-01-27 14:02:04 +0000 | [diff] [blame] | 1544 | cur2 = cur; |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 1545 | while ( cur2 < limit && is_alpha( *cur2 ) ) |
| 1546 | cur2++; |
David Turner | e49ab25 | 2000-05-16 23:44:38 +0000 | [diff] [blame] | 1547 | |
Werner Lemberg | 914b289 | 2001-03-10 17:07:42 +0000 | [diff] [blame] | 1548 | len = (FT_Int)( cur2 - cur ); |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 1549 | if ( len > 0 && len < 22 ) |
David Turner | 2dfb5ac | 2000-01-27 14:02:04 +0000 | [diff] [blame] | 1550 | { |
David Turner | 1c9a1ca | 2000-05-24 21:12:02 +0000 | [diff] [blame] | 1551 | { |
| 1552 | /* now, compare the immediate name to the keyword table */ |
David Turner | 4e7eeee | 2002-02-28 16:10:29 +0000 | [diff] [blame] | 1553 | T1_Field keyword = (T1_Field)t1_keywords; |
Werner Lemberg | b48a609 | 2000-07-09 19:15:30 +0000 | [diff] [blame] | 1554 | |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 1555 | |
David Turner | 1c9a1ca | 2000-05-24 21:12:02 +0000 | [diff] [blame] | 1556 | for (;;) |
David Turner | 2dfb5ac | 2000-01-27 14:02:04 +0000 | [diff] [blame] | 1557 | { |
David Turner | f9b8dec | 2000-06-16 19:34:52 +0000 | [diff] [blame] | 1558 | FT_Byte* name; |
Werner Lemberg | b48a609 | 2000-07-09 19:15:30 +0000 | [diff] [blame] | 1559 | |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 1560 | |
David Turner | 34f1c2f | 2000-08-23 22:47:44 +0000 | [diff] [blame] | 1561 | name = (FT_Byte*)keyword->ident; |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 1562 | if ( !name ) |
| 1563 | break; |
Werner Lemberg | b48a609 | 2000-07-09 19:15:30 +0000 | [diff] [blame] | 1564 | |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 1565 | if ( cur[0] == name[0] && |
| 1566 | len == (FT_Int)strlen( (const char*)name ) ) |
David Turner | 2dfb5ac | 2000-01-27 14:02:04 +0000 | [diff] [blame] | 1567 | { |
David Turner | f9b8dec | 2000-06-16 19:34:52 +0000 | [diff] [blame] | 1568 | FT_Int n; |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 1569 | |
| 1570 | |
David Turner | 1c9a1ca | 2000-05-24 21:12:02 +0000 | [diff] [blame] | 1571 | for ( n = 1; n < len; n++ ) |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 1572 | if ( cur[n] != name[n] ) |
David Turner | 1c9a1ca | 2000-05-24 21:12:02 +0000 | [diff] [blame] | 1573 | break; |
Werner Lemberg | b48a609 | 2000-07-09 19:15:30 +0000 | [diff] [blame] | 1574 | |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 1575 | if ( n >= len ) |
David Turner | 1c9a1ca | 2000-05-24 21:12:02 +0000 | [diff] [blame] | 1576 | { |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 1577 | /* we found it -- run the parsing callback! */ |
David Turner | a39acf5 | 2000-08-23 02:47:57 +0000 | [diff] [blame] | 1578 | parser->root.cursor = cur2; |
Werner Lemberg | b5084e1 | 2000-10-28 17:10:06 +0000 | [diff] [blame] | 1579 | T1_Skip_Spaces( parser ); |
Werner Lemberg | 8728f29 | 2000-08-23 17:32:42 +0000 | [diff] [blame] | 1580 | parser->root.error = t1_load_keyword( face, |
| 1581 | loader, |
| 1582 | keyword ); |
David Turner | a39acf5 | 2000-08-23 02:47:57 +0000 | [diff] [blame] | 1583 | if ( parser->root.error ) |
| 1584 | return parser->root.error; |
Werner Lemberg | b48a609 | 2000-07-09 19:15:30 +0000 | [diff] [blame] | 1585 | |
David Turner | a39acf5 | 2000-08-23 02:47:57 +0000 | [diff] [blame] | 1586 | cur = parser->root.cursor; |
David Turner | 1c9a1ca | 2000-05-24 21:12:02 +0000 | [diff] [blame] | 1587 | break; |
| 1588 | } |
David Turner | 2dfb5ac | 2000-01-27 14:02:04 +0000 | [diff] [blame] | 1589 | } |
David Turner | 1c9a1ca | 2000-05-24 21:12:02 +0000 | [diff] [blame] | 1590 | keyword++; |
David Turner | 2dfb5ac | 2000-01-27 14:02:04 +0000 | [diff] [blame] | 1591 | } |
David Turner | 2dfb5ac | 2000-01-27 14:02:04 +0000 | [diff] [blame] | 1592 | } |
| 1593 | } |
| 1594 | } |
| 1595 | } |
| 1596 | } |
David Turner | a39acf5 | 2000-08-23 02:47:57 +0000 | [diff] [blame] | 1597 | return parser->root.error; |
David Turner | 2dfb5ac | 2000-01-27 14:02:04 +0000 | [diff] [blame] | 1598 | } |
| 1599 | |
David Turner | e49ab25 | 2000-05-16 23:44:38 +0000 | [diff] [blame] | 1600 | |
Werner Lemberg | 4a2305c | 2001-06-28 07:17:51 +0000 | [diff] [blame] | 1601 | static void |
| 1602 | t1_init_loader( T1_Loader* loader, |
| 1603 | T1_Face face ) |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 1604 | { |
| 1605 | FT_UNUSED( face ); |
| 1606 | |
David Turner | e459d74 | 2002-03-22 13:52:37 +0000 | [diff] [blame^] | 1607 | FT_MEM_SET( loader, 0, sizeof ( *loader ) ); |
David Turner | 2dfb5ac | 2000-01-27 14:02:04 +0000 | [diff] [blame] | 1608 | loader->num_glyphs = 0; |
| 1609 | loader->num_chars = 0; |
David Turner | 95bec28 | 2000-02-15 12:55:57 +0000 | [diff] [blame] | 1610 | |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 1611 | /* initialize the tables -- simply set their `init' field to 0 */ |
David Turner | 2dfb5ac | 2000-01-27 14:02:04 +0000 | [diff] [blame] | 1612 | loader->encoding_table.init = 0; |
| 1613 | loader->charstrings.init = 0; |
| 1614 | loader->glyph_names.init = 0; |
| 1615 | loader->subrs.init = 0; |
Tom Kacvinsky | cad797e | 2001-04-10 18:15:17 +0000 | [diff] [blame] | 1616 | loader->swap_table.init = 0; |
David Turner | 1c9a1ca | 2000-05-24 21:12:02 +0000 | [diff] [blame] | 1617 | loader->fontdata = 0; |
David Turner | 2dfb5ac | 2000-01-27 14:02:04 +0000 | [diff] [blame] | 1618 | } |
David Turner | e49ab25 | 2000-05-16 23:44:38 +0000 | [diff] [blame] | 1619 | |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 1620 | |
Werner Lemberg | 4a2305c | 2001-06-28 07:17:51 +0000 | [diff] [blame] | 1621 | static void |
| 1622 | t1_done_loader( T1_Loader* loader ) |
David Turner | 2dfb5ac | 2000-01-27 14:02:04 +0000 | [diff] [blame] | 1623 | { |
David Turner | 4e7eeee | 2002-02-28 16:10:29 +0000 | [diff] [blame] | 1624 | T1_Parser parser = &loader->parser; |
David Turner | e49ab25 | 2000-05-16 23:44:38 +0000 | [diff] [blame] | 1625 | |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 1626 | |
David Turner | 2dfb5ac | 2000-01-27 14:02:04 +0000 | [diff] [blame] | 1627 | /* finalize tables */ |
Werner Lemberg | b5084e1 | 2000-10-28 17:10:06 +0000 | [diff] [blame] | 1628 | T1_Release_Table( &loader->encoding_table ); |
| 1629 | T1_Release_Table( &loader->charstrings ); |
| 1630 | T1_Release_Table( &loader->glyph_names ); |
Tom Kacvinsky | cad797e | 2001-04-10 18:15:17 +0000 | [diff] [blame] | 1631 | T1_Release_Table( &loader->swap_table ); |
Werner Lemberg | b5084e1 | 2000-10-28 17:10:06 +0000 | [diff] [blame] | 1632 | T1_Release_Table( &loader->subrs ); |
David Turner | e49ab25 | 2000-05-16 23:44:38 +0000 | [diff] [blame] | 1633 | |
David Turner | 2dfb5ac | 2000-01-27 14:02:04 +0000 | [diff] [blame] | 1634 | /* finalize parser */ |
Werner Lemberg | 27695e5 | 2000-11-23 08:21:13 +0000 | [diff] [blame] | 1635 | T1_Finalize_Parser( parser ); |
David Turner | 2dfb5ac | 2000-01-27 14:02:04 +0000 | [diff] [blame] | 1636 | } |
| 1637 | |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 1638 | |
David Turner | bc82f1b | 2002-03-01 02:26:22 +0000 | [diff] [blame] | 1639 | FT_LOCAL_DEF( FT_Error ) |
Werner Lemberg | 4a2305c | 2001-06-28 07:17:51 +0000 | [diff] [blame] | 1640 | T1_Open_Face( T1_Face face ) |
David Turner | 2dfb5ac | 2000-01-27 14:02:04 +0000 | [diff] [blame] | 1641 | { |
David Turner | 4e7eeee | 2002-02-28 16:10:29 +0000 | [diff] [blame] | 1642 | T1_Loader loader; |
| 1643 | T1_Parser parser; |
David Turner | 2964417 | 2002-02-28 18:59:37 +0000 | [diff] [blame] | 1644 | T1_Font type1 = &face->type1; |
David Turner | 4e7eeee | 2002-02-28 16:10:29 +0000 | [diff] [blame] | 1645 | FT_Error error; |
Werner Lemberg | e4b32a5 | 2000-10-31 20:42:18 +0000 | [diff] [blame] | 1646 | |
David Turner | 4e7eeee | 2002-02-28 16:10:29 +0000 | [diff] [blame] | 1647 | PSAux_Service psaux = (PSAux_Service)face->psaux; |
David Turner | 2dfb5ac | 2000-01-27 14:02:04 +0000 | [diff] [blame] | 1648 | |
Werner Lemberg | 8728f29 | 2000-08-23 17:32:42 +0000 | [diff] [blame] | 1649 | |
David Turner | 2dfb5ac | 2000-01-27 14:02:04 +0000 | [diff] [blame] | 1650 | t1_init_loader( &loader, face ); |
| 1651 | |
| 1652 | /* default lenIV */ |
David Turner | 9a9315f | 2000-05-02 10:59:01 +0000 | [diff] [blame] | 1653 | type1->private_dict.lenIV = 4; |
David Turner | e49ab25 | 2000-05-16 23:44:38 +0000 | [diff] [blame] | 1654 | |
David Turner | 2dfb5ac | 2000-01-27 14:02:04 +0000 | [diff] [blame] | 1655 | parser = &loader.parser; |
Werner Lemberg | b5084e1 | 2000-10-28 17:10:06 +0000 | [diff] [blame] | 1656 | error = T1_New_Parser( parser, |
Werner Lemberg | 8728f29 | 2000-08-23 17:32:42 +0000 | [diff] [blame] | 1657 | face->root.stream, |
| 1658 | face->root.memory, |
| 1659 | psaux ); |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 1660 | if ( error ) |
| 1661 | goto Exit; |
David Turner | 2dfb5ac | 2000-01-27 14:02:04 +0000 | [diff] [blame] | 1662 | |
| 1663 | error = parse_dict( face, &loader, parser->base_dict, parser->base_len ); |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 1664 | if ( error ) |
| 1665 | goto Exit; |
David Turner | e49ab25 | 2000-05-16 23:44:38 +0000 | [diff] [blame] | 1666 | |
Werner Lemberg | 27695e5 | 2000-11-23 08:21:13 +0000 | [diff] [blame] | 1667 | error = T1_Get_Private_Dict( parser, psaux ); |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 1668 | if ( error ) |
| 1669 | goto Exit; |
David Turner | e49ab25 | 2000-05-16 23:44:38 +0000 | [diff] [blame] | 1670 | |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 1671 | error = parse_dict( face, &loader, parser->private_dict, |
| 1672 | parser->private_len ); |
| 1673 | if ( error ) |
| 1674 | goto Exit; |
David Turner | 2dfb5ac | 2000-01-27 14:02:04 +0000 | [diff] [blame] | 1675 | |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 1676 | /* now, propagate the subrs, charstrings, and glyphnames tables */ |
| 1677 | /* to the Type1 data */ |
David Turner | 2dfb5ac | 2000-01-27 14:02:04 +0000 | [diff] [blame] | 1678 | type1->num_glyphs = loader.num_glyphs; |
David Turner | e49ab25 | 2000-05-16 23:44:38 +0000 | [diff] [blame] | 1679 | |
Tom Kacvinsky | b2d5fef | 2001-01-24 22:41:20 +0000 | [diff] [blame] | 1680 | if ( loader.subrs.init ) |
David Turner | 95bec28 | 2000-02-15 12:55:57 +0000 | [diff] [blame] | 1681 | { |
Tom Kacvinsky | b2d5fef | 2001-01-24 22:41:20 +0000 | [diff] [blame] | 1682 | loader.subrs.init = 0; |
| 1683 | type1->num_subrs = loader.num_subrs; |
| 1684 | type1->subrs_block = loader.subrs.block; |
| 1685 | type1->subrs = loader.subrs.elements; |
| 1686 | type1->subrs_len = loader.subrs.lengths; |
David Turner | 95bec28 | 2000-02-15 12:55:57 +0000 | [diff] [blame] | 1687 | } |
David Turner | e49ab25 | 2000-05-16 23:44:38 +0000 | [diff] [blame] | 1688 | |
David Turner | 95bec28 | 2000-02-15 12:55:57 +0000 | [diff] [blame] | 1689 | if ( !loader.charstrings.init ) |
| 1690 | { |
Werner Lemberg | b5084e1 | 2000-10-28 17:10:06 +0000 | [diff] [blame] | 1691 | FT_ERROR(( "T1_Open_Face: no charstrings array in face!\n" )); |
Werner Lemberg | e35cac6 | 2000-06-11 03:46:57 +0000 | [diff] [blame] | 1692 | error = T1_Err_Invalid_File_Format; |
David Turner | 95bec28 | 2000-02-15 12:55:57 +0000 | [diff] [blame] | 1693 | } |
David Turner | e49ab25 | 2000-05-16 23:44:38 +0000 | [diff] [blame] | 1694 | |
David Turner | 2dfb5ac | 2000-01-27 14:02:04 +0000 | [diff] [blame] | 1695 | loader.charstrings.init = 0; |
| 1696 | type1->charstrings_block = loader.charstrings.block; |
| 1697 | type1->charstrings = loader.charstrings.elements; |
| 1698 | type1->charstrings_len = loader.charstrings.lengths; |
David Turner | e49ab25 | 2000-05-16 23:44:38 +0000 | [diff] [blame] | 1699 | |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 1700 | /* we copy the glyph names `block' and `elements' fields; */ |
| 1701 | /* the `lengths' field must be released later */ |
David Turner | 2dfb5ac | 2000-01-27 14:02:04 +0000 | [diff] [blame] | 1702 | type1->glyph_names_block = loader.glyph_names.block; |
David Turner | f9b8dec | 2000-06-16 19:34:52 +0000 | [diff] [blame] | 1703 | type1->glyph_names = (FT_String**)loader.glyph_names.elements; |
David Turner | 2dfb5ac | 2000-01-27 14:02:04 +0000 | [diff] [blame] | 1704 | loader.glyph_names.block = 0; |
| 1705 | loader.glyph_names.elements = 0; |
| 1706 | |
| 1707 | /* we must now build type1.encoding when we have a custom */ |
| 1708 | /* array.. */ |
David Turner | 2964417 | 2002-02-28 18:59:37 +0000 | [diff] [blame] | 1709 | if ( type1->encoding_type == T1_ENCODING_TYPE_ARRAY ) |
David Turner | 2dfb5ac | 2000-01-27 14:02:04 +0000 | [diff] [blame] | 1710 | { |
Werner Lemberg | 0d9165e | 2002-03-07 21:59:59 +0000 | [diff] [blame] | 1711 | FT_Int charcode, idx, min_char, max_char; |
David Turner | f9b8dec | 2000-06-16 19:34:52 +0000 | [diff] [blame] | 1712 | FT_Byte* char_name; |
| 1713 | FT_Byte* glyph_name; |
David Turner | 2dfb5ac | 2000-01-27 14:02:04 +0000 | [diff] [blame] | 1714 | |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 1715 | |
| 1716 | /* OK, we do the following: for each element in the encoding */ |
| 1717 | /* table, look up the index of the glyph having the same name */ |
David Turner | 2dfb5ac | 2000-01-27 14:02:04 +0000 | [diff] [blame] | 1718 | /* the index is then stored in type1.encoding.char_index, and */ |
| 1719 | /* a the name to type1.encoding.char_name */ |
David Turner | e49ab25 | 2000-05-16 23:44:38 +0000 | [diff] [blame] | 1720 | |
David Turner | 2dfb5ac | 2000-01-27 14:02:04 +0000 | [diff] [blame] | 1721 | min_char = +32000; |
| 1722 | max_char = -32000; |
David Turner | e49ab25 | 2000-05-16 23:44:38 +0000 | [diff] [blame] | 1723 | |
David Turner | 2dfb5ac | 2000-01-27 14:02:04 +0000 | [diff] [blame] | 1724 | charcode = 0; |
Tom Kacvinsky | 95ac657 | 2000-10-15 08:53:27 +0000 | [diff] [blame] | 1725 | for ( ; charcode < loader.encoding_table.max_elems; charcode++ ) |
David Turner | 2dfb5ac | 2000-01-27 14:02:04 +0000 | [diff] [blame] | 1726 | { |
| 1727 | type1->encoding.char_index[charcode] = 0; |
Werner Lemberg | b1dd353 | 2000-07-31 22:51:00 +0000 | [diff] [blame] | 1728 | type1->encoding.char_name [charcode] = (char *)".notdef"; |
David Turner | e49ab25 | 2000-05-16 23:44:38 +0000 | [diff] [blame] | 1729 | |
David Turner | 2dfb5ac | 2000-01-27 14:02:04 +0000 | [diff] [blame] | 1730 | char_name = loader.encoding_table.elements[charcode]; |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 1731 | if ( char_name ) |
Werner Lemberg | 0d9165e | 2002-03-07 21:59:59 +0000 | [diff] [blame] | 1732 | for ( idx = 0; idx < type1->num_glyphs; idx++ ) |
David Turner | 2dfb5ac | 2000-01-27 14:02:04 +0000 | [diff] [blame] | 1733 | { |
Werner Lemberg | 0d9165e | 2002-03-07 21:59:59 +0000 | [diff] [blame] | 1734 | glyph_name = (FT_Byte*)type1->glyph_names[idx]; |
David Turner | 0dd3434 | 2000-02-02 12:20:53 +0000 | [diff] [blame] | 1735 | if ( strcmp( (const char*)char_name, |
| 1736 | (const char*)glyph_name ) == 0 ) |
David Turner | 2dfb5ac | 2000-01-27 14:02:04 +0000 | [diff] [blame] | 1737 | { |
Werner Lemberg | 0d9165e | 2002-03-07 21:59:59 +0000 | [diff] [blame] | 1738 | type1->encoding.char_index[charcode] = (FT_UShort)idx; |
David Turner | 0dd3434 | 2000-02-02 12:20:53 +0000 | [diff] [blame] | 1739 | type1->encoding.char_name [charcode] = (char*)glyph_name; |
David Turner | e49ab25 | 2000-05-16 23:44:38 +0000 | [diff] [blame] | 1740 | |
Werner Lemberg | 05f0ad0 | 2000-10-19 05:12:00 +0000 | [diff] [blame] | 1741 | /* Change min/max encoded char only if glyph name is */ |
| 1742 | /* not /.notdef */ |
| 1743 | if ( strcmp( (const char*)".notdef", |
| 1744 | (const char*)glyph_name ) != 0 ) |
| 1745 | { |
| 1746 | if (charcode < min_char) min_char = charcode; |
| 1747 | if (charcode > max_char) max_char = charcode; |
| 1748 | } |
David Turner | 2dfb5ac | 2000-01-27 14:02:04 +0000 | [diff] [blame] | 1749 | break; |
| 1750 | } |
| 1751 | } |
| 1752 | } |
| 1753 | type1->encoding.code_first = min_char; |
| 1754 | type1->encoding.code_last = max_char; |
| 1755 | type1->encoding.num_chars = loader.num_chars; |
Werner Lemberg | 556ad08 | 2002-01-28 13:34:52 +0000 | [diff] [blame] | 1756 | } |
David Turner | e49ab25 | 2000-05-16 23:44:38 +0000 | [diff] [blame] | 1757 | |
David Turner | 2dfb5ac | 2000-01-27 14:02:04 +0000 | [diff] [blame] | 1758 | Exit: |
| 1759 | t1_done_loader( &loader ); |
| 1760 | return error; |
David Turner | e49ab25 | 2000-05-16 23:44:38 +0000 | [diff] [blame] | 1761 | } |
Werner Lemberg | 681e8ee | 2000-07-09 00:48:37 +0000 | [diff] [blame] | 1762 | |
| 1763 | |
| 1764 | /* END */ |