1 /* This file is part of the GNU libxmi package. Copyright (C) 1998, 1999,
2 2000, 2005, Free Software Foundation, Inc.
3
4 The GNU libxmi package is free software. You may redistribute it
5 and/or modify it under the terms of the GNU General Public License as
6 published by the Free Software foundation; either version 2, or (at your
7 option) any later version.
8
9 The GNU libxmi package is distributed in the hope that it will be
10 useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 General Public License for more details.
13
14 You should have received a copy of the GNU General Public License along
15 with the GNU plotutils package; see the file COPYING. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin St., Fifth Floor,
17 Boston, MA 02110-1301, USA. */
18
19 /* This file defines the core libxmi API, consisting of:
20
21 1. miDrawPoints, miDrawLines, miFillPolygon.
22 2. miDrawRectangles, miFillRectangles.
23 3. miDrawArcs, miFillArcs. Also the reentrant miDrawArcs_r.
24
25 Each of these is a wrapper around an internal function that takes as first
26 argument a (miPaintedSet *). A miPaintedSet struct is a structure that is
27 used by Joel McCormack's span-merging module to implement the
28 `touch-each-pixel-once' rule. See mi_spans.c and mi_spans.h. */
29
30 #include "sys-defines.h"
31 #include "extern.h"
32
33 #include "xmi.h"
34 #include "mi_spans.h"
35 #include "mi_gc.h"
36 #include "mi_api.h"
37
38 #define MI_SETUP_PAINTED_SET(paintedSet, pGC) \
39 {\
40 }
41
42 #define MI_TEAR_DOWN_PAINTED_SET(paintedSet) \
43 {\
44 miUniquifyPaintedSet (paintedSet); \
45 }
46
47 /* ARGS: mode = Origin or Previous */
48 void
miDrawPoints(miPaintedSet * paintedSet,const miGC * pGC,miCoordMode mode,int npt,const miPoint * pPts)49 miDrawPoints (miPaintedSet *paintedSet, const miGC *pGC, miCoordMode mode, int npt, const miPoint *pPts)
50 {
51 MI_SETUP_PAINTED_SET(paintedSet, pGC)
52 miDrawPoints_internal (paintedSet, pGC, mode, npt, pPts);
53 MI_TEAR_DOWN_PAINTED_SET(paintedSet)
54 }
55
56 /* ARGS: mode = Origin or Previous */
57 void
miDrawLines(miPaintedSet * paintedSet,const miGC * pGC,miCoordMode mode,int npt,const miPoint * pPts)58 miDrawLines (miPaintedSet *paintedSet, const miGC *pGC, miCoordMode mode, int npt, const miPoint *pPts)
59 {
60 MI_SETUP_PAINTED_SET(paintedSet, pGC)
61 miDrawLines_internal (paintedSet, pGC, mode, npt, pPts);
62 MI_TEAR_DOWN_PAINTED_SET(paintedSet)
63 }
64
65 /* ARGS: mode = Origin or Previous */
66 void
miFillPolygon(miPaintedSet * paintedSet,const miGC * pGC,miPolygonShape shape,miCoordMode mode,int count,const miPoint * pPts)67 miFillPolygon (miPaintedSet *paintedSet, const miGC *pGC, miPolygonShape shape, miCoordMode mode, int count, const miPoint *pPts)
68 {
69 MI_SETUP_PAINTED_SET(paintedSet, pGC)
70 miFillPolygon_internal (paintedSet, pGC, shape, mode, count, pPts);
71 MI_TEAR_DOWN_PAINTED_SET(paintedSet)
72 }
73
74 void
miDrawRectangles(miPaintedSet * paintedSet,const miGC * pGC,int nrects,const miRectangle * prectInit)75 miDrawRectangles (miPaintedSet *paintedSet, const miGC *pGC, int nrects, const miRectangle *prectInit)
76 {
77 MI_SETUP_PAINTED_SET(paintedSet, pGC);
78 miDrawRectangles_internal (paintedSet, pGC, nrects, prectInit);
79 MI_TEAR_DOWN_PAINTED_SET(paintedSet)
80 }
81
82 void
miFillRectangles(miPaintedSet * paintedSet,const miGC * pGC,int nrectFill,const miRectangle * prectInit)83 miFillRectangles (miPaintedSet *paintedSet, const miGC *pGC, int nrectFill, const miRectangle *prectInit)
84 {
85 fprintf (stderr, "miFillRectangles()\n");
86
87 MI_SETUP_PAINTED_SET(paintedSet, pGC);
88 miFillRectangles_internal (paintedSet, pGC, nrectFill, prectInit);
89 MI_TEAR_DOWN_PAINTED_SET(paintedSet)
90 }
91
92 #ifndef NO_NONREENTRANT_POLYARC_SUPPORT
93 void
miDrawArcs(miPaintedSet * paintedSet,const miGC * pGC,int narcs,const miArc * parcs)94 miDrawArcs (miPaintedSet *paintedSet, const miGC *pGC, int narcs, const miArc *parcs)
95 {
96 MI_SETUP_PAINTED_SET(paintedSet, pGC)
97 miDrawArcs_internal (paintedSet, pGC, narcs, parcs);
98 MI_TEAR_DOWN_PAINTED_SET(paintedSet)
99 }
100 #endif /* not NO_NONREENTRANT_POLYARC_SUPPORT */
101
102 void
miFillArcs(miPaintedSet * paintedSet,const miGC * pGC,int narcs,const miArc * parcs)103 miFillArcs (miPaintedSet *paintedSet, const miGC *pGC, int narcs, const miArc *parcs)
104 {
105 MI_SETUP_PAINTED_SET(paintedSet, pGC)
106 miFillArcs_internal (paintedSet, pGC, narcs, parcs);
107 MI_TEAR_DOWN_PAINTED_SET(paintedSet)
108 }
109
110 /* ARGS: ellipseCache = pointer to ellipse data cache */
111 void
miDrawArcs_r(miPaintedSet * paintedSet,const miGC * pGC,int narcs,const miArc * parcs,miEllipseCache * ellipseCache)112 miDrawArcs_r (miPaintedSet *paintedSet, const miGC *pGC, int narcs, const miArc *parcs, miEllipseCache *ellipseCache)
113 {
114 MI_SETUP_PAINTED_SET(paintedSet, pGC)
115 miDrawArcs_r_internal (paintedSet, pGC, narcs, parcs, ellipseCache);
116 MI_TEAR_DOWN_PAINTED_SET(paintedSet)
117 }
118
119 /**********************************************************************/
120 /* Further wrappers that should really be moved to other file(s). */
121 /**********************************************************************/
122
123 /* ARGS: ellipseCache = pointer to ellipse data cache */
124 void
miDrawArcs_r_internal(miPaintedSet * paintedSet,const miGC * pGC,int narcs,const miArc * parcs,miEllipseCache * ellipseCache)125 miDrawArcs_r_internal (miPaintedSet *paintedSet, const miGC *pGC, int narcs, const miArc *parcs, miEllipseCache *ellipseCache)
126 {
127 if (pGC->lineWidth == 0)
128 /* use Bresenham algorithm */
129 miZeroPolyArc_r (paintedSet, pGC, narcs, parcs, ellipseCache);
130 else
131 miPolyArc_r (paintedSet, pGC, narcs, parcs, ellipseCache);
132 }
133
134 #ifndef NO_NONREENTRANT_POLYARC_SUPPORT
135 void
miDrawArcs_internal(miPaintedSet * paintedSet,const miGC * pGC,int narcs,const miArc * parcs)136 miDrawArcs_internal (miPaintedSet *paintedSet, const miGC *pGC, int narcs, const miArc *parcs)
137 {
138 if (pGC->lineWidth == 0)
139 /* use Bresenham algorithm */
140 miZeroPolyArc (paintedSet, pGC, narcs, parcs);
141 else
142 miPolyArc (paintedSet, pGC, narcs, parcs);
143 }
144 #endif /* not NO_NONREENTRANT_POLYARC_SUPPORT */
145
146 /* ARGS: mode = Origin or Previous */
147 void
miDrawLines_internal(miPaintedSet * paintedSet,const miGC * pGC,miCoordMode mode,int npt,const miPoint * pPts)148 miDrawLines_internal (miPaintedSet *paintedSet, const miGC *pGC, miCoordMode mode, int npt, const miPoint *pPts)
149 {
150 if (pGC->lineWidth == 0)
151 {
152 /* use Bresenham algorithm */
153 if (pGC->lineStyle == (int)MI_LINE_SOLID)
154 miZeroLine (paintedSet, pGC, mode, npt, pPts);
155 else
156 miZeroDash (paintedSet, pGC, mode, npt, pPts);
157 }
158 else
159 {
160 if (pGC->lineStyle == (int)MI_LINE_SOLID)
161 miWideLine (paintedSet, pGC, mode, npt, pPts);
162 else
163 miWideDash (paintedSet, pGC, mode, npt, pPts);
164 }
165 }
166
167 void
miDrawRectangles_internal(miPaintedSet * paintedSet,const miGC * pGC,int nrects,const miRectangle * prectInit)168 miDrawRectangles_internal (miPaintedSet *paintedSet, const miGC *pGC, int nrects, const miRectangle *prectInit)
169 {
170 const miRectangle *pR = prectInit;
171 miPoint rect[5];
172 int i;
173
174 fprintf (stderr, "miDrawRectangles_internal()\n");
175
176 for (i = 0; i < nrects; i++)
177 {
178 rect[0].x = pR->x;
179 rect[0].y = pR->y;
180
181 rect[1].x = pR->x + (int) pR->width;
182 rect[1].y = rect[0].y;
183
184 rect[2].x = rect[1].x;
185 rect[2].y = pR->y + (int) pR->height;
186
187 rect[3].x = rect[0].x;
188 rect[3].y = rect[2].y;
189
190 /* close the polyline */
191 rect[4].x = rect[0].x;
192 rect[4].y = rect[0].y;
193
194 miDrawLines_internal (paintedSet, pGC, MI_COORD_MODE_ORIGIN, 5, rect);
195 pR++;
196 }
197 }
198