1 /***********************************************************
3 Copyright 1987, 1998 The Open Group
5 Permission to use, copy, modify, distribute, and sell this software and its
6 documentation for any purpose is hereby granted without fee, provided that
7 the above copyright notice appear in all copies and that both that
8 copyright notice and this permission notice appear in supporting
11 The above copyright notice and this permission notice shall be included in
12 all copies or substantial portions of the Software.
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
18 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 Except as contained in this notice, the name of The Open Group shall not be
22 used in advertising or otherwise to promote the sale, use or other dealings
23 in this Software without prior written authorization from The Open Group.
25 Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
29 Permission to use, copy, modify, and distribute this software and its
30 documentation for any purpose and without fee is hereby granted,
31 provided that the above copyright notice appear in all copies and that
32 both that copyright notice and this permission notice appear in
33 supporting documentation, and that the name of Digital not be
34 used in advertising or publicity pertaining to distribution of the
35 software without specific, written prior permission.
37 DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
38 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
39 DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
40 ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
41 WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
42 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
45 ******************************************************************/
46 #ifdef HAVE_DIX_CONFIG_H
47 #include <dix-config.h>
53 #include "scrnintstr.h"
55 #include "windowstr.h"
60 /* Draw lineSolid, fillStyle-independent zero width lines.
62 * Must keep X and Y coordinates in "ints" at least until after they're
63 * translated and clipped to accomodate CoordModePrevious lines with very
66 * Draws the same pixels regardless of sign(dx) or sign(dy).
72 /* largest positive value that can fit into a component of a point.
73 * Assumes that the point structure is {type x, y;} where type is
76 #define MAX_COORDINATE ((1 << (((sizeof(DDXPointRec) >> 1) << 3) - 1)) - 1)
78 #define MI_OUTPUT_POINT(xx, yy)\
80 if ( !new_span && yy == current_y)\
100 miZeroLine(DrawablePtr pDraw
, GCPtr pGC
, int mode
, /* Origin or Previous */
101 int npt
, /* number of points */
104 int Nspans
, current_y
= 0;
106 DDXPointPtr pspanInit
, spans
;
107 int *pwidthInit
, *widths
, list_len
;
108 int xleft
, ytop
, xright
, ybottom
;
109 int new_x1
, new_y1
, new_x2
, new_y2
;
110 int x
= 0, y
= 0, x1
, y1
, x2
, y2
, xstart
, ystart
;
113 int pt1_clipped
, pt2_clipped
= 0;
120 unsigned int bias
= miGetZeroLineBias(pDraw
->pScreen
);
121 int e
, e1
, e2
, e3
; /* Bresenham error terms */
122 int length
; /* length of lines == # of pixels on major axis */
126 xright
= pDraw
->x
+ pDraw
->width
- 1;
127 ybottom
= pDraw
->y
+ pDraw
->height
- 1;
129 if (!pGC
->miTranslate
) {
130 /* do everything in drawable-relative coordinates */
137 /* it doesn't matter whether we're in drawable or screen coordinates,
138 * FillSpans simply cannot take starting coordinates outside of the
139 * range of a DDXPointRec component.
141 if (xright
> MAX_COORDINATE
)
142 xright
= MAX_COORDINATE
;
143 if (ybottom
> MAX_COORDINATE
)
144 ybottom
= MAX_COORDINATE
;
146 /* since we're clipping to the drawable's boundaries & coordinate
147 * space boundaries, we're guaranteed that the larger of width/height
148 * is the longest span we'll need to output
150 width
= xright
- xleft
+ 1;
151 height
= ybottom
- ytop
+ 1;
152 list_len
= (height
>= width
) ? height
: width
;
153 pspanInit
= malloc(list_len
* sizeof(DDXPointRec
));
154 pwidthInit
= malloc(list_len
* sizeof(int));
155 if (!pspanInit
|| !pwidthInit
) {
162 spans
= pspanInit
- 1;
163 widths
= pwidthInit
- 1;
168 if (pGC
->miTranslate
) {
173 /* x2, y2, oc2 copied to x1, y1, oc1 at top of loop to simplify
179 MIOUTCODES(oc2
, x2
, y2
, xleft
, ytop
, xright
, ybottom
);
183 (*pGC
->ops
->FillSpans
) (pDraw
, pGC
, Nspans
, pspanInit
,
187 spans
= pspanInit
- 1;
188 widths
= pwidthInit
- 1;
197 if (pGC
->miTranslate
&& (mode
!= CoordModePrevious
)) {
201 else if (mode
== CoordModePrevious
) {
207 MIOUTCODES(oc2
, x2
, y2
, xleft
, ytop
, xright
, ybottom
);
209 CalcLineDeltas(x1
, y1
, x2
, y2
, adx
, ady
, signdx
, signdy
, 1, 1, octant
);
213 e2
= e1
- (adx
<< 1);
215 length
= adx
; /* don't draw endpoint in main loop */
217 FIXUP_ERROR(e
, octant
, bias
);
226 if ((oc1
| oc2
) != 0) {
227 result
= miZeroClipLine(xleft
, ytop
, xright
, ybottom
,
228 &new_x1
, &new_y1
, &new_x2
, &new_y2
,
230 &pt1_clipped
, &pt2_clipped
,
231 octant
, bias
, oc1
, oc2
);
235 length
= abs(new_x2
- new_x1
);
237 /* if we've clipped the endpoint, always draw the full length
238 * of the segment, because then the capstyle doesn't matter
244 /* must calculate new error terms */
245 clipdx
= abs(new_x1
- x1
);
246 clipdy
= abs(new_y1
- y1
);
247 e
+= (clipdy
* e2
) + ((clipdx
- clipdy
) * e1
);
251 /* draw the segment */
260 MI_OUTPUT_POINT(x
, y
);
269 else { /* Y major line */
272 e2
= e1
- (ady
<< 1);
274 length
= ady
; /* don't draw endpoint in main loop */
276 SetYMajorOctant(octant
);
277 FIXUP_ERROR(e
, octant
, bias
);
286 if ((oc1
| oc2
) != 0) {
287 result
= miZeroClipLine(xleft
, ytop
, xright
, ybottom
,
288 &new_x1
, &new_y1
, &new_x2
, &new_y2
,
290 &pt1_clipped
, &pt2_clipped
,
291 octant
, bias
, oc1
, oc2
);
295 length
= abs(new_y2
- new_y1
);
297 /* if we've clipped the endpoint, always draw the full length
298 * of the segment, because then the capstyle doesn't matter
304 /* must calculate new error terms */
305 clipdx
= abs(new_x1
- x1
);
306 clipdy
= abs(new_y1
- y1
);
307 e
+= (clipdx
* e2
) + ((clipdy
- clipdx
) * e1
);
311 /* draw the segment */
320 MI_OUTPUT_POINT(x
, y
);
331 /* only do the capnotlast check on the last segment
332 * and only if the endpoint wasn't clipped. And then, if the last
333 * point is the same as the first point, do not draw it, unless the
336 if ((!pt2_clipped
) && (pGC
->capStyle
!= CapNotLast
) &&
337 (((xstart
!= x2
) || (ystart
!= y2
)) || (ppt
== pptInit
+ 1))) {
338 MI_OUTPUT_POINT(x
, y
);
342 (*pGC
->ops
->FillSpans
) (pDraw
, pGC
, Nspans
, pspanInit
,
350 miZeroDashLine(DrawablePtr dst
, GCPtr pgc
, int mode
, int nptInit
, /* number of points in polyline */
351 DDXPointRec
* pptInit
/* points in the polyline */
354 /* XXX kludge until real zero-width dash code is written */
356 miWideDash(dst
, pgc
, mode
, nptInit
, pptInit
);