/* Copyright (C) 1989, 1992 Aladdin Enterprises. All rights reserved.
Distributed by Free Software Foundation, Inc.
This file is part of Ghostscript.
Ghostscript is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY. No author or distributor accepts responsibility
to anyone for the consequences of using it or for whether it serves any
particular purpose or works at all, unless he says so in writing. Refer
to the Ghostscript General Public License for full details.
Everyone is granted permission to copy, modify and redistribute
Ghostscript, but only under the conditions described in the Ghostscript
General Public License. A copy of this license is supposed to have been
given to you along with Ghostscript so you can know your rights and
responsibilities. It should be in a file named COPYING. Among other
things, the copyright notice and this notice must be preserved on all
/* Non-constructor path routines for GhostScript library */
private int common_clip(P2(gs_state
*, int));
private int set_clip_path(P3(gs_state
*, gx_clip_path
*, int));
/* Path enumeration structure */
/* Size of path enumeration structure, so clients can allocate */
const uint gs_path_enum_sizeof
= sizeof(gs_path_enum
);
/* ------ Path transformers ------ */
gs_flattenpath(gs_state
*pgs
)
if ( !pgs
->path
->curve_count
) return 0; /* no curves */
code
= gx_path_flatten(pgs
->path
, &fpath
, pgs
->flatness
);
if ( code
< 0 ) return code
;
gx_path_release(pgs
->path
);
gs_reversepath(gs_state
*pgs
)
int code
= gx_path_reverse(pgs
->path
, &rpath
);
if ( code
< 0 ) return code
;
gx_path_release(pgs
->path
);
/* ------ Accessors ------ */
gs_pathbbox(gs_state
*pgs
, gs_rect
*pbox
)
{ gs_fixed_rect fbox
; /* box in device coordinates */
int code
= gx_path_bbox(pgs
->path
, &fbox
);
if ( code
< 0 ) return code
;
/* Transform the result back to user coordinates. */
dbox
.p
.x
= fixed2float(fbox
.p
.x
);
dbox
.p
.y
= fixed2float(fbox
.p
.y
);
dbox
.q
.x
= fixed2float(fbox
.q
.x
);
dbox
.q
.y
= fixed2float(fbox
.q
.y
);
return gs_bbox_transform_inverse(&dbox
, &ctm_only(pgs
), pbox
);
/* ------ Enumerators ------ */
/* Start enumerating a path */
gs_path_enum_init(gs_path_enum
*penum
, const gs_state
*pgs
)
{ penum
->pseg
= (segment
*)pgs
->path
->first_subpath
;
/* Enumerate the next element of a path. */
/* If the path is finished, return 0; */
/* otherwise, return the element type. */
gs_path_enum_next(gs_path_enum
*penum
, gs_point ppts
[3])
{ segment
*pseg
= penum
->pseg
;
const gs_state
*pgs
= penum
->pgs
;
if ( pseg
== 0 ) return 0; /* finished */
penum
->pseg
= pseg
->next
;
if ( pseg
->type
== s_line_close
)
if ( (code
= gs_itransform(pgs
, fixed2float(pseg
->pt
.x
),
fixed2float(pseg
->pt
.y
), &pt
)) < 0 )
#define pcurve ((curve_segment *)pseg)
gs_itransform(pgs
, fixed2float(pcurve
->p1
.x
),
fixed2float(pcurve
->p1
.y
), &ppts
[0])) < 0 ||
gs_itransform(pgs
, fixed2float(pcurve
->p2
.x
),
fixed2float(pcurve
->p2
.y
), &ppts
[1])) < 0 )
lprintf1("bad type %x in gs_path_enum_next!\n", pseg
->type
);
/* ------ Clipping ------ */
gs_clippath(gs_state
*pgs
)
int code
= gx_cpath_path(pgs
->clip_path
, &path
);
if ( code
< 0 ) return code
;
return gx_path_copy(&path
, pgs
->path
);
gs_initclip(gs_state
*pgs
)
{ register gx_device
*dev
= pgs
->device
->info
;
if ( is_fzero2(dev
->l_margin
, dev
->r_margin
) &&
is_fzero2(dev
->b_margin
, dev
->t_margin
)
{ /* Shortcut, don't need to worry about density. */
box
.q
.x
= int2fixed(dev
->width
);
box
.q
.y
= int2fixed(dev
->height
);
{ /* Indent from bounding rectangle. */
(*dev
->procs
->get_initial_matrix
)(dev
, (gs_matrix
*)&imat
);
gs_update_matrix_fixed(&imat
);
gs_point_transform2fixed(&imat
,
gs_point_transform2fixed(&imat
,
(dev
->width
/ dev
->x_pixels_per_inch
- dev
->r_margin
) * 72,
(dev
->height
/ dev
->y_pixels_per_inch
- dev
->t_margin
) * 72,
return gx_clip_to_rectangle(pgs
, &box
);
{ return common_clip(pgs
, gx_rule_winding_number
);
{ return common_clip(pgs
, gx_rule_even_odd
);
common_clip(gs_state
*pgs
, int rule
)
int code
= gx_path_flatten(pgs
->path
, &fpath
, pgs
->flatness
);
if ( code
< 0 ) return code
;
code
= gx_cpath_intersect(pgs
, pgs
->clip_path
, &fpath
, rule
);
if ( code
< 0 ) return code
;
return set_clip_path(pgs
, pgs
->clip_path
, rule
);
/* Establish a rectangle as the clipping path. */
/* Used by initclip and by the character cache logic. */
gx_clip_to_rectangle(gs_state
*pgs
, gs_fixed_rect
*pbox
)
int code
= gx_cpath_from_rectangle(&cpath
, pbox
, &pgs
->memory_procs
);
if ( code
< 0 ) return code
;
gx_cpath_release(pgs
->clip_path
);
return set_clip_path(pgs
, &cpath
, gx_rule_winding_number
);
/* Set the clipping path to the current path, without intersecting. */
/* Currently only used by the insideness testing operators, */
/* but might be used by viewclip eventually. */
/* The algorithm is very inefficient; we'll improve it later if needed. */
gx_clip_to_path(gs_state
*pgs
)
(code
= gx_path_bbox(pgs
->path
, &bbox
)) < 0 ||
(code
= gx_clip_to_rectangle(pgs
, &bbox
)) < 0 ||
/* Set the clipping path (internal). */
set_clip_path(gs_state
*pgs
, gx_clip_path
*pcpath
, int rule
)
{ *pgs
->clip_path
= *pcpath
;
dprintf("[p]Clipping path:\n"),