Coverage Report

Created: 2026-04-09 07:06

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