Coverage Report

Created: 2026-04-01 07:17

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