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.
26 Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
30 Permission to use, copy, modify, and distribute this software and its
31 documentation for any purpose and without fee is hereby granted,
32 provided that the above copyright notice appear in all copies and that
33 both that copyright notice and this permission notice appear in
34 supporting documentation, and that the name of Digital not be
35 used in advertising or publicity pertaining to distribution of the
36 software without specific, written prior permission.
38 DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
39 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
40 DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
41 ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
42 WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
43 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
46 ******************************************************************/
47 #ifdef HAVE_DIX_CONFIG_H
48 #include <dix-config.h>
54 #include "scrnintstr.h"
56 #include "windowstr.h"
61 /* Draw lineSolid, fillStyle-independent zero width lines.
63 * Must keep X and Y coordinates in "ints" at least until after they're
64 * translated and clipped to accomodate CoordModePrevious lines with very
67 * Draws the same pixels regardless of sign(dx) or sign(dy).
73 /* largest positive value that can fit into a component of a point.
74 * Assumes that the point structure is {type x, y;} where type is
77 #define MAX_COORDINATE ((1 << (((sizeof(DDXPointRec) >> 1) << 3) - 1)) - 1)
79 #define MI_OUTPUT_POINT(xx, yy)\
81 if ( !new_span && yy == current_y)\
101 miZeroLine(pDraw
, pGC
, mode
, npt
, pptInit
)
104 int mode
; /* Origin or Previous */
105 int npt
; /* number of points */
108 int Nspans
, current_y
= 0;
110 DDXPointPtr pspanInit
, spans
;
111 int *pwidthInit
, *widths
, list_len
;
112 int xleft
, ytop
, xright
, ybottom
;
113 int new_x1
, new_y1
, new_x2
, new_y2
;
114 int x
= 0, y
= 0, x1
, y1
, x2
, y2
, xstart
, ystart
;
117 int pt1_clipped
, pt2_clipped
= 0;
124 unsigned int bias
= miGetZeroLineBias(pDraw
->pScreen
);
125 int e
, e1
, e2
, e3
; /* Bresenham error terms */
126 int length
; /* length of lines == # of pixels on major axis */
130 xright
= pDraw
->x
+ pDraw
->width
- 1;
131 ybottom
= pDraw
->y
+ pDraw
->height
- 1;
133 if (!pGC
->miTranslate
)
135 /* do everything in drawable-relative coordinates */
142 /* it doesn't matter whether we're in drawable or screen coordinates,
143 * FillSpans simply cannot take starting coordinates outside of the
144 * range of a DDXPointRec component.
146 if (xright
> MAX_COORDINATE
)
147 xright
= MAX_COORDINATE
;
148 if (ybottom
> MAX_COORDINATE
)
149 ybottom
= MAX_COORDINATE
;
151 /* since we're clipping to the drawable's boundaries & coordinate
152 * space boundaries, we're guaranteed that the larger of width/height
153 * is the longest span we'll need to output
155 width
= xright
- xleft
+ 1;
156 height
= ybottom
- ytop
+ 1;
157 list_len
= (height
>= width
) ? height
: width
;
158 pspanInit
= (DDXPointPtr
)ALLOCATE_LOCAL(list_len
* sizeof(DDXPointRec
));
159 pwidthInit
= (int *)ALLOCATE_LOCAL(list_len
* sizeof(int));
160 if (!pspanInit
|| !pwidthInit
)
165 spans
= pspanInit
- 1;
166 widths
= pwidthInit
- 1;
171 if (pGC
->miTranslate
)
177 /* x2, y2, oc2 copied to x1, y1, oc1 at top of loop to simplify
183 MIOUTCODES(oc2
, x2
, y2
, xleft
, ytop
, xright
, ybottom
);
188 (*pGC
->ops
->FillSpans
)(pDraw
, pGC
, Nspans
, pspanInit
,
192 spans
= pspanInit
- 1;
193 widths
= pwidthInit
- 1;
202 if (pGC
->miTranslate
&& (mode
!= CoordModePrevious
))
207 else if (mode
== CoordModePrevious
)
214 MIOUTCODES(oc2
, x2
, y2
, xleft
, ytop
, xright
, ybottom
);
216 CalcLineDeltas(x1
, y1
, x2
, y2
, adx
, ady
, signdx
, signdy
, 1, 1, octant
);
221 e2
= e1
- (adx
<< 1);
223 length
= adx
; /* don't draw endpoint in main loop */
225 FIXUP_ERROR(e
, octant
, bias
);
234 if ((oc1
| oc2
) != 0)
236 result
= miZeroClipLine(xleft
, ytop
, xright
, ybottom
,
237 &new_x1
, &new_y1
, &new_x2
, &new_y2
,
239 &pt1_clipped
, &pt2_clipped
,
240 octant
, bias
, oc1
, oc2
);
244 length
= abs(new_x2
- new_x1
);
246 /* if we've clipped the endpoint, always draw the full length
247 * of the segment, because then the capstyle doesn't matter
254 /* must calculate new error terms */
255 clipdx
= abs(new_x1
- x1
);
256 clipdy
= abs(new_y1
- y1
);
257 e
+= (clipdy
* e2
) + ((clipdx
- clipdy
) * e1
);
261 /* draw the segment */
271 MI_OUTPUT_POINT(x
, y
);
281 else /* Y major line */
284 e2
= e1
- (ady
<< 1);
286 length
= ady
; /* don't draw endpoint in main loop */
288 SetYMajorOctant(octant
);
289 FIXUP_ERROR(e
, octant
, bias
);
298 if ((oc1
| oc2
) != 0)
300 result
= miZeroClipLine(xleft
, ytop
, xright
, ybottom
,
301 &new_x1
, &new_y1
, &new_x2
, &new_y2
,
303 &pt1_clipped
, &pt2_clipped
,
304 octant
, bias
, oc1
, oc2
);
308 length
= abs(new_y2
- new_y1
);
310 /* if we've clipped the endpoint, always draw the full length
311 * of the segment, because then the capstyle doesn't matter
318 /* must calculate new error terms */
319 clipdx
= abs(new_x1
- x1
);
320 clipdy
= abs(new_y1
- y1
);
321 e
+= (clipdx
* e2
) + ((clipdy
- clipdx
) * e1
);
325 /* draw the segment */
335 MI_OUTPUT_POINT(x
, y
);
347 /* only do the capnotlast check on the last segment
348 * and only if the endpoint wasn't clipped. And then, if the last
349 * point is the same as the first point, do not draw it, unless the
352 if ( (! pt2_clipped
) && (pGC
->capStyle
!= CapNotLast
) &&
353 (((xstart
!= x2
) || (ystart
!= y2
)) || (ppt
== pptInit
+ 1)))
355 MI_OUTPUT_POINT(x
, y
);
359 (*pGC
->ops
->FillSpans
)(pDraw
, pGC
, Nspans
, pspanInit
,
362 DEALLOCATE_LOCAL(pwidthInit
);
363 DEALLOCATE_LOCAL(pspanInit
);
367 miZeroDashLine(dst
, pgc
, mode
, nptInit
, pptInit
)
371 int nptInit
; /* number of points in polyline */
372 DDXPointRec
*pptInit
; /* points in the polyline */
374 /* XXX kludge until real zero-width dash code is written */
376 miWideDash (dst
, pgc
, mode
, nptInit
, pptInit
);