Werner Lemberg | 8728f29 | 2000-08-23 17:32:42 +0000 | [diff] [blame] | 1 | /***************************************************************************/ |
| 2 | /* */ |
| 3 | /* t1decode.c */ |
| 4 | /* */ |
| 5 | /* PostScript Type 1 decoding routines (body). */ |
| 6 | /* */ |
Werner Lemberg | 415235d | 2001-06-28 17:49:10 +0000 | [diff] [blame] | 7 | /* Copyright 2000-2001 by */ |
Werner Lemberg | 8728f29 | 2000-08-23 17:32:42 +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 | |
Werner Lemberg | cc069be | 2000-12-08 16:17:16 +0000 | [diff] [blame] | 18 | |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 19 | #include <ft2build.h> |
| 20 | #include FT_INTERNAL_DEBUG_H |
David Turner | 5893c1b | 2001-10-18 11:49:26 +0000 | [diff] [blame] | 21 | #include FT_INTERNAL_POSTSCRIPT_HINTS_H |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 22 | #include FT_OUTLINE_H |
Werner Lemberg | 1f7f0e8 | 2001-06-06 17:30:41 +0000 | [diff] [blame] | 23 | |
David Turner | 8d3a401 | 2001-03-20 11:14:24 +0000 | [diff] [blame] | 24 | #include "t1decode.h" |
| 25 | #include "psobjs.h" |
Werner Lemberg | 8925009 | 2000-09-26 13:25:15 +0000 | [diff] [blame] | 26 | |
Werner Lemberg | 1f7f0e8 | 2001-06-06 17:30:41 +0000 | [diff] [blame] | 27 | #include "psauxerr.h" |
| 28 | |
Werner Lemberg | cc069be | 2000-12-08 16:17:16 +0000 | [diff] [blame] | 29 | |
David Turner | 9748807 | 2000-08-22 22:36:33 +0000 | [diff] [blame] | 30 | /*************************************************************************/ |
| 31 | /* */ |
| 32 | /* The macro FT_COMPONENT is used in trace mode. It is an implicit */ |
| 33 | /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */ |
| 34 | /* messages during execution. */ |
| 35 | /* */ |
| 36 | #undef FT_COMPONENT |
| 37 | #define FT_COMPONENT trace_t1decode |
| 38 | |
| 39 | |
| 40 | typedef enum T1_Operator_ |
| 41 | { |
| 42 | op_none = 0, |
| 43 | op_endchar, |
| 44 | op_hsbw, |
| 45 | op_seac, |
| 46 | op_sbw, |
| 47 | op_closepath, |
| 48 | op_hlineto, |
| 49 | op_hmoveto, |
| 50 | op_hvcurveto, |
| 51 | op_rlineto, |
| 52 | op_rmoveto, |
| 53 | op_rrcurveto, |
| 54 | op_vhcurveto, |
| 55 | op_vlineto, |
| 56 | op_vmoveto, |
| 57 | op_dotsection, |
| 58 | op_hstem, |
| 59 | op_hstem3, |
| 60 | op_vstem, |
| 61 | op_vstem3, |
| 62 | op_div, |
| 63 | op_callothersubr, |
| 64 | op_callsubr, |
| 65 | op_pop, |
| 66 | op_return, |
| 67 | op_setcurrentpoint, |
| 68 | |
| 69 | op_max /* never remove this one */ |
| 70 | |
| 71 | } T1_Operator; |
| 72 | |
| 73 | static |
| 74 | const FT_Int t1_args_count[op_max] = |
| 75 | { |
| 76 | 0, /* none */ |
| 77 | 0, /* endchar */ |
| 78 | 2, /* hsbw */ |
| 79 | 5, /* seac */ |
| 80 | 4, /* sbw */ |
| 81 | 0, /* closepath */ |
| 82 | 1, /* hlineto */ |
| 83 | 1, /* hmoveto */ |
| 84 | 4, /* hvcurveto */ |
| 85 | 2, /* rlineto */ |
| 86 | 2, /* rmoveto */ |
| 87 | 6, /* rrcurveto */ |
| 88 | 4, /* vhcurveto */ |
| 89 | 1, /* vlineto */ |
| 90 | 1, /* vmoveto */ |
| 91 | 0, /* dotsection */ |
| 92 | 2, /* hstem */ |
| 93 | 6, /* hstem3 */ |
| 94 | 2, /* vstem */ |
| 95 | 6, /* vstem3 */ |
| 96 | 2, /* div */ |
| 97 | -1, /* callothersubr */ |
| 98 | 1, /* callsubr */ |
| 99 | 0, /* pop */ |
| 100 | 0, /* return */ |
| 101 | 2 /* setcurrentpoint */ |
| 102 | }; |
| 103 | |
| 104 | |
| 105 | /*************************************************************************/ |
| 106 | /* */ |
| 107 | /* <Function> */ |
Werner Lemberg | 8728f29 | 2000-08-23 17:32:42 +0000 | [diff] [blame] | 108 | /* t1_lookup_glyph_by_stdcharcode */ |
David Turner | 9748807 | 2000-08-22 22:36:33 +0000 | [diff] [blame] | 109 | /* */ |
| 110 | /* <Description> */ |
Werner Lemberg | 8728f29 | 2000-08-23 17:32:42 +0000 | [diff] [blame] | 111 | /* Looks up a given glyph by its StandardEncoding charcode. Used to */ |
| 112 | /* implement the SEAC Type 1 operator. */ |
David Turner | 9748807 | 2000-08-22 22:36:33 +0000 | [diff] [blame] | 113 | /* */ |
| 114 | /* <Input> */ |
| 115 | /* face :: The current face object. */ |
| 116 | /* */ |
| 117 | /* charcode :: The character code to look for. */ |
| 118 | /* */ |
| 119 | /* <Return> */ |
| 120 | /* A glyph index in the font face. Returns -1 if the corresponding */ |
| 121 | /* glyph wasn't found. */ |
| 122 | /* */ |
Werner Lemberg | 93616ec | 2001-06-27 19:46:12 +0000 | [diff] [blame] | 123 | static FT_Int |
David Turner | 4e7eeee | 2002-02-28 16:10:29 +0000 | [diff] [blame] | 124 | t1_lookup_glyph_by_stdcharcode( T1_Decoder decoder, |
Werner Lemberg | 93616ec | 2001-06-27 19:46:12 +0000 | [diff] [blame] | 125 | FT_Int charcode ) |
David Turner | 9748807 | 2000-08-22 22:36:33 +0000 | [diff] [blame] | 126 | { |
| 127 | FT_UInt n; |
| 128 | const FT_String* glyph_name; |
David Turner | 4e7eeee | 2002-02-28 16:10:29 +0000 | [diff] [blame] | 129 | PSNames_Service psnames = decoder->psnames; |
David Turner | 9748807 | 2000-08-22 22:36:33 +0000 | [diff] [blame] | 130 | |
| 131 | |
| 132 | /* check range of standard char code */ |
| 133 | if ( charcode < 0 || charcode > 255 ) |
| 134 | return -1; |
| 135 | |
| 136 | glyph_name = psnames->adobe_std_strings( |
| 137 | psnames->adobe_std_encoding[charcode]); |
| 138 | |
| 139 | for ( n = 0; n < decoder->num_glyphs; n++ ) |
| 140 | { |
| 141 | FT_String* name = (FT_String*)decoder->glyph_names[n]; |
| 142 | |
| 143 | |
Werner Lemberg | c3b2160 | 2001-12-05 01:22:05 +0000 | [diff] [blame] | 144 | if ( name && name[0] == glyph_name[0] && |
| 145 | strcmp( name,glyph_name ) == 0 ) |
David Turner | 9748807 | 2000-08-22 22:36:33 +0000 | [diff] [blame] | 146 | return n; |
| 147 | } |
| 148 | |
| 149 | return -1; |
| 150 | } |
| 151 | |
| 152 | |
| 153 | /*************************************************************************/ |
| 154 | /* */ |
| 155 | /* <Function> */ |
| 156 | /* t1operator_seac */ |
| 157 | /* */ |
| 158 | /* <Description> */ |
| 159 | /* Implements the `seac' Type 1 operator for a Type 1 decoder. */ |
| 160 | /* */ |
| 161 | /* <Input> */ |
| 162 | /* decoder :: The current CID decoder. */ |
| 163 | /* */ |
| 164 | /* asb :: The accent's side bearing. */ |
| 165 | /* */ |
| 166 | /* adx :: The horizontal offset of the accent. */ |
| 167 | /* */ |
| 168 | /* ady :: The vertical offset of the accent. */ |
| 169 | /* */ |
| 170 | /* bchar :: The base character's StandardEncoding charcode. */ |
| 171 | /* */ |
| 172 | /* achar :: The accent character's StandardEncoding charcode. */ |
| 173 | /* */ |
| 174 | /* <Return> */ |
| 175 | /* FreeType error code. 0 means success. */ |
| 176 | /* */ |
Werner Lemberg | 93616ec | 2001-06-27 19:46:12 +0000 | [diff] [blame] | 177 | static FT_Error |
David Turner | 4e7eeee | 2002-02-28 16:10:29 +0000 | [diff] [blame] | 178 | t1operator_seac( T1_Decoder decoder, |
Werner Lemberg | 93616ec | 2001-06-27 19:46:12 +0000 | [diff] [blame] | 179 | FT_Pos asb, |
| 180 | FT_Pos adx, |
| 181 | FT_Pos ady, |
| 182 | FT_Int bchar, |
| 183 | FT_Int achar ) |
David Turner | 9748807 | 2000-08-22 22:36:33 +0000 | [diff] [blame] | 184 | { |
| 185 | FT_Error error; |
Werner Lemberg | b5349a9 | 2002-02-19 16:30:15 +0000 | [diff] [blame] | 186 | FT_Int bchar_index, achar_index; |
| 187 | #if 0 |
| 188 | FT_Int n_base_points; |
David Turner | 9748807 | 2000-08-22 22:36:33 +0000 | [diff] [blame] | 189 | FT_Outline* base = decoder->builder.base; |
Werner Lemberg | b5349a9 | 2002-02-19 16:30:15 +0000 | [diff] [blame] | 190 | #endif |
David Turner | 9748807 | 2000-08-22 22:36:33 +0000 | [diff] [blame] | 191 | FT_Vector left_bearing, advance; |
| 192 | |
| 193 | |
| 194 | /* seac weirdness */ |
| 195 | adx += decoder->builder.left_bearing.x; |
| 196 | |
Werner Lemberg | d1b7475 | 2000-08-24 16:29:15 +0000 | [diff] [blame] | 197 | /* `glyph_names' is set to 0 for CID fonts which do not */ |
| 198 | /* include an encoding. How can we deal with these? */ |
| 199 | if ( decoder->glyph_names == 0 ) |
David Turner | 34f1c2f | 2000-08-23 22:47:44 +0000 | [diff] [blame] | 200 | { |
| 201 | FT_ERROR(( "t1operator_seac:" )); |
Werner Lemberg | d1b7475 | 2000-08-24 16:29:15 +0000 | [diff] [blame] | 202 | FT_ERROR(( " glyph names table not available in this font!\n" )); |
Werner Lemberg | 1f7f0e8 | 2001-06-06 17:30:41 +0000 | [diff] [blame] | 203 | return PSaux_Err_Syntax_Error; |
David Turner | 34f1c2f | 2000-08-23 22:47:44 +0000 | [diff] [blame] | 204 | } |
Werner Lemberg | e4b32a5 | 2000-10-31 20:42:18 +0000 | [diff] [blame] | 205 | |
David Turner | 9748807 | 2000-08-22 22:36:33 +0000 | [diff] [blame] | 206 | bchar_index = t1_lookup_glyph_by_stdcharcode( decoder, bchar ); |
| 207 | achar_index = t1_lookup_glyph_by_stdcharcode( decoder, achar ); |
| 208 | |
| 209 | if ( bchar_index < 0 || achar_index < 0 ) |
| 210 | { |
| 211 | FT_ERROR(( "t1operator_seac:" )); |
| 212 | FT_ERROR(( " invalid seac character code arguments\n" )); |
Werner Lemberg | 1f7f0e8 | 2001-06-06 17:30:41 +0000 | [diff] [blame] | 213 | return PSaux_Err_Syntax_Error; |
David Turner | 9748807 | 2000-08-22 22:36:33 +0000 | [diff] [blame] | 214 | } |
| 215 | |
| 216 | /* if we are trying to load a composite glyph, do not load the */ |
| 217 | /* accent character and return the array of subglyphs. */ |
| 218 | if ( decoder->builder.no_recurse ) |
| 219 | { |
| 220 | FT_GlyphSlot glyph = (FT_GlyphSlot)decoder->builder.glyph; |
David Turner | 4d57024 | 2002-02-24 02:59:24 +0000 | [diff] [blame] | 221 | FT_GlyphLoader loader = glyph->internal->loader; |
David Turner | eba5ad4 | 2002-03-14 12:56:35 +0000 | [diff] [blame] | 222 | FT_SubGlyph subg; |
David Turner | 9748807 | 2000-08-22 22:36:33 +0000 | [diff] [blame] | 223 | |
| 224 | |
| 225 | /* reallocate subglyph array if necessary */ |
David Turner | eba5ad4 | 2002-03-14 12:56:35 +0000 | [diff] [blame] | 226 | error = FT_GlyphLoader_CheckSubGlyphs( loader, 2 ); |
David Turner | 9748807 | 2000-08-22 22:36:33 +0000 | [diff] [blame] | 227 | if ( error ) |
| 228 | goto Exit; |
| 229 | |
| 230 | subg = loader->current.subglyphs; |
| 231 | |
| 232 | /* subglyph 0 = base character */ |
| 233 | subg->index = bchar_index; |
| 234 | subg->flags = FT_SUBGLYPH_FLAG_ARGS_ARE_XY_VALUES | |
| 235 | FT_SUBGLYPH_FLAG_USE_MY_METRICS; |
| 236 | subg->arg1 = 0; |
| 237 | subg->arg2 = 0; |
| 238 | subg++; |
| 239 | |
| 240 | /* subglyph 1 = accent character */ |
| 241 | subg->index = achar_index; |
| 242 | subg->flags = FT_SUBGLYPH_FLAG_ARGS_ARE_XY_VALUES; |
| 243 | subg->arg1 = adx - asb; |
| 244 | subg->arg2 = ady; |
| 245 | |
| 246 | /* set up remaining glyph fields */ |
| 247 | glyph->num_subglyphs = 2; |
| 248 | glyph->subglyphs = loader->base.subglyphs; |
| 249 | glyph->format = ft_glyph_format_composite; |
| 250 | |
| 251 | loader->current.num_subglyphs = 2; |
David Turner | 5893c1b | 2001-10-18 11:49:26 +0000 | [diff] [blame] | 252 | goto Exit; |
David Turner | 9748807 | 2000-08-22 22:36:33 +0000 | [diff] [blame] | 253 | } |
| 254 | |
| 255 | /* First load `bchar' in builder */ |
| 256 | /* now load the unscaled outline */ |
| 257 | |
| 258 | FT_GlyphLoader_Prepare( decoder->builder.loader ); /* prepare loader */ |
| 259 | |
| 260 | error = T1_Decoder_Parse_Glyph( decoder, bchar_index ); |
| 261 | if ( error ) |
| 262 | goto Exit; |
| 263 | |
Werner Lemberg | b5349a9 | 2002-02-19 16:30:15 +0000 | [diff] [blame] | 264 | #if 0 |
David Turner | 9748807 | 2000-08-22 22:36:33 +0000 | [diff] [blame] | 265 | n_base_points = base->n_points; |
Werner Lemberg | b5349a9 | 2002-02-19 16:30:15 +0000 | [diff] [blame] | 266 | #endif |
David Turner | 9748807 | 2000-08-22 22:36:33 +0000 | [diff] [blame] | 267 | |
| 268 | /* save the left bearing and width of the base character */ |
| 269 | /* as they will be erased by the next load. */ |
| 270 | |
| 271 | left_bearing = decoder->builder.left_bearing; |
| 272 | advance = decoder->builder.advance; |
| 273 | |
| 274 | decoder->builder.left_bearing.x = 0; |
| 275 | decoder->builder.left_bearing.y = 0; |
| 276 | |
David Turner | 5893c1b | 2001-10-18 11:49:26 +0000 | [diff] [blame] | 277 | decoder->builder.pos_x = adx - asb; |
| 278 | decoder->builder.pos_y = ady; |
| 279 | |
David Turner | 9748807 | 2000-08-22 22:36:33 +0000 | [diff] [blame] | 280 | /* Now load `achar' on top of */ |
| 281 | /* the base outline */ |
| 282 | error = T1_Decoder_Parse_Glyph( decoder, achar_index ); |
| 283 | if ( error ) |
| 284 | goto Exit; |
| 285 | |
| 286 | /* restore the left side bearing and */ |
| 287 | /* advance width of the base character */ |
| 288 | |
| 289 | decoder->builder.left_bearing = left_bearing; |
| 290 | decoder->builder.advance = advance; |
| 291 | |
David Turner | 5893c1b | 2001-10-18 11:49:26 +0000 | [diff] [blame] | 292 | /* XXX: old code doesn't work with postscript hinter */ |
David Turner | 4d57024 | 2002-02-24 02:59:24 +0000 | [diff] [blame] | 293 | #if 0 |
David Turner | 9748807 | 2000-08-22 22:36:33 +0000 | [diff] [blame] | 294 | /* Finally, move the accent */ |
| 295 | if ( decoder->builder.load_points ) |
| 296 | { |
| 297 | FT_Outline dummy; |
| 298 | |
Werner Lemberg | c3b2160 | 2001-12-05 01:22:05 +0000 | [diff] [blame] | 299 | |
Werner Lemberg | 8eb0353 | 2001-06-19 23:03:41 +0000 | [diff] [blame] | 300 | dummy.n_points = (short)( base->n_points - n_base_points ); |
| 301 | dummy.points = base->points + n_base_points; |
Werner Lemberg | 8728f29 | 2000-08-23 17:32:42 +0000 | [diff] [blame] | 302 | |
David Turner | 9748807 | 2000-08-22 22:36:33 +0000 | [diff] [blame] | 303 | FT_Outline_Translate( &dummy, adx - asb, ady ); |
| 304 | } |
David Turner | 4d57024 | 2002-02-24 02:59:24 +0000 | [diff] [blame] | 305 | #else |
David Turner | 5893c1b | 2001-10-18 11:49:26 +0000 | [diff] [blame] | 306 | decoder->builder.pos_x = 0; |
| 307 | decoder->builder.pos_y = 0; |
| 308 | #endif |
David Turner | 9748807 | 2000-08-22 22:36:33 +0000 | [diff] [blame] | 309 | |
| 310 | Exit: |
| 311 | return error; |
| 312 | } |
| 313 | |
| 314 | |
David Turner | 9748807 | 2000-08-22 22:36:33 +0000 | [diff] [blame] | 315 | /*************************************************************************/ |
| 316 | /* */ |
| 317 | /* <Function> */ |
| 318 | /* T1_Decoder_Parse_Charstrings */ |
| 319 | /* */ |
| 320 | /* <Description> */ |
| 321 | /* Parses a given Type 1 charstrings program. */ |
| 322 | /* */ |
| 323 | /* <Input> */ |
| 324 | /* decoder :: The current Type 1 decoder. */ |
| 325 | /* */ |
| 326 | /* charstring_base :: The base address of the charstring stream. */ |
| 327 | /* */ |
| 328 | /* charstring_len :: The length in bytes of the charstring stream. */ |
| 329 | /* */ |
| 330 | /* <Return> */ |
Werner Lemberg | 8728f29 | 2000-08-23 17:32:42 +0000 | [diff] [blame] | 331 | /* FreeType error code. 0 means success. */ |
David Turner | 9748807 | 2000-08-22 22:36:33 +0000 | [diff] [blame] | 332 | /* */ |
David Turner | bc82f1b | 2002-03-01 02:26:22 +0000 | [diff] [blame] | 333 | FT_LOCAL_DEF( FT_Error ) |
David Turner | 4e7eeee | 2002-02-28 16:10:29 +0000 | [diff] [blame] | 334 | T1_Decoder_Parse_Charstrings( T1_Decoder decoder, |
Werner Lemberg | 93616ec | 2001-06-27 19:46:12 +0000 | [diff] [blame] | 335 | FT_Byte* charstring_base, |
| 336 | FT_UInt charstring_len ) |
David Turner | 9748807 | 2000-08-22 22:36:33 +0000 | [diff] [blame] | 337 | { |
| 338 | FT_Error error; |
David Turner | 4e7eeee | 2002-02-28 16:10:29 +0000 | [diff] [blame] | 339 | T1_Decoder_Zone zone; |
David Turner | 9748807 | 2000-08-22 22:36:33 +0000 | [diff] [blame] | 340 | FT_Byte* ip; |
| 341 | FT_Byte* limit; |
David Turner | 429978b | 2002-03-14 10:09:35 +0000 | [diff] [blame] | 342 | T1_Builder builder = &decoder->builder; |
David Turner | 5893c1b | 2001-10-18 11:49:26 +0000 | [diff] [blame] | 343 | FT_Pos x, y, orig_x, orig_y; |
David Turner | 9748807 | 2000-08-22 22:36:33 +0000 | [diff] [blame] | 344 | |
David Turner | 5893c1b | 2001-10-18 11:49:26 +0000 | [diff] [blame] | 345 | T1_Hints_Funcs hinter; |
Werner Lemberg | 8728f29 | 2000-08-23 17:32:42 +0000 | [diff] [blame] | 346 | |
Werner Lemberg | c3b2160 | 2001-12-05 01:22:05 +0000 | [diff] [blame] | 347 | |
David Turner | 9748807 | 2000-08-22 22:36:33 +0000 | [diff] [blame] | 348 | /* we don't want to touch the source code -- use macro trick */ |
Werner Lemberg | 8728f29 | 2000-08-23 17:32:42 +0000 | [diff] [blame] | 349 | #define start_point T1_Builder_Start_Point |
| 350 | #define check_points T1_Builder_Check_Points |
| 351 | #define add_point T1_Builder_Add_Point |
| 352 | #define add_point1 T1_Builder_Add_Point1 |
| 353 | #define add_contour T1_Builder_Add_Contour |
| 354 | #define close_contour T1_Builder_Close_Contour |
David Turner | 9748807 | 2000-08-22 22:36:33 +0000 | [diff] [blame] | 355 | |
| 356 | /* First of all, initialize the decoder */ |
| 357 | decoder->top = decoder->stack; |
| 358 | decoder->zone = decoder->zones; |
| 359 | zone = decoder->zones; |
| 360 | |
| 361 | builder->path_begun = 0; |
| 362 | |
David Turner | 5893c1b | 2001-10-18 11:49:26 +0000 | [diff] [blame] | 363 | hinter = (T1_Hints_Funcs) builder->hints_funcs; |
| 364 | |
David Turner | 9748807 | 2000-08-22 22:36:33 +0000 | [diff] [blame] | 365 | zone->base = charstring_base; |
| 366 | limit = zone->limit = charstring_base + charstring_len; |
| 367 | ip = zone->cursor = zone->base; |
| 368 | |
Werner Lemberg | cf24d51 | 2001-06-18 14:23:45 +0000 | [diff] [blame] | 369 | error = PSaux_Err_Ok; |
David Turner | 9748807 | 2000-08-22 22:36:33 +0000 | [diff] [blame] | 370 | |
David Turner | 5893c1b | 2001-10-18 11:49:26 +0000 | [diff] [blame] | 371 | x = orig_x = builder->pos_x; |
| 372 | y = orig_y = builder->pos_y; |
| 373 | |
| 374 | /* begin hints recording session, if any */ |
| 375 | if ( hinter ) |
| 376 | hinter->open( hinter->hints ); |
David Turner | 9748807 | 2000-08-22 22:36:33 +0000 | [diff] [blame] | 377 | |
| 378 | /* now, execute loop */ |
| 379 | while ( ip < limit ) |
| 380 | { |
| 381 | FT_Long* top = decoder->top; |
| 382 | T1_Operator op = op_none; |
| 383 | FT_Long value = 0; |
| 384 | |
| 385 | |
| 386 | /*********************************************************************/ |
| 387 | /* */ |
| 388 | /* Decode operator or operand */ |
| 389 | /* */ |
| 390 | /* */ |
| 391 | |
| 392 | /* first of all, decompress operator or value */ |
| 393 | switch ( *ip++ ) |
| 394 | { |
| 395 | case 1: |
| 396 | op = op_hstem; |
| 397 | break; |
| 398 | |
| 399 | case 3: |
| 400 | op = op_vstem; |
| 401 | break; |
| 402 | case 4: |
| 403 | op = op_vmoveto; |
| 404 | break; |
| 405 | case 5: |
| 406 | op = op_rlineto; |
| 407 | break; |
| 408 | case 6: |
| 409 | op = op_hlineto; |
| 410 | break; |
| 411 | case 7: |
| 412 | op = op_vlineto; |
| 413 | break; |
| 414 | case 8: |
| 415 | op = op_rrcurveto; |
| 416 | break; |
| 417 | case 9: |
| 418 | op = op_closepath; |
| 419 | break; |
| 420 | case 10: |
| 421 | op = op_callsubr; |
| 422 | break; |
| 423 | case 11: |
| 424 | op = op_return; |
| 425 | break; |
| 426 | |
| 427 | case 13: |
| 428 | op = op_hsbw; |
| 429 | break; |
| 430 | case 14: |
| 431 | op = op_endchar; |
| 432 | break; |
| 433 | |
| 434 | case 21: |
| 435 | op = op_rmoveto; |
| 436 | break; |
| 437 | case 22: |
| 438 | op = op_hmoveto; |
| 439 | break; |
| 440 | |
| 441 | case 30: |
| 442 | op = op_vhcurveto; |
| 443 | break; |
| 444 | case 31: |
| 445 | op = op_hvcurveto; |
| 446 | break; |
| 447 | |
| 448 | case 12: |
| 449 | if ( ip > limit ) |
| 450 | { |
Werner Lemberg | 9a8b536 | 2001-03-12 22:33:52 +0000 | [diff] [blame] | 451 | FT_ERROR(( "T1_Decoder_Parse_CharStrings: " |
| 452 | "invalid escape (12+EOF)\n" )); |
David Turner | 9748807 | 2000-08-22 22:36:33 +0000 | [diff] [blame] | 453 | goto Syntax_Error; |
| 454 | } |
| 455 | |
| 456 | switch ( *ip++ ) |
| 457 | { |
| 458 | case 0: |
| 459 | op = op_dotsection; |
| 460 | break; |
| 461 | case 1: |
| 462 | op = op_vstem3; |
| 463 | break; |
| 464 | case 2: |
| 465 | op = op_hstem3; |
| 466 | break; |
| 467 | case 6: |
| 468 | op = op_seac; |
| 469 | break; |
| 470 | case 7: |
| 471 | op = op_sbw; |
| 472 | break; |
| 473 | case 12: |
| 474 | op = op_div; |
| 475 | break; |
| 476 | case 16: |
| 477 | op = op_callothersubr; |
| 478 | break; |
| 479 | case 17: |
| 480 | op = op_pop; |
| 481 | break; |
| 482 | case 33: |
| 483 | op = op_setcurrentpoint; |
| 484 | break; |
| 485 | |
| 486 | default: |
Werner Lemberg | 9a8b536 | 2001-03-12 22:33:52 +0000 | [diff] [blame] | 487 | FT_ERROR(( "T1_Decoder_Parse_CharStrings: " |
| 488 | "invalid escape (12+%d)\n", |
David Turner | 9748807 | 2000-08-22 22:36:33 +0000 | [diff] [blame] | 489 | ip[-1] )); |
| 490 | goto Syntax_Error; |
| 491 | } |
| 492 | break; |
| 493 | |
| 494 | case 255: /* four bytes integer */ |
| 495 | if ( ip + 4 > limit ) |
| 496 | { |
Werner Lemberg | 9a8b536 | 2001-03-12 22:33:52 +0000 | [diff] [blame] | 497 | FT_ERROR(( "T1_Decoder_Parse_CharStrings: " |
| 498 | "unexpected EOF in integer\n" )); |
David Turner | 9748807 | 2000-08-22 22:36:33 +0000 | [diff] [blame] | 499 | goto Syntax_Error; |
| 500 | } |
| 501 | |
David Turner | b89fb71 | 2000-10-11 23:39:03 +0000 | [diff] [blame] | 502 | value = (FT_Int32)( ((FT_Long)ip[0] << 24) | |
| 503 | ((FT_Long)ip[1] << 16) | |
| 504 | ((FT_Long)ip[2] << 8 ) | |
| 505 | ip[3] ); |
David Turner | 9748807 | 2000-08-22 22:36:33 +0000 | [diff] [blame] | 506 | ip += 4; |
| 507 | break; |
| 508 | |
| 509 | default: |
| 510 | if ( ip[-1] >= 32 ) |
| 511 | { |
| 512 | if ( ip[-1] < 247 ) |
| 513 | value = (FT_Long)ip[-1] - 139; |
| 514 | else |
| 515 | { |
| 516 | if ( ++ip > limit ) |
| 517 | { |
Werner Lemberg | 9a8b536 | 2001-03-12 22:33:52 +0000 | [diff] [blame] | 518 | FT_ERROR(( "T1_Decoder_Parse_CharStrings: " )); |
| 519 | FT_ERROR(( "unexpected EOF in integer\n" )); |
David Turner | 9748807 | 2000-08-22 22:36:33 +0000 | [diff] [blame] | 520 | goto Syntax_Error; |
| 521 | } |
| 522 | |
Tom Kacvinsky | 9b59f2c | 2001-03-12 01:42:38 +0000 | [diff] [blame] | 523 | if ( ip[-2] < 251 ) |
| 524 | value = ( ( (FT_Long)ip[-2] - 247 ) << 8 ) + ip[-1] + 108; |
| 525 | else |
| 526 | value = -( ( ( (FT_Long)ip[-2] - 251 ) << 8 ) + ip[-1] + 108 ); |
David Turner | 9748807 | 2000-08-22 22:36:33 +0000 | [diff] [blame] | 527 | } |
| 528 | } |
| 529 | else |
| 530 | { |
Werner Lemberg | 9a8b536 | 2001-03-12 22:33:52 +0000 | [diff] [blame] | 531 | FT_ERROR(( "T1_Decoder_Parse_CharStrings: " |
| 532 | "invalid byte (%d)\n", ip[-1] )); |
David Turner | 9748807 | 2000-08-22 22:36:33 +0000 | [diff] [blame] | 533 | goto Syntax_Error; |
| 534 | } |
| 535 | } |
| 536 | |
| 537 | /*********************************************************************/ |
| 538 | /* */ |
| 539 | /* Push value on stack, or process operator */ |
| 540 | /* */ |
| 541 | /* */ |
| 542 | if ( op == op_none ) |
| 543 | { |
| 544 | if ( top - decoder->stack >= T1_MAX_CHARSTRINGS_OPERANDS ) |
| 545 | { |
Werner Lemberg | 9a8b536 | 2001-03-12 22:33:52 +0000 | [diff] [blame] | 546 | FT_ERROR(( "T1_Decoder_Parse_CharStrings: stack overflow!\n" )); |
David Turner | 9748807 | 2000-08-22 22:36:33 +0000 | [diff] [blame] | 547 | goto Syntax_Error; |
| 548 | } |
| 549 | |
| 550 | FT_TRACE4(( " %ld", value )); |
| 551 | |
| 552 | *top++ = value; |
| 553 | decoder->top = top; |
| 554 | } |
| 555 | else if ( op == op_callothersubr ) /* callothersubr */ |
| 556 | { |
| 557 | FT_TRACE4(( " callothersubr" )); |
| 558 | |
| 559 | if ( top - decoder->stack < 2 ) |
| 560 | goto Stack_Underflow; |
| 561 | |
| 562 | top -= 2; |
| 563 | switch ( top[1] ) |
| 564 | { |
| 565 | case 1: /* start flex feature */ |
| 566 | if ( top[0] != 0 ) |
| 567 | goto Unexpected_OtherSubr; |
| 568 | |
| 569 | decoder->flex_state = 1; |
| 570 | decoder->num_flex_vectors = 0; |
| 571 | if ( start_point( builder, x, y ) || |
| 572 | check_points( builder, 6 ) ) |
| 573 | goto Memory_Error; |
| 574 | break; |
| 575 | |
| 576 | case 2: /* add flex vectors */ |
| 577 | { |
Werner Lemberg | 0d9165e | 2002-03-07 21:59:59 +0000 | [diff] [blame] | 578 | FT_Int idx; |
| 579 | |
David Turner | 9748807 | 2000-08-22 22:36:33 +0000 | [diff] [blame] | 580 | |
| 581 | if ( top[0] != 0 ) |
| 582 | goto Unexpected_OtherSubr; |
| 583 | |
| 584 | /* note that we should not add a point for index 0; */ |
| 585 | /* this will move our current position to the flex */ |
| 586 | /* point without adding any point to the outline */ |
Werner Lemberg | 0d9165e | 2002-03-07 21:59:59 +0000 | [diff] [blame] | 587 | idx = decoder->num_flex_vectors++; |
| 588 | if ( idx > 0 && idx < 7 ) |
David Turner | 9748807 | 2000-08-22 22:36:33 +0000 | [diff] [blame] | 589 | add_point( builder, |
| 590 | x, |
| 591 | y, |
Werner Lemberg | 0d9165e | 2002-03-07 21:59:59 +0000 | [diff] [blame] | 592 | (FT_Byte)( idx == 3 || idx == 6 ) ); |
David Turner | 9748807 | 2000-08-22 22:36:33 +0000 | [diff] [blame] | 593 | } |
| 594 | break; |
| 595 | |
| 596 | case 0: /* end flex feature */ |
| 597 | if ( top[0] != 3 ) |
| 598 | goto Unexpected_OtherSubr; |
| 599 | |
| 600 | if ( decoder->flex_state == 0 || |
| 601 | decoder->num_flex_vectors != 7 ) |
| 602 | { |
Werner Lemberg | 9a8b536 | 2001-03-12 22:33:52 +0000 | [diff] [blame] | 603 | FT_ERROR(( "T1_Decoder_Parse_CharStrings: " |
| 604 | "unexpected flex end\n" )); |
David Turner | 9748807 | 2000-08-22 22:36:33 +0000 | [diff] [blame] | 605 | goto Syntax_Error; |
| 606 | } |
| 607 | |
| 608 | /* now consume the remaining `pop pop setcurpoint' */ |
| 609 | if ( ip + 6 > limit || |
| 610 | ip[0] != 12 || ip[1] != 17 || /* pop */ |
| 611 | ip[2] != 12 || ip[3] != 17 || /* pop */ |
| 612 | ip[4] != 12 || ip[5] != 33 ) /* setcurpoint */ |
| 613 | { |
Werner Lemberg | 9a8b536 | 2001-03-12 22:33:52 +0000 | [diff] [blame] | 614 | FT_ERROR(( "T1_Decoder_Parse_CharStrings: " |
| 615 | "invalid flex charstring\n" )); |
David Turner | 9748807 | 2000-08-22 22:36:33 +0000 | [diff] [blame] | 616 | goto Syntax_Error; |
| 617 | } |
| 618 | |
| 619 | ip += 6; |
| 620 | decoder->flex_state = 0; |
| 621 | break; |
| 622 | |
| 623 | case 3: /* change hints */ |
| 624 | if ( top[0] != 1 ) |
| 625 | goto Unexpected_OtherSubr; |
| 626 | |
| 627 | /* eat the following `pop' */ |
| 628 | if ( ip + 2 > limit ) |
| 629 | { |
Werner Lemberg | 9a8b536 | 2001-03-12 22:33:52 +0000 | [diff] [blame] | 630 | FT_ERROR(( "T1_Decoder_Parse_CharStrings: " |
| 631 | "invalid escape (12+%d)\n", ip[-1] )); |
David Turner | 9748807 | 2000-08-22 22:36:33 +0000 | [diff] [blame] | 632 | goto Syntax_Error; |
| 633 | } |
| 634 | |
| 635 | if ( ip[0] != 12 || ip[1] != 17 ) |
| 636 | { |
Werner Lemberg | 9a8b536 | 2001-03-12 22:33:52 +0000 | [diff] [blame] | 637 | FT_ERROR(( "T1_Decoder_Parse_CharStrings: " )); |
| 638 | FT_ERROR(( "`pop' expected, found (%d %d)\n", ip[0], ip[1] )); |
David Turner | 9748807 | 2000-08-22 22:36:33 +0000 | [diff] [blame] | 639 | goto Syntax_Error; |
| 640 | } |
| 641 | ip += 2; |
David Turner | 4d57024 | 2002-02-24 02:59:24 +0000 | [diff] [blame] | 642 | |
David Turner | 5893c1b | 2001-10-18 11:49:26 +0000 | [diff] [blame] | 643 | if ( hinter ) |
| 644 | hinter->reset( hinter->hints, builder->current->n_points ); |
David Turner | 4d57024 | 2002-02-24 02:59:24 +0000 | [diff] [blame] | 645 | |
David Turner | 9748807 | 2000-08-22 22:36:33 +0000 | [diff] [blame] | 646 | break; |
| 647 | |
| 648 | case 12: |
| 649 | case 13: |
| 650 | /* counter control hints, clear stack */ |
| 651 | top = decoder->stack; |
| 652 | break; |
| 653 | |
| 654 | case 14: |
| 655 | case 15: |
| 656 | case 16: |
| 657 | case 17: |
| 658 | case 18: /* multiple masters */ |
| 659 | { |
David Turner | 2964417 | 2002-02-28 18:59:37 +0000 | [diff] [blame] | 660 | PS_Blend blend = decoder->blend; |
David Turner | 9748807 | 2000-08-22 22:36:33 +0000 | [diff] [blame] | 661 | FT_UInt num_points, nn, mm; |
| 662 | FT_Long* delta; |
| 663 | FT_Long* values; |
| 664 | |
| 665 | |
| 666 | if ( !blend ) |
| 667 | { |
Werner Lemberg | 9a8b536 | 2001-03-12 22:33:52 +0000 | [diff] [blame] | 668 | FT_ERROR(( "T1_Decoder_Parse_CharStrings: " )); |
| 669 | FT_ERROR(( "unexpected multiple masters operator!\n" )); |
David Turner | 9748807 | 2000-08-22 22:36:33 +0000 | [diff] [blame] | 670 | goto Syntax_Error; |
| 671 | } |
| 672 | |
| 673 | num_points = top[1] - 13 + ( top[1] == 18 ); |
| 674 | if ( top[0] != (FT_Int)( num_points * blend->num_designs ) ) |
| 675 | { |
Werner Lemberg | 9a8b536 | 2001-03-12 22:33:52 +0000 | [diff] [blame] | 676 | FT_ERROR(( "T1_Decoder_Parse_CharStrings: " )); |
| 677 | FT_ERROR(( "incorrect number of mm arguments\n" )); |
David Turner | 9748807 | 2000-08-22 22:36:33 +0000 | [diff] [blame] | 678 | goto Syntax_Error; |
| 679 | } |
| 680 | |
| 681 | top -= blend->num_designs*num_points; |
| 682 | if ( top < decoder->stack ) |
| 683 | goto Stack_Underflow; |
| 684 | |
| 685 | /* we want to compute: */ |
| 686 | /* */ |
| 687 | /* a0*w0 + a1*w1 + ... + ak*wk */ |
| 688 | /* */ |
| 689 | /* but we only have the a0, a1-a0, a2-a0, .. ak-a0 */ |
| 690 | /* however, given that w0 + w1 + ... + wk == 1, we can */ |
| 691 | /* rewrite it easily as: */ |
| 692 | /* */ |
| 693 | /* a0 + (a1-a0)*w1 + (a2-a0)*w2 + .. + (ak-a0)*wk */ |
| 694 | /* */ |
| 695 | /* where k == num_designs-1 */ |
| 696 | /* */ |
| 697 | /* I guess that's why it's written in this `compact' */ |
| 698 | /* form. */ |
| 699 | /* */ |
| 700 | delta = top + num_points; |
| 701 | values = top; |
| 702 | for ( nn = 0; nn < num_points; nn++ ) |
| 703 | { |
| 704 | FT_Int tmp = values[0]; |
| 705 | |
| 706 | |
| 707 | for ( mm = 1; mm < blend->num_designs; mm++ ) |
| 708 | tmp += FT_MulFix( *delta++, blend->weight_vector[mm] ); |
| 709 | |
| 710 | *values++ = tmp; |
| 711 | } |
| 712 | /* note that `top' will be incremented later by calls to `pop' */ |
| 713 | break; |
| 714 | } |
| 715 | |
| 716 | default: |
| 717 | Unexpected_OtherSubr: |
Werner Lemberg | 9a8b536 | 2001-03-12 22:33:52 +0000 | [diff] [blame] | 718 | FT_ERROR(( "T1_Decoder_Parse_CharStrings: " |
| 719 | "invalid othersubr [%d %d]!\n", top[0], top[1] )); |
David Turner | 9748807 | 2000-08-22 22:36:33 +0000 | [diff] [blame] | 720 | goto Syntax_Error; |
| 721 | } |
| 722 | decoder->top = top; |
| 723 | } |
| 724 | else /* general operator */ |
| 725 | { |
| 726 | FT_Int num_args = t1_args_count[op]; |
| 727 | |
| 728 | |
| 729 | if ( top - decoder->stack < num_args ) |
| 730 | goto Stack_Underflow; |
| 731 | |
| 732 | top -= num_args; |
| 733 | |
| 734 | switch ( op ) |
| 735 | { |
| 736 | case op_endchar: |
| 737 | FT_TRACE4(( " endchar" )); |
| 738 | |
| 739 | close_contour( builder ); |
David Turner | 4d57024 | 2002-02-24 02:59:24 +0000 | [diff] [blame] | 740 | |
David Turner | 5893c1b | 2001-10-18 11:49:26 +0000 | [diff] [blame] | 741 | /* close hints recording session */ |
| 742 | if ( hinter ) |
| 743 | { |
| 744 | if (hinter->close( hinter->hints, builder->current->n_points )) |
| 745 | goto Syntax_Error; |
David Turner | 4d57024 | 2002-02-24 02:59:24 +0000 | [diff] [blame] | 746 | |
David Turner | 5893c1b | 2001-10-18 11:49:26 +0000 | [diff] [blame] | 747 | /* apply hints to the loaded glyph outline now */ |
| 748 | hinter->apply( hinter->hints, |
| 749 | builder->current, |
Werner Lemberg | c3b2160 | 2001-12-05 01:22:05 +0000 | [diff] [blame] | 750 | (PSH_Globals)builder->hints_globals ); |
David Turner | 5893c1b | 2001-10-18 11:49:26 +0000 | [diff] [blame] | 751 | } |
David Turner | 4d57024 | 2002-02-24 02:59:24 +0000 | [diff] [blame] | 752 | |
David Turner | 9748807 | 2000-08-22 22:36:33 +0000 | [diff] [blame] | 753 | /* add current outline to the glyph slot */ |
| 754 | FT_GlyphLoader_Add( builder->loader ); |
| 755 | |
| 756 | /* return now! */ |
| 757 | FT_TRACE4(( "\n\n" )); |
Werner Lemberg | 1f7f0e8 | 2001-06-06 17:30:41 +0000 | [diff] [blame] | 758 | return PSaux_Err_Ok; |
David Turner | 9748807 | 2000-08-22 22:36:33 +0000 | [diff] [blame] | 759 | |
| 760 | case op_hsbw: |
| 761 | FT_TRACE4(( " hsbw" )); |
| 762 | |
| 763 | builder->left_bearing.x += top[0]; |
| 764 | builder->advance.x = top[1]; |
| 765 | builder->advance.y = 0; |
| 766 | |
David Turner | 5893c1b | 2001-10-18 11:49:26 +0000 | [diff] [blame] | 767 | orig_x = builder->last.x = x = builder->pos_x + top[0]; |
| 768 | orig_y = builder->last.y = y = builder->pos_y; |
David Turner | 9748807 | 2000-08-22 22:36:33 +0000 | [diff] [blame] | 769 | |
Werner Lemberg | b5349a9 | 2002-02-19 16:30:15 +0000 | [diff] [blame] | 770 | FT_UNUSED( orig_y ); |
| 771 | |
David Turner | 9748807 | 2000-08-22 22:36:33 +0000 | [diff] [blame] | 772 | /* the `metrics_only' indicates that we only want to compute */ |
| 773 | /* the glyph's metrics (lsb + advance width), not load the */ |
| 774 | /* rest of it; so exit immediately */ |
| 775 | if ( builder->metrics_only ) |
Werner Lemberg | 1f7f0e8 | 2001-06-06 17:30:41 +0000 | [diff] [blame] | 776 | return PSaux_Err_Ok; |
David Turner | 9748807 | 2000-08-22 22:36:33 +0000 | [diff] [blame] | 777 | |
| 778 | break; |
| 779 | |
| 780 | case op_seac: |
| 781 | /* return immediately after the processing */ |
| 782 | return t1operator_seac( decoder, top[0], top[1], |
| 783 | top[2], top[3], top[4] ); |
| 784 | |
| 785 | case op_sbw: |
| 786 | FT_TRACE4(( " sbw" )); |
| 787 | |
| 788 | builder->left_bearing.x += top[0]; |
| 789 | builder->left_bearing.y += top[1]; |
| 790 | builder->advance.x = top[2]; |
| 791 | builder->advance.y = top[3]; |
| 792 | |
David Turner | 5893c1b | 2001-10-18 11:49:26 +0000 | [diff] [blame] | 793 | builder->last.x = x = builder->pos_x + top[0]; |
| 794 | builder->last.y = y = builder->pos_y + top[1]; |
David Turner | 9748807 | 2000-08-22 22:36:33 +0000 | [diff] [blame] | 795 | |
| 796 | /* the `metrics_only' indicates that we only want to compute */ |
| 797 | /* the glyph's metrics (lsb + advance width), not load the */ |
| 798 | /* rest of it; so exit immediately */ |
| 799 | if ( builder->metrics_only ) |
Werner Lemberg | 1f7f0e8 | 2001-06-06 17:30:41 +0000 | [diff] [blame] | 800 | return PSaux_Err_Ok; |
David Turner | 9748807 | 2000-08-22 22:36:33 +0000 | [diff] [blame] | 801 | |
| 802 | break; |
| 803 | |
| 804 | case op_closepath: |
| 805 | FT_TRACE4(( " closepath" )); |
| 806 | |
| 807 | close_contour( builder ); |
| 808 | builder->path_begun = 0; |
| 809 | break; |
| 810 | |
| 811 | case op_hlineto: |
| 812 | FT_TRACE4(( " hlineto" )); |
| 813 | |
| 814 | if ( start_point( builder, x, y ) ) |
| 815 | goto Memory_Error; |
| 816 | |
| 817 | x += top[0]; |
| 818 | goto Add_Line; |
| 819 | |
| 820 | case op_hmoveto: |
| 821 | FT_TRACE4(( " hmoveto" )); |
| 822 | |
| 823 | x += top[0]; |
Werner Lemberg | 0634ced | 2000-10-09 01:44:40 +0000 | [diff] [blame] | 824 | if ( !decoder->flex_state ) |
| 825 | builder->path_begun = 0; |
David Turner | 9748807 | 2000-08-22 22:36:33 +0000 | [diff] [blame] | 826 | break; |
| 827 | |
| 828 | case op_hvcurveto: |
| 829 | FT_TRACE4(( " hvcurveto" )); |
| 830 | |
| 831 | if ( start_point( builder, x, y ) || |
| 832 | check_points( builder, 3 ) ) |
| 833 | goto Memory_Error; |
| 834 | |
| 835 | x += top[0]; |
| 836 | add_point( builder, x, y, 0 ); |
| 837 | x += top[1]; |
| 838 | y += top[2]; |
| 839 | add_point( builder, x, y, 0 ); |
| 840 | y += top[3]; |
| 841 | add_point( builder, x, y, 1 ); |
| 842 | break; |
| 843 | |
| 844 | case op_rlineto: |
| 845 | FT_TRACE4(( " rlineto" )); |
| 846 | |
| 847 | if ( start_point( builder, x, y ) ) |
| 848 | goto Memory_Error; |
| 849 | |
| 850 | x += top[0]; |
| 851 | y += top[1]; |
| 852 | |
| 853 | Add_Line: |
| 854 | if ( add_point1( builder, x, y ) ) |
| 855 | goto Memory_Error; |
| 856 | break; |
| 857 | |
| 858 | case op_rmoveto: |
| 859 | FT_TRACE4(( " rmoveto" )); |
| 860 | |
| 861 | x += top[0]; |
| 862 | y += top[1]; |
Werner Lemberg | 0634ced | 2000-10-09 01:44:40 +0000 | [diff] [blame] | 863 | if ( !decoder->flex_state ) |
| 864 | builder->path_begun = 0; |
David Turner | 9748807 | 2000-08-22 22:36:33 +0000 | [diff] [blame] | 865 | break; |
| 866 | |
| 867 | case op_rrcurveto: |
| 868 | FT_TRACE4(( " rcurveto" )); |
| 869 | |
| 870 | if ( start_point( builder, x, y ) || |
| 871 | check_points( builder, 3 ) ) |
| 872 | goto Memory_Error; |
| 873 | |
| 874 | x += top[0]; |
| 875 | y += top[1]; |
| 876 | add_point( builder, x, y, 0 ); |
| 877 | |
| 878 | x += top[2]; |
| 879 | y += top[3]; |
| 880 | add_point( builder, x, y, 0 ); |
| 881 | |
| 882 | x += top[4]; |
| 883 | y += top[5]; |
| 884 | add_point( builder, x, y, 1 ); |
| 885 | break; |
| 886 | |
| 887 | case op_vhcurveto: |
| 888 | FT_TRACE4(( " vhcurveto" )); |
| 889 | |
| 890 | if ( start_point( builder, x, y ) || |
| 891 | check_points( builder, 3 ) ) |
| 892 | goto Memory_Error; |
| 893 | |
| 894 | y += top[0]; |
| 895 | add_point( builder, x, y, 0 ); |
| 896 | x += top[1]; |
| 897 | y += top[2]; |
| 898 | add_point( builder, x, y, 0 ); |
| 899 | x += top[3]; |
| 900 | add_point( builder, x, y, 1 ); |
| 901 | break; |
| 902 | |
| 903 | case op_vlineto: |
| 904 | FT_TRACE4(( " vlineto" )); |
| 905 | |
| 906 | if ( start_point( builder, x, y ) ) |
| 907 | goto Memory_Error; |
| 908 | |
| 909 | y += top[0]; |
| 910 | goto Add_Line; |
| 911 | |
| 912 | case op_vmoveto: |
| 913 | FT_TRACE4(( " vmoveto" )); |
| 914 | |
| 915 | y += top[0]; |
Werner Lemberg | 0634ced | 2000-10-09 01:44:40 +0000 | [diff] [blame] | 916 | if ( !decoder->flex_state ) |
| 917 | builder->path_begun = 0; |
David Turner | 9748807 | 2000-08-22 22:36:33 +0000 | [diff] [blame] | 918 | break; |
| 919 | |
| 920 | case op_div: |
| 921 | FT_TRACE4(( " div" )); |
| 922 | |
| 923 | if ( top[1] ) |
| 924 | { |
| 925 | *top = top[0] / top[1]; |
| 926 | ++top; |
| 927 | } |
| 928 | else |
| 929 | { |
Werner Lemberg | 9a8b536 | 2001-03-12 22:33:52 +0000 | [diff] [blame] | 930 | FT_ERROR(( "T1_Decoder_Parse_CharStrings: division by 0\n" )); |
David Turner | 9748807 | 2000-08-22 22:36:33 +0000 | [diff] [blame] | 931 | goto Syntax_Error; |
| 932 | } |
| 933 | break; |
| 934 | |
| 935 | case op_callsubr: |
| 936 | { |
Werner Lemberg | 0d9165e | 2002-03-07 21:59:59 +0000 | [diff] [blame] | 937 | FT_Int idx; |
David Turner | 9748807 | 2000-08-22 22:36:33 +0000 | [diff] [blame] | 938 | |
| 939 | |
| 940 | FT_TRACE4(( " callsubr" )); |
| 941 | |
Werner Lemberg | 0d9165e | 2002-03-07 21:59:59 +0000 | [diff] [blame] | 942 | idx = top[0]; |
| 943 | if ( idx < 0 || idx >= (FT_Int)decoder->num_subrs ) |
David Turner | 9748807 | 2000-08-22 22:36:33 +0000 | [diff] [blame] | 944 | { |
Werner Lemberg | 9a8b536 | 2001-03-12 22:33:52 +0000 | [diff] [blame] | 945 | FT_ERROR(( "T1_Decoder_Parse_CharStrings: " |
| 946 | "invalid subrs index\n" )); |
David Turner | 9748807 | 2000-08-22 22:36:33 +0000 | [diff] [blame] | 947 | goto Syntax_Error; |
| 948 | } |
| 949 | |
| 950 | if ( zone - decoder->zones >= T1_MAX_SUBRS_CALLS ) |
| 951 | { |
Werner Lemberg | 9a8b536 | 2001-03-12 22:33:52 +0000 | [diff] [blame] | 952 | FT_ERROR(( "T1_Decoder_Parse_CharStrings: " |
| 953 | "too many nested subrs\n" )); |
David Turner | 9748807 | 2000-08-22 22:36:33 +0000 | [diff] [blame] | 954 | goto Syntax_Error; |
| 955 | } |
| 956 | |
| 957 | zone->cursor = ip; /* save current instruction pointer */ |
| 958 | |
| 959 | zone++; |
Tom Kacvinsky | 9b59f2c | 2001-03-12 01:42:38 +0000 | [diff] [blame] | 960 | |
Werner Lemberg | 9a8b536 | 2001-03-12 22:33:52 +0000 | [diff] [blame] | 961 | /* The Type 1 driver stores subroutines without the seed bytes. */ |
| 962 | /* The CID driver stores subroutines with seed bytes. This */ |
| 963 | /* case is taken care of when decoder->subrs_len == 0. */ |
Werner Lemberg | 0d9165e | 2002-03-07 21:59:59 +0000 | [diff] [blame] | 964 | zone->base = decoder->subrs[idx]; |
Werner Lemberg | e4b32a5 | 2000-10-31 20:42:18 +0000 | [diff] [blame] | 965 | |
Werner Lemberg | 9a8b536 | 2001-03-12 22:33:52 +0000 | [diff] [blame] | 966 | if ( decoder->subrs_len ) |
Werner Lemberg | 0d9165e | 2002-03-07 21:59:59 +0000 | [diff] [blame] | 967 | zone->limit = zone->base + decoder->subrs_len[idx]; |
David Turner | 9748807 | 2000-08-22 22:36:33 +0000 | [diff] [blame] | 968 | else |
Tom Kacvinsky | 9b59f2c | 2001-03-12 01:42:38 +0000 | [diff] [blame] | 969 | { |
| 970 | /* We are using subroutines from a CID font. We must adjust */ |
| 971 | /* for the seed bytes. */ |
Werner Lemberg | 93616ec | 2001-06-27 19:46:12 +0000 | [diff] [blame] | 972 | zone->base += ( decoder->lenIV >= 0 ? decoder->lenIV : 0 ); |
Werner Lemberg | 0d9165e | 2002-03-07 21:59:59 +0000 | [diff] [blame] | 973 | zone->limit = decoder->subrs[idx + 1]; |
Tom Kacvinsky | 9b59f2c | 2001-03-12 01:42:38 +0000 | [diff] [blame] | 974 | } |
Werner Lemberg | e4b32a5 | 2000-10-31 20:42:18 +0000 | [diff] [blame] | 975 | |
David Turner | 9748807 | 2000-08-22 22:36:33 +0000 | [diff] [blame] | 976 | zone->cursor = zone->base; |
| 977 | |
| 978 | if ( !zone->base ) |
| 979 | { |
Werner Lemberg | 9a8b536 | 2001-03-12 22:33:52 +0000 | [diff] [blame] | 980 | FT_ERROR(( "T1_Decoder_Parse_CharStrings: " |
| 981 | "invoking empty subrs!\n" )); |
David Turner | 9748807 | 2000-08-22 22:36:33 +0000 | [diff] [blame] | 982 | goto Syntax_Error; |
| 983 | } |
| 984 | |
| 985 | decoder->zone = zone; |
| 986 | ip = zone->base; |
| 987 | limit = zone->limit; |
| 988 | break; |
| 989 | } |
| 990 | |
| 991 | case op_pop: |
| 992 | FT_TRACE4(( " pop" )); |
| 993 | |
Werner Lemberg | 8728f29 | 2000-08-23 17:32:42 +0000 | [diff] [blame] | 994 | /* theoretically, the arguments are already on the stack */ |
David Turner | 9748807 | 2000-08-22 22:36:33 +0000 | [diff] [blame] | 995 | top++; |
| 996 | break; |
| 997 | |
| 998 | case op_return: |
| 999 | FT_TRACE4(( " return" )); |
| 1000 | |
| 1001 | if ( zone <= decoder->zones ) |
| 1002 | { |
Werner Lemberg | 9a8b536 | 2001-03-12 22:33:52 +0000 | [diff] [blame] | 1003 | FT_ERROR(( "T1_Decoder_Parse_CharStrings: unexpected return\n" )); |
David Turner | 9748807 | 2000-08-22 22:36:33 +0000 | [diff] [blame] | 1004 | goto Syntax_Error; |
| 1005 | } |
| 1006 | |
| 1007 | zone--; |
| 1008 | ip = zone->cursor; |
| 1009 | limit = zone->limit; |
| 1010 | decoder->zone = zone; |
| 1011 | break; |
| 1012 | |
| 1013 | case op_dotsection: |
| 1014 | FT_TRACE4(( " dotsection" )); |
| 1015 | |
| 1016 | break; |
| 1017 | |
| 1018 | case op_hstem: |
| 1019 | FT_TRACE4(( " hstem" )); |
David Turner | 4d57024 | 2002-02-24 02:59:24 +0000 | [diff] [blame] | 1020 | |
David Turner | 5893c1b | 2001-10-18 11:49:26 +0000 | [diff] [blame] | 1021 | /* record horizontal hint */ |
| 1022 | if ( hinter ) |
| 1023 | { |
| 1024 | /* top[0] += builder->left_bearing.y; */ |
David Turner | 7c0d208 | 2001-12-21 15:59:43 +0000 | [diff] [blame] | 1025 | hinter->stem( hinter->hints, 1, top ); |
David Turner | 5893c1b | 2001-10-18 11:49:26 +0000 | [diff] [blame] | 1026 | } |
David Turner | 9748807 | 2000-08-22 22:36:33 +0000 | [diff] [blame] | 1027 | |
| 1028 | break; |
| 1029 | |
| 1030 | case op_hstem3: |
| 1031 | FT_TRACE4(( " hstem3" )); |
| 1032 | |
David Turner | 5893c1b | 2001-10-18 11:49:26 +0000 | [diff] [blame] | 1033 | /* record horizontal counter-controlled hints */ |
| 1034 | if ( hinter ) |
David Turner | 7c0d208 | 2001-12-21 15:59:43 +0000 | [diff] [blame] | 1035 | hinter->stem3( hinter->hints, 1, top ); |
David Turner | 4d57024 | 2002-02-24 02:59:24 +0000 | [diff] [blame] | 1036 | |
David Turner | 9748807 | 2000-08-22 22:36:33 +0000 | [diff] [blame] | 1037 | break; |
| 1038 | |
| 1039 | case op_vstem: |
| 1040 | FT_TRACE4(( " vstem" )); |
| 1041 | |
David Turner | 5893c1b | 2001-10-18 11:49:26 +0000 | [diff] [blame] | 1042 | /* record vertical hint */ |
| 1043 | if ( hinter ) |
| 1044 | { |
| 1045 | top[0] += orig_x; |
David Turner | 7c0d208 | 2001-12-21 15:59:43 +0000 | [diff] [blame] | 1046 | hinter->stem( hinter->hints, 0, top ); |
David Turner | 5893c1b | 2001-10-18 11:49:26 +0000 | [diff] [blame] | 1047 | } |
| 1048 | |
David Turner | 9748807 | 2000-08-22 22:36:33 +0000 | [diff] [blame] | 1049 | break; |
| 1050 | |
| 1051 | case op_vstem3: |
| 1052 | FT_TRACE4(( " vstem3" )); |
| 1053 | |
David Turner | 5893c1b | 2001-10-18 11:49:26 +0000 | [diff] [blame] | 1054 | /* record vertical counter-controlled hints */ |
| 1055 | if ( hinter ) |
| 1056 | { |
| 1057 | FT_Pos dx = orig_x; |
David Turner | 4d57024 | 2002-02-24 02:59:24 +0000 | [diff] [blame] | 1058 | |
David Turner | 5893c1b | 2001-10-18 11:49:26 +0000 | [diff] [blame] | 1059 | top[0] += dx; |
| 1060 | top[2] += dx; |
| 1061 | top[4] += dx; |
David Turner | 7c0d208 | 2001-12-21 15:59:43 +0000 | [diff] [blame] | 1062 | hinter->stem3( hinter->hints, 0, top ); |
David Turner | 5893c1b | 2001-10-18 11:49:26 +0000 | [diff] [blame] | 1063 | } |
David Turner | 9748807 | 2000-08-22 22:36:33 +0000 | [diff] [blame] | 1064 | break; |
| 1065 | |
| 1066 | case op_setcurrentpoint: |
| 1067 | FT_TRACE4(( " setcurrentpoint" )); |
| 1068 | |
Werner Lemberg | 9a8b536 | 2001-03-12 22:33:52 +0000 | [diff] [blame] | 1069 | FT_ERROR(( "T1_Decoder_Parse_CharStrings: " )); |
| 1070 | FT_ERROR(( "unexpected `setcurrentpoint'\n" )); |
David Turner | 9748807 | 2000-08-22 22:36:33 +0000 | [diff] [blame] | 1071 | goto Syntax_Error; |
| 1072 | |
| 1073 | default: |
Werner Lemberg | 9a8b536 | 2001-03-12 22:33:52 +0000 | [diff] [blame] | 1074 | FT_ERROR(( "T1_Decoder_Parse_CharStrings: " |
| 1075 | "unhandled opcode %d\n", op )); |
David Turner | 9748807 | 2000-08-22 22:36:33 +0000 | [diff] [blame] | 1076 | goto Syntax_Error; |
| 1077 | } |
| 1078 | |
| 1079 | decoder->top = top; |
| 1080 | |
| 1081 | } /* general operator processing */ |
| 1082 | |
| 1083 | } /* while ip < limit */ |
| 1084 | |
| 1085 | FT_TRACE4(( "..end..\n\n" )); |
David Turner | 5893c1b | 2001-10-18 11:49:26 +0000 | [diff] [blame] | 1086 | |
David Turner | 9748807 | 2000-08-22 22:36:33 +0000 | [diff] [blame] | 1087 | return error; |
| 1088 | |
| 1089 | Syntax_Error: |
Werner Lemberg | 1f7f0e8 | 2001-06-06 17:30:41 +0000 | [diff] [blame] | 1090 | return PSaux_Err_Syntax_Error; |
David Turner | 9748807 | 2000-08-22 22:36:33 +0000 | [diff] [blame] | 1091 | |
| 1092 | Stack_Underflow: |
Werner Lemberg | 1f7f0e8 | 2001-06-06 17:30:41 +0000 | [diff] [blame] | 1093 | return PSaux_Err_Stack_Underflow; |
David Turner | 9748807 | 2000-08-22 22:36:33 +0000 | [diff] [blame] | 1094 | |
| 1095 | Memory_Error: |
| 1096 | return builder->error; |
| 1097 | } |
| 1098 | |
| 1099 | |
Werner Lemberg | c3b2160 | 2001-12-05 01:22:05 +0000 | [diff] [blame] | 1100 | /* parse a single Type 1 glyph */ |
David Turner | bc82f1b | 2002-03-01 02:26:22 +0000 | [diff] [blame] | 1101 | FT_LOCAL_DEF( FT_Error ) |
David Turner | 4e7eeee | 2002-02-28 16:10:29 +0000 | [diff] [blame] | 1102 | T1_Decoder_Parse_Glyph( T1_Decoder decoder, |
Werner Lemberg | 93616ec | 2001-06-27 19:46:12 +0000 | [diff] [blame] | 1103 | FT_UInt glyph ) |
David Turner | 9748807 | 2000-08-22 22:36:33 +0000 | [diff] [blame] | 1104 | { |
David Turner | a39acf5 | 2000-08-23 02:47:57 +0000 | [diff] [blame] | 1105 | return decoder->parse_callback( decoder, glyph ); |
David Turner | 9748807 | 2000-08-22 22:36:33 +0000 | [diff] [blame] | 1106 | } |
| 1107 | |
| 1108 | |
Werner Lemberg | c3b2160 | 2001-12-05 01:22:05 +0000 | [diff] [blame] | 1109 | /* initialise T1 decoder */ |
David Turner | bc82f1b | 2002-03-01 02:26:22 +0000 | [diff] [blame] | 1110 | FT_LOCAL_DEF( FT_Error ) |
David Turner | 4e7eeee | 2002-02-28 16:10:29 +0000 | [diff] [blame] | 1111 | T1_Decoder_Init( T1_Decoder decoder, |
Werner Lemberg | 93616ec | 2001-06-27 19:46:12 +0000 | [diff] [blame] | 1112 | FT_Face face, |
| 1113 | FT_Size size, |
| 1114 | FT_GlyphSlot slot, |
| 1115 | FT_Byte** glyph_names, |
David Turner | 2964417 | 2002-02-28 18:59:37 +0000 | [diff] [blame] | 1116 | PS_Blend blend, |
David Turner | 5893c1b | 2001-10-18 11:49:26 +0000 | [diff] [blame] | 1117 | FT_Bool hinting, |
Werner Lemberg | 93616ec | 2001-06-27 19:46:12 +0000 | [diff] [blame] | 1118 | T1_Decoder_Callback parse_callback ) |
David Turner | 9748807 | 2000-08-22 22:36:33 +0000 | [diff] [blame] | 1119 | { |
David Turner | e459d74 | 2002-03-22 13:52:37 +0000 | [diff] [blame^] | 1120 | FT_MEM_SET( decoder, 0, sizeof ( *decoder ) ); |
Werner Lemberg | e4b32a5 | 2000-10-31 20:42:18 +0000 | [diff] [blame] | 1121 | |
David Turner | 9748807 | 2000-08-22 22:36:33 +0000 | [diff] [blame] | 1122 | /* retrieve PSNames interface from list of current modules */ |
| 1123 | { |
David Turner | 4e7eeee | 2002-02-28 16:10:29 +0000 | [diff] [blame] | 1124 | PSNames_Service psnames = 0; |
Werner Lemberg | e4b32a5 | 2000-10-31 20:42:18 +0000 | [diff] [blame] | 1125 | |
Werner Lemberg | 8728f29 | 2000-08-23 17:32:42 +0000 | [diff] [blame] | 1126 | |
David Turner | 4e7eeee | 2002-02-28 16:10:29 +0000 | [diff] [blame] | 1127 | psnames = (PSNames_Service)FT_Get_Module_Interface( |
David Turner | 9748807 | 2000-08-22 22:36:33 +0000 | [diff] [blame] | 1128 | FT_FACE_LIBRARY(face), "psnames" ); |
Werner Lemberg | 8728f29 | 2000-08-23 17:32:42 +0000 | [diff] [blame] | 1129 | if ( !psnames ) |
David Turner | 9748807 | 2000-08-22 22:36:33 +0000 | [diff] [blame] | 1130 | { |
Werner Lemberg | 8728f29 | 2000-08-23 17:32:42 +0000 | [diff] [blame] | 1131 | FT_ERROR(( "T1_Decoder_Init: " )); |
| 1132 | FT_ERROR(( "the `psnames' module is not available\n" )); |
Werner Lemberg | 1f7f0e8 | 2001-06-06 17:30:41 +0000 | [diff] [blame] | 1133 | return PSaux_Err_Unimplemented_Feature; |
David Turner | 9748807 | 2000-08-22 22:36:33 +0000 | [diff] [blame] | 1134 | } |
Werner Lemberg | e4b32a5 | 2000-10-31 20:42:18 +0000 | [diff] [blame] | 1135 | |
David Turner | 9748807 | 2000-08-22 22:36:33 +0000 | [diff] [blame] | 1136 | decoder->psnames = psnames; |
| 1137 | } |
David Turner | 5893c1b | 2001-10-18 11:49:26 +0000 | [diff] [blame] | 1138 | T1_Builder_Init( &decoder->builder, face, size, slot, hinting ); |
Werner Lemberg | e4b32a5 | 2000-10-31 20:42:18 +0000 | [diff] [blame] | 1139 | |
David Turner | a39acf5 | 2000-08-23 02:47:57 +0000 | [diff] [blame] | 1140 | decoder->num_glyphs = face->num_glyphs; |
| 1141 | decoder->glyph_names = glyph_names; |
| 1142 | decoder->blend = blend; |
| 1143 | decoder->parse_callback = parse_callback; |
Werner Lemberg | e4b32a5 | 2000-10-31 20:42:18 +0000 | [diff] [blame] | 1144 | |
David Turner | a39acf5 | 2000-08-23 02:47:57 +0000 | [diff] [blame] | 1145 | decoder->funcs = t1_decoder_funcs; |
Werner Lemberg | 8728f29 | 2000-08-23 17:32:42 +0000 | [diff] [blame] | 1146 | |
David Turner | 9748807 | 2000-08-22 22:36:33 +0000 | [diff] [blame] | 1147 | return 0; |
| 1148 | } |
| 1149 | |
| 1150 | |
Werner Lemberg | c3b2160 | 2001-12-05 01:22:05 +0000 | [diff] [blame] | 1151 | /* finalize T1 decoder */ |
David Turner | bc82f1b | 2002-03-01 02:26:22 +0000 | [diff] [blame] | 1152 | FT_LOCAL_DEF( void ) |
David Turner | 4e7eeee | 2002-02-28 16:10:29 +0000 | [diff] [blame] | 1153 | T1_Decoder_Done( T1_Decoder decoder ) |
David Turner | 9748807 | 2000-08-22 22:36:33 +0000 | [diff] [blame] | 1154 | { |
| 1155 | T1_Builder_Done( &decoder->builder ); |
| 1156 | } |
| 1157 | |
Werner Lemberg | 8728f29 | 2000-08-23 17:32:42 +0000 | [diff] [blame] | 1158 | |
| 1159 | /* END */ |