/src/ghostpdl/pdf/pdf_path.c
Line | Count | Source |
1 | | /* Copyright (C) 2018-2026 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 | | /* Path operations for the PDF interpreter */ |
17 | | |
18 | | #include "pdf_int.h" |
19 | | #include "pdf_font_types.h" |
20 | | #include "pdf_gstate.h" |
21 | | #include "pdf_path.h" |
22 | | #include "pdf_stack.h" |
23 | | #include "pdf_trans.h" |
24 | | #include "gstypes.h" |
25 | | #include "pdf_optcontent.h" |
26 | | #include "gspath.h" /* For gs_moveto() and friends */ |
27 | | #include "gspaint.h" /* For gs_fill() and friends */ |
28 | | #include "gxdevsop.h" /* For special ops */ |
29 | | |
30 | | typedef enum path_segment_e { |
31 | | pdfi_moveto_seg, |
32 | | pdfi_lineto_seg, |
33 | | pdfi_curveto_seg, |
34 | | pdfi_re_seg, |
35 | | pdfi_v_curveto_seg, |
36 | | pdfi_y_curveto_seg, |
37 | | pdfi_closepath_seg |
38 | | } pdfi_path_segment; |
39 | | |
40 | | static int StorePathSegment(pdf_context *ctx, pdfi_path_segment segment, double *pts) |
41 | 25.8M | { |
42 | 25.8M | int size = 0; |
43 | 25.8M | path_record *PathRecord; |
44 | | |
45 | 25.8M | switch (segment) |
46 | 25.8M | { |
47 | 4.48M | case pdfi_moveto_seg: |
48 | 14.1M | case pdfi_lineto_seg: |
49 | 14.1M | size = 2; |
50 | 14.1M | break; |
51 | 2.23M | case pdfi_re_seg: |
52 | 2.37M | case pdfi_v_curveto_seg: |
53 | 2.51M | case pdfi_y_curveto_seg: |
54 | 2.51M | size = 4; |
55 | 2.51M | break; |
56 | 8.69M | case pdfi_curveto_seg: |
57 | 8.69M | size = 6; |
58 | 8.69M | break; |
59 | 532k | case pdfi_closepath_seg: |
60 | 532k | break; |
61 | 0 | default: |
62 | 0 | return_error(gs_error_undefined); |
63 | 0 | break; |
64 | 25.8M | } |
65 | 25.8M | if (ctx->PathRecord == NULL) { |
66 | 4.80M | ctx->PathRecord = (path_record *)gs_alloc_bytes(ctx->memory, sizeof(path_record), "StorePathSegment"); |
67 | 4.80M | if (ctx->PathRecord == NULL) |
68 | 0 | return_error(gs_error_VMerror); |
69 | 4.80M | memset(ctx->PathRecord, 0x00, sizeof(path_record)); |
70 | 4.80M | } |
71 | 25.8M | PathRecord = ctx->PathRecord; |
72 | | |
73 | 25.8M | if (PathRecord->PathSegments == NULL) { |
74 | 4.80M | PathRecord->PathSegments = (char *)gs_alloc_bytes(ctx->memory, 1024, "StorePathSegment"); |
75 | 4.80M | if (PathRecord->PathSegments == NULL) |
76 | 0 | return_error(gs_error_VMerror); |
77 | 4.80M | PathRecord->PathSegmentsCurrent = PathRecord->PathSegments; |
78 | 4.80M | PathRecord->PathSegmentsTop = PathRecord->PathSegments + 1024; |
79 | 4.80M | } |
80 | 25.8M | if (PathRecord->PathSegmentsCurrent == PathRecord->PathSegmentsTop) { |
81 | 1.54k | char *new_accumulator = NULL; |
82 | 1.54k | uint64_t old_size; |
83 | | |
84 | 1.54k | old_size = PathRecord->PathSegmentsCurrent - PathRecord->PathSegments; |
85 | 1.54k | new_accumulator = (char *)gs_alloc_bytes(ctx->memory, old_size + 1024, "StorePathSegment"); |
86 | 1.54k | if (new_accumulator == NULL) |
87 | 0 | return_error(gs_error_VMerror); |
88 | 1.54k | memcpy(new_accumulator, PathRecord->PathSegments, old_size); |
89 | 1.54k | PathRecord->PathSegmentsCurrent = new_accumulator + old_size; |
90 | 1.54k | gs_free_object(ctx->memory, PathRecord->PathSegments, "StorePathSegment"); |
91 | 1.54k | PathRecord->PathSegments = new_accumulator; |
92 | 1.54k | PathRecord->PathSegmentsTop = PathRecord->PathSegments + old_size + 1024; |
93 | 1.54k | } |
94 | | |
95 | 25.8M | if (PathRecord->PathPts == NULL) { |
96 | 4.80M | PathRecord->PathPts = (double *)gs_alloc_bytes(ctx->memory, 4096, "StorePathSegment"); |
97 | 4.80M | if (PathRecord->PathPts == NULL) |
98 | 0 | return_error(gs_error_VMerror); |
99 | 4.80M | PathRecord->PathPtsCurrent = PathRecord->PathPts; |
100 | 4.80M | PathRecord->PathPtsTop = PathRecord->PathPts + (4096 / sizeof(double)); |
101 | 4.80M | } |
102 | 25.8M | if (PathRecord->PathPtsCurrent + size > PathRecord->PathPtsTop) { |
103 | 25.1k | double *new_accumulator = NULL; |
104 | 25.1k | uint64_t old_size; |
105 | | |
106 | 25.1k | old_size = (char *)PathRecord->PathPtsCurrent - (char *)PathRecord->PathPts; |
107 | 25.1k | new_accumulator = (double *)gs_alloc_bytes(ctx->memory, old_size + 4096, "StorePathSegment"); |
108 | 25.1k | if (new_accumulator == NULL) |
109 | 0 | return_error(gs_error_VMerror); |
110 | 25.1k | memcpy(new_accumulator, PathRecord->PathPts, old_size); |
111 | 25.1k | PathRecord->PathPtsCurrent = new_accumulator + (old_size / sizeof(double)); |
112 | 25.1k | gs_free_object(ctx->memory, PathRecord->PathPts, "StorePathSegment"); |
113 | 25.1k | PathRecord->PathPts = new_accumulator; |
114 | 25.1k | PathRecord->PathPtsTop = PathRecord->PathPts + ((old_size + 4096) / sizeof(double)); |
115 | 25.1k | } |
116 | | |
117 | 25.8M | *(PathRecord->PathSegmentsCurrent++) = (char)segment; |
118 | 25.8M | switch (segment) |
119 | 25.8M | { |
120 | 4.48M | case pdfi_moveto_seg: |
121 | 14.1M | case pdfi_lineto_seg: |
122 | 14.1M | memcpy(PathRecord->PathPtsCurrent, pts, 2 * sizeof(double)); |
123 | 14.1M | PathRecord->PathPtsCurrent += 2; |
124 | 14.1M | break; |
125 | 2.23M | case pdfi_re_seg: |
126 | 2.37M | case pdfi_v_curveto_seg: |
127 | 2.51M | case pdfi_y_curveto_seg: |
128 | 2.51M | memcpy(PathRecord->PathPtsCurrent, pts, 4 * sizeof(double)); |
129 | 2.51M | PathRecord->PathPtsCurrent += 4; |
130 | 2.51M | break; |
131 | 8.69M | case pdfi_curveto_seg: |
132 | 8.69M | memcpy(PathRecord->PathPtsCurrent, pts, 6 * sizeof(double)); |
133 | 8.69M | PathRecord->PathPtsCurrent += 6; |
134 | 8.69M | break; |
135 | 532k | case pdfi_closepath_seg: |
136 | 532k | break; |
137 | 25.8M | } |
138 | 25.8M | return 0; |
139 | 25.8M | } |
140 | | |
141 | | int FreePathRecord (pdf_context *ctx) |
142 | 4.90M | { |
143 | 4.90M | path_record *PathRecord; |
144 | | |
145 | 4.90M | if (ctx->PathRecord == NULL) |
146 | 102k | return 0; |
147 | | |
148 | 4.80M | PathRecord = ctx->PathRecord; |
149 | | |
150 | 4.80M | gs_free_object(ctx->memory, PathRecord->PathSegments, "FreePathRecord"); |
151 | 4.80M | PathRecord->PathSegmentsTop = PathRecord->PathSegmentsCurrent = PathRecord->PathSegments = NULL; |
152 | 4.80M | gs_free_object(ctx->memory, PathRecord->PathPts, "FreePathRecord"); |
153 | 4.80M | PathRecord->PathPtsTop = PathRecord->PathPtsCurrent = PathRecord->PathPts = NULL; |
154 | 4.80M | gs_free_object(ctx->memory, PathRecord, "FreePathRecord"); |
155 | 4.80M | ctx->PathRecord = NULL; |
156 | | |
157 | 4.80M | return 0; |
158 | 4.90M | } |
159 | | |
160 | | static int ApplyStoredPath(pdf_context *ctx) |
161 | 5.12M | { |
162 | 5.12M | int code = 0; |
163 | 5.12M | char *op = NULL; |
164 | 5.12M | double *dpts = NULL; |
165 | 5.12M | double *current; |
166 | 5.12M | path_record *PathRecord; |
167 | | |
168 | 5.12M | if (ctx->PathRecord == NULL) |
169 | 403k | return 0; |
170 | | |
171 | 4.71M | PathRecord = ctx->PathRecord; |
172 | | |
173 | 4.71M | if (PathRecord->PathSegments == NULL) { |
174 | 0 | code = gs_note_error(gs_error_unknownerror); |
175 | 0 | goto error; |
176 | 0 | } |
177 | | |
178 | 4.71M | if (PathRecord->PathPts == NULL) { |
179 | 0 | code = gs_note_error(gs_error_unknownerror); |
180 | 0 | goto error; |
181 | 0 | } |
182 | | |
183 | 4.71M | if (ctx->pgs->current_point_valid) { |
184 | 125k | code = gs_newpath(ctx->pgs); |
185 | 125k | if (code < 0) |
186 | 0 | goto error; |
187 | 125k | } |
188 | | |
189 | 4.71M | op = PathRecord->PathSegments; |
190 | 4.71M | dpts = PathRecord->PathPts; |
191 | 4.71M | current = dpts; /* Stop stupid compilers complaining. */ |
192 | | |
193 | 29.3M | while (op < PathRecord->PathSegmentsCurrent) { |
194 | 24.8M | if (dpts > PathRecord->PathPtsCurrent) { |
195 | 0 | code = gs_note_error(gs_error_unknownerror); |
196 | 0 | goto error; |
197 | 0 | } |
198 | | |
199 | 24.8M | switch(*op++) { |
200 | 4.23M | case pdfi_moveto_seg: |
201 | 4.23M | code = gs_moveto(ctx->pgs, dpts[0], dpts[1]); |
202 | 4.23M | current = dpts; |
203 | 4.23M | dpts+= 2; |
204 | 4.23M | break; |
205 | 9.10M | case pdfi_lineto_seg: |
206 | 9.10M | code = gs_lineto(ctx->pgs, dpts[0], dpts[1]); |
207 | 9.10M | current = dpts; |
208 | 9.10M | dpts+= 2; |
209 | 9.10M | break; |
210 | 2.18M | case pdfi_re_seg: |
211 | 2.18M | code = gs_moveto(ctx->pgs, dpts[0], dpts[1]); |
212 | 2.18M | if (code >= 0) { |
213 | 2.18M | code = gs_rlineto(ctx->pgs, dpts[2], 0); |
214 | 2.18M | if (code >= 0) { |
215 | 2.18M | code = gs_rlineto(ctx->pgs, 0, dpts[3]); |
216 | 2.18M | if (code >= 0) { |
217 | 2.18M | code = gs_rlineto(ctx->pgs, -dpts[2], 0); |
218 | 2.18M | if (code >= 0) |
219 | 2.18M | code = gs_closepath(ctx->pgs); |
220 | 2.18M | } |
221 | 2.18M | } |
222 | 2.18M | } |
223 | 2.18M | current = dpts; |
224 | 2.18M | dpts+= 4; |
225 | 2.18M | break; |
226 | 134k | case pdfi_v_curveto_seg: |
227 | 134k | code = gs_curveto(ctx->pgs, current[0], current[1], dpts[0], dpts[1], dpts[2], dpts[3]); |
228 | 134k | current = dpts + 2; |
229 | 134k | dpts+= 4; |
230 | 134k | break; |
231 | 141k | case pdfi_y_curveto_seg: |
232 | 141k | code = gs_curveto(ctx->pgs, dpts[0], dpts[1], dpts[2], dpts[3], dpts[2], dpts[3]); |
233 | 141k | current = dpts + 2; |
234 | 141k | dpts+= 4; |
235 | 141k | break; |
236 | 8.52M | case pdfi_curveto_seg: |
237 | 8.52M | code = gs_curveto(ctx->pgs, dpts[0], dpts[1], dpts[2], dpts[3], dpts[4], dpts[5]); |
238 | 8.52M | current = dpts + 4; |
239 | 8.52M | dpts+= 6; |
240 | 8.52M | break; |
241 | 491k | case pdfi_closepath_seg: |
242 | 491k | code = gs_closepath(ctx->pgs); |
243 | 491k | break; |
244 | 0 | default: |
245 | 0 | code = gs_note_error(gs_error_rangecheck); |
246 | 0 | break; |
247 | 24.8M | } |
248 | 24.8M | if (code < 0) |
249 | 157k | break; |
250 | 24.8M | } |
251 | | |
252 | 4.71M | error: |
253 | 4.71M | FreePathRecord(ctx); |
254 | 4.71M | return code; |
255 | 4.71M | } |
256 | | |
257 | | int pdfi_moveto (pdf_context *ctx) |
258 | 5.31M | { |
259 | 5.31M | int code; |
260 | 5.31M | double xy[2]; |
261 | | |
262 | 5.31M | if (ctx->text.BlockDepth != 0) { |
263 | 22.7k | if (ctx->text.TextClip) { |
264 | 4 | gx_device *dev = gs_currentdevice_inline(ctx->pgs); |
265 | | |
266 | 4 | ctx->text.TextClip = false; |
267 | 4 | (void)dev_proc(dev, dev_spec_op)(dev, gxdso_hilevel_text_clip, (void *)0, 1); |
268 | 4 | } |
269 | 22.7k | code = pdfi_set_warning_stop(ctx, gs_note_error(gs_error_syntaxerror), NULL, W_PDF_OPINVALIDINTEXT, "pdfi_moveto", NULL); |
270 | 22.7k | if (code < 0) |
271 | 0 | return code; |
272 | 22.7k | } |
273 | | |
274 | 5.31M | code = pdfi_destack_reals(ctx, xy, 2); |
275 | 5.31M | if (code < 0) |
276 | 825k | return code; |
277 | | |
278 | 4.48M | return StorePathSegment(ctx, pdfi_moveto_seg, (double *)&xy); |
279 | 5.31M | } |
280 | | |
281 | | int pdfi_lineto (pdf_context *ctx) |
282 | 10.1M | { |
283 | 10.1M | int code; |
284 | 10.1M | double xy[2]; |
285 | | |
286 | 10.1M | if (ctx->text.BlockDepth != 0) { |
287 | 6.92k | ctx->text.BlockDepth = 0; |
288 | 6.92k | if (ctx->text.TextClip) { |
289 | 0 | gx_device *dev = gs_currentdevice_inline(ctx->pgs); |
290 | |
|
291 | 0 | ctx->text.TextClip = false; |
292 | 0 | (void)dev_proc(dev, dev_spec_op)(dev, gxdso_hilevel_text_clip, (void *)0, 1); |
293 | 0 | } |
294 | 6.92k | code = pdfi_set_warning_stop(ctx, gs_note_error(gs_error_syntaxerror), NULL, W_PDF_OPINVALIDINTEXT, "pdfi_lineto", NULL); |
295 | 6.92k | if (code < 0) |
296 | 0 | return code; |
297 | 6.92k | } |
298 | | |
299 | 10.1M | code = pdfi_destack_reals(ctx, xy, 2); |
300 | 10.1M | if (code < 0) |
301 | 517k | return code; |
302 | | |
303 | 9.63M | return StorePathSegment(ctx, pdfi_lineto_seg, (double *)&xy); |
304 | 10.1M | } |
305 | | |
306 | | static int pdfi_fill_inner(pdf_context *ctx, bool use_eofill) |
307 | 2.07M | { |
308 | 2.07M | int code=0, code1; |
309 | 2.07M | pdfi_trans_state_t state; |
310 | | |
311 | 2.07M | if (ctx->text.BlockDepth != 0) { |
312 | 12.2k | ctx->text.BlockDepth = 0; |
313 | 12.2k | if (ctx->text.TextClip) { |
314 | 4 | gx_device *dev = gs_currentdevice_inline(ctx->pgs); |
315 | | |
316 | 4 | ctx->text.TextClip = false; |
317 | 4 | (void)dev_proc(dev, dev_spec_op)(dev, gxdso_hilevel_text_clip, (void *)0, 1); |
318 | 4 | } |
319 | 12.2k | code = pdfi_set_warning_stop(ctx, gs_note_error(gs_error_syntaxerror), NULL, W_PDF_OPINVALIDINTEXT, "pdfi_fill_inner", NULL); |
320 | 12.2k | if (code < 0) |
321 | 0 | return code; |
322 | 12.2k | } |
323 | | |
324 | 2.07M | if (pdfi_oc_is_off(ctx)) |
325 | 45.8k | goto exit; |
326 | | |
327 | 2.02M | code = ApplyStoredPath(ctx); |
328 | 2.02M | if (code < 0) |
329 | 11.2k | return code; |
330 | | |
331 | 2.01M | code = pdfi_trans_setup(ctx, &state, NULL, TRANSPARENCY_Caller_Fill); |
332 | 2.01M | if (code == 0) { |
333 | | /* If we don't gsave/grestore round the fill, then the file |
334 | | * /tests_private/pdf/sumatra/954_-_dashed_lines_hardly_visible.pdf renders |
335 | | * incorrectly. However we must not gsave/grestore round the trans_setup |
336 | | * trans_teardown, because that might set pgs->soft_mask_id and if we restore |
337 | | * back to a point where that is not set then pdfwrite doesn't work properly. |
338 | | */ |
339 | 2.01M | code = pdfi_gsave(ctx); |
340 | 2.01M | if (code < 0) goto exit; |
341 | | |
342 | 2.01M | if (use_eofill) |
343 | 46.8k | code = gs_eofill(ctx->pgs); |
344 | 1.96M | else |
345 | 1.96M | code = gs_fill(ctx->pgs); |
346 | 2.01M | code1 = pdfi_grestore(ctx); |
347 | 2.01M | if (code == 0) code = code1; |
348 | | |
349 | 2.01M | code1 = pdfi_trans_teardown(ctx, &state); |
350 | 2.01M | if (code == 0) code = code1; |
351 | 2.01M | } |
352 | | |
353 | 2.06M | exit: |
354 | 2.06M | code1 = pdfi_newpath(ctx); |
355 | 2.06M | if (code == 0) code = code1; |
356 | | |
357 | 2.06M | return code; |
358 | 2.01M | } |
359 | | |
360 | | int pdfi_fill(pdf_context *ctx) |
361 | 2.02M | { |
362 | 2.02M | return pdfi_fill_inner(ctx, false); |
363 | 2.02M | } |
364 | | |
365 | | int pdfi_eofill(pdf_context *ctx) |
366 | 49.0k | { |
367 | 49.0k | return pdfi_fill_inner(ctx, true); |
368 | 49.0k | } |
369 | | |
370 | | int pdfi_stroke(pdf_context *ctx) |
371 | 2.47M | { |
372 | 2.47M | int code=0, code1; |
373 | 2.47M | pdfi_trans_state_t state; |
374 | | |
375 | 2.47M | if (ctx->text.BlockDepth != 0) { |
376 | 5.59k | ctx->text.BlockDepth = 0; |
377 | 5.59k | if (ctx->text.TextClip) { |
378 | 0 | gx_device *dev = gs_currentdevice_inline(ctx->pgs); |
379 | |
|
380 | 0 | ctx->text.TextClip = false; |
381 | 0 | (void)dev_proc(dev, dev_spec_op)(dev, gxdso_hilevel_text_clip, (void *)0, 1); |
382 | 0 | } |
383 | 5.59k | code = pdfi_set_warning_stop(ctx, gs_note_error(gs_error_syntaxerror), NULL, W_PDF_OPINVALIDINTEXT, "pdfi_stroke", NULL); |
384 | 5.59k | if (code < 0) |
385 | 0 | return code; |
386 | 5.59k | } |
387 | | |
388 | 2.47M | if (pdfi_oc_is_off(ctx)) |
389 | 38 | goto exit; |
390 | | |
391 | 2.47M | code = ApplyStoredPath(ctx); |
392 | 2.47M | if (code < 0) |
393 | 121k | return code; |
394 | | |
395 | 2.35M | gs_swapcolors_quick(ctx->pgs); |
396 | 2.35M | code = pdfi_trans_setup(ctx, &state, NULL, TRANSPARENCY_Caller_Stroke); |
397 | 2.35M | if (code == 0) { |
398 | 2.35M | code = pdfi_gsave(ctx); |
399 | 2.35M | if (code < 0) goto exit; |
400 | | |
401 | 2.35M | code = gs_stroke(ctx->pgs); |
402 | | |
403 | 2.35M | code1 = pdfi_grestore(ctx); |
404 | 2.35M | if (code == 0) code = code1; |
405 | | |
406 | 2.35M | code1 = pdfi_trans_teardown(ctx, &state); |
407 | 2.35M | if (code == 0) code = code1; |
408 | 2.35M | } |
409 | 2.35M | gs_swapcolors_quick(ctx->pgs); |
410 | | |
411 | 2.35M | exit: |
412 | 2.35M | code1 = pdfi_newpath(ctx); |
413 | 2.35M | if (code == 0) code = code1; |
414 | | |
415 | 2.35M | return code; |
416 | 2.35M | } |
417 | | |
418 | | int pdfi_closepath_stroke(pdf_context *ctx) |
419 | 69.4k | { |
420 | 69.4k | int code; |
421 | | |
422 | 69.4k | if (ctx->text.BlockDepth != 0) { |
423 | 2.36k | ctx->text.BlockDepth = 0; |
424 | 2.36k | if (ctx->text.TextClip) { |
425 | 0 | gx_device *dev = gs_currentdevice_inline(ctx->pgs); |
426 | |
|
427 | 0 | ctx->text.TextClip = false; |
428 | 0 | (void)dev_proc(dev, dev_spec_op)(dev, gxdso_hilevel_text_clip, (void *)0, 1); |
429 | 0 | } |
430 | 2.36k | code = pdfi_set_warning_stop(ctx, gs_note_error(gs_error_syntaxerror), NULL, W_PDF_OPINVALIDINTEXT, "pdfi_closepath_stroke", NULL); |
431 | 2.36k | if (code < 0) |
432 | 0 | return code; |
433 | 2.36k | } |
434 | | |
435 | 69.4k | code = StorePathSegment(ctx, pdfi_closepath_seg, NULL); |
436 | 69.4k | if (code < 0) |
437 | 0 | return code; |
438 | | |
439 | 69.4k | return pdfi_stroke(ctx); |
440 | 69.4k | } |
441 | | |
442 | | int pdfi_curveto(pdf_context *ctx) |
443 | 9.08M | { |
444 | 9.08M | int code; |
445 | 9.08M | double Values[6]; |
446 | | |
447 | 9.08M | code = pdfi_destack_reals(ctx, Values, 6); |
448 | 9.08M | if (code < 0) |
449 | 382k | return code; |
450 | | |
451 | 8.69M | if (ctx->text.BlockDepth != 0) { |
452 | 235 | ctx->text.BlockDepth = 0; |
453 | 235 | if (ctx->text.TextClip) { |
454 | 0 | gx_device *dev = gs_currentdevice_inline(ctx->pgs); |
455 | |
|
456 | 0 | ctx->text.TextClip = false; |
457 | 0 | (void)dev_proc(dev, dev_spec_op)(dev, gxdso_hilevel_text_clip, (void *)0, 1); |
458 | 0 | } |
459 | 235 | code = pdfi_set_warning_stop(ctx, gs_note_error(gs_error_syntaxerror), NULL, W_PDF_OPINVALIDINTEXT, "pdfi_curveto", NULL); |
460 | 235 | if (code < 0) |
461 | 0 | return code; |
462 | 235 | } |
463 | | |
464 | 8.69M | return StorePathSegment(ctx, pdfi_curveto_seg, (double *)&Values); |
465 | 8.69M | } |
466 | | |
467 | | int pdfi_v_curveto(pdf_context *ctx) |
468 | 140k | { |
469 | 140k | int code; |
470 | 140k | double Values[4]; |
471 | | |
472 | 140k | code = pdfi_destack_reals(ctx, Values, 4); |
473 | 140k | if (code < 0) |
474 | 4.61k | return code; |
475 | | |
476 | 135k | if (ctx->text.BlockDepth != 0) { |
477 | 21 | ctx->text.BlockDepth = 0; |
478 | 21 | if (ctx->text.TextClip) { |
479 | 0 | gx_device *dev = gs_currentdevice_inline(ctx->pgs); |
480 | |
|
481 | 0 | ctx->text.TextClip = false; |
482 | 0 | (void)dev_proc(dev, dev_spec_op)(dev, gxdso_hilevel_text_clip, (void *)0, 1); |
483 | 0 | } |
484 | 21 | code = pdfi_set_warning_stop(ctx, gs_note_error(gs_error_syntaxerror), NULL, W_PDF_OPINVALIDINTEXT, "pdfi_v_curveto", NULL); |
485 | 21 | if (code < 0) |
486 | 0 | return code; |
487 | 21 | } |
488 | | |
489 | 135k | return StorePathSegment(ctx, pdfi_v_curveto_seg, (double *)&Values); |
490 | 135k | } |
491 | | |
492 | | int pdfi_y_curveto(pdf_context *ctx) |
493 | 155k | { |
494 | 155k | int code; |
495 | 155k | double Values[4]; |
496 | | |
497 | 155k | code = pdfi_destack_reals(ctx, Values, 4); |
498 | 155k | if (code < 0) |
499 | 12.6k | return code; |
500 | | |
501 | 143k | if (ctx->text.BlockDepth != 0) { |
502 | 21 | ctx->text.BlockDepth = 0; |
503 | 21 | if (ctx->text.TextClip) { |
504 | 0 | gx_device *dev = gs_currentdevice_inline(ctx->pgs); |
505 | |
|
506 | 0 | ctx->text.TextClip = false; |
507 | 0 | (void)dev_proc(dev, dev_spec_op)(dev, gxdso_hilevel_text_clip, (void *)0, 1); |
508 | 0 | } |
509 | 21 | code = pdfi_set_warning_stop(ctx, gs_note_error(gs_error_syntaxerror), NULL, W_PDF_OPINVALIDINTEXT, "pdfi_y_curveto", NULL); |
510 | 21 | if (code < 0) |
511 | 0 | return code; |
512 | 21 | } |
513 | | |
514 | 143k | return StorePathSegment(ctx, pdfi_y_curveto_seg, (double *)&Values); |
515 | 143k | } |
516 | | |
517 | | int pdfi_closepath(pdf_context *ctx) |
518 | 446k | { |
519 | 446k | int code; |
520 | | |
521 | 446k | if (ctx->text.BlockDepth != 0) { |
522 | 712 | ctx->text.BlockDepth = 0; |
523 | 712 | if (ctx->text.TextClip) { |
524 | 3 | gx_device *dev = gs_currentdevice_inline(ctx->pgs); |
525 | | |
526 | 3 | ctx->text.TextClip = false; |
527 | 3 | (void)dev_proc(dev, dev_spec_op)(dev, gxdso_hilevel_text_clip, (void *)0, 1); |
528 | 3 | } |
529 | 712 | code = pdfi_set_warning_stop(ctx, gs_note_error(gs_error_syntaxerror), NULL, W_PDF_OPINVALIDINTEXT, "pdfi_closepath", NULL); |
530 | 712 | if (code < 0) |
531 | 0 | return code; |
532 | 712 | } |
533 | | |
534 | 446k | return StorePathSegment(ctx, pdfi_closepath_seg, NULL); |
535 | 446k | } |
536 | | |
537 | | int pdfi_newpath(pdf_context *ctx) |
538 | 5.54M | { |
539 | 5.54M | int code = 0, code1; |
540 | | |
541 | | /* This code is to deal with the wacky W and W* operators */ |
542 | 5.54M | if (ctx->clip_active) { |
543 | 599k | if (ctx->PathRecord != NULL) { |
544 | 564k | code = ApplyStoredPath(ctx); |
545 | 564k | if (code < 0) |
546 | 22.0k | return code; |
547 | 564k | } |
548 | 577k | if (ctx->pgs->current_point_valid) { |
549 | 539k | if (ctx->do_eoclip) |
550 | 51.0k | code = gs_eoclip(ctx->pgs); |
551 | 488k | else |
552 | 488k | code = gs_clip(ctx->pgs); |
553 | 539k | } |
554 | 577k | } |
555 | 5.52M | ctx->clip_active = false; |
556 | | |
557 | 5.52M | if (ctx->PathRecord != NULL) |
558 | 75.1k | FreePathRecord(ctx); |
559 | | |
560 | 5.52M | code1 = gs_newpath(ctx->pgs); |
561 | 5.52M | if (code == 0) code = code1; |
562 | | |
563 | 5.52M | if (ctx->text.BlockDepth != 0) { |
564 | 3.70k | ctx->text.BlockDepth = 0; |
565 | 3.70k | if (ctx->text.TextClip) { |
566 | 0 | gx_device *dev = gs_currentdevice_inline(ctx->pgs); |
567 | |
|
568 | 0 | ctx->text.TextClip = false; |
569 | 0 | (void)dev_proc(dev, dev_spec_op)(dev, gxdso_hilevel_text_clip, (void *)0, 1); |
570 | 0 | } |
571 | 3.70k | code = pdfi_set_warning_stop(ctx, gs_note_error(gs_error_syntaxerror), NULL, W_PDF_OPINVALIDINTEXT, "pdfi_newpath", NULL); |
572 | 3.70k | if (code < 0) |
573 | 0 | return code; |
574 | 3.70k | } |
575 | | |
576 | 5.52M | return code; |
577 | 5.52M | } |
578 | | |
579 | | int pdfi_b(pdf_context *ctx) |
580 | 15.2k | { |
581 | 15.2k | int code; |
582 | | |
583 | 15.2k | if (ctx->text.BlockDepth != 0) { |
584 | 422 | ctx->text.BlockDepth = 0; |
585 | 422 | if (ctx->text.TextClip) { |
586 | 0 | gx_device *dev = gs_currentdevice_inline(ctx->pgs); |
587 | |
|
588 | 0 | ctx->text.TextClip = false; |
589 | 0 | (void)dev_proc(dev, dev_spec_op)(dev, gxdso_hilevel_text_clip, (void *)0, 1); |
590 | 0 | } |
591 | 422 | code = pdfi_set_warning_stop(ctx, gs_note_error(gs_error_syntaxerror), NULL, W_PDF_OPINVALIDINTEXT, "pdfi_b", NULL); |
592 | 422 | if (code < 0) |
593 | 0 | return code; |
594 | 422 | } |
595 | | |
596 | 15.2k | code = StorePathSegment(ctx, pdfi_closepath_seg, NULL); |
597 | 15.2k | if (code < 0) |
598 | 0 | return code; |
599 | | |
600 | 15.2k | return pdfi_B(ctx); |
601 | 15.2k | } |
602 | | |
603 | | int pdfi_b_star(pdf_context *ctx) |
604 | 520 | { |
605 | 520 | int code; |
606 | | |
607 | 520 | if (ctx->text.BlockDepth != 0) { |
608 | 0 | ctx->text.BlockDepth = 0; |
609 | 0 | if (ctx->text.TextClip) { |
610 | 0 | gx_device *dev = gs_currentdevice_inline(ctx->pgs); |
611 | |
|
612 | 0 | ctx->text.TextClip = false; |
613 | 0 | (void)dev_proc(dev, dev_spec_op)(dev, gxdso_hilevel_text_clip, (void *)0, 1); |
614 | 0 | } |
615 | 0 | code = pdfi_set_warning_stop(ctx, gs_note_error(gs_error_syntaxerror), NULL, W_PDF_OPINVALIDINTEXT, "pdfi_b_star", NULL); |
616 | 0 | if (code < 0) |
617 | 0 | return code; |
618 | 0 | } |
619 | | |
620 | 520 | code = StorePathSegment(ctx, pdfi_closepath_seg, NULL); |
621 | 520 | if (code < 0) |
622 | 0 | return code; |
623 | | |
624 | 520 | return pdfi_B_star(ctx); |
625 | 520 | } |
626 | | |
627 | | /* common code for B and B* */ |
628 | | static int pdfi_B_inner(pdf_context *ctx, bool use_eofill) |
629 | 55.4k | { |
630 | 55.4k | int code=0, code1=0; |
631 | 55.4k | pdfi_trans_state_t state; |
632 | | |
633 | 55.4k | if (ctx->text.BlockDepth != 0) { |
634 | 3.88k | ctx->text.BlockDepth = 0; |
635 | 3.88k | if (ctx->text.TextClip) { |
636 | 13 | gx_device *dev = gs_currentdevice_inline(ctx->pgs); |
637 | | |
638 | 13 | ctx->text.TextClip = false; |
639 | 13 | (void)dev_proc(dev, dev_spec_op)(dev, gxdso_hilevel_text_clip, (void *)0, 1); |
640 | 13 | } |
641 | 3.88k | code = pdfi_set_warning_stop(ctx, gs_note_error(gs_error_syntaxerror), NULL, W_PDF_OPINVALIDINTEXT, "pdfi_B_inner", NULL); |
642 | 3.88k | if (code < 0) |
643 | 0 | goto exit; |
644 | 3.88k | } |
645 | | |
646 | 55.4k | if (pdfi_oc_is_off(ctx)) |
647 | 8 | goto exit; |
648 | | |
649 | 55.4k | code = ApplyStoredPath(ctx); |
650 | 55.4k | if (code < 0) |
651 | 2.17k | return code; |
652 | | |
653 | 53.3k | code = pdfi_trans_setup(ctx, &state, NULL, TRANSPARENCY_Caller_FillStroke); |
654 | 53.3k | if (code == 0) { |
655 | 53.3k | code = pdfi_gsave(ctx); |
656 | 53.3k | if (code < 0) goto exit; |
657 | | |
658 | 53.3k | if (use_eofill) |
659 | 2.07k | code = gs_eofillstroke(ctx->pgs, &code1); |
660 | 51.2k | else |
661 | 51.2k | code = gs_fillstroke(ctx->pgs, &code1); |
662 | | |
663 | 53.3k | code1 = pdfi_grestore(ctx); |
664 | 53.3k | if (code == 0) code = code1; |
665 | | |
666 | 53.3k | code1 = pdfi_trans_teardown(ctx, &state); |
667 | 53.3k | if (code >= 0) code = code1; |
668 | 53.3k | } |
669 | | |
670 | 53.3k | exit: |
671 | 53.3k | code1 = pdfi_newpath(ctx); |
672 | 53.3k | if (code == 0) code = code1; |
673 | | |
674 | 53.3k | return code; |
675 | 53.3k | } |
676 | | |
677 | | int pdfi_B(pdf_context *ctx) |
678 | 53.2k | { |
679 | 53.2k | return pdfi_B_inner(ctx, false); |
680 | 53.2k | } |
681 | | |
682 | | int pdfi_B_star(pdf_context *ctx) |
683 | 2.20k | { |
684 | 2.20k | return pdfi_B_inner(ctx, true); |
685 | 2.20k | } |
686 | | |
687 | | int pdfi_clip(pdf_context *ctx) |
688 | 0 | { |
689 | 0 | int code = gs_clip(ctx->pgs); |
690 | |
|
691 | 0 | if (ctx->text.BlockDepth != 0) { |
692 | 0 | ctx->text.BlockDepth = 0; |
693 | 0 | if (ctx->text.TextClip) { |
694 | 0 | gx_device *dev = gs_currentdevice_inline(ctx->pgs); |
695 | |
|
696 | 0 | ctx->text.TextClip = false; |
697 | 0 | (void)dev_proc(dev, dev_spec_op)(dev, gxdso_hilevel_text_clip, (void *)0, 1); |
698 | 0 | } |
699 | 0 | code = pdfi_set_warning_stop(ctx, gs_note_error(gs_error_syntaxerror), NULL, W_PDF_OPINVALIDINTEXT, "pdfi_B_clip", NULL); |
700 | 0 | if (code < 0) |
701 | 0 | return code; |
702 | 0 | } |
703 | | |
704 | 0 | return code; |
705 | 0 | } |
706 | | |
707 | | int pdfi_eoclip(pdf_context *ctx) |
708 | 0 | { |
709 | 0 | int code = gs_eoclip(ctx->pgs); |
710 | |
|
711 | 0 | if (ctx->text.BlockDepth != 0) { |
712 | 0 | ctx->text.BlockDepth = 0; |
713 | 0 | if (ctx->text.TextClip) { |
714 | 0 | gx_device *dev = gs_currentdevice_inline(ctx->pgs); |
715 | |
|
716 | 0 | ctx->text.TextClip = false; |
717 | 0 | (void)dev_proc(dev, dev_spec_op)(dev, gxdso_hilevel_text_clip, (void *)0, 1); |
718 | 0 | } |
719 | 0 | code = pdfi_set_warning_stop(ctx, gs_note_error(gs_error_syntaxerror), NULL, W_PDF_OPINVALIDINTEXT, "pdfi_eoclip", NULL); |
720 | 0 | if (code < 0) |
721 | 0 | return code; |
722 | 0 | } |
723 | | |
724 | 0 | return code; |
725 | 0 | } |
726 | | |
727 | | int pdfi_rectpath(pdf_context *ctx) |
728 | 2.36M | { |
729 | 2.36M | int code; |
730 | 2.36M | double Values[4]; |
731 | | |
732 | 2.36M | code = pdfi_destack_reals(ctx, Values, 4); |
733 | 2.36M | if (code < 0) |
734 | 125k | return code; |
735 | | |
736 | 2.23M | if (ctx->text.BlockDepth != 0) { |
737 | 19.9k | ctx->text.BlockDepth = 0; |
738 | 19.9k | if (ctx->text.TextClip) { |
739 | 0 | gx_device *dev = gs_currentdevice_inline(ctx->pgs); |
740 | |
|
741 | 0 | ctx->text.TextClip = false; |
742 | 0 | (void)dev_proc(dev, dev_spec_op)(dev, gxdso_hilevel_text_clip, (void *)0, 1); |
743 | 0 | } |
744 | 19.9k | code = pdfi_set_warning_stop(ctx, gs_note_error(gs_error_syntaxerror), NULL, W_PDF_OPINVALIDINTEXT, "pdfi_rectpath", NULL); |
745 | 19.9k | if (code < 0) |
746 | 0 | return code; |
747 | 19.9k | } |
748 | | |
749 | 2.23M | return StorePathSegment(ctx, pdfi_re_seg, (double *)&Values); |
750 | 2.23M | } |