Coverage Report

Created: 2025-06-10 06:49

/src/ghostpdl/base/gspath.c
Line
Count
Source (jump to first uncovered line)
1
/* Copyright (C) 2001-2023 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
/* Basic path routines for Ghostscript library */
18
#include "gx.h"
19
#include "math_.h"
20
#include "gserrors.h"
21
#include "gxfixed.h"
22
#include "gxmatrix.h"
23
#include "gscoord.h"    /* requires gsmatrix.h */
24
#include "gspath.h"   /* for checking prototypes */
25
#include "gzstate.h"
26
#include "gzpath.h"
27
#include "gxdevice.h"   /* for gxcpath.h */
28
#include "gxdevmem.h"   /* for gs_device_is_memory */
29
#include "gzcpath.h"
30
#include "gxpaint.h"
31
32
/* ------ Miscellaneous ------ */
33
34
int
35
gs_newpath(gs_gstate * pgs)
36
326k
{
37
326k
    pgs->current_point_valid = false;
38
326k
    return gx_path_new(pgs->path);
39
326k
}
40
41
int
42
gs_closepath(gs_gstate * pgs)
43
24.1k
{
44
24.1k
    gx_path *ppath = pgs->path;
45
24.1k
    int code = gx_path_close_subpath(ppath);
46
47
24.1k
    if (code < 0)
48
0
        return code;
49
24.1k
    pgs->current_point = pgs->subpath_start;
50
24.1k
    return code;
51
24.1k
}
52
53
int
54
gs_upmergepath(gs_gstate * pgs)
55
0
{
56
    /*
57
     * We really should be able to implement this as simply
58
     *   return gx_path_add_path(pgs->saved->path, pgs->path);
59
     * But because of the current_point members in the gs_gstate,
60
     * we can't.
61
     */
62
0
    gs_gstate *saved = pgs->saved;
63
0
    int code;
64
65
0
    code = gx_path_add_path(saved->path, pgs->path);
66
0
    if (code < 0)
67
0
        return code;
68
0
    if (pgs->current_point_valid) {
69
0
        saved->current_point = pgs->current_point;
70
0
        saved->subpath_start = pgs->subpath_start;
71
0
        saved->current_point_valid = true;
72
0
    }
73
0
    return code;
74
0
}
75
76
/* Get the current path (for internal use only). */
77
gx_path *
78
gx_current_path(const gs_gstate * pgs)
79
0
{
80
0
    return pgs->path;
81
0
}
82
83
/* ------ Points and lines ------ */
84
85
static inline void
86
clamp_point(gs_fixed_point * ppt, double x, double y)
87
1.34k
{
88
1.34k
    ppt->x = clamp_coord(x);
89
1.34k
    ppt->y = clamp_coord(y);
90
1.34k
}
91
92
int
93
gs_currentpoint(gs_gstate * pgs, gs_point * ppt)
94
86.9k
{
95
86.9k
    if (!pgs->current_point_valid)
96
957
        return_error(gs_error_nocurrentpoint);
97
85.9k
    return gs_itransform(pgs, pgs->current_point.x,
98
85.9k
                              pgs->current_point.y, ppt);
99
86.9k
}
100
101
static inline int
102
gs_point_transform_compat(double x, double y, const gs_matrix_fixed *m, gs_point *pt)
103
132k
{
104
#if !PRECISE_CURRENTPOINT
105
    gs_fixed_point p;
106
    int code = gs_point_transform2fixed(m, x, y, &p);
107
108
    if (code < 0)
109
        return code;
110
    pt->x = fixed2float(p.x);
111
    pt->y = fixed2float(p.y);
112
    return 0;
113
#else
114
132k
    return gs_point_transform(x, y, (const gs_matrix *)m, pt);
115
132k
#endif
116
132k
}
117
118
static inline int
119
gs_distance_transform_compat(double x, double y, const gs_matrix_fixed *m, gs_point *pt)
120
11.5k
{
121
#if !PRECISE_CURRENTPOINT
122
    gs_fixed_point p;
123
    int code = gs_distance_transform2fixed(m, x, y, &p);
124
125
    if (code < 0)
126
        return code;
127
    pt->x = fixed2float(p.x);
128
    pt->y = fixed2float(p.y);
129
    return 0;
130
#else
131
11.5k
    return gs_distance_transform(x, y, (const gs_matrix *)m, pt);
132
11.5k
#endif
133
11.5k
}
134
135
static inline int
136
clamp_point_aux(bool clamp_coordinates, gs_fixed_point *ppt, double x, double y)
137
514k
{
138
514k
    if (!f_fits_in_bits(x, fixed_int_bits) || !f_fits_in_bits(y, fixed_int_bits)) {
139
1.34k
        if (!clamp_coordinates)
140
0
            return_error(gs_error_limitcheck);
141
1.34k
        clamp_point(ppt, x, y);
142
512k
    } else {
143
        /* 181-01.ps" fails with no rounding in
144
           "Verify as last element of a userpath and effect on setbbox." */
145
512k
        ppt->x = float2fixed_rounded(x);
146
512k
        ppt->y = float2fixed_rounded(y);
147
512k
    }
148
514k
    return 0;
149
514k
}
150
151
int
152
gs_moveto_aux(gs_gstate *pgs, gx_path *ppath, double x, double y)
153
456k
{
154
456k
    gs_fixed_point pt;
155
456k
    int code;
156
157
456k
    code = clamp_point_aux(pgs->clamp_coordinates, &pt, x, y);
158
456k
    if (code < 0)
159
0
        return code;
160
456k
    if (pgs->hpgl_path_mode && path_subpath_open(ppath))
161
0
    {
162
0
        code = gx_path_add_gap_notes(ppath, pt.x, pt.y, 0);
163
0
        if (code < 0)
164
0
            return code;
165
0
        gx_setcurrentpoint(pgs, x, y);
166
0
    }
167
456k
    else
168
456k
    {
169
456k
        code = gx_path_add_point(ppath, pt.x, pt.y);
170
456k
        if (code < 0)
171
0
            return code;
172
456k
        ppath->start_flags = ppath->state_flags;
173
456k
        gx_setcurrentpoint(pgs, x, y);
174
456k
        pgs->subpath_start = pgs->current_point;
175
456k
    }
176
456k
    pgs->current_point_valid = true;
177
456k
    return 0;
178
456k
}
179
180
int
181
gs_moveto(gs_gstate * pgs, double x, double y)
182
78.1k
{
183
78.1k
    gs_point pt;
184
78.1k
    int code = gs_point_transform_compat(x, y, &pgs->ctm, &pt);
185
186
78.1k
    if (code < 0)
187
0
        return code;
188
78.1k
    return gs_moveto_aux(pgs, pgs->path, pt.x, pt.y);
189
78.1k
}
190
191
int
192
gs_rmoveto(gs_gstate * pgs, double x, double y)
193
8.10k
{
194
8.10k
    gs_point dd;
195
8.10k
    int code;
196
197
8.10k
    if (!pgs->current_point_valid)
198
36
        return_error(gs_error_nocurrentpoint);
199
8.07k
    code = gs_distance_transform_compat(x, y, &pgs->ctm, &dd);
200
8.07k
    if (code < 0)
201
0
        return code;
202
    /* fixme : check in range. */
203
8.07k
    return gs_moveto_aux(pgs, pgs->path,
204
8.07k
                dd.x + pgs->current_point.x, dd.y + pgs->current_point.y);
205
8.07k
}
206
207
static inline int
208
gs_lineto_aux(gs_gstate * pgs, double x, double y)
209
57.2k
{
210
57.2k
    gx_path *ppath = pgs->path;
211
57.2k
    gs_fixed_point pt;
212
57.2k
    int code;
213
214
57.2k
    code = clamp_point_aux(pgs->clamp_coordinates, &pt, x, y);
215
57.2k
    if (code < 0)
216
0
        return code;
217
57.2k
    code = gx_path_add_line(ppath, pt.x, pt.y);
218
57.2k
    if (code < 0)
219
854
        return code;
220
56.3k
    gx_setcurrentpoint(pgs, x, y);
221
56.3k
    return 0;
222
57.2k
}
223
224
int
225
gs_lineto(gs_gstate * pgs, double x, double y)
226
53.7k
{
227
53.7k
    gs_point pt;
228
53.7k
    int code = gs_point_transform_compat(x, y, &pgs->ctm, &pt);
229
230
53.7k
    if (code < 0)
231
0
        return code;
232
53.7k
    return gs_lineto_aux(pgs, pt.x, pt.y);
233
53.7k
}
234
235
int
236
gs_rlineto(gs_gstate * pgs, double x, double y)
237
3.51k
{
238
3.51k
    gs_point dd;
239
3.51k
    int code;
240
241
3.51k
    if (!pgs->current_point_valid)
242
1
        return_error(gs_error_nocurrentpoint);
243
3.51k
    code = gs_distance_transform_compat(x, y, &pgs->ctm, &dd);
244
3.51k
    if (code < 0)
245
0
        return code;
246
    /* fixme : check in range. */
247
3.51k
    return gs_lineto_aux(pgs, dd.x + pgs->current_point.x,
248
3.51k
                              dd.y + pgs->current_point.y);
249
3.51k
}
250
251
/* ------ Curves ------ */
252
253
static inline int
254
gs_curveto_aux(gs_gstate * pgs,
255
           double x1, double y1, double x2, double y2, double x3, double y3)
256
125
{
257
125
    gs_fixed_point p1, p2, p3;
258
125
    int code;
259
125
    gx_path *ppath = pgs->path;
260
261
125
    code = clamp_point_aux(pgs->clamp_coordinates, &p1, x1, y1);
262
125
    if (code < 0)
263
0
        return code;
264
125
    code = clamp_point_aux(pgs->clamp_coordinates, &p2, x2, y2);
265
125
    if (code < 0)
266
0
        return code;
267
125
    code = clamp_point_aux(pgs->clamp_coordinates, &p3, x3, y3);
268
125
    if (code < 0)
269
0
        return code;
270
125
    code = gx_path_add_curve(ppath, p1.x, p1.y, p2.x, p2.y, p3.x, p3.y);
271
125
    if (code < 0)
272
27
        return code;
273
98
    gx_setcurrentpoint(pgs, x3, y3);
274
98
    return 0;
275
125
}
276
277
int
278
gs_curveto(gs_gstate * pgs,
279
           double x1, double y1, double x2, double y2, double x3, double y3)
280
123
{
281
123
    gs_point pt1, pt2, pt3;
282
123
    int code;
283
284
123
    code = gs_point_transform_compat(x1, y1, &pgs->ctm, &pt1);
285
123
    if (code < 0)
286
0
        return code;
287
123
    code = gs_point_transform_compat(x2, y2, &pgs->ctm, &pt2);
288
123
    if (code < 0)
289
0
        return code;
290
123
    code = gs_point_transform_compat(x3, y3, &pgs->ctm, &pt3);
291
123
    if (code < 0)
292
0
        return code;
293
123
    return gs_curveto_aux(pgs,   pt1.x, pt1.y,   pt2.x, pt2.y,   pt3.x, pt3.y);
294
123
}
295
296
int
297
gs_rcurveto(gs_gstate * pgs,
298
     double dx1, double dy1, double dx2, double dy2, double dx3, double dy3)
299
3
{
300
3
    gs_point dd1, dd2, dd3;
301
3
    int code;
302
303
3
    if (!pgs->current_point_valid)
304
1
        return_error(gs_error_nocurrentpoint);
305
2
    code = gs_distance_transform_compat(dx1, dy1, &pgs->ctm, &dd1);
306
2
    if (code < 0)
307
0
        return code;
308
2
    code = gs_distance_transform_compat(dx2, dy2, &pgs->ctm, &dd2);
309
2
    if (code < 0)
310
0
        return code;
311
2
    code = gs_distance_transform_compat(dx3, dy3, &pgs->ctm, &dd3);
312
2
    if (code < 0)
313
0
        return code;
314
    /* fixme : check in range. */
315
2
    return gs_curveto_aux(pgs, dd1.x + pgs->current_point.x, dd1.y + pgs->current_point.y,
316
2
                               dd2.x + pgs->current_point.x, dd2.y + pgs->current_point.y,
317
2
                               dd3.x + pgs->current_point.x, dd3.y + pgs->current_point.y);
318
2
}
319
320
/* ------ Clipping ------ */
321
322
/* Forward references */
323
static int common_clip(gs_gstate *, int);
324
325
/* Figure out the bbox for a path and a clip path with adjustment if we are
326
   also doing a stroke.  This is used by the xps interpeter to deteremine
327
   how big of a transparency group or softmask should be pushed.  Often in
328
   xps we fill a path with a particular softmask and some other graphic object.
329
   The transparency group will be the intersection of the path and clipping
330
   path */
331
int
332
gx_curr_fixed_bbox(gs_gstate * pgs, gs_fixed_rect *bbox, gs_bbox_comp_t comp_type)
333
0
{
334
0
    int code;
335
0
    gx_clip_path *clip_path;
336
0
    gs_fixed_rect path_bbox;
337
0
    int expansion_code;
338
0
    bool include_path = true;
339
0
    gs_fixed_point expansion;
340
341
0
    code = gx_effective_clip_path(pgs, &clip_path);
342
0
    if (code < 0 || clip_path == NULL) {
343
0
        bbox->p.x = bbox->p.y = bbox->q.x = bbox->q.y = 0;
344
0
        return (code < 0) ? code : gs_error_unknownerror;
345
0
    } else {
346
0
        *bbox = clip_path->outer_box;
347
0
    }
348
0
    if (comp_type == NO_PATH) {
349
0
       return 0;
350
0
    }
351
0
    code = gx_path_bbox(pgs->path, &path_bbox);
352
0
    if (code < 0)
353
0
        return code;
354
0
    if (comp_type == PATH_STROKE) {
355
        /* Handle any stroke expansion of our bounding box */
356
0
        expansion_code = gx_stroke_path_expansion(pgs, pgs->path, &expansion);
357
0
        if (expansion_code >= 0) {
358
0
            path_bbox.p.x -= expansion.x;
359
0
            path_bbox.p.y -= expansion.y;
360
0
            path_bbox.q.x += expansion.x;
361
0
            path_bbox.q.y += expansion.y;
362
0
        } else {
363
            /* Stroke is super wide or we could not figure out the stroke bbox
364
               due to wacky joints etc. Just use the clip path */
365
0
            include_path = false;
366
0
        }
367
0
    }
368
0
    if (include_path) {
369
0
        rect_intersect(*bbox, path_bbox);
370
0
    }
371
0
    return 0;
372
0
}
373
374
/* A variation of the above that returns a gs_rect (double) bbox */
375
int
376
gx_curr_bbox(gs_gstate * pgs, gs_rect *bbox, gs_bbox_comp_t comp_type)
377
0
{
378
0
    gs_fixed_rect curr_fixed_bbox;
379
380
0
    gx_curr_fixed_bbox(pgs, &curr_fixed_bbox, comp_type);
381
0
    bbox->p.x = fixed2float(curr_fixed_bbox.p.x);
382
0
    bbox->p.y = fixed2float(curr_fixed_bbox.p.y);
383
0
    bbox->q.x = fixed2float(curr_fixed_bbox.q.x);
384
0
    bbox->q.y = fixed2float(curr_fixed_bbox.q.y);
385
0
    return 0;
386
0
}
387
388
/*
389
 * Return the effective clipping path of a graphics state.  Sometimes this
390
 * is the intersection of the clip path and the view clip path; sometimes it
391
 * is just the clip path.  We aren't sure what the correct algorithm is for
392
 * this: for now, we use view clipping unless the current device is a memory
393
 * device.  This takes care of the most important case, where the current
394
 * device is a cache device.
395
 */
396
int
397
gx_effective_clip_path(gs_gstate * pgs, gx_clip_path ** ppcpath)
398
148k
{
399
148k
    gs_id view_clip_id =
400
148k
        (pgs->view_clip == 0 || pgs->view_clip->rule == 0 ? gs_no_id :
401
148k
         pgs->view_clip->id);
402
403
148k
    if (pgs->device == NULL || gs_device_is_memory(pgs->device) || pgs->clip_path == NULL) {
404
6
        *ppcpath = pgs->clip_path;
405
6
        return 0;
406
6
    }
407
148k
    if (pgs->effective_clip_id == pgs->clip_path->id &&
408
148k
        pgs->effective_view_clip_id == view_clip_id
409
148k
        ) {
410
135k
        *ppcpath = pgs->effective_clip_path;
411
135k
        return 0;
412
135k
    }
413
    /* Update the cache. */
414
13.4k
    if (view_clip_id == gs_no_id) {
415
13.4k
        if (!pgs->effective_clip_shared)
416
0
            gx_cpath_free(pgs->effective_clip_path, "gx_effective_clip_path");
417
13.4k
        pgs->effective_clip_path = pgs->clip_path;
418
13.4k
        pgs->effective_clip_shared = true;
419
13.4k
    } else {
420
0
        gs_fixed_rect cbox, vcbox;
421
422
0
        gx_cpath_inner_box(pgs->clip_path, &cbox);
423
0
        gx_cpath_outer_box(pgs->view_clip, &vcbox);
424
0
        if (rect_within(vcbox, cbox)) {
425
0
            if (!pgs->effective_clip_shared)
426
0
                gx_cpath_free(pgs->effective_clip_path,
427
0
                              "gx_effective_clip_path");
428
0
            pgs->effective_clip_path = pgs->view_clip;
429
0
            pgs->effective_clip_shared = true;
430
0
        } else {
431
            /* Construct the intersection of the two clip paths. */
432
0
            int code;
433
0
            gx_clip_path ipath;
434
0
            gx_path vpath;
435
0
            gx_clip_path *npath = pgs->effective_clip_path;
436
437
0
            if (pgs->effective_clip_shared) {
438
0
                npath = gx_cpath_alloc(pgs->memory, "gx_effective_clip_path");
439
0
                if (npath == 0)
440
0
                    return_error(gs_error_VMerror);
441
0
            }
442
0
            gx_cpath_init_local(&ipath, pgs->memory);
443
0
            code = gx_cpath_assign_preserve(&ipath, pgs->clip_path);
444
0
            if (code < 0)
445
0
                return code;
446
0
            gx_path_init_local(&vpath, pgs->memory);
447
0
            code = gx_cpath_to_path(pgs->view_clip, &vpath);
448
0
            if (code < 0 ||
449
0
                (code = gx_cpath_clip(pgs, &ipath, &vpath,
450
0
                                      gx_rule_winding_number)) < 0 ||
451
0
                (code = gx_cpath_assign_free(npath, &ipath)) < 0
452
0
                )
453
0
                DO_NOTHING;
454
0
            gx_path_free(&vpath, "gx_effective_clip_path");
455
0
            gx_cpath_free(&ipath, "gx_effective_clip_path");
456
0
            if (code < 0)
457
0
                return code;
458
0
            pgs->effective_clip_path = npath;
459
0
            pgs->effective_clip_shared = false;
460
0
        }
461
0
    }
462
13.4k
    pgs->effective_clip_id = pgs->effective_clip_path->id;
463
13.4k
    pgs->effective_view_clip_id = view_clip_id;
464
13.4k
    *ppcpath = pgs->effective_clip_path;
465
13.4k
    return 0;
466
13.4k
}
467
468
#ifdef DEBUG
469
/* Note that we just set the clipping path (internal). */
470
static void
471
note_set_clip_path(const gs_gstate * pgs)
472
{
473
    if (gs_debug_c('P')) {
474
        dmlprintf(pgs->memory, "[P]Clipping path:\n");
475
        gx_cpath_print(pgs->memory, pgs->clip_path);
476
    }
477
}
478
#else
479
321k
#  define note_set_clip_path(pgs) DO_NOTHING
480
#endif
481
482
int
483
gs_clippath(gs_gstate * pgs)
484
264
{
485
264
    gx_path cpath;
486
264
    int code;
487
488
264
    gx_path_init_local(&cpath, pgs->path->memory);
489
264
    code = gx_cpath_to_path(pgs->clip_path, &cpath);
490
264
    if (code >= 0) {
491
264
        code = gx_path_assign_free(pgs->path, &cpath);
492
264
        pgs->current_point.x = fixed2float(pgs->path->position.x);
493
264
        pgs->current_point.y = fixed2float(pgs->path->position.y);
494
264
        pgs->current_point_valid = true;
495
264
    }
496
264
    if (code < 0)
497
0
        gx_path_free(&cpath, "gs_clippath");
498
264
    return code;
499
264
}
500
501
int
502
gs_initclip(gs_gstate * pgs)
503
281k
{
504
281k
    gs_fixed_rect box;
505
281k
    int code = gx_default_clip_box(pgs, &box);
506
507
281k
    if (code < 0)
508
0
        return code;
509
281k
    return gx_clip_to_rectangle(pgs, &box);
510
281k
}
511
512
int
513
gs_clip(gs_gstate * pgs)
514
14.0k
{
515
14.0k
    return common_clip(pgs, gx_rule_winding_number);
516
14.0k
}
517
518
int
519
gs_eoclip(gs_gstate * pgs)
520
622
{
521
622
    return common_clip(pgs, gx_rule_even_odd);
522
622
}
523
524
static int
525
common_clip(gs_gstate * pgs, int rule)
526
14.6k
{
527
14.6k
    int code = gx_cpath_clip(pgs, pgs->clip_path, pgs->path, rule);
528
14.6k
    if (code < 0)
529
0
        return code;
530
14.6k
    pgs->clip_path->rule = rule;
531
14.6k
    note_set_clip_path(pgs);
532
14.6k
    return 0;
533
14.6k
}
534
535
/* Establish a rectangle as the clipping path. */
536
/* Used by initclip and by the character and Pattern cache logic. */
537
int
538
gx_clip_to_rectangle(gs_gstate * pgs, gs_fixed_rect * pbox)
539
307k
{
540
307k
    int code = gx_cpath_from_rectangle(pgs->clip_path, pbox);
541
542
307k
    if (code < 0)
543
0
        return code;
544
307k
    pgs->clip_path->rule = gx_rule_winding_number;
545
    /* We are explicitly setting the clip to a specific rectangle, the path list
546
     * must therefore be reset (it bears no relation to the actual clip now).
547
     */
548
307k
    rc_decrement(pgs->clip_path->path_list, "gx_clip_to_rectangle");
549
307k
    pgs->clip_path->path_list = 0;
550
307k
    note_set_clip_path(pgs);
551
307k
    return 0;
552
307k
}
553
554
/* Set the clipping path to the current path, without intersecting. */
555
/* This is very inefficient right now. */
556
int
557
gx_clip_to_path(gs_gstate * pgs)
558
0
{
559
0
    gs_fixed_rect bbox;
560
0
    int code;
561
562
0
    if ((code = gx_path_bbox(pgs->path, &bbox)) < 0 ||
563
0
        (code = gx_clip_to_rectangle(pgs, &bbox)) < 0 ||
564
0
        (code = gs_clip(pgs)) < 0
565
0
        )
566
0
        return code;
567
0
    note_set_clip_path(pgs);
568
0
    return 0;
569
0
}
570
571
/* Get the default clipping box. */
572
int
573
gx_default_clip_box(const gs_gstate * pgs, gs_fixed_rect * pbox)
574
281k
{
575
281k
    register gx_device *dev = gs_currentdevice(pgs);
576
281k
    gs_rect bbox;
577
281k
    gs_matrix imat;
578
281k
    int code;
579
580
281k
    if (dev->ImagingBBox_set) { /* Use the ImagingBBox, relative to default user space. */
581
0
        gs_defaultmatrix(pgs, &imat);
582
0
        bbox.p.x = dev->ImagingBBox[0];
583
0
        bbox.p.y = dev->ImagingBBox[1];
584
0
        bbox.q.x = dev->ImagingBBox[2];
585
0
        bbox.q.y = dev->ImagingBBox[3];
586
281k
    } else {     /* Use the MediaSize indented by the HWMargins, */
587
        /* relative to unrotated user space adjusted by */
588
        /* the Margins.  (We suspect this isn't quite right, */
589
        /* but the whole issue of "margins" is such a mess that */
590
        /* we don't think we can do any better.) */
591
281k
        (*dev_proc(dev, get_initial_matrix)) (dev, &imat);
592
        /* Adjust for the Margins. */
593
281k
        imat.tx += dev->Margins[0];
594
281k
        imat.ty += dev->Margins[1];
595
281k
        bbox.p.x = dev->HWMargins[0];
596
281k
        bbox.p.y = dev->HWMargins[1];
597
281k
        bbox.q.x = dev->MediaSize[0] - dev->HWMargins[2];
598
281k
        bbox.q.y = dev->MediaSize[1] - dev->HWMargins[3];
599
281k
    }
600
281k
    code = gs_bbox_transform(&bbox, &imat, &bbox);
601
281k
    if (code < 0)
602
0
        return code;
603
    /* Round the clipping box so that it doesn't get ceilinged. */
604
281k
    pbox->p.x = fixed_rounded(float2fixed(bbox.p.x));
605
281k
    pbox->p.y = fixed_rounded(float2fixed(bbox.p.y));
606
281k
    pbox->q.x = fixed_rounded(float2fixed(bbox.q.x));
607
281k
    pbox->q.y = fixed_rounded(float2fixed(bbox.q.y));
608
281k
    return 0;
609
281k
}