Coverage Report

Created: 2026-08-08 08:00

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
26.7M
{
42
26.7M
    int size = 0;
43
44
26.7M
    switch (segment)
45
26.7M
    {
46
4.52M
        case pdfi_moveto_seg:
47
14.3M
        case pdfi_lineto_seg:
48
14.3M
            size = 2;
49
14.3M
            break;
50
2.31M
        case pdfi_re_seg:
51
2.45M
        case pdfi_v_curveto_seg:
52
2.59M
        case pdfi_y_curveto_seg:
53
2.59M
            size = 4;
54
2.59M
                break;
55
9.16M
        case pdfi_curveto_seg:
56
9.16M
            size = 6;
57
9.16M
            break;
58
541k
        case pdfi_closepath_seg:
59
541k
            break;
60
0
        default:
61
0
            return_error(gs_error_undefined);
62
0
            break;
63
26.7M
    }
64
26.7M
    if (ctx->PathSegments == NULL) {
65
4.87M
        ctx->PathSegments = (char *)gs_alloc_bytes(ctx->memory, 1024, "StorePathSegment");
66
4.87M
        if (ctx->PathSegments == NULL)
67
0
            return_error(gs_error_VMerror);
68
4.87M
        ctx->PathSegmentsCurrent = ctx->PathSegments;
69
4.87M
        ctx->PathSegmentsTop = ctx->PathSegments + 1024;
70
4.87M
    }
71
26.7M
    if (ctx->PathSegmentsCurrent == ctx->PathSegmentsTop) {
72
1.58k
        char *new_accumulator = NULL;
73
1.58k
        uint64_t old_size;
74
75
1.58k
        old_size = ctx->PathSegmentsCurrent - ctx->PathSegments;
76
1.58k
        new_accumulator = (char *)gs_alloc_bytes(ctx->memory, old_size + 1024, "StorePathSegment");
77
1.58k
        if (new_accumulator == NULL)
78
0
            return_error(gs_error_VMerror);
79
1.58k
        memcpy(new_accumulator, ctx->PathSegments, old_size);
80
1.58k
        ctx->PathSegmentsCurrent = new_accumulator + old_size;
81
1.58k
        gs_free_object(ctx->memory, ctx->PathSegments, "StorePathSegment");
82
1.58k
        ctx->PathSegments = new_accumulator;
83
1.58k
        ctx->PathSegmentsTop = ctx->PathSegments + old_size + 1024;
84
1.58k
    }
85
86
26.7M
    if (ctx->PathPts == NULL) {
87
4.87M
        ctx->PathPts = (double *)gs_alloc_bytes(ctx->memory, 4096, "StorePathSegment");
88
4.87M
        if (ctx->PathPts == NULL)
89
0
            return_error(gs_error_VMerror);
90
4.87M
        ctx->PathPtsCurrent = ctx->PathPts;
91
4.87M
        ctx->PathPtsTop = ctx->PathPts + (4096 / sizeof(double));
92
4.87M
    }
93
26.7M
    if (ctx->PathPtsCurrent + size > ctx->PathPtsTop) {
94
27.0k
        double *new_accumulator = NULL;
95
27.0k
        uint64_t old_size;
96
97
27.0k
        old_size = (char *)ctx->PathPtsCurrent - (char *)ctx->PathPts;
98
27.0k
        new_accumulator = (double *)gs_alloc_bytes(ctx->memory, old_size + 4096, "StorePathSegment");
99
27.0k
        if (new_accumulator == NULL)
100
0
            return_error(gs_error_VMerror);
101
27.0k
        memcpy(new_accumulator, ctx->PathPts, old_size);
102
27.0k
        ctx->PathPtsCurrent = new_accumulator + (old_size / sizeof(double));
103
27.0k
        gs_free_object(ctx->memory, ctx->PathPts, "StorePathSegment");
104
27.0k
        ctx->PathPts = new_accumulator;
105
27.0k
        ctx->PathPtsTop = ctx->PathPts + ((old_size + 4096) / sizeof(double));
106
27.0k
    }
107
108
26.7M
    *(ctx->PathSegmentsCurrent++) = (char)segment;
109
26.7M
    switch (segment)
110
26.7M
    {
111
4.52M
        case pdfi_moveto_seg:
112
14.3M
        case pdfi_lineto_seg:
113
14.3M
            memcpy(ctx->PathPtsCurrent, pts, 2 * sizeof(double));
114
14.3M
            ctx->PathPtsCurrent += 2;
115
14.3M
            break;
116
2.31M
        case pdfi_re_seg:
117
2.45M
        case pdfi_v_curveto_seg:
118
2.59M
        case pdfi_y_curveto_seg:
119
2.59M
            memcpy(ctx->PathPtsCurrent, pts, 4 * sizeof(double));
120
2.59M
            ctx->PathPtsCurrent += 4;
121
2.59M
            break;
122
9.16M
        case pdfi_curveto_seg:
123
9.16M
            memcpy(ctx->PathPtsCurrent, pts, 6 * sizeof(double));
124
9.16M
            ctx->PathPtsCurrent += 6;
125
9.16M
            break;
126
541k
        case pdfi_closepath_seg:
127
541k
            break;
128
26.7M
    }
129
26.7M
    return 0;
130
26.7M
}
131
132
static int ApplyStoredPath(pdf_context *ctx)
133
5.19M
{
134
5.19M
    int code = 0;
135
5.19M
    char *op = NULL;
136
5.19M
    double *dpts = NULL;
137
5.19M
    double *current;
138
139
5.19M
    if (ctx->PathSegments == NULL)
140
405k
        return 0;
141
142
4.79M
    if (ctx->PathPts == NULL) {
143
0
        code = gs_note_error(gs_error_unknownerror);
144
0
        goto error;
145
0
    }
146
147
4.79M
    if (ctx->pgs->current_point_valid) {
148
126k
        code = gs_newpath(ctx->pgs);
149
126k
        if (code < 0)
150
0
            goto error;
151
126k
    }
152
153
4.79M
    op = ctx->PathSegments;
154
4.79M
    dpts = ctx->PathPts;
155
4.79M
    current = dpts; /* Stop stupid compilers complaining. */
156
157
30.3M
    while (op < ctx->PathSegmentsCurrent) {
158
25.7M
        if (dpts > ctx->PathPtsCurrent) {
159
0
            code = gs_note_error(gs_error_unknownerror);
160
0
            goto error;
161
0
        }
162
163
25.7M
        switch(*op++) {
164
4.28M
            case pdfi_moveto_seg:
165
4.28M
                code = gs_moveto(ctx->pgs, dpts[0], dpts[1]);
166
4.28M
                current = dpts;
167
4.28M
                dpts+= 2;
168
4.28M
                break;
169
9.38M
            case pdfi_lineto_seg:
170
9.38M
                code = gs_lineto(ctx->pgs, dpts[0], dpts[1]);
171
9.38M
                current = dpts;
172
9.38M
                dpts+= 2;
173
9.38M
                break;
174
2.25M
            case pdfi_re_seg:
175
2.25M
                code = gs_moveto(ctx->pgs, dpts[0], dpts[1]);
176
2.25M
                if (code >= 0) {
177
2.25M
                    code = gs_rlineto(ctx->pgs, dpts[2], 0);
178
2.25M
                    if (code >= 0) {
179
2.25M
                        code = gs_rlineto(ctx->pgs, 0, dpts[3]);
180
2.25M
                        if (code >= 0) {
181
2.25M
                            code = gs_rlineto(ctx->pgs, -dpts[2], 0);
182
2.25M
                            if (code >= 0)
183
2.25M
                                code = gs_closepath(ctx->pgs);
184
2.25M
                        }
185
2.25M
                    }
186
2.25M
                }
187
2.25M
                current = dpts;
188
2.25M
                dpts+= 4;
189
2.25M
                break;
190
137k
            case pdfi_v_curveto_seg:
191
137k
                code = gs_curveto(ctx->pgs, current[0], current[1], dpts[0], dpts[1], dpts[2], dpts[3]);
192
137k
                current = dpts + 2;
193
137k
                dpts+= 4;
194
137k
                break;
195
145k
            case pdfi_y_curveto_seg:
196
145k
                code = gs_curveto(ctx->pgs, dpts[0], dpts[1], dpts[2], dpts[3], dpts[2], dpts[3]);
197
145k
                current = dpts + 2;
198
145k
                dpts+= 4;
199
145k
                break;
200
9.04M
            case pdfi_curveto_seg:
201
9.04M
                code = gs_curveto(ctx->pgs, dpts[0], dpts[1], dpts[2], dpts[3], dpts[4], dpts[5]);
202
9.04M
                current = dpts + 4;
203
9.04M
                dpts+= 6;
204
9.04M
                break;
205
501k
            case pdfi_closepath_seg:
206
501k
                code = gs_closepath(ctx->pgs);
207
501k
                break;
208
0
            default:
209
0
                code = gs_note_error(gs_error_rangecheck);
210
0
                break;
211
25.7M
        }
212
25.7M
        if (code < 0)
213
157k
            break;
214
25.7M
    }
215
216
4.79M
error:
217
4.79M
    gs_free_object(ctx->memory, ctx->PathSegments, "ApplyStoredPath");
218
4.79M
    ctx->PathSegmentsTop = ctx->PathSegmentsCurrent = ctx->PathSegments = NULL;
219
4.79M
    gs_free_object(ctx->memory, ctx->PathPts, "ApplyStoredPath");
220
4.79M
    ctx->PathPtsTop = ctx->PathPtsCurrent = ctx->PathPts = NULL;
221
4.79M
    return code;
222
4.79M
}
223
224
int pdfi_moveto (pdf_context *ctx)
225
5.28M
{
226
5.28M
    int code;
227
5.28M
    double xy[2];
228
229
5.28M
    if (ctx->text.BlockDepth != 0) {
230
22.2k
        if (ctx->text.TextClip) {
231
1
            gx_device *dev = gs_currentdevice_inline(ctx->pgs);
232
233
1
            ctx->text.TextClip = false;
234
1
            (void)dev_proc(dev, dev_spec_op)(dev, gxdso_hilevel_text_clip, (void *)0, 1);
235
1
        }
236
22.2k
        code = pdfi_set_warning_stop(ctx, gs_note_error(gs_error_syntaxerror), NULL, W_PDF_OPINVALIDINTEXT, "pdfi_moveto", NULL);
237
22.2k
        if (code < 0)
238
0
            return code;
239
22.2k
    }
240
241
5.28M
    code = pdfi_destack_reals(ctx, xy, 2);
242
5.28M
    if (code < 0)
243
756k
        return code;
244
245
4.52M
    return StorePathSegment(ctx, pdfi_moveto_seg, (double *)&xy);
246
5.28M
}
247
248
int pdfi_lineto (pdf_context *ctx)
249
10.3M
{
250
10.3M
    int code;
251
10.3M
    double xy[2];
252
253
10.3M
    if (ctx->text.BlockDepth != 0) {
254
7.09k
        ctx->text.BlockDepth = 0;
255
7.09k
        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.09k
        code = pdfi_set_warning_stop(ctx, gs_note_error(gs_error_syntaxerror), NULL, W_PDF_OPINVALIDINTEXT, "pdfi_lineto", NULL);
262
7.09k
        if (code < 0)
263
0
            return code;
264
7.09k
    }
265
266
10.3M
    code = pdfi_destack_reals(ctx, xy, 2);
267
10.3M
    if (code < 0)
268
520k
        return code;
269
270
9.87M
    return StorePathSegment(ctx, pdfi_lineto_seg, (double *)&xy);
271
10.3M
}
272
273
static int pdfi_fill_inner(pdf_context *ctx, bool use_eofill)
274
2.12M
{
275
2.12M
    int code=0, code1;
276
2.12M
    pdfi_trans_state_t state;
277
278
2.12M
    if (ctx->text.BlockDepth != 0) {
279
12.0k
        ctx->text.BlockDepth = 0;
280
12.0k
        if (ctx->text.TextClip) {
281
4
            gx_device *dev = gs_currentdevice_inline(ctx->pgs);
282
283
4
            ctx->text.TextClip = false;
284
4
            (void)dev_proc(dev, dev_spec_op)(dev, gxdso_hilevel_text_clip, (void *)0, 1);
285
4
        }
286
12.0k
        code = pdfi_set_warning_stop(ctx, gs_note_error(gs_error_syntaxerror), NULL, W_PDF_OPINVALIDINTEXT, "pdfi_fill_inner", NULL);
287
12.0k
        if (code < 0)
288
0
            return code;
289
12.0k
    }
290
291
2.12M
    if (pdfi_oc_is_off(ctx))
292
48.1k
        goto exit;
293
294
2.07M
    code = ApplyStoredPath(ctx);
295
2.07M
    if (code < 0)
296
11.6k
        return code;
297
298
2.06M
    code = pdfi_trans_setup(ctx, &state, NULL, TRANSPARENCY_Caller_Fill);
299
2.06M
    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.06M
        code = pdfi_gsave(ctx);
307
2.06M
        if (code < 0) goto exit;
308
309
2.06M
        if (use_eofill)
310
47.1k
            code = gs_eofill(ctx->pgs);
311
2.01M
        else
312
2.01M
            code = gs_fill(ctx->pgs);
313
2.06M
        code1 = pdfi_grestore(ctx);
314
2.06M
        if (code == 0) code = code1;
315
316
2.06M
        code1 = pdfi_trans_teardown(ctx, &state);
317
2.06M
        if (code == 0) code = code1;
318
2.06M
    }
319
320
2.11M
 exit:
321
2.11M
    code1 = pdfi_newpath(ctx);
322
2.11M
    if (code == 0) code = code1;
323
324
2.11M
    return code;
325
2.06M
}
326
327
int pdfi_fill(pdf_context *ctx)
328
2.07M
{
329
2.07M
    return pdfi_fill_inner(ctx, false);
330
2.07M
}
331
332
int pdfi_eofill(pdf_context *ctx)
333
49.5k
{
334
49.5k
    return pdfi_fill_inner(ctx, true);
335
49.5k
}
336
337
int pdfi_stroke(pdf_context *ctx)
338
2.49M
{
339
2.49M
    int code=0, code1;
340
2.49M
    pdfi_trans_state_t state;
341
342
2.49M
    if (ctx->text.BlockDepth != 0) {
343
5.69k
        ctx->text.BlockDepth = 0;
344
5.69k
        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
5.69k
        code = pdfi_set_warning_stop(ctx, gs_note_error(gs_error_syntaxerror), NULL, W_PDF_OPINVALIDINTEXT, "pdfi_stroke", NULL);
351
5.69k
        if (code < 0)
352
0
            return code;
353
5.69k
    }
354
355
2.49M
    if (pdfi_oc_is_off(ctx))
356
22
        goto exit;
357
358
2.49M
    code = ApplyStoredPath(ctx);
359
2.49M
    if (code < 0)
360
121k
        return code;
361
362
2.36M
    gs_swapcolors_quick(ctx->pgs);
363
2.36M
    code = pdfi_trans_setup(ctx, &state, NULL, TRANSPARENCY_Caller_Stroke);
364
2.36M
    if (code == 0) {
365
2.36M
        code = pdfi_gsave(ctx);
366
2.36M
        if (code < 0) goto exit;
367
368
2.36M
        code = gs_stroke(ctx->pgs);
369
370
2.36M
        code1 = pdfi_grestore(ctx);
371
2.36M
        if (code == 0) code = code1;
372
373
2.36M
        code1 = pdfi_trans_teardown(ctx, &state);
374
2.36M
        if (code == 0) code = code1;
375
2.36M
    }
376
2.36M
    gs_swapcolors_quick(ctx->pgs);
377
378
2.36M
 exit:
379
2.36M
    code1 = pdfi_newpath(ctx);
380
2.36M
    if (code == 0) code = code1;
381
382
2.36M
    return code;
383
2.36M
}
384
385
int pdfi_closepath_stroke(pdf_context *ctx)
386
72.1k
{
387
72.1k
    int code;
388
389
72.1k
    if (ctx->text.BlockDepth != 0) {
390
2.36k
        ctx->text.BlockDepth = 0;
391
2.36k
        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.36k
        code = pdfi_set_warning_stop(ctx, gs_note_error(gs_error_syntaxerror), NULL, W_PDF_OPINVALIDINTEXT, "pdfi_closepath_stroke", NULL);
398
2.36k
        if (code < 0)
399
0
            return code;
400
2.36k
    }
401
402
72.1k
    code = StorePathSegment(ctx, pdfi_closepath_seg, NULL);
403
72.1k
    if (code < 0)
404
0
        return code;
405
406
72.1k
    return pdfi_stroke(ctx);
407
72.1k
}
408
409
int pdfi_curveto(pdf_context *ctx)
410
9.57M
{
411
9.57M
    int code;
412
9.57M
    double Values[6];
413
414
9.57M
    code = pdfi_destack_reals(ctx, Values, 6);
415
9.57M
    if (code < 0)
416
403k
        return code;
417
418
9.16M
    if (ctx->text.BlockDepth != 0) {
419
248
        ctx->text.BlockDepth = 0;
420
248
        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
248
        code = pdfi_set_warning_stop(ctx, gs_note_error(gs_error_syntaxerror), NULL, W_PDF_OPINVALIDINTEXT, "pdfi_curveto", NULL);
427
248
        if (code < 0)
428
0
            return code;
429
248
    }
430
431
9.16M
    return StorePathSegment(ctx, pdfi_curveto_seg, (double *)&Values);
432
9.16M
}
433
434
int pdfi_v_curveto(pdf_context *ctx)
435
142k
{
436
142k
    int code;
437
142k
    double Values[4];
438
439
142k
    code = pdfi_destack_reals(ctx, Values, 4);
440
142k
    if (code < 0)
441
4.55k
        return code;
442
443
138k
    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
138k
    return StorePathSegment(ctx, pdfi_v_curveto_seg, (double *)&Values);
457
138k
}
458
459
int pdfi_y_curveto(pdf_context *ctx)
460
158k
{
461
158k
    int code;
462
158k
    double Values[4];
463
464
158k
    code = pdfi_destack_reals(ctx, Values, 4);
465
158k
    if (code < 0)
466
12.1k
        return code;
467
468
146k
    if (ctx->text.BlockDepth != 0) {
469
18
        ctx->text.BlockDepth = 0;
470
18
        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
18
        code = pdfi_set_warning_stop(ctx, gs_note_error(gs_error_syntaxerror), NULL, W_PDF_OPINVALIDINTEXT, "pdfi_y_curveto", NULL);
477
18
        if (code < 0)
478
0
            return code;
479
18
    }
480
481
146k
    return StorePathSegment(ctx, pdfi_y_curveto_seg, (double *)&Values);
482
146k
}
483
484
int pdfi_closepath(pdf_context *ctx)
485
453k
{
486
453k
    int code;
487
488
453k
    if (ctx->text.BlockDepth != 0) {
489
718
        ctx->text.BlockDepth = 0;
490
718
        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
718
        code = pdfi_set_warning_stop(ctx, gs_note_error(gs_error_syntaxerror), NULL, W_PDF_OPINVALIDINTEXT, "pdfi_closepath", NULL);
497
718
        if (code < 0)
498
0
            return code;
499
718
    }
500
501
453k
    return StorePathSegment(ctx, pdfi_closepath_seg, NULL);
502
453k
}
503
504
int pdfi_newpath(pdf_context *ctx)
505
5.60M
{
506
5.60M
    int code = 0, code1;
507
508
    /* This code is to deal with the wacky W and W* operators */
509
5.60M
    if (ctx->clip_active) {
510
609k
        if (ctx->PathSegments != NULL) {
511
574k
            code = ApplyStoredPath(ctx);
512
574k
            if (code < 0)
513
21.7k
                return code;
514
574k
        }
515
587k
        if (ctx->pgs->current_point_valid) {
516
549k
            if (ctx->do_eoclip)
517
49.7k
                code = gs_eoclip(ctx->pgs);
518
499k
            else
519
499k
                code = gs_clip(ctx->pgs);
520
549k
        }
521
587k
    }
522
5.57M
    ctx->clip_active = false;
523
524
5.57M
    if (ctx->PathSegments != NULL){
525
75.8k
        gs_free_object(ctx->memory, ctx->PathSegments, "ApplyStoredPath");
526
75.8k
        ctx->PathSegmentsTop = ctx->PathSegmentsCurrent = ctx->PathSegments = NULL;
527
75.8k
        gs_free_object(ctx->memory, ctx->PathPts, "ApplyStoredPath");
528
75.8k
        ctx->PathPtsTop = ctx->PathPtsCurrent = ctx->PathPts = NULL;
529
75.8k
    }
530
531
5.57M
    code1 = gs_newpath(ctx->pgs);
532
5.57M
    if (code == 0) code = code1;
533
534
5.57M
    if (ctx->text.BlockDepth != 0) {
535
3.51k
        ctx->text.BlockDepth = 0;
536
3.51k
        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
3.51k
        code = pdfi_set_warning_stop(ctx, gs_note_error(gs_error_syntaxerror), NULL, W_PDF_OPINVALIDINTEXT, "pdfi_newpath", NULL);
543
3.51k
        if (code < 0)
544
0
            return code;
545
3.51k
    }
546
547
5.57M
    return code;
548
5.57M
}
549
550
int pdfi_b(pdf_context *ctx)
551
15.3k
{
552
15.3k
    int code;
553
554
15.3k
    if (ctx->text.BlockDepth != 0) {
555
426
        ctx->text.BlockDepth = 0;
556
426
        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
426
        code = pdfi_set_warning_stop(ctx, gs_note_error(gs_error_syntaxerror), NULL, W_PDF_OPINVALIDINTEXT, "pdfi_b", NULL);
563
426
        if (code < 0)
564
0
            return code;
565
426
    }
566
567
15.3k
    code = StorePathSegment(ctx, pdfi_closepath_seg, NULL);
568
15.3k
    if (code < 0)
569
0
        return code;
570
571
15.3k
    return pdfi_B(ctx);
572
15.3k
}
573
574
int pdfi_b_star(pdf_context *ctx)
575
434
{
576
434
    int code;
577
578
434
    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
434
    code = StorePathSegment(ctx, pdfi_closepath_seg, NULL);
592
434
    if (code < 0)
593
0
        return code;
594
595
434
    return pdfi_B_star(ctx);
596
434
}
597
598
/* common code for B and B* */
599
static int pdfi_B_inner(pdf_context *ctx, bool use_eofill)
600
55.0k
{
601
55.0k
    int code=0, code1=0;
602
55.0k
    pdfi_trans_state_t state;
603
604
55.0k
    if (ctx->text.BlockDepth != 0) {
605
3.83k
        ctx->text.BlockDepth = 0;
606
3.83k
        if (ctx->text.TextClip) {
607
12
            gx_device *dev = gs_currentdevice_inline(ctx->pgs);
608
609
12
            ctx->text.TextClip = false;
610
12
            (void)dev_proc(dev, dev_spec_op)(dev, gxdso_hilevel_text_clip, (void *)0, 1);
611
12
        }
612
3.83k
        code = pdfi_set_warning_stop(ctx, gs_note_error(gs_error_syntaxerror), NULL, W_PDF_OPINVALIDINTEXT, "pdfi_B_inner", NULL);
613
3.83k
        if (code < 0)
614
0
            goto exit;
615
3.83k
    }
616
617
55.0k
    if (pdfi_oc_is_off(ctx))
618
8
        goto exit;
619
620
55.0k
    code = ApplyStoredPath(ctx);
621
55.0k
    if (code < 0)
622
2.18k
        return code;
623
624
52.8k
    code = pdfi_trans_setup(ctx, &state, NULL, TRANSPARENCY_Caller_FillStroke);
625
52.8k
    if (code == 0) {
626
52.8k
        code = pdfi_gsave(ctx);
627
52.8k
        if (code < 0) goto exit;
628
629
52.8k
        if (use_eofill)
630
1.98k
            code = gs_eofillstroke(ctx->pgs, &code1);
631
50.8k
        else
632
50.8k
            code = gs_fillstroke(ctx->pgs, &code1);
633
634
52.8k
        code1 = pdfi_grestore(ctx);
635
52.8k
        if (code == 0) code = code1;
636
637
52.8k
        code1 = pdfi_trans_teardown(ctx, &state);
638
52.8k
        if (code >= 0) code = code1;
639
52.8k
    }
640
641
52.8k
 exit:
642
52.8k
    code1 = pdfi_newpath(ctx);
643
52.8k
    if (code == 0) code = code1;
644
645
52.8k
    return code;
646
52.8k
}
647
648
int pdfi_B(pdf_context *ctx)
649
52.9k
{
650
52.9k
    return pdfi_B_inner(ctx, false);
651
52.9k
}
652
653
int pdfi_B_star(pdf_context *ctx)
654
2.10k
{
655
2.10k
    return pdfi_B_inner(ctx, true);
656
2.10k
}
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.44M
{
700
2.44M
    int code;
701
2.44M
    double Values[4];
702
703
2.44M
    code = pdfi_destack_reals(ctx, Values, 4);
704
2.44M
    if (code < 0)
705
127k
        return code;
706
707
2.31M
    if (ctx->text.BlockDepth != 0) {
708
19.9k
        ctx->text.BlockDepth = 0;
709
19.9k
        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
19.9k
        code = pdfi_set_warning_stop(ctx, gs_note_error(gs_error_syntaxerror), NULL, W_PDF_OPINVALIDINTEXT, "pdfi_rectpath", NULL);
716
19.9k
        if (code < 0)
717
0
            return code;
718
19.9k
    }
719
720
2.31M
    return StorePathSegment(ctx, pdfi_re_seg, (double *)&Values);
721
2.31M
}