/src/ghostpdl/devices/vector/gdevpsfx.c
Line | Count | Source |
1 | | /* Copyright (C) 2001-2025 Artifex Software, Inc. |
2 | | All Rights Reserved. |
3 | | |
4 | | This software is provided AS-IS with no warranty, either express or |
5 | | implied. |
6 | | |
7 | | This software is distributed under license and may not be copied, |
8 | | modified or distributed except as expressly authorized under the terms |
9 | | of the license contained in the file LICENSE in this distribution. |
10 | | |
11 | | Refer to licensing information at http://www.artifex.com or contact |
12 | | Artifex Software, Inc., 39 Mesa Street, Suite 108A, San Francisco, |
13 | | CA 94129, USA, for further information. |
14 | | */ |
15 | | |
16 | | |
17 | | /* Convert Type 1 Charstrings to Type 2 */ |
18 | | #include "math_.h" |
19 | | #include "memory_.h" |
20 | | #include "gx.h" |
21 | | #include "gserrors.h" |
22 | | #include "gxfixed.h" |
23 | | #include "gxmatrix.h" /* for gsfont.h */ |
24 | | #include "gxfont.h" |
25 | | #include "gxfont1.h" |
26 | | #include "gxtype1.h" |
27 | | #include "stream.h" |
28 | | #include "gdevpsf.h" |
29 | | #include "gxgstate.h" |
30 | | |
31 | | /* ------ Type 1 Charstring parsing ------ */ |
32 | | |
33 | | /* |
34 | | * The parsing code handles numbers on its own; it reports callsubr and |
35 | | * return operators to the caller, but also executes them. |
36 | | * |
37 | | * Only the following elements of the Type 1 state are used: |
38 | | * ostack, os_count, ipstack, ips_count |
39 | | */ |
40 | | |
41 | 26.2M | #define CE_OFFSET 32 /* offset for extended opcodes */ |
42 | | |
43 | | typedef struct { |
44 | | fixed v0, v1; /* coordinates */ |
45 | | ushort index; /* sequential index of hint */ |
46 | | } cv_stem_hint; |
47 | | typedef struct { |
48 | | int count; |
49 | | int current; /* cache cursor for search */ |
50 | | /* |
51 | | * For dotsection and Type 1 Charstring hint replacement, |
52 | | * we store active hints at the bottom of the table, and |
53 | | * replaced hints at the top. |
54 | | */ |
55 | | int replaced_count; /* # of replaced hints at top */ |
56 | | cv_stem_hint data[max_total_stem_hints]; |
57 | | } cv_stem_hint_table; |
58 | | |
59 | | /* Skip over the initial bytes in a Charstring, if any. */ |
60 | | static void |
61 | | skip_iv(gs_type1_state *pcis) |
62 | 9.61M | { |
63 | 9.61M | int skip = pcis->pfont->data.lenIV; |
64 | 9.61M | ip_state_t *ipsp = &pcis->ipstack[pcis->ips_count - 1]; |
65 | 9.61M | const byte *cip = ipsp->cs_data.bits.data; |
66 | 9.61M | crypt_state state = crypt_charstring_seed; |
67 | | |
68 | 48.0M | for (; skip > 0; ++cip, --skip) |
69 | 38.4M | decrypt_skip_next(*cip, state); |
70 | 9.61M | ipsp->ip = cip; |
71 | 9.61M | ipsp->dstate = state; |
72 | 9.61M | } |
73 | | |
74 | | /* |
75 | | * Set up for parsing a Type 1 Charstring. |
76 | | * |
77 | | * Only uses the following elements of *pfont: |
78 | | * data.lenIV |
79 | | */ |
80 | | static void |
81 | | type1_next_init(gs_type1_state *pcis, const gs_glyph_data_t *pgd, |
82 | | gs_font_type1 *pfont) |
83 | 4.98M | { |
84 | 4.98M | gs_type1_interp_init(pcis, NULL, NULL, NULL, NULL, false, 0, pfont); |
85 | 4.98M | pcis->flex_count = flex_max; |
86 | 4.98M | pcis->ipstack[0].cs_data = *pgd; |
87 | 4.98M | skip_iv(pcis); |
88 | 4.98M | } |
89 | | |
90 | | /* Clear the Type 1 operand stack. */ |
91 | | static inline void |
92 | | type1_clear(gs_type1_state *pcis) |
93 | 92.4M | { |
94 | 92.4M | pcis->os_count = 0; |
95 | 92.4M | } |
96 | | |
97 | | /* Execute a callsubr. */ |
98 | | static int |
99 | | type1_callsubr(gs_type1_state *pcis, int index) |
100 | 4.62M | { |
101 | 4.62M | gs_font_type1 *pfont = pcis->pfont; |
102 | 4.62M | ip_state_t *ipsp1 = &pcis->ipstack[pcis->ips_count]; |
103 | 4.62M | int code = pfont->data.procs.subr_data(pfont, index, false, |
104 | 4.62M | &ipsp1->cs_data); |
105 | | |
106 | 4.62M | if (code < 0) |
107 | 8 | return_error(code); |
108 | 4.62M | pcis->ips_count++; |
109 | 4.62M | skip_iv(pcis); |
110 | 4.62M | return code; |
111 | 4.62M | } |
112 | | |
113 | | /* Add 1 or 3 stem hints. */ |
114 | | static int |
115 | | type1_stem1(gs_type1_state *pcis, cv_stem_hint_table *psht, const fixed *pv, |
116 | | fixed lsb, byte *active_hints) |
117 | 23.5M | { |
118 | 23.5M | fixed v0 = pv[0] + lsb, v1 = v0 + pv[1]; |
119 | 23.5M | cv_stem_hint *bot = &psht->data[0]; |
120 | 23.5M | cv_stem_hint *orig_top = bot + psht->count; |
121 | 23.5M | cv_stem_hint *top = orig_top; |
122 | | |
123 | 23.5M | if (psht->count >= max_total_stem_hints) |
124 | 0 | return_error(gs_error_limitcheck); |
125 | 36.1M | while (top > bot && |
126 | 31.5M | (v0 < top[-1].v0 || (v0 == top[-1].v0 && v1 < top[-1].v1)) |
127 | 23.5M | ) { |
128 | 12.5M | *top = top[-1]; |
129 | 12.5M | top--; |
130 | 12.5M | } |
131 | 23.5M | if (top > bot && v0 == top[-1].v0 && v1 == top[-1].v1) { |
132 | | /* Duplicate hint, don't add it. */ |
133 | 14.7M | memmove(top, top + 1, (char *)orig_top - (char *)top); |
134 | 14.7M | if (active_hints) { |
135 | 11.7M | uint index = top[-1].index; |
136 | | |
137 | 11.7M | active_hints[index >> 3] |= 0x80 >> (index & 7); |
138 | 11.7M | } |
139 | 14.7M | return 0; |
140 | 14.7M | } |
141 | 8.82M | top->v0 = v0; |
142 | 8.82M | top->v1 = v1; |
143 | 8.82M | psht->count++; |
144 | 8.82M | return 0; |
145 | 23.5M | } |
146 | | static void |
147 | | type1_stem3(gs_type1_state *pcis, cv_stem_hint_table *psht, const fixed *pv3, |
148 | | fixed lsb, byte *active_hints) |
149 | 12.0k | { |
150 | 12.0k | type1_stem1(pcis, psht, pv3, lsb, active_hints); |
151 | 12.0k | type1_stem1(pcis, psht, pv3 + 2, lsb, active_hints); |
152 | 12.0k | type1_stem1(pcis, psht, pv3 + 4, lsb, active_hints); |
153 | 12.0k | } |
154 | | |
155 | | /* |
156 | | * Get the next operator from a Type 1 Charstring. This procedure handles |
157 | | * numbers, div, blend, pop, and callsubr/return. |
158 | | */ |
159 | | static int |
160 | | type1_next(gs_type1_state *pcis) |
161 | 105M | { |
162 | 105M | ip_state_t *ipsp = &pcis->ipstack[pcis->ips_count - 1]; |
163 | 105M | const byte *cip, *cipe; |
164 | 105M | crypt_state state; |
165 | 105M | #define CLEAR (csp = pcis->ostack - 1) |
166 | 105M | fixed *csp = (&pcis->ostack[pcis->os_count]) - 1; |
167 | 105M | const bool encrypted = pcis->pfont->data.lenIV >= 0; |
168 | 105M | int c, code, num_results, c0; |
169 | | |
170 | 114M | load: |
171 | 114M | cip = ipsp->ip; |
172 | 114M | cipe = ipsp->cs_data.bits.data + ipsp->cs_data.bits.size; |
173 | 114M | state = ipsp->dstate; |
174 | 382M | for (;;) { |
175 | 382M | if (cip >= cipe) |
176 | | /* We used to treat buffer overrun as a simple invalid font, now we assume that |
177 | | * there is an implicit endchar, so we return a particular error for later |
178 | | * interception. Returning an error allows any other code to continue as before. |
179 | | * Part of bug #693170 where the fonts are invalid (no endchar on some glyphs). |
180 | | */ |
181 | 439 | return_error(gs_error_unknownerror); |
182 | 382M | c0 = *cip++; |
183 | 382M | charstring_next(c0, state, c, encrypted); |
184 | 382M | if (c >= c_num1) { |
185 | | /* This is a number, decode it and push it on the stack. */ |
186 | 265M | if (c < c_pos2_0) { /* 1-byte number */ |
187 | 204M | decode_push_num1(csp, pcis->ostack, c); |
188 | 204M | } else if (c < cx_num4) { /* 2-byte number */ |
189 | 60.7M | decode_push_num2(csp, pcis->ostack, c, cip, state, encrypted); |
190 | 60.7M | } else if (c == cx_num4) { /* 4-byte number */ |
191 | 56.1k | long lw; |
192 | | |
193 | 56.1k | decode_num4(lw, cip, state, encrypted); |
194 | 56.1k | CS_CHECK_PUSH(csp, pcis->ostack); |
195 | 56.1k | *++csp = int2fixed(lw); |
196 | 56.1k | if (lw != fixed2long(*csp)) { |
197 | | /* |
198 | | * The integer was too large to handle in fixed point. |
199 | | * Handle this case specially. |
200 | | */ |
201 | 17 | code = gs_type1_check_float(&state, encrypted, &cip, csp, lw); |
202 | 17 | if (code < 0) |
203 | 17 | return code; |
204 | 17 | } |
205 | 56.1k | } else /* not possible */ |
206 | 0 | return_error(gs_error_invalidfont); |
207 | 265M | continue; |
208 | 265M | } |
209 | | #ifdef DEBUG |
210 | | if (gs_debug_c('1')) { |
211 | | const fixed *p; |
212 | | |
213 | | for (p = pcis->ostack; p <= csp; ++p) |
214 | | dmprintf1(pcis->pgs->memory, " %g", fixed2float(*p)); |
215 | | if (c == cx_escape) { |
216 | | crypt_state cstate = state; |
217 | | int cn; |
218 | | |
219 | | charstring_next(*cip, cstate, cn, encrypted); |
220 | | dmprintf1(pcis->pgs->memory, " [*%d]\n", cn); |
221 | | } else |
222 | | dmprintf1(pcis->pgs->memory, " [%d]\n", c); |
223 | | } |
224 | | #endif |
225 | 117M | switch ((char_command) c) { |
226 | 103M | default: |
227 | 103M | break; |
228 | 103M | case c_undef0: |
229 | 27 | case c_undef2: |
230 | 48 | case c_undef17: |
231 | 48 | return_error(gs_error_invalidfont); |
232 | 4.62M | case c_callsubr: |
233 | 4.62M | if (csp + 1 - &pcis->ostack[0] < 1) |
234 | 2 | return_error(gs_error_invalidfont); |
235 | 4.62M | code = type1_callsubr(pcis, fixed2int_var(*csp) + |
236 | 4.62M | pcis->pfont->data.subroutineNumberBias); |
237 | 4.62M | if (code < 0) |
238 | 8 | return_error(code); |
239 | 4.62M | ipsp->ip = cip, ipsp->dstate = state; |
240 | 4.62M | --csp; |
241 | 4.62M | ++ipsp; |
242 | 4.62M | goto load; |
243 | 4.62M | case c_return: |
244 | 4.62M | if (pcis->ips_count > 1) { |
245 | 4.62M | gs_glyph_data_free(&ipsp->cs_data, "type1_next"); |
246 | 4.62M | pcis->ips_count--; |
247 | 4.62M | --ipsp; |
248 | 4.62M | } else |
249 | 10 | return_error(gs_error_invalidfont); |
250 | 4.62M | goto load; |
251 | 4.62M | case c_undoc15: |
252 | | /* See gstype1.h for information on this opcode. */ |
253 | 61 | CLEAR; |
254 | 61 | continue; |
255 | 4.59M | case cx_escape: |
256 | 4.59M | charstring_next(*cip, state, c, encrypted); |
257 | 4.59M | ++cip; |
258 | 4.59M | switch ((char1_extended_command) c) { |
259 | 16.1k | default: |
260 | 16.1k | c += CE_OFFSET; |
261 | 16.1k | break; |
262 | 45.9k | case ce1_div: |
263 | 45.9k | if (csp + 1 - &pcis->ostack[0] < 1) |
264 | 0 | return_error(gs_error_invalidfont); |
265 | 45.9k | csp[-1] = float2fixed((double)csp[-1] / (double)*csp); |
266 | 45.9k | --csp; |
267 | 45.9k | continue; |
268 | 0 | case ce1_undoc15: /* see gstype1.h */ |
269 | 0 | CLEAR; |
270 | 0 | continue; |
271 | 2.28M | case ce1_callothersubr: |
272 | 2.28M | if (csp + 1 - &pcis->ostack[0] < 2) |
273 | 0 | return_error(gs_error_invalidfont); |
274 | 2.28M | switch (fixed2int_var(*csp)) { |
275 | 3.83k | case 0: |
276 | 3.83k | pcis->ignore_pops = 2; |
277 | 3.83k | break; /* pass to caller */ |
278 | 2.24M | case 3: |
279 | 2.24M | pcis->ignore_pops = 1; |
280 | 2.24M | break; /* pass to caller */ |
281 | 0 | case 14: |
282 | 0 | num_results = 1; goto blend; |
283 | 0 | case 15: |
284 | 0 | num_results = 2; goto blend; |
285 | 0 | case 16: |
286 | 0 | num_results = 3; goto blend; |
287 | 0 | case 17: |
288 | 0 | num_results = 4; goto blend; |
289 | 0 | case 18: |
290 | 0 | num_results = 6; |
291 | 0 | blend: |
292 | 0 | code = gs_type1_blend(pcis, csp, num_results); |
293 | 0 | if (code < 0) |
294 | 0 | return code; |
295 | 0 | csp -= code; |
296 | 0 | continue; |
297 | 30.7k | default: |
298 | 30.7k | break; /* pass to caller */ |
299 | 2.28M | } |
300 | 2.28M | break; |
301 | 2.28M | case ce1_pop: |
302 | 2.25M | if (pcis->ignore_pops != 0) { |
303 | 2.25M | pcis->ignore_pops--; |
304 | 2.25M | continue; |
305 | 2.25M | } |
306 | 4.59M | return_error(gs_error_rangecheck); |
307 | 4.59M | } |
308 | 2.29M | break; |
309 | 117M | } |
310 | 105M | break; |
311 | 117M | } |
312 | 105M | ipsp->ip = cip, ipsp->dstate = state; |
313 | 105M | pcis->ips_count = ipsp + 1 - &pcis->ipstack[0]; |
314 | 105M | pcis->os_count = csp + 1 - &pcis->ostack[0]; |
315 | 105M | return c; |
316 | 114M | } |
317 | | |
318 | | /* ------ Output ------ */ |
319 | | |
320 | | /* Put 2 or 4 bytes on a stream (big-endian). */ |
321 | | static void |
322 | | sputc2(stream *s, int i) |
323 | 28.2M | { |
324 | 28.2M | sputc(s, (byte)(i >> 8)); |
325 | 28.2M | sputc(s, (byte)i); |
326 | 28.2M | } |
327 | | static void |
328 | | sputc4(stream *s, int i) |
329 | 22.9k | { |
330 | 22.9k | sputc2(s, i >> 16); |
331 | 22.9k | sputc2(s, i); |
332 | 22.9k | } |
333 | | |
334 | | /* Put a Type 2 operator on a stream. */ |
335 | | static void |
336 | | type2_put_op(stream *s, int op) |
337 | 26.1M | { |
338 | 26.1M | if (op >= CE_OFFSET) { |
339 | 1.91k | spputc(s, cx_escape); |
340 | 1.91k | spputc(s, (byte)(op - CE_OFFSET)); |
341 | 1.91k | } else |
342 | 26.1M | sputc(s, (byte)op); |
343 | 26.1M | } |
344 | | |
345 | | /* Put a Type 2 number on a stream. */ |
346 | | static void |
347 | | type2_put_int(stream *s, int i) |
348 | 117M | { |
349 | 117M | if (i >= -107 && i <= 107) |
350 | 89.4M | sputc(s, (byte)(i + 139)); |
351 | 28.1M | else if (i <= 1131 && i >= 0) |
352 | 19.3M | sputc2(s, (c_pos2_0 << 8) + i - 108); |
353 | 8.84M | else if (i >= -1131 && i < 0) |
354 | 8.84M | sputc2(s, (c_neg2_0 << 8) - i - 108); |
355 | 6.00k | else if (i >= -32768 && i <= 32767) { |
356 | 6.00k | spputc(s, c2_shortint); |
357 | 6.00k | sputc2(s, i); |
358 | 6.00k | } else { |
359 | | /* |
360 | | * We can't represent this number directly: compute it. |
361 | | * (This can be done much more efficiently in particular cases; |
362 | | * we'll do this if it ever seems worthwhile.) |
363 | | */ |
364 | 0 | type2_put_int(s, i >> 10); |
365 | 0 | type2_put_int(s, 1024); |
366 | 0 | type2_put_op(s, CE_OFFSET + ce2_mul); |
367 | 0 | type2_put_int(s, i & 1023); |
368 | 0 | type2_put_op(s, CE_OFFSET + ce2_add); |
369 | 0 | } |
370 | 117M | } |
371 | | |
372 | | /* Put a fixed value on a stream. */ |
373 | | static void |
374 | | type2_put_fixed(stream *s, fixed v) |
375 | 117M | { |
376 | 117M | if (fixed_is_int(v)) |
377 | 117M | type2_put_int(s, fixed2int_var(v)); |
378 | 22.9k | else if (v >= int2fixed(-32768) && v < int2fixed(32768)) { |
379 | | /* We can represent this as a 16:16 number. */ |
380 | 22.9k | spputc(s, cx_num4); |
381 | 22.9k | sputc4(s, v << (16 - _fixed_shift)); |
382 | 22.9k | } else { |
383 | 0 | type2_put_int(s, fixed2int_var(v)); |
384 | 0 | type2_put_fixed(s, fixed_fraction(v)); |
385 | 0 | type2_put_op(s, CE_OFFSET + ce2_add); |
386 | 0 | } |
387 | 117M | } |
388 | | |
389 | | /* Put a stem hint table on a stream. */ |
390 | | static void |
391 | | type2_put_stems(stream *s, int os_count, const cv_stem_hint_table *psht, int op) |
392 | 4.17M | { |
393 | 4.17M | fixed prev = 0; |
394 | 4.17M | int pushed = os_count; |
395 | 4.17M | int i; |
396 | | |
397 | 12.9M | for (i = 0; i < psht->count; ++i, pushed += 2) { |
398 | 8.82M | fixed v0 = psht->data[i].v0; |
399 | 8.82M | fixed v1 = psht->data[i].v1; |
400 | | |
401 | 8.82M | if (pushed > ostack_size - 2) { |
402 | 0 | type2_put_op(s, op); |
403 | 0 | pushed = 0; |
404 | 0 | } |
405 | 8.82M | type2_put_fixed(s, v0 - prev); |
406 | 8.82M | type2_put_fixed(s, v1 - v0); |
407 | 8.82M | prev = v1; |
408 | 8.82M | } |
409 | 4.17M | type2_put_op(s, op); |
410 | 4.17M | } |
411 | | |
412 | | /* Put out a hintmask command. */ |
413 | | static void |
414 | | type2_put_hintmask(stream *s, const byte *mask, uint size) |
415 | 1.68M | { |
416 | 1.68M | uint ignore; |
417 | | |
418 | 1.68M | type2_put_op(s, c2_hintmask); |
419 | 1.68M | sputs(s, mask, size, &ignore); |
420 | 1.68M | } |
421 | | |
422 | | /* ------ Main program ------ */ |
423 | | |
424 | | /* |
425 | | * Convert a Type 1 Charstring to (unencrypted) Type 2. |
426 | | * For simplicity, we expand all Subrs in-line. |
427 | | * We still need to optimize the output using these patterns: |
428 | | * (vhcurveto hvcurveto)* (vhcurveto hrcurveto | vrcurveto) => |
429 | | * vhcurveto |
430 | | * (hvcurveto vhcurveto)* (hvcurveto vrcurveto | hrcurveto) => |
431 | | * hvcurveto |
432 | | */ |
433 | 27.0M | #define MAX_STACK ostack_size |
434 | | int |
435 | | psf_convert_type1_to_type2(stream *s, const gs_glyph_data_t *pgd, |
436 | | gs_font_type1 *pfont) |
437 | 2.49M | { |
438 | 2.49M | gs_type1_state cis; |
439 | 2.49M | cv_stem_hint_table hstem_hints; /* horizontal stem hints */ |
440 | 2.49M | cv_stem_hint_table vstem_hints; /* vertical stem hints */ |
441 | 2.49M | bool first = true; |
442 | 2.49M | bool need_moveto = true; |
443 | 2.49M | bool replace_hints = false; |
444 | 2.49M | bool hints_changed = false; |
445 | 2.49M | bool width_on_stack = false; |
446 | 2.49M | enum { |
447 | 2.49M | dotsection_in = 0, |
448 | 2.49M | dotsection_out = -1 |
449 | 2.49M | } dotsection_flag = dotsection_out; |
450 | 2.49M | byte active_hints[(max_total_stem_hints + 7) / 8]; |
451 | 2.49M | byte dot_save_hints[(max_total_stem_hints + 7) / 8]; |
452 | 2.49M | uint hintmask_size; |
453 | 2.49M | #define HINTS_CHANGED()\ |
454 | 12.8M | BEGIN\ |
455 | 12.8M | hints_changed = replace_hints;\ |
456 | 12.8M | if (hints_changed)\ |
457 | 12.8M | CHECK_OP(); /* see below */\ |
458 | 12.8M | END |
459 | 2.49M | #define CHECK_HINTS_CHANGED()\ |
460 | 21.0M | BEGIN\ |
461 | 21.0M | if (hints_changed) {\ |
462 | 1.68M | type2_put_hintmask(s, active_hints, hintmask_size);\ |
463 | 1.68M | hints_changed = false;\ |
464 | 1.68M | }\ |
465 | 21.0M | END |
466 | | /* |
467 | | * In order to combine Type 1 operators, we usually delay writing |
468 | | * out operators (but not their operands). We must keep track of |
469 | | * the stack depth so we don't exceed it when combining operators. |
470 | | */ |
471 | 2.49M | int depth; /* of operands on stack */ |
472 | 2.49M | int prev_op; /* operator to write, -1 if none */ |
473 | 2.49M | #define CLEAR_OP()\ |
474 | 20.3M | (depth = 0, prev_op = -1) |
475 | 2.49M | #define CHECK_OP()\ |
476 | 37.2M | BEGIN\ |
477 | 37.2M | if (prev_op >= 0) {\ |
478 | 17.8M | type2_put_op(s, prev_op);\ |
479 | 17.8M | CLEAR_OP();\ |
480 | 17.8M | }\ |
481 | 37.2M | END |
482 | 2.49M | fixed mx0 = 0, my0 = 0; /* See ce1_setcurrentpoint. */ |
483 | | |
484 | | /* Really this is to silence Coverity, but it makes sense and we do it a lot so no penatly */ |
485 | 2.49M | memset(active_hints, 0, (max_total_stem_hints + 7) / 8); |
486 | | |
487 | | /* In case we do not get an sbw or hsbw op */ |
488 | 2.49M | cis.lsb.x = cis.lsb.y = cis.width.x = cis.width.y = fixed_0; |
489 | | |
490 | | /* |
491 | | * Do a first pass to collect hints. Note that we must also process |
492 | | * [h]sbw, because the hint coordinates are relative to the lsb. |
493 | | */ |
494 | 2.49M | hstem_hints.count = hstem_hints.replaced_count = hstem_hints.current = 0; |
495 | 2.49M | vstem_hints.count = vstem_hints.replaced_count = vstem_hints.current = 0; |
496 | 2.49M | type1_next_init(&cis, pgd, pfont); |
497 | 52.7M | for (;;) { |
498 | 52.7M | int c = type1_next(&cis); |
499 | 52.7M | fixed *csp = (&cis.ostack[cis.os_count]) - 1; |
500 | | |
501 | 52.7M | switch (c) { |
502 | 34.8M | default: |
503 | | /* We used to treat buffer overrun as a simple invalid font, now we assume that |
504 | | * there is an implicit endchar, this is handled by looking for a specific error. |
505 | | * Part of bug #693170 where the fonts are invalid (no endchar on some glyphs). |
506 | | */ |
507 | 34.8M | if (c == gs_error_unknownerror) |
508 | 223 | break; |
509 | 34.8M | if (c < 0) |
510 | 85 | return c; |
511 | 34.8M | type1_clear(&cis); |
512 | 34.8M | continue; |
513 | 2.49M | case c1_hsbw: |
514 | 2.49M | if (cis.os_count < 2) |
515 | 5 | return_error(gs_error_invalidfont); |
516 | 2.49M | gs_type1_sbw(&cis, cis.ostack[0], fixed_0, cis.ostack[1], fixed_0); |
517 | 2.49M | goto clear; |
518 | 6.96M | case cx_hstem: |
519 | 6.96M | if (cis.os_count < 2) |
520 | 3 | return_error(gs_error_invalidfont); |
521 | 6.96M | type1_stem1(&cis, &hstem_hints, csp - 1, cis.lsb.y, NULL); |
522 | 6.96M | goto clear; |
523 | 4.79M | case cx_vstem: |
524 | 4.79M | if (cis.os_count < 2) |
525 | 6 | return_error(gs_error_invalidfont); |
526 | 4.79M | type1_stem1(&cis, &vstem_hints, csp - 1, cis.lsb.x, NULL); |
527 | 4.79M | goto clear; |
528 | 0 | case CE_OFFSET + ce1_sbw: |
529 | 0 | if (cis.os_count < 4) |
530 | 0 | return_error(gs_error_invalidfont); |
531 | 0 | gs_type1_sbw(&cis, cis.ostack[0], cis.ostack[1], |
532 | 0 | cis.ostack[2], cis.ostack[3]); |
533 | 0 | goto clear; |
534 | 5.99k | case CE_OFFSET + ce1_vstem3: |
535 | 5.99k | if (cis.os_count < 6) |
536 | 0 | return_error(gs_error_invalidfont); |
537 | 5.99k | type1_stem3(&cis, &vstem_hints, csp - 5, cis.lsb.x, NULL); |
538 | 5.99k | goto clear; |
539 | 9 | case CE_OFFSET + ce1_hstem3: |
540 | 9 | if (cis.os_count < 6) |
541 | 0 | return_error(gs_error_invalidfont); |
542 | 9 | type1_stem3(&cis, &hstem_hints, csp - 5, cis.lsb.y, NULL); |
543 | 14.2M | clear: |
544 | 14.2M | type1_clear(&cis); |
545 | 14.2M | continue; |
546 | 1.14M | case ce1_callothersubr: |
547 | 1.14M | if (cis.os_count < 2) |
548 | 2 | return_error(gs_error_invalidfont); |
549 | 1.14M | if (*csp == int2fixed(3)) |
550 | 1.12M | replace_hints = true; |
551 | 1.14M | if (*csp == int2fixed(12) || *csp == int2fixed(13)) |
552 | 0 | cis.os_count -= fixed2int(csp[-1]); |
553 | 1.14M | cis.os_count -= 2; |
554 | 1.14M | continue; |
555 | 162 | case CE_OFFSET + ce1_dotsection: |
556 | 162 | replace_hints = true; |
557 | 162 | continue; |
558 | 0 | case CE_OFFSET + ce1_seac: |
559 | 0 | if (cis.os_count < 5) |
560 | 0 | return_error(gs_error_invalidfont); |
561 | 2.49M | case cx_endchar: |
562 | 2.49M | break; |
563 | 52.7M | } |
564 | 2.49M | break; |
565 | 52.7M | } |
566 | | /* |
567 | | * Number the hints for hintmask. We must do this even if we never |
568 | | * replace hints, because type1_stem# uses the index to set bits in |
569 | | * active_hints. |
570 | | */ |
571 | 2.49M | { |
572 | 2.49M | int i; |
573 | | |
574 | 7.96M | for (i = 0; i < hstem_hints.count; ++i) |
575 | 5.47M | hstem_hints.data[i].index = i; |
576 | 5.84M | for (i = 0; i < vstem_hints.count; ++i) |
577 | 3.35M | vstem_hints.data[i].index = i + hstem_hints.count; |
578 | 2.49M | } |
579 | 2.49M | if (replace_hints) { |
580 | 563k | hintmask_size = |
581 | 563k | (hstem_hints.count + vstem_hints.count + 7) / 8; |
582 | 563k | memset(active_hints, 0, hintmask_size); |
583 | 563k | } else |
584 | 1.92M | hintmask_size = 0; |
585 | | |
586 | | /* Do a second pass to write the result. */ |
587 | 2.49M | type1_next_init(&cis, pgd, pfont); |
588 | 2.49M | CLEAR_OP(); |
589 | 52.7M | for (;;) { |
590 | 52.7M | int c = type1_next(&cis); |
591 | 52.7M | fixed *csp = (&cis.ostack[cis.os_count]) - 1; |
592 | 52.7M | #define POP(n)\ |
593 | 52.7M | (csp -= (n), cis.os_count -= (n)) |
594 | 52.7M | int i; |
595 | 52.7M | fixed mx, my; |
596 | | |
597 | 52.7M | if (need_moveto && ((c >= cx_rlineto && c <= cx_rrcurveto) || |
598 | 17.0M | c == cx_vhcurveto || c == cx_hvcurveto)) |
599 | 0 | { |
600 | 0 | mx = my = 0; |
601 | 0 | need_moveto = false; |
602 | 0 | CHECK_OP(); |
603 | 0 | if (first) { |
604 | 0 | if (width_on_stack) { |
605 | 0 | type2_put_fixed(s, *csp); /* width */ |
606 | | /* We need to move all the stored numeric values up by |
607 | | * one in the stack, eliminating the width, so that later |
608 | | * processing when we handle the drswing operator emits the correct |
609 | | * values. This is different to the 'move' case below. |
610 | | */ |
611 | 0 | cis.os_count--; |
612 | 0 | for (i = 0; i < cis.os_count; ++i) |
613 | 0 | cis.ostack[i] = cis.ostack[i+1]; |
614 | 0 | } |
615 | 0 | mx += cis.lsb.x + mx0, my += cis.lsb.y + my0; |
616 | 0 | first = false; |
617 | 0 | } |
618 | 0 | CHECK_HINTS_CHANGED(); |
619 | 0 | if (mx == 0) { |
620 | 0 | type2_put_fixed(s, my); |
621 | 0 | depth = 1, prev_op = cx_vmoveto; |
622 | 0 | } else if (my == 0) { |
623 | 0 | type2_put_fixed(s, mx); |
624 | 0 | depth = 1, prev_op = cx_hmoveto; |
625 | 0 | } else { |
626 | 0 | type2_put_fixed(s, mx); |
627 | 0 | type2_put_fixed(s, my); |
628 | 0 | depth = 2, prev_op = cx_rmoveto; |
629 | 0 | } |
630 | 0 | } |
631 | | |
632 | 52.7M | switch (c) { |
633 | 412 | default: |
634 | | /* We used to treat buffer overrun as a simple invalid font, now we assume that |
635 | | * there is an implicit endchar, this is handled by looking for a specific error. |
636 | | * Part of bug #693170 where the fonts are invalid (no endchar on some glyphs). |
637 | | */ |
638 | 412 | if (c == gs_error_unknownerror) { |
639 | 216 | type2_put_op(s, cx_endchar); |
640 | 216 | return 0; |
641 | 216 | } |
642 | 196 | if (c < 0) |
643 | 0 | return c; |
644 | 196 | if (c >= CE_OFFSET) |
645 | 1 | return_error(gs_error_rangecheck); |
646 | | /* The Type 1 use of all other operators is the same in Type 2. */ |
647 | 14.6M | copy: |
648 | 14.6M | CHECK_OP(); |
649 | 14.6M | CHECK_HINTS_CHANGED(); |
650 | 28.3M | put: |
651 | 119M | for (i = 0; i < cis.os_count; ++i) |
652 | 91.5M | type2_put_fixed(s, cis.ostack[i]); |
653 | 28.3M | depth += cis.os_count; |
654 | 28.3M | prev_op = c; |
655 | 28.3M | type1_clear(&cis); |
656 | 28.3M | continue; |
657 | 6.96M | case cx_hstem: |
658 | 6.96M | if (cis.os_count < 2) |
659 | 0 | return_error(gs_error_invalidfont); |
660 | 6.96M | type1_stem1(&cis, &hstem_hints, csp - 1, cis.lsb.y, active_hints); |
661 | 11.7M | hint: |
662 | 11.7M | HINTS_CHANGED(); |
663 | 11.7M | type1_clear(&cis); |
664 | 11.7M | continue; |
665 | 4.79M | case cx_vstem: |
666 | 4.79M | if (cis.os_count < 2) |
667 | 0 | return_error(gs_error_invalidfont); |
668 | 4.79M | type1_stem1(&cis, &vstem_hints, csp - 1, cis.lsb.x, active_hints); |
669 | 4.79M | goto hint; |
670 | 5.99k | case CE_OFFSET + ce1_vstem3: |
671 | 5.99k | if (cis.os_count < 6) |
672 | 0 | return_error(gs_error_invalidfont); |
673 | 5.99k | type1_stem3(&cis, &vstem_hints, csp - 5, cis.lsb.x, active_hints); |
674 | 5.99k | goto hint; |
675 | 9 | case CE_OFFSET + ce1_hstem3: |
676 | 9 | if (cis.os_count < 6) |
677 | 0 | return_error(gs_error_invalidfont); |
678 | 9 | type1_stem3(&cis, &hstem_hints, csp - 5, cis.lsb.y, active_hints); |
679 | 9 | goto hint; |
680 | 162 | case CE_OFFSET + ce1_dotsection: |
681 | 162 | if (dotsection_flag == dotsection_out) { |
682 | 90 | memcpy(dot_save_hints, active_hints, hintmask_size); |
683 | 90 | memset(active_hints, 0, hintmask_size); |
684 | 90 | dotsection_flag = dotsection_in; |
685 | 90 | } else { |
686 | 72 | memcpy(active_hints, dot_save_hints, hintmask_size); |
687 | 72 | dotsection_flag = dotsection_out; |
688 | 72 | } |
689 | 162 | HINTS_CHANGED(); |
690 | 162 | continue; |
691 | 3.23M | case c1_closepath: |
692 | 3.23M | need_moveto = true; |
693 | 3.23M | continue; |
694 | 1.91k | case CE_OFFSET + ce1_setcurrentpoint: |
695 | 1.91k | if (first) { |
696 | | /* A workaround for fonts which use ce1_setcurrentpoint |
697 | | in an illegal way for shifting a path. |
698 | | See t1_hinter__setcurrentpoint for more information. */ |
699 | 0 | mx0 = csp[-1], my0 = *csp; |
700 | 0 | } |
701 | 1.91k | continue; |
702 | 557k | case cx_vmoveto: |
703 | 557k | if (cis.os_count < 1) |
704 | 0 | return_error(gs_error_invalidfont); |
705 | 557k | mx = 0, my = *csp; |
706 | 557k | POP(1); goto move; |
707 | 159k | case cx_hmoveto: |
708 | 159k | if (cis.os_count < 1) |
709 | 1 | return_error(gs_error_invalidfont); |
710 | 159k | mx = *csp, my = 0; |
711 | 159k | POP(1); goto move; |
712 | 2.53M | case cx_rmoveto: |
713 | 2.53M | if (cis.os_count < 2) |
714 | 1 | return_error(gs_error_invalidfont); |
715 | 2.53M | mx = csp[-1], my = *csp; |
716 | 2.53M | POP(2); |
717 | 3.25M | move: |
718 | 3.25M | need_moveto = false; |
719 | 3.25M | CHECK_OP(); |
720 | 3.25M | if (first) { |
721 | 2.30M | if (cis.os_count) |
722 | 14.8k | type2_put_fixed(s, *csp); /* width */ |
723 | 2.30M | mx += cis.lsb.x + mx0, my += cis.lsb.y + my0; |
724 | 2.30M | first = false; |
725 | 2.30M | } |
726 | 3.25M | if (cis.flex_count != flex_max) { |
727 | | /* We're accumulating points for a flex. */ |
728 | 13.4k | if (type1_next(&cis) != ce1_callothersubr) |
729 | 0 | return_error(gs_error_rangecheck); |
730 | 13.4k | csp = &cis.ostack[cis.os_count - 1]; |
731 | 13.4k | if (*csp != int2fixed(2) || csp[-1] != fixed_0) |
732 | 0 | return_error(gs_error_rangecheck); |
733 | 13.4k | cis.flex_count++; |
734 | 13.4k | csp[-1] = mx, *csp = my; |
735 | 13.4k | continue; |
736 | 13.4k | } |
737 | 3.25M | CHECK_HINTS_CHANGED(); |
738 | 3.23M | if (mx == 0) { |
739 | 235k | type2_put_fixed(s, my); |
740 | 235k | depth = 1, prev_op = cx_vmoveto; |
741 | 3.00M | } else if (my == 0) { |
742 | 217k | type2_put_fixed(s, mx); |
743 | 217k | depth = 1, prev_op = cx_hmoveto; |
744 | 2.78M | } else { |
745 | 2.78M | type2_put_fixed(s, mx); |
746 | 2.78M | type2_put_fixed(s, my); |
747 | 2.78M | depth = 2, prev_op = cx_rmoveto; |
748 | 2.78M | } |
749 | 3.23M | type1_clear(&cis); |
750 | 3.23M | continue; |
751 | 2.49M | case c1_hsbw: |
752 | 2.49M | if (cis.os_count < 2) |
753 | 0 | return_error(gs_error_invalidfont); |
754 | 2.49M | gs_type1_sbw(&cis, cis.ostack[0], fixed_0, cis.ostack[1], fixed_0); |
755 | | /* |
756 | | * Leave the l.s.b. on the operand stack for the initial hint, |
757 | | * moveto, or endchar command. |
758 | | */ |
759 | 2.49M | cis.ostack[0] = cis.ostack[1]; |
760 | 2.49M | sbw: |
761 | | /* cff_write_Private doesn't write defaultWidthX |
762 | | when called with the Type 1 font, |
763 | | so the reader will assume |
764 | | defaultWidthX = defaultWidthX_DEFAULT |
765 | | Use the latter here. |
766 | | */ |
767 | 2.49M | if (cis.ostack[0] == default_defaultWidthX) |
768 | 3.15k | cis.os_count = 0; |
769 | 2.48M | else { |
770 | 2.48M | cis.ostack[0] -= default_defaultWidthX; |
771 | 2.48M | cis.os_count = 1; |
772 | 2.48M | width_on_stack = true; |
773 | 2.48M | } |
774 | 2.49M | if (hstem_hints.count) { |
775 | 2.26M | if (cis.os_count) |
776 | 2.26M | type2_put_fixed(s, cis.ostack[0]); |
777 | 2.26M | type2_put_stems(s, cis.os_count, &hstem_hints, |
778 | 2.26M | (replace_hints ? c2_hstemhm : cx_hstem)); |
779 | 2.26M | cis.os_count = 0; |
780 | 2.26M | width_on_stack = false; |
781 | 2.26M | } |
782 | 2.49M | if (vstem_hints.count) { |
783 | 1.90M | if (cis.os_count) |
784 | 21.5k | type2_put_fixed(s, cis.ostack[0]); |
785 | 1.90M | type2_put_stems(s, cis.os_count, &vstem_hints, |
786 | 1.90M | (replace_hints ? c2_vstemhm : cx_vstem)); |
787 | 1.90M | cis.os_count = 0; |
788 | 1.90M | width_on_stack = false; |
789 | 1.90M | } |
790 | 2.49M | continue; |
791 | 0 | case CE_OFFSET + ce1_seac: |
792 | 0 | if (cis.os_count < 5) |
793 | 0 | return_error(gs_error_invalidfont); |
794 | | /* |
795 | | * It is an undocumented feature of the Type 2 CharString |
796 | | * format that endchar + 4 or 5 operands is equivalent to |
797 | | * seac with an implicit asb operand + endchar with 0 or 1 |
798 | | * operands. Remove the asb argument from the stack, but |
799 | | * adjust the adx argument to compensate for the fact that |
800 | | * Type 2 CharStrings don't have any concept of l.s.b. |
801 | | */ |
802 | 0 | csp[-3] += cis.lsb.x - csp[-4]; |
803 | 0 | memmove(csp - 4, csp - 3, sizeof(*csp) * 4); |
804 | 0 | POP(1); |
805 | | /* (falls through) */ |
806 | 2.49M | case cx_endchar: |
807 | 2.49M | CHECK_OP(); |
808 | 2.67M | for (i = 0; i < cis.os_count; ++i) |
809 | 183k | type2_put_fixed(s, cis.ostack[i]); |
810 | 2.49M | type2_put_op(s, cx_endchar); |
811 | 2.49M | return 0; |
812 | 0 | case CE_OFFSET + ce1_sbw: |
813 | 0 | if (cis.os_count < 4) |
814 | 0 | return_error(gs_error_invalidfont); |
815 | 0 | gs_type1_sbw(&cis, cis.ostack[0], cis.ostack[1], |
816 | 0 | cis.ostack[2], cis.ostack[3]); |
817 | 0 | cis.ostack[0] = cis.ostack[2]; |
818 | 0 | goto sbw; |
819 | 1.12M | case ce1_callothersubr: |
820 | 1.12M | if (cis.os_count < 2) |
821 | 0 | return_error(gs_error_invalidfont); |
822 | 1.12M | CHECK_OP(); |
823 | 1.12M | switch (fixed2int_var(*csp)) { |
824 | 2 | default: |
825 | 2 | return_error(gs_error_rangecheck); |
826 | 1.91k | case 0: |
827 | | /* |
828 | | * The operand stack contains: delta to reference point, |
829 | | * 6 deltas for the two curves, fd, final point, 3, 0. |
830 | | */ |
831 | 1.91k | csp[-18] += csp[-16], csp[-17] += csp[-15]; |
832 | 1.91k | memmove(csp - 16, csp - 14, sizeof(*csp) * 11); |
833 | 1.91k | cis.os_count -= 6, csp -= 6; |
834 | | /* |
835 | | * We could optimize by using [h]flex[1], |
836 | | * but it isn't worth the trouble. |
837 | | */ |
838 | 1.91k | c = CE_OFFSET + ce2_flex; |
839 | 1.91k | cis.flex_count = flex_max; /* not inside flex */ |
840 | 1.91k | cis.ignore_pops = 2; |
841 | 1.91k | goto copy; |
842 | 1.91k | case 1: |
843 | 1.91k | cis.flex_count = 0; |
844 | 1.91k | cis.os_count -= 2; |
845 | 1.91k | continue; |
846 | | /*case 2:*/ /* detected in *moveto */ |
847 | 1.12M | case 3: |
848 | 1.12M | memset(active_hints, 0, hintmask_size); |
849 | 1.12M | HINTS_CHANGED(); |
850 | 1.12M | cis.ignore_pops = 1; |
851 | 1.12M | cis.os_count -= 2; |
852 | 1.12M | continue; |
853 | 0 | case 12: |
854 | 0 | case 13: |
855 | | /* Counter control is not implemented. */ |
856 | 0 | cis.os_count -= 2 + fixed2int(csp[-1]); |
857 | 0 | continue; |
858 | 1.12M | } |
859 | | /* |
860 | | * The remaining cases are strictly for optimization. |
861 | | */ |
862 | 2.84M | case cx_rlineto: |
863 | 2.84M | if (cis.os_count < 2) |
864 | 1 | return_error(gs_error_invalidfont); |
865 | 2.84M | if (depth > MAX_STACK - 2) |
866 | 970 | goto copy; |
867 | 2.84M | switch (prev_op) { |
868 | 670k | case cx_rlineto: /* rlineto+ => rlineto */ |
869 | 670k | goto put; |
870 | 306k | case cx_rrcurveto: /* rrcurveto+ rlineto => rcurveline */ |
871 | 306k | c = c2_rcurveline; |
872 | 306k | goto put; |
873 | 1.86M | default: |
874 | 1.86M | goto copy; |
875 | 2.84M | } |
876 | 5.54M | case cx_hlineto: /* hlineto (vlineto hlineto)* [vlineto] => hlineto */ |
877 | 5.54M | if (cis.os_count < 1) |
878 | 0 | return_error(gs_error_invalidfont); |
879 | 5.54M | if (depth > MAX_STACK - 1 || |
880 | 5.54M | prev_op != (depth & 1 ? cx_vlineto : cx_hlineto)) |
881 | 2.87M | goto copy; |
882 | 2.67M | c = prev_op; |
883 | 2.67M | goto put; |
884 | 5.09M | case cx_vlineto: /* vlineto (hlineto vlineto)* [hlineto] => vlineto */ |
885 | 5.09M | if (cis.os_count < 1) |
886 | 0 | return_error(gs_error_invalidfont); |
887 | 5.09M | if (depth > MAX_STACK - 1 || |
888 | 5.09M | prev_op != (depth & 1 ? cx_hlineto : cx_vlineto)) |
889 | 2.45M | goto copy; |
890 | 2.63M | c = prev_op; |
891 | 2.63M | goto put; |
892 | 2.88M | case cx_hvcurveto: /* hvcurveto (vhcurveto hvcurveto)* => hvcurveto */ |
893 | | /* (vhcurveto hvcurveto)+ => vhcurveto */ |
894 | 2.88M | if (cis.os_count < 4) |
895 | 1 | return_error(gs_error_invalidfont); |
896 | | /* |
897 | | * We have to check (depth & 1) because the last curve might |
898 | | * have 5 parameters rather than 4 (see rrcurveto below). |
899 | | */ |
900 | 2.88M | if ((depth & 1) || depth > MAX_STACK - 4 || |
901 | 2.54M | prev_op != (depth & 4 ? cx_vhcurveto : cx_hvcurveto)) |
902 | 1.98M | goto copy; |
903 | 905k | c = prev_op; |
904 | 905k | goto put; |
905 | 3.05M | case cx_vhcurveto: /* vhcurveto (hvcurveto vhcurveto)* => vhcurveto */ |
906 | | /* (hvcurveto vhcurveto)+ => hvcurveto */ |
907 | 3.05M | if (cis.os_count < 4) |
908 | 2 | return_error(gs_error_invalidfont); |
909 | | /* See above re the (depth & 1) check. */ |
910 | 3.05M | if ((depth & 1) || depth > MAX_STACK - 4 || |
911 | 2.56M | prev_op != (depth & 4 ? cx_hvcurveto : cx_vhcurveto)) |
912 | 1.41M | goto copy; |
913 | 1.64M | c = prev_op; |
914 | 1.64M | goto put; |
915 | 8.90M | case cx_rrcurveto: |
916 | 8.90M | if (cis.os_count < 6) |
917 | 1 | return_error(gs_error_invalidfont); |
918 | 8.90M | if (depth == 0) { |
919 | 463k | if (csp[-1] == 0) { |
920 | | /* A|0 B C D 0 F rrcurveto => [A] B C D F vvcurveto */ |
921 | 88.4k | c = c2_vvcurveto; |
922 | 88.4k | csp[-1] = csp[0]; |
923 | 88.4k | if (csp[-5] == 0) { |
924 | 9 | memmove(csp - 5, csp - 4, sizeof(*csp) * 4); |
925 | 9 | POP(2); |
926 | 9 | } else |
927 | 88.4k | POP(1); |
928 | 374k | } else if (*csp == 0) { |
929 | | /* A B|0 C D E 0 rrcurveto => [B] A C D E hhcurveto */ |
930 | 193k | c = c2_hhcurveto; |
931 | 193k | if (csp[-4] == 0) { |
932 | 110 | memmove(csp - 4, csp - 3, sizeof(*csp) * 3); |
933 | 110 | POP(2); |
934 | 193k | } else { |
935 | 193k | *csp = csp[-5], csp[-5] = csp[-4], csp[-4] = *csp; |
936 | 193k | POP(1); |
937 | 193k | } |
938 | 193k | } |
939 | | /* |
940 | | * We could also optimize: |
941 | | * 0 B C D E F|0 rrcurveto => B C D E [F] vhcurveto |
942 | | * A 0 C D E|0 F rrcurveto => A C D F [E] hvcurveto |
943 | | * but this gets in the way of subsequent optimization |
944 | | * of multiple rrcurvetos, so we don't do it. |
945 | | */ |
946 | 463k | goto copy; |
947 | 463k | } |
948 | 8.44M | if (depth > MAX_STACK - 6) |
949 | 4.28k | goto copy; |
950 | 8.44M | switch (prev_op) { |
951 | 85.7k | case c2_hhcurveto: /* hrcurveto (x1 0 x2 y2 x3 0 rrcurveto)* => */ |
952 | | /* hhcurveto */ |
953 | 85.7k | if (csp[-4] == 0 && *csp == 0) { |
954 | 0 | memmove(csp - 4, csp - 3, sizeof(*csp) * 3); |
955 | 0 | c = prev_op; |
956 | 0 | POP(2); |
957 | 0 | goto put; |
958 | 0 | } |
959 | 85.7k | goto copy; |
960 | 85.7k | case c2_vvcurveto: /* rvcurveto (0 y1 x2 y2 0 y3 rrcurveto)* => */ |
961 | | /* vvcurveto */ |
962 | 34.0k | if (csp[-5] == 0 && csp[-1] == 0) { |
963 | 0 | memmove(csp - 5, csp - 4, sizeof(*csp) * 3); |
964 | 0 | csp[-2] = *csp; |
965 | 0 | c = prev_op; |
966 | 0 | POP(2); |
967 | 0 | goto put; |
968 | 0 | } |
969 | 34.0k | goto copy; |
970 | 1.24M | case cx_hvcurveto: |
971 | 1.24M | if (depth & 1) |
972 | 318k | goto copy; |
973 | 929k | if (!(depth & 4)) |
974 | 456k | goto hrc; |
975 | 582k | vrc: /* (vhcurveto hvcurveto)+ vrcurveto => vhcurveto */ |
976 | | /* hvcurveto (vhcurveto hvcurveto)* vrcurveto => hvcurveto */ |
977 | 582k | if (csp[-5] != 0) |
978 | 3.08k | goto copy; |
979 | 579k | memmove(csp - 5, csp - 4, sizeof(*csp) * 5); |
980 | 579k | c = prev_op; |
981 | 579k | POP(1); |
982 | 579k | goto put; |
983 | 1.30M | case cx_vhcurveto: |
984 | 1.30M | if (depth & 1) |
985 | 414k | goto copy; |
986 | 885k | if (!(depth & 4)) |
987 | 110k | goto vrc; |
988 | 1.23M | hrc: /* (hvcurveto vhcurveto)+ hrcurveto => hvcurveto */ |
989 | | /* vhcurveto (hvcurveto vhcurveto)* hrcurveto => vhcurveto */ |
990 | 1.23M | if (csp[-4] != 0) |
991 | 9.82k | goto copy; |
992 | | /* A 0 C D E F => A C D F E */ |
993 | 1.22M | memmove(csp - 4, csp - 3, sizeof(*csp) * 2); |
994 | 1.22M | csp[-2] = *csp; |
995 | 1.22M | c = prev_op; |
996 | 1.22M | POP(1); |
997 | 1.22M | goto put; |
998 | 512k | case cx_rlineto: /* rlineto+ rrcurveto => rlinecurve */ |
999 | 512k | c = c2_rlinecurve; |
1000 | 512k | goto put; |
1001 | 2.58M | case cx_rrcurveto: /* rrcurveto+ => rrcurveto */ |
1002 | 2.58M | goto put; |
1003 | 2.67M | default: |
1004 | 2.67M | goto copy; |
1005 | 8.44M | } |
1006 | 52.7M | } |
1007 | 52.7M | } |
1008 | 2.49M | } |