Coverage Report

Created: 2026-11-12 07:09

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/ghostpdl/base/gsstate.c
Line
Count
Source
1
/* Copyright (C) 2001-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
17
/* Miscellaneous graphics state operators for Ghostscript library */
18
#include "gx.h"
19
#include "memory_.h"
20
#include "gserrors.h"
21
#include "gsstruct.h"
22
#include "gsutil.h"             /* for gs_next_ids */
23
#include "gzstate.h"
24
#include "gxcspace.h"           /* here for gscolor2.h */
25
#include "gscolor2.h"
26
#include "gscoord.h"            /* for gs_initmatrix */
27
#include "gscie.h"
28
#include "gxclipsr.h"
29
#include "gxcmap.h"
30
#include "gxdevice.h"
31
#include "gxpcache.h"
32
#include "gzht.h"
33
#include "gzline.h"
34
#include "gspath.h"
35
#include "gzpath.h"
36
#include "gzcpath.h"
37
#include "gsovrc.h"
38
#include "gxcolor2.h"
39
#include "gscolor3.h" /* for gs_smoothness() */
40
#include "gxpcolor.h"
41
#include "gsicc_manage.h"
42
#include "gxdevsop.h"
43
44
/* Forward references */
45
static gs_gstate *gstate_alloc(gs_memory_t *, client_name_t,
46
                               const gs_gstate *);
47
static gs_gstate *gstate_clone_for_gsave(gs_gstate *,
48
                                         client_name_t);
49
static gs_gstate *gstate_clone_for_gstate(const gs_gstate *, gs_memory_t *,
50
                                          client_name_t);
51
static void gstate_free_contents(gs_gstate *);
52
static int gstate_copy(gs_gstate *, const gs_gstate *,
53
                        gs_gstate_copy_reason_t, client_name_t);
54
static void clip_stack_rc_adjust(gx_clip_stack_t *cs, int delta, client_name_t cname);
55
56
/*
57
 * Graphics state storage management is complicated.  There are many
58
 * different classes of storage associated with a graphics state:
59
 *
60
 * (1) The gstate object itself.  This includes some objects physically
61
 *      embedded within the gstate object, but because of garbage collection
62
 *      requirements, there are no embedded objects that can be
63
 *      referenced by non-transient pointers.  We assume that the gstate
64
 *      stack "owns" its gstates and that we can free the top gstate when
65
 *      doing a restore.
66
 *
67
 * (2) Objects that are referenced directly by the gstate and whose lifetime
68
 *      is independent of the gstate.  These are garbage collected, not
69
 *      reference counted, so we don't need to do anything special with them
70
 *      when manipulating gstates.  Currently this includes:
71
 *              font
72
 *
73
 * (3) Objects that are referenced directly by the gstate, may be shared
74
 *      among gstates, and should disappear when no gstates reference them.
75
 *      These fall into two groups:
76
 *
77
 *   (3a) Objects that are logically connected to individual gstates.
78
 *      We use reference counting to manage these.  Currently these are:
79
 *              halftone, dev_ht(4), cie_render, black_generation,
80
 *              undercolor_removal, set_transfer.*, cie_joint_caches,
81
 *              clip_stack, {opacity,shape}.mask
82
 *      effective_transfer.* may point to some of the same objects as
83
 *      set_transfer.*, but don't contribute to the reference count.
84
 *      Similarly, dev_color may point to the dev_ht object.  For
85
 *      simplicity, we initialize all of these pointers to 0 and then
86
 *      allocate the object itself when needed.
87
 *
88
 *   (3b) Objects whose lifetimes are associated with something else.
89
 *      Currently these are:
90
 *              pattern_cache, which is associated with the entire
91
 *                stack, is allocated when first needed, and currently
92
 *                is never freed;
93
 *              view_clip, which is associated with the current
94
 *                save level (effectively, with the gstate sub-stack
95
 *                back to the save) and is managed specially;
96
 *
97
 * (4) Objects that are referenced directly by exactly one gstate and that
98
 *      are not referenced (except transiently) from any other object.
99
 *      These fall into two groups:
100
 *
101
 *   (4b) Objects allocated individually, for the given reason:
102
 *              line_params.dash.pattern (variable-length),
103
 *              color_space, path, clip_path, effective_clip.path,
104
 *              ccolor, dev_color
105
 *                  (may be referenced from image enumerators or elsewhere)
106
 *
107
 *   (4b) The "client data" for a gstate.  For the interpreter, this is
108
 *      the refs associated with the gstate, such as the screen procedures.
109
 *      Client-supplied procedures manage client data.
110
 *
111
 * (5) Objects referenced indirectly from gstate objects of category (4),
112
 *      including objects that may also be referenced directly by the gstate.
113
 *      The individual routines that manipulate these are responsible
114
 *      for doing the right kind of reference counting or whatever.
115
 *      Currently:
116
 *              devices, path, clip_path, and (if different from both clip_path
117
 *                and view_clip) effective_clip.path require
118
 *                gx_path_assign/free, which uses a reference count;
119
 *              color_space and ccolor require cs_adjust_color/cspace_count
120
 *                or cs_adjust_counts, which use a reference count;
121
 *              dev_color has no references to storage that it owns.
122
 *      We count on garbage collection or restore to deallocate
123
 *        sub-objects of halftone.
124
 *
125
 * Note that when after a gsave, the existing gstate references the related
126
 * objects that we allocate at the same time, and the newly allocated gstate
127
 * references the old related objects.  Similarly, during a grestore, we
128
 * free the related objects referenced by the current gstate, but after the
129
 * grestore, we free the saved gstate, not the current one.  However, when
130
 * we allocate gstates off-stack, the newly allocated gstate does reference
131
 * the newly allocated component objects.  Note also that setgstate /
132
 * currentgstate may produce gstates in which different allocators own
133
 * different sub-objects; this is OK, because restore guarantees that there
134
 * won't be any dangling pointers (as long as we don't allow pointers from
135
 * global gstates to local objects).
136
 */
137
138
/*
139
 * Define these elements of the graphics state that are allocated
140
 * individually for each state, except for line_params.dash.pattern.
141
 * Note that effective_clip_shared is not on the list.
142
 */
143
typedef struct gs_gstate_parts_s {
144
    gx_path *path;
145
    gx_clip_path *clip_path;
146
    gx_clip_path *effective_clip_path;
147
    struct {
148
        gs_client_color *ccolor;
149
        gx_device_color *dev_color;
150
    } color[2];
151
} gs_gstate_parts;
152
153
#define GSTATE_ASSIGN_PARTS(pto, pfrom)\
154
87.6M
  ((pto)->path = (pfrom)->path, (pto)->clip_path = (pfrom)->clip_path,\
155
87.6M
   (pto)->effective_clip_path = (pfrom)->effective_clip_path,\
156
87.6M
   (pto)->color[0].ccolor = (pfrom)->color[0].ccolor,\
157
87.6M
   (pto)->color[0].dev_color = (pfrom)->color[0].dev_color,\
158
87.6M
   (pto)->color[1].ccolor = (pfrom)->color[1].ccolor,\
159
87.6M
   (pto)->color[1].dev_color = (pfrom)->color[1].dev_color)
160
161
extern_st(st_gs_gstate); /* for gstate_alloc() */
162
163
/* Copy client data, using the copy_for procedure if available, */
164
/* the copy procedure otherwise. */
165
static int
166
gstate_copy_client_data(const gs_gstate * pgs, void *dto, void *dfrom,
167
                        gs_gstate_copy_reason_t reason)
168
86.0M
{
169
86.0M
    return (pgs->client_procs.copy_for != 0 ?
170
9.47M
            (*pgs->client_procs.copy_for) (dto, dfrom, reason) :
171
86.0M
            (*pgs->client_procs.copy) (dto, dfrom));
172
86.0M
}
173
174
/* ------ Operations on the entire graphics state ------ */
175
176
/*
177
 * Allocate a path for the graphics state.  We use stable memory because
178
 * some PostScript files have Type 3 fonts whose BuildChar procedure
179
 * uses the sequence save ... setcachedevice ... restore, and the path
180
 * built between the setcachedevice and the restore must not be freed.
181
 * If it weren't for this, we don't think stable memory would be needed.
182
 */
183
static gs_memory_t *
184
gstate_path_memory(gs_memory_t *mem)
185
44.6M
{
186
44.6M
    return gs_memory_stable(mem);
187
44.6M
}
188
189
/* Allocate and initialize a graphics state. */
190
gs_gstate *
191
gs_gstate_alloc(gs_memory_t * mem)
192
456k
{
193
456k
    gs_gstate *pgs = gstate_alloc(mem, "gs_gstate_alloc", NULL);
194
456k
    gs_memory_t *path_mem = gstate_path_memory(mem);
195
456k
    int code;
196
197
456k
    if (pgs == 0)
198
0
        return 0;
199
456k
    GS_STATE_INIT_VALUES(pgs, 1.0);
200
    /* Need to set up at least enough to make gs_gstate_free happy */
201
456k
    pgs->saved = 0;
202
456k
    pgs->clip_stack = NULL;
203
456k
    pgs->view_clip = NULL;
204
456k
    pgs->font = NULL;
205
456k
    pgs->root_font = NULL;
206
456k
    pgs->show_gstate = NULL;
207
456k
    pgs->device = NULL;
208
209
    /*
210
     * Just enough of the state is initialized at this point
211
     * that it's OK to call gs_gstate_free if an allocation fails.
212
     */
213
214
456k
    code = gs_gstate_initialize(pgs, mem);
215
456k
    if (code < 0)
216
0
        goto fail;
217
218
    /* Finish initializing the color rendering state. */
219
220
456k
    rc_alloc_struct_1(pgs->halftone, gs_halftone, &st_halftone, mem,
221
456k
                      goto fail, "gs_gstate_alloc(halftone)");
222
456k
    pgs->halftone->type = ht_type_none;
223
224
    /* Initialize other things not covered by initgraphics */
225
226
456k
    pgs->clip_stack = 0;
227
456k
    pgs->view_clip = gx_cpath_alloc(path_mem, "gs_gstate_alloc(view_clip)");
228
456k
    if (pgs->view_clip == NULL)
229
0
        goto fail;
230
456k
    pgs->view_clip->rule = 0;   /* no clipping */
231
456k
    pgs->effective_clip_id = pgs->clip_path->id;
232
456k
    pgs->effective_view_clip_id = gs_no_id;
233
456k
    pgs->in_cachedevice = 0;
234
456k
    pgs->device = 0;            /* setting device adjusts refcts */
235
456k
    code = gs_nulldevice(pgs);
236
456k
    if (code < 0)
237
0
        goto fail;
238
456k
    gs_setfillconstantalpha(pgs, 1.0);
239
456k
    gs_setstrokeconstantalpha(pgs, 1.0);
240
456k
    gs_setalphaisshape(pgs, false);
241
456k
    gs_settransfer(pgs, gs_identity_transfer);
242
456k
    gs_setflat(pgs, 1.0);
243
456k
    gs_setfilladjust(pgs, 0.3, 0.3);
244
456k
    gs_setlimitclamp(pgs, false);
245
456k
    gs_setstrokeadjust(pgs, true);
246
456k
    pgs->font = 0;              /* Not right, but acceptable until the */
247
    /* PostScript code does the first setfont. */
248
456k
    pgs->root_font = 0;         /* ditto */
249
456k
    pgs->in_charpath = (gs_char_path_mode) 0;
250
456k
    pgs->show_gstate = 0;
251
456k
    pgs->level = 0;
252
456k
    if (gs_initgraphics(pgs) >= 0)
253
456k
        return pgs;
254
    /* Something went very wrong. */
255
0
fail:
256
0
    gs_gstate_free(pgs);
257
0
    return 0;
258
456k
}
259
260
/* Set the client data in a graphics state. */
261
/* This should only be done to a newly created state. */
262
void
263
gs_gstate_set_client(gs_gstate * pgs, void *pdata,
264
                    const gs_gstate_client_procs * pprocs, bool client_has_pattern_streams)
265
1.05M
{
266
1.05M
    pgs->client_data = pdata;
267
1.05M
    pgs->client_procs = *pprocs;
268
1.05M
    pgs->have_pattern_streams = client_has_pattern_streams;
269
1.05M
}
270
271
/* Get the client data from a graphics state. */
272
#undef gs_gstate_client_data     /* gzstate.h makes this a macro */
273
void *
274
gs_gstate_client_data(const gs_gstate * pgs)
275
48.6M
{
276
48.6M
    return pgs->client_data;
277
48.6M
}
278
279
/* Free the chain of gstates.*/
280
void
281
gs_gstate_free_chain(gs_gstate * pgs)
282
151k
{
283
151k
   gs_gstate *saved = pgs, *tmp;
284
285
435k
   while(saved != 0) {
286
284k
       tmp = saved->saved;
287
284k
       gs_gstate_free(saved);
288
284k
       saved = tmp;
289
284k
   }
290
151k
}
291
292
/* Free a graphics state. */
293
void
294
gs_gstate_free(gs_gstate * pgs)
295
1.46M
{
296
1.46M
    if (pgs == NULL)
297
5.99k
        return;
298
1.45M
    gstate_free_contents(pgs);
299
1.45M
    gs_free_object(pgs->memory, pgs, "gs_gstate_free");
300
1.45M
}
301
302
/* Save the graphics state. */
303
int
304
gs_gsave(gs_gstate * pgs)
305
42.7M
{
306
42.7M
    gs_gstate *pnew = gstate_clone_for_gsave(pgs, "gs_gsave");
307
308
42.7M
    if (pnew == NULL)
309
7
        return_error(gs_error_VMerror);
310
    /* As of PLRM3, the interaction between gsave and the clip stack is
311
     * now clear. gsave stores the clip stack into the saved graphics
312
     * state, but then clears it in the current graphics state.
313
     *
314
     * Ordinarily, reference count rules would indicate an rc_decrement()
315
     * on pgs->clip_stack, but gstate_clone() has an exception for
316
     * the clip_stack field.
317
     */
318
42.7M
    pgs->clip_stack = NULL;
319
42.7M
    pgs->saved = pnew;
320
42.7M
    if (pgs->show_gstate == pgs)
321
0
        pgs->show_gstate = pnew->show_gstate = pnew;
322
42.7M
    pgs->trans_flags.xstate_change = false;
323
42.7M
    pgs->level++;
324
42.7M
    if_debug2m('g', pgs->memory, "[g]gsave -> "PRI_INTPTR", level = %d\n",
325
42.7M
              (intptr_t)pnew, pgs->level);
326
42.7M
    return 0;
327
42.7M
}
328
329
/*
330
 * Save the graphics state for a 'save'.
331
 * We cut the stack below the new gstate, and return the old one.
332
 * In addition to an ordinary gsave, we create a new view clip path.
333
 */
334
int
335
gs_gsave_for_save(gs_gstate * pgs, gs_gstate ** psaved)
336
1.21M
{
337
1.21M
    int code;
338
1.21M
    gx_clip_path *old_cpath = pgs->view_clip;
339
1.21M
    gx_clip_path *new_cpath;
340
341
1.21M
    if (old_cpath) {
342
1.21M
        new_cpath =
343
1.21M
            gx_cpath_alloc_shared(old_cpath, pgs->memory,
344
1.21M
                                  "gs_gsave_for_save(view_clip)");
345
1.21M
        if (new_cpath == 0)
346
0
            return_error(gs_error_VMerror);
347
1.21M
    } else {
348
0
        new_cpath = 0;
349
0
    }
350
1.21M
    code = gs_gsave(pgs);
351
1.21M
    if (code < 0)
352
1
        goto fail;
353
1.21M
    if (pgs->effective_clip_path == pgs->view_clip)
354
0
        pgs->effective_clip_path = new_cpath;
355
1.21M
    pgs->view_clip = new_cpath;
356
    /* Cut the stack so we can't grestore past here. */
357
1.21M
    *psaved = pgs->saved;
358
1.21M
    pgs->saved = 0;
359
360
1.21M
    code = gs_gsave(pgs);
361
1.21M
    if (code < 0) {
362
4
        pgs->saved = *psaved;
363
4
        *psaved = NULL;
364
4
        gs_grestore(pgs);
365
4
        return code;
366
4
    }
367
1.21M
    return code;
368
1
fail:
369
1
    if (new_cpath)
370
1
        gx_cpath_free(new_cpath, "gs_gsave_for_save(view_clip)");
371
1
    return code;
372
1.21M
}
373
374
/* Restore the graphics state. Can fully empty graphics stack */
375
int     /* return 0 if ok, 1 if stack was empty */
376
gs_grestore_only(gs_gstate * pgs)
377
42.4M
{
378
42.4M
    gs_gstate *saved = pgs->saved;
379
42.4M
    gs_gstate tmp_gstate;
380
42.4M
    void *pdata = pgs->client_data;
381
42.4M
    void *sdata;
382
383
42.4M
    if_debug2m('g', pgs->memory, "[g]grestore "PRI_INTPTR", level was %d\n",
384
42.4M
               (intptr_t)saved, pgs->level);
385
42.4M
    if (!saved)
386
53
        return 1;
387
42.4M
    sdata = saved->client_data;
388
42.4M
    if (saved->pattern_cache == 0)
389
4.23M
        saved->pattern_cache = pgs->pattern_cache;
390
    /* Swap back the client data pointers. */
391
42.4M
    pgs->client_data = sdata;
392
42.4M
    saved->client_data = pdata;
393
42.4M
    if (pdata != 0 && sdata != 0)
394
42.4M
        gstate_copy_client_data(pgs, pdata, sdata, copy_for_grestore);
395
42.4M
    gstate_free_contents(pgs);
396
42.4M
    tmp_gstate = *pgs;              /* temp after contents freed (with pointers zeroed) */
397
42.4M
    *pgs = *saved;
398
42.4M
    if (pgs->show_gstate == saved)
399
0
        pgs->show_gstate = pgs;
400
42.4M
    *saved = tmp_gstate;            /* restore "freed" state (pointers zeroed after contents freed) */
401
42.4M
    gs_free_object(pgs->memory, saved, "gs_grestore");
402
403
42.4M
    return 0;
404
42.4M
}
405
406
/* Restore the graphics state per PostScript semantics */
407
int
408
gs_grestore(gs_gstate * pgs)
409
42.2M
{
410
42.2M
    int code;
411
42.2M
    if (!pgs->saved)
412
0
        return gs_gsave(pgs);   /* shouldn't ever happen */
413
42.2M
    code = gs_grestore_only(pgs);
414
42.2M
    if (code < 0)
415
0
        return code;
416
417
    /* Wraparound: make sure there are always >= 1 saves on stack */
418
42.2M
    if (pgs->saved)
419
35.1M
        return 0;
420
7.16M
    return gs_gsave(pgs);
421
42.2M
}
422
423
/* Restore the graphics state for a 'restore', splicing the old stack */
424
/* back on.  Note that we actually do a grestoreall + 2 grestores. */
425
int
426
gs_grestoreall_for_restore(gs_gstate * pgs, gs_gstate * saved)
427
1.21M
{
428
1.21M
    int code;
429
430
1.87M
    while (pgs->saved->saved) {
431
656k
        code = gs_grestore(pgs);
432
656k
        if (code < 0)
433
0
            return code;
434
656k
    }
435
    /* Make sure we don't leave dangling pointers in the caches. */
436
1.21M
    if (pgs->pattern_cache)
437
1.21M
        (*pgs->pattern_cache->free_all) (pgs->pattern_cache);
438
1.21M
    pgs->saved->saved = saved;
439
1.21M
    code = gs_grestore(pgs);
440
1.21M
    if (code < 0)
441
0
        return code;
442
1.21M
    if (pgs->view_clip) {
443
1.21M
        gx_cpath_free(pgs->view_clip, "gs_grestoreall_for_restore");
444
1.21M
        pgs->view_clip = 0;
445
1.21M
    }
446
1.21M
    return gs_grestore(pgs);
447
1.21M
}
448
449
/* Restore to the bottommost graphics state (at this save level). */
450
int
451
gs_grestoreall(gs_gstate * pgs)
452
555
{
453
555
    if (!pgs->saved)            /* shouldn't happen */
454
0
        return gs_gsave(pgs);
455
1.03k
    while (pgs->saved->saved) {
456
478
        int code = gs_grestore(pgs);
457
458
478
        if (code < 0)
459
0
            return code;
460
478
    }
461
555
    return gs_grestore(pgs);
462
555
}
463
464
/* Allocate and return a new graphics state. */
465
gs_gstate *
466
gs_gstate_copy(const gs_gstate * pgs, gs_memory_t * mem)
467
1.03M
{
468
1.03M
    gs_gstate *pnew;
469
470
1.03M
    pnew = gstate_clone_for_gstate(pgs, mem, "gs_gstate");
471
1.03M
    if (pnew == NULL)
472
0
        return NULL;
473
1.03M
    clip_stack_rc_adjust(pnew->clip_stack, 1, "gs_gstate_copy");
474
1.03M
    pnew->saved = NULL;
475
    /*
476
     * Prevent dangling references from the show_gstate pointer.  If
477
     * this context is its own show_gstate, set the pointer in the clone
478
     * to point to the clone; otherwise, set the pointer in the clone to
479
     * NULL, and let gs_setgstate fix it up.
480
     */
481
1.03M
    pnew->show_gstate =
482
1.03M
        (pgs->show_gstate == pgs ? pnew : NULL);
483
1.03M
    return pnew;
484
1.03M
}
485
486
/* Copy one previously allocated graphics state to another. */
487
int
488
gs_copygstate(gs_gstate * pto, const gs_gstate * pfrom)
489
0
{
490
0
    return gstate_copy(pto, pfrom, copy_for_copygstate, "gs_copygstate");
491
0
}
492
493
/* Copy the current graphics state to a previously allocated one. */
494
int
495
gs_currentgstate(gs_gstate * pto, const gs_gstate * pgs)
496
2
{
497
2
    int code =
498
2
        gstate_copy(pto, pgs, copy_for_currentgstate, "gs_currentgstate");
499
500
2
    if (code >= 0)
501
2
        pto->view_clip = 0;
502
2
    return code;
503
2
}
504
505
/* Restore the current graphics state from a previously allocated one. */
506
int
507
gs_setgstate(gs_gstate * pgs, const gs_gstate * pfrom)
508
35.0k
{
509
    /*
510
     * The implementation is the same as currentgstate,
511
     * except we must preserve the saved pointer, the level,
512
     * the view clip, and possibly the show_gstate.
513
     */
514
35.0k
    gs_gstate *saved_show = pgs->show_gstate;
515
35.0k
    int level = pgs->level;
516
35.0k
    gx_clip_path *view_clip = pgs->view_clip;
517
35.0k
    int code;
518
519
35.0k
    pgs->view_clip = 0;         /* prevent refcount decrementing */
520
35.0k
    code = gstate_copy(pgs, pfrom, copy_for_setgstate, "gs_setgstate");
521
35.0k
    if (code < 0)
522
0
        return code;
523
35.0k
    pgs->level = level;
524
35.0k
    pgs->view_clip = view_clip;
525
35.0k
    pgs->show_gstate =
526
35.0k
        (pgs->show_gstate == pfrom ? pgs : saved_show);
527
35.0k
    return 0;
528
35.0k
}
529
530
/* Get the allocator pointer of a graphics state. */
531
/* This is provided only for the interpreter */
532
/* and for color space implementation. */
533
gs_memory_t *
534
gs_gstate_memory(const gs_gstate * pgs)
535
504k
{
536
504k
    return pgs->memory;
537
504k
}
538
539
/* Get the saved pointer of the graphics state. */
540
/* This is provided only for Level 2 grestore. */
541
gs_gstate *
542
gs_gstate_saved(const gs_gstate * pgs)
543
12.9M
{
544
12.9M
    return pgs->saved;
545
12.9M
}
546
547
/* Swap the saved pointer of the graphics state. */
548
/* This is provided only for save/restore. */
549
gs_gstate *
550
gs_gstate_swap_saved(gs_gstate * pgs, gs_gstate * new_saved)
551
0
{
552
0
    gs_gstate *saved = pgs->saved;
553
554
0
    pgs->saved = new_saved;
555
0
    return saved;
556
0
}
557
558
/* Swap the memory pointer of the graphics state. */
559
/* This is provided only for the interpreter. */
560
gs_memory_t *
561
gs_gstate_swap_memory(gs_gstate * pgs, gs_memory_t * mem)
562
4
{
563
4
    gs_memory_t *memory = pgs->memory;
564
565
4
    pgs->memory = mem;
566
4
    return memory;
567
4
}
568
569
/* ------ Operations on components ------ */
570
571
/*
572
 * Push an overprint compositor onto the current device. Note that if
573
 * the current device already is an overprint compositor, the
574
 * composite will update its parameters but not create a new
575
 * compositor device.
576
 */
577
int
578
gs_gstate_update_overprint(gs_gstate * pgs, const gs_overprint_params_t * pparams)
579
1.01M
{
580
1.01M
    gs_composite_t *    pct = 0;
581
1.01M
    int                 code;
582
1.01M
    gx_device *         dev = pgs->device;
583
1.01M
    gx_device *         ovptdev;
584
1.01M
    gs_overprint_params_t params;
585
586
1.01M
    if (pparams->op_state == GS_OP_STATE_NONE) {
587
506k
        gx_overprint_adjust_t op_adj;
588
589
506k
        params = *pparams;
590
506k
        pparams = &params;
591
506k
        op_adj.pgs = pgs;
592
506k
        op_adj.retain_any_comps = params.retain_any_comps;
593
506k
        op_adj.is_fill_color = params.is_fill_color;
594
506k
        op_adj.effective_opm = params.effective_opm;
595
506k
        op_adj.drawn_comps = params.drawn_comps;
596
506k
        op_adj.op_was_active = false;
597
506k
        if (dev_proc(dev, dev_spec_op)(dev, gxdso_overprint_adjust,
598
506k
                                       &op_adj, sizeof(op_adj)) > 0) {
599
0
            params.retain_any_comps = op_adj.retain_any_comps;
600
0
            params.effective_opm = op_adj.effective_opm;
601
0
            params.drawn_comps = op_adj.drawn_comps;
602
0
            pgs->color[0].effective_opm = params.effective_opm;
603
506k
        } else if (!params.retain_any_comps && !op_adj.op_was_active &&
604
484k
                   !(params.is_fill_color ? pgs->overprint : pgs->stroke_overprint)) {
605
0
            return 0;
606
0
        }
607
506k
    }
608
609
1.01M
    code = gs_create_overprint(&pct, pparams, pgs->memory);
610
1.01M
    if (code >= 0) {
611
1.01M
        code = dev_proc(dev, composite)( dev,
612
1.01M
                                                   &ovptdev,
613
1.01M
                                                   pct,
614
1.01M
                                                   pgs,
615
1.01M
                                                   pgs->memory,
616
1.01M
                                                   NULL);
617
1.01M
        if (code >= 0 || code == gs_error_handled){
618
1.01M
            if (code == 1) {
619
0
                gx_set_device_only(pgs, ovptdev);
620
                /* Get rid of extra reference */
621
0
                rc_decrement(ovptdev, "gs_gstate_update_overprint(ovptdev)");
622
0
            }
623
1.01M
            code = 0;
624
1.01M
        }
625
1.01M
    }
626
1.01M
    if (pct != 0)
627
1.01M
        gs_free_object(pgs->memory, pct, "gs_gstate_update_overprint");
628
629
    /* the following hack handles devices that don't support compositors */
630
1.01M
    if (code == gs_error_unknownerror && !pparams->retain_any_comps)
631
0
        code = 0;
632
1.01M
    return code;
633
1.01M
}
634
635
/*
636
 * Reset the overprint mode for the current color space and color. This
637
 * routine should be called  whenever the current device (i.e.: color
638
 * model), overprint, overprint mode, color space, or color are modified.
639
 *
640
 * The need reason this routine must be called for changes in the current
641
 * color and must consider the current color involves the Pattern color
642
 * space. In that space, the "color" (pattern) can determine if the base
643
 * color space is used (PatternType 1 with PaintType 2), or may provide
644
 * is own color space (PatternType 1 with PaintType 1, PatternType 2).
645
 *
646
 * The most general situation (PatternType 1 with PaintType 1) cannot be
647
 * handled properly due to limitations of the pattern cache mechanism,
648
 * so in this case overprint is effectively disable by making all color
649
 * components "drawn".
650
 */
651
int
652
gs_do_set_overprint(gs_gstate * pgs)
653
506k
{
654
506k
    const gs_color_space *  pcs = gs_currentcolorspace_inline(pgs);
655
506k
    const gs_client_color * pcc = gs_currentcolor_inline(pgs);
656
506k
    int                     code = 0;
657
658
506k
    if (cs_num_components(pcs) < 0 && pcc->pattern != 0)
659
0
        code = pcc->pattern->type->procs.set_color(pcc, pgs);
660
506k
    else {
661
506k
        gx_device* dev = pgs->device;
662
506k
        cmm_dev_profile_t* dev_profile;
663
506k
        gs_color_space_index pcs_index = gs_color_space_get_index(pcs);
664
665
506k
        dev_proc(dev, get_profile)(dev, &dev_profile);
666
506k
        if (dev_profile->overprint_control == gs_overprint_control_disable)
667
0
            return code;
668
669
        /* Transparency device that supports spots and where we have
670
           sep or devicen colors needs special consideration if the device
671
           is in a additive blend mode.  This could
672
           be written more compactly, but it would be unreadable. */
673
506k
        if (dev_proc(dev, dev_spec_op)(dev, gxdso_pdf14_sep_device, NULL, 0) > 0 &&
674
188k
            (dev->color_info.polarity != GX_CINFO_POLARITY_SUBTRACTIVE)) {
675
188k
            if (pcs_index == gs_color_space_index_Separation) {
676
8.88k
                if (!(pcs->params.separation.color_type == SEP_MIX ||
677
0
                      pcs->params.separation.color_type == SEP_ENUM)) {
678
                    /* Sep color is not a spot color.  We can't do OP and trans */
679
0
                    return code;
680
0
                }
681
179k
            } else if (pcs_index == gs_color_space_index_DeviceN) {
682
0
                if (pcs->params.device_n.color_type != SEP_PURE_SPOT) {
683
                    /* DeviceN has process colors  We can't do OP and trans. */
684
0
                    return code;
685
0
                }
686
0
            }
687
188k
        }
688
689
        /* If we have a CIE-based space, use the ICC equivalent space */
690
506k
        if (gs_color_space_is_PSCIE(pcs) && pcs->icc_equivalent != NULL)
691
0
            pcs = pcs->icc_equivalent;
692
693
        /* The spaces that do not allow opm (e.g. ones that are not ICC or DeviceCMYK)
694
           will blow away any true setting later. But we have to be prepared
695
           in case this is a CMYK ICC space for example. Hence we set effective mode
696
           to mode here (Bug 698721)*/
697
506k
        pgs->color[0].effective_opm = pgs->overprint_mode;
698
699
506k
        if_debug2m(gs_debug_flag_overprint, pgs->memory,
700
506k
            "[overprint] gs_do_set_overprint. Preset effective mode. pgs->color[0].effective_opm = %d pgs->color[1].effective_opm = %d\n",
701
506k
            pgs->color[0].effective_opm, pgs->color[1].effective_opm);
702
703
506k
        pcs->type->set_overprint(pcs, pgs);
704
506k
    }
705
506k
    return code;
706
506k
}
707
708
/* setoverprint (non-stroke case) interpreter code
709
   ensures that this is called when appropriate. This
710
   should only be coming when we are doing PS files.
711
   As they don't have separate stroke and fill overprint
712
   controls */
713
void
714
gs_setoverprint(gs_gstate * pgs, bool ovp)
715
1.94M
{
716
1.94M
    pgs->overprint = ovp;
717
1.94M
    pgs->stroke_overprint = ovp;
718
1.94M
}
719
720
/* currentoverprint */
721
bool
722
gs_currentoverprint(const gs_gstate * pgs)
723
972k
{
724
972k
    return pgs->overprint;
725
972k
}
726
727
/* setstrokeoverprint */
728
void
729
gs_setstrokeoverprint(gs_gstate * pgs, bool ovp)
730
237k
{
731
237k
    pgs->stroke_overprint = ovp;
732
237k
}
733
734
/* currentstrokeoverprint */
735
bool
736
gs_currentstrokeoverprint(const gs_gstate * pgs)
737
15.1k
{
738
15.1k
    return pgs->stroke_overprint;
739
15.1k
}
740
741
/* setstrokeoverprint */
742
void
743
gs_setfilloverprint(gs_gstate * pgs, bool ovp)
744
243k
{
745
243k
    pgs->overprint = ovp;
746
243k
}
747
748
/* currentstrokeoverprint */
749
bool
750
gs_currentfilloverprint(const gs_gstate * pgs)
751
11.7k
{
752
11.7k
    return pgs->overprint;
753
11.7k
}
754
755
/* setoverprintmode */
756
int
757
gs_setoverprintmode(gs_gstate * pgs, int mode)
758
174k
{
759
174k
    if (mode < 0 || mode > 1)
760
8
        return_error(gs_error_rangecheck);
761
174k
    pgs->overprint_mode = mode;
762
763
174k
    return 0;
764
174k
}
765
766
/* currentoverprintmode */
767
int
768
gs_currentoverprintmode(const gs_gstate * pgs)
769
1
{
770
1
    return pgs->overprint_mode;
771
1
}
772
773
void
774
gs_setcpsimode(gs_memory_t *mem, bool mode)
775
0
{
776
0
    gs_lib_ctx_t *libctx = gs_lib_ctx_get_interp_instance(mem);
777
778
0
    libctx->core->CPSI_mode = mode;
779
0
}
780
781
/* currentcpsimode */
782
bool
783
gs_currentcpsimode(const gs_memory_t * mem)
784
633M
{
785
633M
    gs_lib_ctx_t *libctx = gs_lib_ctx_get_interp_instance(mem);
786
787
633M
    return libctx->core->CPSI_mode;
788
633M
}
789
790
/* The edgebuffer based scanconverter can only cope with values of 0
791
 * or 0.5 (i.e. 'center of pixel' or 'any part of pixel'). These
792
 * are the only values required for correct behaviour according to
793
 * the PDF and PS specs. Therefore, if we are using the edgebuffer
794
 * based scan converter, force these values. */
795
static void
796
sanitize_fill_adjust(gs_gstate * pgs)
797
14.7M
{
798
14.7M
    int scanconverter = gs_getscanconverter(pgs->memory);
799
14.7M
    if (scanconverter >= GS_SCANCONVERTER_EDGEBUFFER || (GS_SCANCONVERTER_DEFAULT_IS_EDGEBUFFER && scanconverter == GS_SCANCONVERTER_DEFAULT)) {
800
14.7M
        fixed adjust = (pgs->fill_adjust.x >= float2fixed(0.25) || pgs->fill_adjust.y >= float2fixed(0.25) ? fixed_half : 0);
801
14.7M
        pgs->fill_adjust.x = adjust;
802
14.7M
        pgs->fill_adjust.y = adjust;
803
14.7M
    }
804
14.7M
}
805
806
void
807
gs_setscanconverter(gs_gstate * gs, int converter)
808
6.96k
{
809
6.96k
    gs_lib_ctx_t *libctx = gs_lib_ctx_get_interp_instance(gs->memory);
810
811
6.96k
    libctx->core->scanconverter = converter;
812
813
6.96k
    sanitize_fill_adjust(gs);
814
6.96k
}
815
816
/* getscanconverter */
817
int
818
gs_getscanconverter(const gs_memory_t * mem)
819
61.8M
{
820
61.8M
    gs_lib_ctx_t *libctx = gs_lib_ctx_get_interp_instance(mem);
821
822
61.8M
    return libctx->core->scanconverter;
823
61.8M
}
824
825
/* setrenderingintent
826
 *
827
 *  Use ICC numbers from Table 18 (section 6.1.11) rather than the PDF order
828
 *  to reduce re-coding and confusion.
829
 *    Perceptual            0
830
 *    Relative Colorimetric 1
831
 *    Saturation            2
832
 *    AbsoluteColorimetric  3
833
 */
834
int
835
74.3k
gs_setrenderingintent(gs_gstate *pgs, int ri) {
836
74.3k
    if (ri < 0 || ri > 3)
837
0
        return_error(gs_error_rangecheck);
838
74.3k
    pgs->renderingintent = ri;
839
74.3k
    return 0;
840
74.3k
}
841
842
/* currentrenderingintent */
843
int
844
gs_currentrenderingintent(const gs_gstate * pgs)
845
0
{
846
0
    return pgs->renderingintent;
847
0
}
848
849
int
850
0
gs_setblackptcomp(gs_gstate *pgs, bool bkpt) {
851
0
    pgs->blackptcomp = bkpt;
852
0
    return 0;
853
0
}
854
855
/* currentrenderingintent */
856
bool
857
gs_currentblackptcomp(const gs_gstate * pgs)
858
0
{
859
0
    return pgs->blackptcomp;
860
0
}
861
862
/*
863
 * Reset most of the graphics state.
864
 */
865
int
866
gs_initgraphics(gs_gstate * pgs)
867
1.37M
{
868
1.37M
    int code;
869
1.37M
    const gs_gstate gstate_initial = {
870
1.37M
            gs_gstate_initial(1.0)
871
1.37M
        };
872
1.37M
    gs_matrix m;
873
1.37M
    gs_make_identity(&m);
874
875
1.37M
    gs_initmatrix(pgs);
876
1.37M
    if ((code = gs_newpath(pgs)) < 0 ||
877
1.37M
        (code = gs_initclip(pgs)) < 0 ||
878
1.37M
        (code = gs_setlinewidth(pgs, 1.0)) < 0 ||
879
1.37M
        (code = gs_setlinestartcap(pgs, gstate_initial.line_params.start_cap)) < 0 ||
880
1.37M
        (code = gs_setlineendcap(pgs, gstate_initial.line_params.end_cap)) < 0 ||
881
1.37M
        (code = gs_setlinedashcap(pgs, gstate_initial.line_params.dash_cap)) < 0 ||
882
1.37M
        (code = gs_setlinejoin(pgs, gstate_initial.line_params.join)) < 0 ||
883
1.37M
        (code = gs_setcurvejoin(pgs, gstate_initial.line_params.curve_join)) < 0 ||
884
1.37M
        (code = gs_setdash(pgs, (float *)0, 0, 0.0)) < 0 ||
885
1.37M
        (gs_setdashadapt(pgs, false),
886
1.37M
         (code = gs_setdotlength(pgs, 0.0, false))) < 0 ||
887
1.37M
        (code = gs_setdotorientation(pgs)) < 0 ||
888
1.37M
        (code = gs_setmiterlimit(pgs, gstate_initial.line_params.miter_limit)) < 0
889
1.37M
        )
890
0
        return code;
891
1.37M
    gs_init_rop(pgs);
892
    /* Initialize things so that gx_remap_color won't crash. */
893
1.37M
    if (pgs->icc_manager->default_gray == 0x00) {
894
166k
        gs_color_space  *pcs1, *pcs2;
895
896
166k
        pcs1 = gs_cspace_new_DeviceGray(pgs->memory);
897
166k
        if (pcs1 == NULL)
898
0
            return_error(gs_error_unknownerror);
899
900
166k
        if (pgs->color[0].color_space != NULL) {
901
0
            gs_setcolorspace(pgs, pcs1);
902
0
            rc_decrement_cs(pcs1, "gs_initgraphics");
903
166k
        } else {
904
166k
            pgs->color[0].color_space = pcs1;
905
166k
            gs_setcolorspace(pgs, pcs1);
906
166k
        }
907
166k
        code = gx_set_dev_color(pgs);
908
166k
        if (code < 0)
909
0
            return code;
910
911
166k
        gs_swapcolors_quick(pgs); /* To color 1 */
912
913
166k
        pcs2 = gs_cspace_new_DeviceGray(pgs->memory);
914
166k
        if (pcs2 == NULL)
915
0
            return_error(gs_error_unknownerror);
916
917
166k
        if (pgs->color[0].color_space != NULL) {
918
0
            gs_setcolorspace(pgs, pcs2);
919
0
            rc_decrement_cs(pcs2, "gs_initgraphics");
920
166k
        } else {
921
166k
            pgs->color[0].color_space = pcs2;
922
166k
            gs_setcolorspace(pgs, pcs2);
923
166k
        }
924
166k
        code = gx_set_dev_color(pgs);
925
926
166k
        gs_swapcolors_quick(pgs); /* To color 0 */
927
928
166k
        if (code < 0)
929
0
            return code;
930
931
1.20M
    } else {
932
1.20M
        gs_color_space  *pcs1, *pcs2;
933
934
1.20M
        pcs1 = gs_cspace_new_ICC(pgs->memory, pgs, 1);
935
1.20M
        if (pcs1 == NULL)
936
0
            return_error(gs_error_unknownerror);
937
938
1.20M
        if (pgs->color[0].color_space != NULL) {
939
916k
            gs_setcolorspace(pgs, pcs1);
940
916k
            rc_decrement_cs(pcs1, "gs_initgraphics");
941
916k
        } else {
942
289k
            pgs->color[0].color_space = pcs1;
943
289k
            gs_setcolorspace(pgs, pcs1);
944
289k
        }
945
1.20M
        code = gx_set_dev_color(pgs);
946
1.20M
        if (code < 0)
947
407
            return code;
948
949
1.20M
        gs_swapcolors_quick(pgs); /* To color 1 */
950
1.20M
        pcs2 = gs_cspace_new_ICC(pgs->memory, pgs, 1);
951
1.20M
        if (pcs2 == NULL)
952
0
            return_error(gs_error_unknownerror);
953
954
1.20M
        if (pgs->color[0].color_space != NULL) {
955
915k
            gs_setcolorspace(pgs, pcs2);
956
915k
            rc_decrement_cs(pcs2, "gs_initgraphics");
957
915k
        } else {
958
289k
            pgs->color[0].color_space = pcs2;
959
289k
            gs_setcolorspace(pgs, pcs2);
960
289k
        }
961
1.20M
        code = gx_set_dev_color(pgs);
962
963
1.20M
        gs_swapcolors_quick(pgs); /* To color 0 */
964
965
1.20M
        if (code < 0)
966
0
            return code;
967
1.20M
    }
968
1.37M
    pgs->in_cachedevice = 0;
969
970
1.37M
    code = gs_settextspacing(pgs, (double)0.0);
971
1.37M
    if (code < 0)
972
0
        goto exit;
973
1.37M
    code = gs_settextleading(pgs, (double)0.0);
974
1.37M
    if (code < 0)
975
0
        goto exit;
976
977
1.37M
    gs_settextrenderingmode(pgs, 0);
978
979
1.37M
    code = gs_setwordspacing(pgs, (double)0.0);
980
1.37M
    if (code < 0)
981
0
        goto exit;
982
1.37M
    code = gs_settexthscaling(pgs, (double)100.0);
983
1.37M
    if (code < 0)
984
0
        goto exit;
985
986
1.37M
    gs_setaccuratecurves(pgs, true);
987
988
1.37M
    code = gs_setstrokeconstantalpha(pgs, 1.0);
989
1.37M
    if (code < 0)
990
0
        goto exit;
991
1.37M
    code = gs_setfillconstantalpha(pgs, 1.0);
992
1.37M
    if (code < 0)
993
0
        goto exit;
994
1.37M
    code = gs_setalphaisshape(pgs, 0);
995
1.37M
    if (code < 0)
996
0
        goto exit;
997
1.37M
    code = gs_setblendmode(pgs, BLEND_MODE_Compatible);
998
1.37M
    if (code < 0)
999
0
        goto exit;
1000
1.37M
    code = gs_settextknockout(pgs, true);
1001
1.37M
    if (code < 0)
1002
0
        goto exit;
1003
1.37M
    code = gs_setsmoothness(pgs, 0.02); /* Match gs code */
1004
1.37M
    if (code < 0)
1005
0
        goto exit;
1006
1007
1.37M
    code = gs_settextmatrix(pgs, &m);
1008
1.37M
    if (code < 0)
1009
0
        goto exit;
1010
1011
1.37M
    code = gs_settextlinematrix(pgs, &m);
1012
1.37M
    if (code < 0)
1013
0
        goto exit;
1014
1.37M
exit:
1015
1.37M
    return code;
1016
1.37M
}
1017
1018
/* setfilladjust */
1019
int
1020
gs_setfilladjust(gs_gstate * pgs, double adjust_x, double adjust_y)
1021
14.6M
{
1022
14.6M
#define CLAMP_TO_HALF(v)\
1023
29.3M
    ((v) <= 0 ? fixed_0 : (v) >= 0.5 ? fixed_half : float2fixed(v));
1024
1025
14.6M
    pgs->fill_adjust.x = CLAMP_TO_HALF(adjust_x);
1026
14.6M
    pgs->fill_adjust.y = CLAMP_TO_HALF(adjust_y);
1027
1028
14.6M
    sanitize_fill_adjust(pgs);
1029
1030
14.6M
    return 0;
1031
14.6M
#undef CLAMP_TO_HALF
1032
14.6M
}
1033
1034
/* currentfilladjust */
1035
int
1036
gs_currentfilladjust(const gs_gstate * pgs, gs_point * adjust)
1037
231k
{
1038
231k
    adjust->x = fixed2float(pgs->fill_adjust.x);
1039
231k
    adjust->y = fixed2float(pgs->fill_adjust.y);
1040
231k
    return 0;
1041
231k
}
1042
1043
/* setlimitclamp */
1044
void
1045
gs_setlimitclamp(gs_gstate * pgs, bool clamp)
1046
754k
{
1047
754k
    pgs->clamp_coordinates = clamp;
1048
754k
}
1049
1050
/* currentlimitclamp */
1051
bool
1052
gs_currentlimitclamp(const gs_gstate * pgs)
1053
0
{
1054
0
    return pgs->clamp_coordinates;
1055
0
}
1056
1057
/* settextrenderingmode */
1058
void
1059
gs_settextrenderingmode(gs_gstate * pgs, uint trm)
1060
1.90M
{
1061
1.90M
    pgs->text_rendering_mode = trm;
1062
1.90M
}
1063
1064
/* currenttextrenderingmode */
1065
uint
1066
gs_currenttextrenderingmode(const gs_gstate * pgs)
1067
19.2M
{
1068
19.2M
    return pgs->text_rendering_mode;
1069
19.2M
}
1070
1071
double
1072
gs_currenttextspacing(const gs_gstate *pgs)
1073
12.3M
{
1074
12.3M
    return pgs->textspacing;
1075
12.3M
}
1076
1077
int
1078
gs_settextspacing(gs_gstate *pgs, double Tc)
1079
2.02M
{
1080
2.02M
    int code = 0;
1081
2.02M
    gs_fixed_point dxy;
1082
1083
2.02M
    code = gs_distance_transform2fixed(&pgs->ctm, Tc, 1, &dxy);
1084
2.02M
    if (code < 0)
1085
5.50k
        return code;
1086
1087
2.01M
    pgs->textspacing = (float)Tc;
1088
2.01M
    return 0;
1089
2.02M
}
1090
1091
double
1092
gs_currenttextleading(const gs_gstate *pgs)
1093
0
{
1094
0
    return pgs->textleading;
1095
0
}
1096
1097
int
1098
gs_settextleading(gs_gstate *pgs, double TL)
1099
1.74M
{
1100
1.74M
    pgs->textleading = (float)TL;
1101
1.74M
    return 0;
1102
1.74M
}
1103
1104
double
1105
gs_currenttextrise(const gs_gstate *pgs)
1106
0
{
1107
0
    return pgs->textrise;
1108
0
}
1109
1110
int
1111
gs_settextrise(gs_gstate *pgs, double Ts)
1112
3.35k
{
1113
3.35k
    pgs->textrise = (float)Ts;
1114
3.35k
    return 0;
1115
3.35k
}
1116
1117
double
1118
gs_currentwordspacing(const gs_gstate *pgs)
1119
12.3M
{
1120
12.3M
    return pgs->wordspacing;
1121
12.3M
}
1122
1123
int
1124
gs_setwordspacing(gs_gstate *pgs, double Tw)
1125
1.51M
{
1126
1.51M
    pgs->wordspacing = (float)Tw;
1127
1.51M
    return 0;
1128
1.51M
}
1129
1130
int
1131
gs_settexthscaling(gs_gstate *pgs, double Tz)
1132
1.46M
{
1133
1.46M
    pgs->texthscaling = (float)Tz;
1134
1.46M
    return 0;
1135
1.46M
}
1136
1137
double
1138
gs_currenttexthscaling(const gs_gstate *pgs)
1139
0
{
1140
0
    return pgs->texthscaling;
1141
0
}
1142
1143
int
1144
gs_setPDFfontsize(gs_gstate *pgs, double Tf)
1145
1.13M
{
1146
1.13M
    pgs->PDFfontsize = (float)Tf;
1147
1.13M
    return 0;
1148
1.13M
}
1149
1150
double
1151
gs_currentPDFfontsize(const gs_gstate *pgs)
1152
0
{
1153
0
    return pgs->PDFfontsize;
1154
0
}
1155
1156
int
1157
gs_settextlinematrix(gs_gstate *pgs, gs_matrix *m)
1158
6.12M
{
1159
6.12M
    pgs->textlinematrix.xx = m->xx;
1160
6.12M
    pgs->textlinematrix.xy = m->xy;
1161
6.12M
    pgs->textlinematrix.yx = m->yx;
1162
6.12M
    pgs->textlinematrix.yy = m->yy;
1163
6.12M
    pgs->textlinematrix.tx = m->tx;
1164
6.12M
    pgs->textlinematrix.ty = m->ty;
1165
6.12M
    return 0;
1166
6.12M
}
1167
int
1168
gs_gettextlinematrix(gs_gstate *pgs, gs_matrix *m)
1169
0
{
1170
0
    m->xx = pgs->textlinematrix.xx;
1171
0
    m->xy = pgs->textlinematrix.xy;
1172
0
    m->yx = pgs->textlinematrix.yx;
1173
0
    m->yy = pgs->textlinematrix.yy;
1174
0
    m->tx = pgs->textlinematrix.tx;
1175
0
    m->ty = pgs->textlinematrix.ty;
1176
0
    return 0;
1177
0
}
1178
1179
int
1180
gs_settextmatrix(gs_gstate *pgs, gs_matrix *m)
1181
6.12M
{
1182
6.12M
    pgs->textmatrix.xx = m->xx;
1183
6.12M
    pgs->textmatrix.xy = m->xy;
1184
6.12M
    pgs->textmatrix.yx = m->yx;
1185
6.12M
    pgs->textmatrix.yy = m->yy;
1186
6.12M
    pgs->textmatrix.tx = m->tx;
1187
6.12M
    pgs->textmatrix.ty = m->ty;
1188
6.12M
    return 0;
1189
6.12M
}
1190
int
1191
gs_gettextmatrix(gs_gstate *pgs, gs_matrix *m)
1192
0
{
1193
0
    m->xx = pgs->textmatrix.xx;
1194
0
    m->xy = pgs->textmatrix.xy;
1195
0
    m->yx = pgs->textmatrix.yx;
1196
0
    m->yy = pgs->textmatrix.yy;
1197
0
    m->tx = pgs->textmatrix.tx;
1198
0
    m->ty = pgs->textmatrix.ty;
1199
0
    return 0;
1200
0
}
1201
1202
1203
/* sethpglpathmode */
1204
void
1205
gs_sethpglpathmode(gs_gstate * pgs, bool path)
1206
567k
{
1207
567k
    pgs->hpgl_path_mode = path;
1208
567k
}
1209
1210
/* currenthpglpathmode */
1211
bool
1212
gs_currenthpglpathmode(const gs_gstate * pgs)
1213
0
{
1214
0
    return pgs->hpgl_path_mode;
1215
0
}
1216
1217
/* ------ Internal routines ------ */
1218
1219
/* Free the privately allocated parts of a gstate. */
1220
static void
1221
gstate_free_parts(gs_gstate * parts, gs_memory_t * mem, client_name_t cname)
1222
88.1M
{
1223
88.1M
    gs_free_object(mem, parts->color[1].dev_color, cname);
1224
88.1M
    gs_free_object(mem, parts->color[1].ccolor, cname);
1225
88.1M
    gs_free_object(mem, parts->color[0].dev_color, cname);
1226
88.1M
    gs_free_object(mem, parts->color[0].ccolor, cname);
1227
88.1M
    parts->color[1].dev_color = 0;
1228
88.1M
    parts->color[1].ccolor = 0;
1229
88.1M
    parts->color[0].dev_color = 0;
1230
88.1M
    parts->color[0].ccolor = 0;
1231
88.1M
    if (!parts->effective_clip_shared && parts->effective_clip_path) {
1232
0
        gx_cpath_free(parts->effective_clip_path, cname);
1233
0
        parts->effective_clip_path = 0;
1234
0
    }
1235
88.1M
    gx_cpath_free(parts->clip_path, cname);
1236
88.1M
    parts->clip_path = 0;
1237
88.1M
    if (parts->path) {
1238
44.2M
        gx_path_free(parts->path, cname);
1239
44.2M
        parts->path = 0;
1240
44.2M
    }
1241
88.1M
}
1242
1243
static inline void
1244
gstate_parts_init_dev_color(gx_device_color *dc)
1245
88.4M
{
1246
88.4M
    gx_device_color_type dct = dc->type;
1247
88.4M
    gs_graphics_type_tag_t gtt = dc->tag;
1248
88.4M
    memset(dc, 0x00, sizeof(gx_device_color));
1249
88.4M
    dc->type = dct;
1250
88.4M
    dc->tag = gtt;
1251
88.4M
}
1252
1253
/* Allocate the privately allocated parts of a gstate. */
1254
static int
1255
gstate_alloc_parts(gs_gstate * parts, const gs_gstate * shared,
1256
                   gs_memory_t * mem, client_name_t cname)
1257
44.2M
{
1258
44.2M
    gs_memory_t *path_mem = gstate_path_memory(mem);
1259
1260
44.2M
    parts->path =
1261
44.2M
        (shared ?
1262
43.7M
         gx_path_alloc_shared(shared->path, path_mem,
1263
43.7M
                              "gstate_alloc_parts(path)") :
1264
44.2M
         gx_path_alloc(path_mem, "gstate_alloc_parts(path)"));
1265
44.2M
    parts->clip_path =
1266
44.2M
        (shared ?
1267
43.7M
         gx_cpath_alloc_shared(shared->clip_path, mem,
1268
43.7M
                               "gstate_alloc_parts(clip_path)") :
1269
44.2M
         gx_cpath_alloc(mem, "gstate_alloc_parts(clip_path)"));
1270
44.2M
    if (!shared || shared->effective_clip_shared) {
1271
44.2M
        parts->effective_clip_path = parts->clip_path;
1272
44.2M
        parts->effective_clip_shared = true;
1273
44.2M
    } else {
1274
0
        parts->effective_clip_path =
1275
0
            gx_cpath_alloc_shared(shared->effective_clip_path, mem,
1276
0
                                  "gstate_alloc_parts(effective_clip_path)");
1277
0
        parts->effective_clip_shared = false;
1278
0
    }
1279
44.2M
    parts->color[0].color_space = NULL;
1280
44.2M
    parts->color[1].color_space = NULL;
1281
44.2M
    parts->color[0].ccolor =
1282
44.2M
        gs_alloc_struct(mem, gs_client_color, &st_client_color, cname);
1283
44.2M
    parts->color[1].ccolor =
1284
44.2M
        gs_alloc_struct(mem, gs_client_color, &st_client_color, cname);
1285
44.2M
    parts->color[0].dev_color =
1286
44.2M
        gs_alloc_struct(mem, gx_device_color, &st_device_color, cname);
1287
44.2M
    parts->color[1].dev_color =
1288
44.2M
        gs_alloc_struct(mem, gx_device_color, &st_device_color, cname);
1289
44.2M
    if (parts->path == 0 || parts->clip_path == 0 ||
1290
44.2M
        parts->effective_clip_path == 0 ||
1291
44.2M
        parts->color[0].ccolor == 0 || parts->color[0].dev_color == 0 ||
1292
44.2M
        parts->color[1].ccolor == 0 || parts->color[1].dev_color == 0
1293
44.2M
        ) {
1294
2
        gstate_free_parts(parts, mem, cname);
1295
2
        return_error(gs_error_VMerror);
1296
2
    }
1297
44.2M
    gstate_parts_init_dev_color(parts->color[0].dev_color);
1298
44.2M
    gstate_parts_init_dev_color(parts->color[1].dev_color);
1299
44.2M
    return 0;
1300
44.2M
}
1301
1302
/*
1303
 * Allocate a gstate and its contents.
1304
 * If pfrom is not NULL, the path, clip_path, and (if distinct from both
1305
 * clip_path and view_clip) effective_clip_path share the segments of
1306
 * pfrom's corresponding path(s).
1307
 */
1308
static gs_gstate *
1309
gstate_alloc(gs_memory_t * mem, client_name_t cname, const gs_gstate * pfrom)
1310
44.2M
{
1311
44.2M
    gs_gstate *pgs =
1312
44.2M
        gs_alloc_struct(mem, gs_gstate, &st_gs_gstate, cname);
1313
1314
44.2M
    if (pgs == NULL)
1315
5
        return NULL;
1316
44.2M
    memset(pgs, 0x00, sizeof(gs_gstate));
1317
44.2M
    if (gstate_alloc_parts(pgs, pfrom, mem, cname) < 0) {
1318
2
        gs_free_object(mem, pgs, cname);
1319
2
        return NULL;
1320
2
    }
1321
44.2M
    pgs->memory = mem;
1322
44.2M
    return pgs;
1323
44.2M
}
1324
1325
/* Copy the dash pattern from one gstate to another. */
1326
static int
1327
gstate_copy_dash(gs_memory_t *mem, gx_dash_params *dash , const gs_gstate * pfrom)
1328
88.0k
{
1329
88.0k
    return gx_set_dash(dash, pfrom->line_params.dash.pattern,
1330
88.0k
                      pfrom->line_params.dash.pattern_size,
1331
88.0k
                      pfrom->line_params.dash.offset, mem);
1332
88.0k
}
1333
1334
typedef struct {
1335
    gs_gstate_parts  parts;
1336
    gx_dash_params   dash;
1337
} gs_gstate_clone_data;
1338
1339
static gs_gstate *
1340
gstate_clone_core(const gs_gstate               *pfrom,
1341
                        gs_memory_t             *mem,
1342
                        client_name_t            cname,
1343
                        gs_gstate_clone_data    *clone_data,
1344
                        gs_gstate_copy_reason_t  reason)
1345
43.7M
{
1346
43.7M
    gs_gstate *pgs = gstate_alloc(mem, cname, pfrom);
1347
43.7M
    void *pdata = NULL;
1348
1349
43.7M
    if (pgs == NULL)
1350
7
        return NULL;
1351
43.7M
    if (pfrom->client_data != NULL) {
1352
43.5M
        pdata = (*pfrom->client_procs.alloc) (mem);
1353
1354
43.5M
        if (pdata == NULL ||
1355
43.5M
            gstate_copy_client_data(pfrom, pdata, pfrom->client_data,
1356
43.5M
                                    reason) < 0)
1357
0
            goto failEarly;
1358
43.5M
    }
1359
    /* Copy the dash and dash pattern if necessary. */
1360
43.7M
    clone_data->dash = gs_currentlineparams_inline(pfrom)->dash;
1361
43.7M
    if (clone_data->dash.pattern) {
1362
87.1k
        int code;
1363
1364
87.1k
        clone_data->dash.pattern = NULL; /* Ensures a fresh allocation */
1365
87.1k
        code = gstate_copy_dash(mem, &clone_data->dash, pfrom);
1366
87.1k
        if (code < 0)
1367
0
            goto fail;
1368
87.1k
    }
1369
    /* Some records within pgs are allocated. We copy pfrom into pgs
1370
     * wholesale (to avoid problems with the structure being updated and
1371
     * us having to keep it in sync), so we copy those allocated regions
1372
     * out first. The caller of this routine will then put them back
1373
     * into either pgs or pfrom as appropriate. */
1374
43.7M
    GSTATE_ASSIGN_PARTS(&clone_data->parts, pgs);
1375
43.7M
    *pgs = *pfrom;
1376
43.7M
    pgs->client_data = pdata;
1377
1378
43.7M
    gs_gstate_copied(pgs);
1379
    /* Don't do anything to clip_stack. */
1380
1381
43.7M
    rc_increment(pgs->device);
1382
43.7M
    *clone_data->parts.color[0].ccolor    = *pgs->color[0].ccolor;
1383
43.7M
    *clone_data->parts.color[0].dev_color = *pgs->color[0].dev_color;
1384
43.7M
    *clone_data->parts.color[1].ccolor    = *pgs->color[1].ccolor;
1385
43.7M
    *clone_data->parts.color[1].dev_color = *pgs->color[1].dev_color;
1386
43.7M
    cs_adjust_counts_icc(pgs, 1);
1387
43.7M
    cs_adjust_swappedcounts_icc(pgs, 1);
1388
1389
43.7M
    return pgs;
1390
1391
0
  fail:
1392
0
    gs_free_object(mem, clone_data->dash.pattern, cname);
1393
0
    if (pdata != NULL)
1394
0
        (*pfrom->client_procs.free) (pdata, mem, pgs);
1395
0
  failEarly:
1396
0
    gstate_free_parts(pgs, mem, cname);
1397
0
    gs_free_object(mem, pgs, cname);
1398
1399
0
    return NULL;
1400
0
}
1401
1402
1403
/* Clone an existing graphics state for use in gsave. The clone refers
1404
 * to the old contents, and the old state refers to the new contents. */
1405
/* Return NULL if the allocation fails. */
1406
static gs_gstate *
1407
gstate_clone_for_gsave(gs_gstate     *pfrom,
1408
                       client_name_t  cname)
1409
42.7M
{
1410
42.7M
    gs_gstate_clone_data clone_data;
1411
42.7M
    gs_gstate *pgs = gstate_clone_core(pfrom, pfrom->memory, cname,
1412
42.7M
                                       &clone_data, copy_for_gsave);
1413
1414
42.7M
    if (pgs == NULL)
1415
7
        return NULL;
1416
1417
    /* Newly allocated parts go back into pfrom, not pgs! */
1418
42.7M
    GSTATE_ASSIGN_PARTS(pfrom, &clone_data.parts);
1419
42.7M
    gs_currentlineparams_inline(pfrom)->dash = clone_data.dash;
1420
1421
42.7M
    return pgs;
1422
42.7M
}
1423
1424
/* Clone an existing graphics state. The view_clip is not copied. */
1425
/* Return NULL if the allocation fails. */
1426
static gs_gstate *
1427
gstate_clone_for_gstate(const gs_gstate     *pfrom,
1428
                              gs_memory_t   *mem,
1429
                              client_name_t  cname)
1430
1.03M
{
1431
1.03M
    gs_gstate_clone_data clone_data;
1432
1.03M
    gs_gstate *pgs = gstate_clone_core(pfrom, mem, cname, &clone_data,
1433
1.03M
                                       copy_for_gstate);
1434
1435
1.03M
    if (pgs == NULL)
1436
0
        return NULL;
1437
1.03M
    GSTATE_ASSIGN_PARTS(pgs, &clone_data.parts);
1438
1.03M
    pgs->view_clip = NULL;
1439
1.03M
    gs_currentlineparams_inline(pgs)->dash = clone_data.dash;
1440
1.03M
    pgs->memory = mem;
1441
1442
1.03M
    return pgs;
1443
1.03M
}
1444
1445
/* Adjust reference counters for the whole clip stack */
1446
/* accessible from the given point */
1447
static void
1448
clip_stack_rc_adjust(gx_clip_stack_t *cs, int delta, client_name_t cname)
1449
89.1M
{
1450
89.1M
    gx_clip_stack_t *p = cs;
1451
1452
89.1M
    while(p) {
1453
1
        gx_clip_stack_t *q = p;
1454
1
        p = p->next;
1455
1
        rc_adjust(q, delta, cname);
1456
1
    }
1457
89.1M
}
1458
1459
/*
1460
 * Finalization for graphics states. This is where we handle RC for those
1461
 * elements.
1462
 */
1463
void
1464
gs_gstate_finalize(const gs_memory_t *cmem,void *vptr)
1465
44.2M
{
1466
44.2M
    gs_gstate *pgs = (gs_gstate *)vptr;
1467
44.2M
    (void)cmem; /* unused */
1468
1469
44.2M
    if (cmem == NULL)
1470
0
        return;     /* place for breakpoint */
1471
44.2M
    gstate_free_contents(pgs);
1472
44.2M
}
1473
1474
/* Release the composite parts of a graphics state, */
1475
/* but not the state itself. */
1476
static void
1477
gstate_free_contents(gs_gstate * pgs)
1478
88.1M
{
1479
88.1M
    gs_memory_t *mem = pgs->memory;
1480
88.1M
    const char *const cname = "gstate_free_contents";
1481
1482
88.1M
    rc_decrement(pgs->device, cname);
1483
88.1M
    pgs->device = 0;
1484
88.1M
    clip_stack_rc_adjust(pgs->clip_stack, -1, cname);
1485
88.1M
    pgs->clip_stack = 0;
1486
88.1M
    if (pgs->view_clip != NULL && pgs->level == 0) {
1487
456k
        gx_cpath_free(pgs->view_clip, cname);
1488
456k
        pgs->view_clip = NULL;
1489
456k
    }
1490
88.1M
    if (pgs->client_data != 0)
1491
43.8M
        (*pgs->client_procs.free) (pgs->client_data, mem, pgs);
1492
88.1M
    pgs->client_data = 0;
1493
88.1M
    cs_adjust_counts_icc(pgs, -1);
1494
88.1M
    cs_adjust_swappedcounts_icc(pgs, -1);
1495
88.1M
    pgs->color[0].color_space = 0;
1496
88.1M
    pgs->color[1].color_space = 0;
1497
88.1M
    gs_free_object(mem, pgs->line_params.dash.pattern, cname);
1498
88.1M
    pgs->line_params.dash.pattern = 0;
1499
88.1M
    gstate_free_parts(pgs, mem, cname);     /* this also clears pointers to freed elements */
1500
88.1M
    gs_gstate_release(pgs);
1501
88.1M
}
1502
1503
/* Copy one gstate to another. */
1504
static int
1505
gstate_copy(gs_gstate * pto, const gs_gstate * pfrom,
1506
            gs_gstate_copy_reason_t reason, client_name_t cname)
1507
35.0k
{
1508
35.0k
    gs_gstate_parts parts;
1509
1510
35.0k
    GSTATE_ASSIGN_PARTS(&parts, pto);
1511
    /* Copy the dash pattern if necessary. */
1512
35.0k
    if (pfrom->line_params.dash.pattern || pto->line_params.dash.pattern) {
1513
845
        int code = gstate_copy_dash(pto->memory,
1514
845
                             &(gs_currentlineparams_inline(pto)->dash), pfrom);
1515
1516
845
        if (code < 0)
1517
0
            return code;
1518
845
    }
1519
    /*
1520
     * It's OK to decrement the counts before incrementing them,
1521
     * because anything that is going to survive has a count of
1522
     * at least 2 (pto and somewhere else) initially.
1523
     * Handle references from contents.
1524
     */
1525
35.0k
    cs_adjust_counts_icc(pto, -1);
1526
35.0k
    cs_adjust_swappedcounts_icc(pto, -1);
1527
35.0k
    gx_path_assign_preserve(pto->path, pfrom->path);
1528
35.0k
    gx_cpath_assign_preserve(pto->clip_path, pfrom->clip_path);
1529
    /*
1530
     * effective_clip_shared will be copied, but we need to do the
1531
     * right thing with effective_clip_path.
1532
     */
1533
35.0k
    if (pfrom->effective_clip_shared) {
1534
        /*
1535
         * pfrom->effective_clip_path is either pfrom->view_clip or
1536
         * pfrom->clip_path.
1537
         */
1538
35.0k
        parts.effective_clip_path =
1539
35.0k
            (pfrom->effective_clip_path == pfrom->view_clip ?
1540
35.0k
             pto->view_clip : parts.clip_path);
1541
35.0k
    } else
1542
0
        gx_cpath_assign_preserve(pto->effective_clip_path,
1543
0
                                 pfrom->effective_clip_path);
1544
35.0k
    *parts.color[0].ccolor    = *pfrom->color[0].ccolor;
1545
35.0k
    *parts.color[0].dev_color = *pfrom->color[0].dev_color;
1546
35.0k
    *parts.color[1].ccolor    = *pfrom->color[1].ccolor;
1547
35.0k
    *parts.color[1].dev_color = *pfrom->color[1].dev_color;
1548
    /* Handle references from gstate object. */
1549
35.0k
    rc_pre_assign(pto->device, pfrom->device, cname);
1550
35.0k
    if (pto->clip_stack != pfrom->clip_stack) {
1551
0
        clip_stack_rc_adjust(pfrom->clip_stack, 1, cname);
1552
0
        clip_stack_rc_adjust(pto->clip_stack, -1, cname);
1553
0
    }
1554
35.0k
    {
1555
35.0k
        struct gx_pattern_cache_s *pcache = pto->pattern_cache;
1556
35.0k
        void *pdata = pto->client_data;
1557
35.0k
        gs_memory_t *mem = pto->memory;
1558
35.0k
        gs_gstate *saved = pto->saved;
1559
35.0k
        float *pattern = pto->line_params.dash.pattern;
1560
1561
35.0k
        gs_gstate_pre_assign(pto, (const gs_gstate *)pfrom);
1562
35.0k
        *pto = *pfrom;
1563
35.0k
        pto->client_data = pdata;
1564
35.0k
        pto->memory = mem;
1565
35.0k
        pto->saved = saved;
1566
35.0k
        pto->line_params.dash.pattern = pattern;
1567
35.0k
        if (pto->pattern_cache == 0)
1568
2
            pto->pattern_cache = pcache;
1569
35.0k
        if (pfrom->client_data != 0) {
1570
            /* We need to break 'const' here. */
1571
33.8k
            gstate_copy_client_data((gs_gstate *) pfrom, pdata,
1572
33.8k
                                    pfrom->client_data, reason);
1573
33.8k
        }
1574
35.0k
    }
1575
35.0k
    GSTATE_ASSIGN_PARTS(pto, &parts);
1576
35.0k
    cs_adjust_counts_icc(pto, 1);
1577
35.0k
    cs_adjust_swappedcounts_icc(pto, 1);
1578
35.0k
    pto->show_gstate =
1579
35.0k
        (pfrom->show_gstate == pfrom ? pto : 0);
1580
35.0k
    return 0;
1581
35.0k
}
1582
1583
/* Accessories. */
1584
gs_id gx_get_clip_path_id(gs_gstate *pgs)
1585
51.3k
{
1586
51.3k
    return pgs->clip_path->id;
1587
51.3k
}
1588
1589
void gs_swapcolors_quick(const gs_gstate *cpgs)
1590
23.8M
{
1591
23.8M
    union {
1592
23.8M
        const gs_gstate *cpgs;
1593
23.8M
        gs_gstate *pgs;
1594
23.8M
    } const_breaker;
1595
23.8M
    gs_gstate *pgs;
1596
23.8M
    struct gx_cie_joint_caches_s *tmp_cie;
1597
23.8M
    gs_devicen_color_map          tmp_ccm;
1598
23.8M
    gs_client_color              *tmp_cc;
1599
23.8M
    int                           tmp;
1600
23.8M
    gx_device_color              *tmp_dc;
1601
23.8M
    gs_color_space               *tmp_cs;
1602
1603
    /* Break const just once, neatly, here rather than
1604
     * hackily in every caller. */
1605
23.8M
    const_breaker.cpgs = cpgs;
1606
23.8M
    pgs = const_breaker.pgs;
1607
1608
23.8M
    tmp_cc               = pgs->color[0].ccolor;
1609
23.8M
    pgs->color[0].ccolor = pgs->color[1].ccolor;
1610
23.8M
    pgs->color[1].ccolor = tmp_cc;
1611
1612
23.8M
    tmp_dc                  = pgs->color[0].dev_color;
1613
23.8M
    pgs->color[0].dev_color = pgs->color[1].dev_color;
1614
23.8M
    pgs->color[1].dev_color = tmp_dc;
1615
1616
23.8M
    tmp_cs                    = pgs->color[0].color_space;
1617
23.8M
    pgs->color[0].color_space = pgs->color[1].color_space;
1618
23.8M
    pgs->color[1].color_space = tmp_cs;
1619
1620
    /* Overprint and effective_op vary with stroke/fill and cs */
1621
23.8M
    tmp                         = pgs->color[0].effective_opm;
1622
23.8M
    pgs->color[0].effective_opm = pgs->color[1].effective_opm;
1623
23.8M
    pgs->color[1].effective_opm = tmp;
1624
1625
    /* Swap the bits of the gs_gstate that depend on the current color */
1626
23.8M
    tmp_cie                   = pgs->cie_joint_caches;
1627
23.8M
    pgs->cie_joint_caches     = pgs->cie_joint_caches_alt;
1628
23.8M
    pgs->cie_joint_caches_alt = tmp_cie;
1629
1630
23.8M
    tmp_ccm                      = pgs->color_component_map;
1631
23.8M
    pgs->color_component_map     = pgs->color_component_map_alt;
1632
23.8M
    pgs->color_component_map_alt = tmp_ccm;
1633
1634
23.8M
    pgs->is_fill_color = !(pgs->is_fill_color); /* used by overprint for fill_stroke */
1635
23.8M
}
1636
1637
int
1638
gs_clip_bounds_in_user_space(gs_gstate *pgs, gs_rect *ubox)
1639
46.2k
{
1640
46.2k
    gx_clip_path *clip_path;
1641
46.2k
    gs_rect dbox;
1642
46.2k
    int code;
1643
1644
46.2k
    code = gx_effective_clip_path(pgs, &clip_path);
1645
46.2k
    if (code < 0)
1646
0
        return code;
1647
1648
46.2k
    dbox.p.x = fixed2float(clip_path->outer_box.p.x);
1649
46.2k
    dbox.p.y = fixed2float(clip_path->outer_box.p.y);
1650
46.2k
    dbox.q.x = fixed2float(clip_path->outer_box.q.x);
1651
46.2k
    dbox.q.y = fixed2float(clip_path->outer_box.q.y);
1652
46.2k
    return gs_bbox_transform_inverse(&dbox, &ctm_only(pgs), ubox);
1653
46.2k
}