Commit | Line | Data |
---|---|---|
16b11121 WJ |
1 | /* Copyright (C) 1991, 1992 Aladdin Enterprises. All rights reserved. |
2 | Distributed by Free Software Foundation, Inc. | |
3 | ||
4 | This file is part of Ghostscript. | |
5 | ||
6 | Ghostscript is distributed in the hope that it will be useful, but | |
7 | WITHOUT ANY WARRANTY. No author or distributor accepts responsibility | |
8 | to anyone for the consequences of using it or for whether it serves any | |
9 | particular purpose or works at all, unless he says so in writing. Refer | |
10 | to the Ghostscript General Public License for full details. | |
11 | ||
12 | Everyone is granted permission to copy, modify and redistribute | |
13 | Ghostscript, but only under the conditions described in the Ghostscript | |
14 | General Public License. A copy of this license is supposed to have been | |
15 | given to you along with Ghostscript so you can know your rights and | |
16 | responsibilities. It should be in a file named COPYING. Among other | |
17 | things, the copyright notice and this notice must be preserved on all | |
18 | copies. */ | |
19 | ||
20 | /* gsdps1.c */ | |
21 | /* Display PostScript graphics additions for Ghostscript library */ | |
22 | #include "gx.h" | |
23 | #include "gserrors.h" | |
24 | #include "gsmatrix.h" | |
25 | #include "gspath.h" | |
26 | ||
27 | /* ------ Graphics state ------ */ | |
28 | ||
29 | /* Set the bounding box for the current path. */ | |
30 | /****** NOT IMPLEMENTED YET. ******/ | |
31 | int | |
32 | gs_setbbox(gs_state *pgs, floatp llx, floatp lly, floatp urx, floatp ury) | |
33 | { if ( llx > urx || lly > ury ) | |
34 | return_error(gs_error_rangecheck); | |
35 | /* Must transform box to device coordinates. */ | |
36 | /* No-op for now. */ | |
37 | return 0; | |
38 | } | |
39 | ||
40 | /* ------ Rectangles ------ */ | |
41 | ||
42 | /* Append a list of rectangles to a path. */ | |
43 | int | |
44 | gs_rectappend(gs_state *pgs, gs_rect *pr, uint count) | |
45 | { for ( ; count != 0; count--, pr++ ) | |
46 | { floatp px = pr->p.x, py = pr->p.y, qx = pr->q.x, qy = pr->q.y; | |
47 | int code; | |
48 | /* Ensure counter-clockwise drawing. */ | |
49 | if ( (qx >= px) != (qy >= py) ) | |
50 | qx = px, px = pr->p.x; /* swap x values */ | |
51 | if ( (code = gs_moveto(pgs, px, py)) < 0 || | |
52 | (code = gs_lineto(pgs, qx, py)) < 0 || | |
53 | (code = gs_lineto(pgs, qx, qy)) < 0 || | |
54 | (code = gs_lineto(pgs, px, qy)) < 0 || | |
55 | (code = gs_closepath(pgs)) < 0 | |
56 | ) | |
57 | return code; | |
58 | } | |
59 | return 0; | |
60 | } | |
61 | ||
62 | /* Clip to a list of rectangles. */ | |
63 | int | |
64 | gs_rectclip(gs_state *pgs, gs_rect *pr, uint count) | |
65 | { int code; | |
66 | if ( (code = gs_newpath(pgs)) < 0 || | |
67 | (code = gs_rectappend(pgs, pr, count)) < 0 || | |
68 | (code = gs_clip(pgs)) < 0 || | |
69 | (code = gs_newpath(pgs)) < 0 | |
70 | ) | |
71 | return code; | |
72 | return 0; | |
73 | } | |
74 | ||
75 | /* Fill a list of rectangles. */ | |
76 | /* (We could do this a lot more efficiently.) */ | |
77 | int | |
78 | gs_rectfill(gs_state *pgs, gs_rect *pr, uint count) | |
79 | { int code; | |
80 | if ( (code = gs_gsave(pgs)) < 0 ) return code; | |
81 | if ( (code = gs_newpath(pgs)) < 0 || | |
82 | (code = gs_rectappend(pgs, pr, count)) < 0 || | |
83 | (code = gs_fill(pgs)) < 0 | |
84 | ) | |
85 | ; | |
86 | gs_grestore(pgs); | |
87 | return code; | |
88 | } | |
89 | ||
90 | /* Stroke a list of rectangles. */ | |
91 | /* (We could do this a lot more efficiently.) */ | |
92 | int | |
93 | gs_rectstroke(gs_state *pgs, gs_rect *pr, uint count, gs_matrix *pmat) | |
94 | { int code; | |
95 | if ( (code = gs_gsave(pgs)) < 0 ) return code; | |
96 | if ( (code = gs_newpath(pgs)) < 0 || | |
97 | (code = gs_rectappend(pgs, pr, count)) < 0 || | |
98 | (pmat != NULL && (code = gs_concat(pgs, pmat)) < 0) || | |
99 | (code = gs_stroke(pgs)) < 0 | |
100 | ) | |
101 | ; | |
102 | gs_grestore(pgs); | |
103 | return code; | |
104 | } |