Debian Codegraph @

pdf/pdf_path.c

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