1 /* Copyright (C) 2001-2019 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.,  1305 Grant Avenue - Suite 200, Novato,
13    CA 94945, U.S.A., +1(415)492-9861, for further information.
14 */
15 
16 
17 /* Structure definitions for clipping paths */
18 /* Requires gzpath.h. */
19 
20 #ifndef gzcpath_INCLUDED
21 #  define gzcpath_INCLUDED
22 
23 #include "gxcpath.h"
24 #include "gzpath.h"
25 
26 /*
27  * The reference counting considerations for clip paths are the same as
28  * for paths.  We need a separate reference count for the clip list,
29  * since its existence and lifetime are not necessarily the same as
30  * those of the path.
31  */
32 
33 typedef struct gx_clip_rect_list_s {
34     rc_header rc;
35     gx_clip_list list;
36 } gx_clip_rect_list;
37 
38 #define private_st_clip_rect_list()	/* in gxcpath.c */\
39   gs_private_st_ptrs_add0(st_clip_rect_list, gx_clip_rect_list,\
40     "gx_clip_rect_list", clip_rect_list_enum_ptrs, clip_rect_list_reloc_ptrs,\
41     st_clip_list, list)
42 
43 /*
44  * When the clip path consists of the intersection of two or more
45  * source paths, we maintain the complete list paths, so that it
46  * can be accurately output for high-level devices.
47  */
48 
49 typedef struct gx_cpath_path_list_s gx_cpath_path_list;
50 
51 struct gx_cpath_path_list_s {
52     gx_path path;
53     rc_header rc;
54     int rule;
55     gx_cpath_path_list *next;
56 };
57 
58 #define private_st_cpath_path_list() 	/* in gxcpath.c */\
59   gs_private_st_suffix_add1(st_cpath_path_list, gx_cpath_path_list,\
60     "gs_cpath_list", cpath_path_list_enum_ptrs, cpath_path_list_reloc_ptrs,\
61     st_path, next)
62 
63 /* gx_clip_path is a 'subclass' of gx_path. */
64 struct gx_clip_path_s {
65     gx_path path;
66     gx_clip_rect_list local_list;
67     int rule;			/* rule for insideness of path */
68     /* Anything within the inner_box is guaranteed to fall */
69     /* entirely within the clipping path. */
70     gs_fixed_rect inner_box;
71     /* Anything outside the outer_box is guaranteed to fall */
72     /* entirely outside the clipping path.  This is the same */
73     /* as the path bounding box, widened to pixel boundaries. */
74     gs_fixed_rect outer_box;
75     gx_clip_rect_list *rect_list;
76     bool path_valid;		/* path representation is valid */
77     gx_cpath_path_list *path_list;
78     /* The id changes whenever the clipping region changes. */
79     gs_id id;
80     /* The last rectangle we accessed while using this clip_path */
81     gx_clip_rect *cached;
82 };
83 
84 extern_st(st_clip_path);
85 #define public_st_clip_path()	/* in gxcpath.c */\
86   gs_public_st_composite(st_clip_path, gx_clip_path, "clip_path",\
87     clip_path_enum_ptrs, clip_path_reloc_ptrs)
88 #define st_clip_path_max_ptrs (st_path_max_ptrs + 1)
89 
90 /* Inline accessors. */
91 #define gx_cpath_is_shared(pcpath)\
92   ((pcpath)->rect_list->rc.ref_count > 1)
93 
94 /* Define the structure for enumerating a clipping list. */
95 typedef enum {
96     visit_left = 1,
97     visit_right = 2
98 } cpe_visit_t;
99 typedef enum {
100     cpe_scan, cpe_left, cpe_right, cpe_close, cpe_done
101 } cpe_state_t;
102 struct gs_cpath_enum_s {
103     gs_path_enum path_enum;	/* used iff clipping path exists as a path, */
104     /* must be first for subclassing */
105     bool using_path;
106     gx_clip_rect *visit;	/* scan pointer for finding next start */
107     gx_clip_rect *rp;		/* scan pointer for current rectangle */
108     cpe_visit_t first_visit;
109     cpe_state_t state;
110     bool have_line;
111     gs_int_point line_end;
112     bool any_rectangles;
113 };
114 
115 #endif /* gzcpath_INCLUDED */
116