1 /* $XFree86: xc/programs/Xserver/mi/mizerline.c,v 3.4 1999/10/14 04:43:16 dawes Exp $ */
2 /***********************************************************
4 Copyright 1987, 1998 The Open Group
8 The above copyright notice and this permission notice shall be included in
9 all copies or substantial portions of the Software.
11 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
12 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
14 OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
15 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
16 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
18 Except as contained in this notice, the name of The Open Group shall not be
19 used in advertising or otherwise to promote the sale, use or other dealings
20 in this Software without prior written authorization from The Open Group.
23 Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
27 Permission to use, copy, modify, and distribute this software and its
28 documentation for any purpose and without fee is hereby granted,
29 provided that the above copyright notice appear in all copies and that
30 both that copyright notice and this permission notice appear in
31 supporting documentation, and that the name of Digital not be
32 used in advertising or publicity pertaining to distribution of the
33 software without specific, written prior permission.
35 DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
36 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
37 DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
38 ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
39 WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
40 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
43 ******************************************************************/
44 /* $TOG: mizerline.c /main/18 1998/02/09 14:49:45 kaleb $ */
49 /* Draw lineSolid, fillStyle-independent zero width lines.
51 * Must keep X and Y coordinates in "ints" at least until after they're
52 * translated and clipped to accomodate CoordModePrevious lines with very
55 * Draws the same pixels regardless of sign(dx) or sign(dy).
61 /* largest positive value that can fit into a component of a point.
62 * Assumes that the point structure is {type x, y;} where type is
65 #define MAX_COORDINATE ((1 << (((sizeof(GdkPoint) >> 1) << 3) - 1)) - 1)
67 #define MI_OUTPUT_POINT(xx, yy)\
69 if ( !new_span && yy == current_y)\
88 miZeroLine(pDraw, pGC, mode, npt, pptInit)
91 int mode; /* Origin or Previous */
92 int npt; /* number of points */
95 int Nspans, current_y = 0;
97 GdkSpan* pspanInit, *spans;
99 int xleft, ytop, xright, ybottom;
100 int new_x1, new_y1, new_x2, new_y2;
101 int x = 0, y = 0, x1, y1, x2, y2, xstart, ystart;
104 int pt1_clipped, pt2_clipped = 0;
111 unsigned int bias = miGetZeroLineBias();
112 int e, e1, e2, e3; /* Bresenham error terms */
113 int length; /* length of lines == # of pixels on major axis */
117 xright = GDK_DRAWABLE_FBDATA(pDraw)->width - 1;
118 ybottom = GDK_DRAWABLE_FBDATA(pDraw)->height - 1;
120 /* it doesn't matter whether we're in drawable or screen coordinates,
121 * FillSpans simply cannot take starting coordinates outside of the
122 * range of a GdkPoint component.
125 /* since we're clipping to the drawable's boundaries & coordinate
126 * space boundaries, we're guaranteed that the larger of width/height
127 * is the longest span we'll need to output
129 width = xright - xleft + 1;
130 height = ybottom - ytop + 1;
131 list_len = (height >= width) ? height : width;
132 pspanInit = (GdkSpan*)ALLOCATE_LOCAL(list_len * sizeof(GdkSpan));
138 spans = pspanInit - 1;
144 /* x2, y2, oc2 copied to x1, y1, oc1 at top of loop to simplify
150 MIOUTCODES(oc2, x2, y2, xleft, ytop, xright, ybottom);
155 gdk_fb_fill_spans(pDraw, pGC, pspanInit, Nspans, FALSE);
158 spans = pspanInit - 1;
169 MIOUTCODES(oc2, x2, y2, xleft, ytop, xright, ybottom);
171 CalcLineDeltas(x1, y1, x2, y2, adx, ady, signdx, signdy, 1, 1, octant);
176 e2 = e1 - (adx << 1);
178 length = adx; /* don't draw endpoint in main loop */
180 FIXUP_ERROR(e, octant, bias);
189 if ((oc1 | oc2) != 0)
191 result = miZeroClipLine(xleft, ytop, xright, ybottom,
192 &new_x1, &new_y1, &new_x2, &new_y2,
194 &pt1_clipped, &pt2_clipped,
195 octant, bias, oc1, oc2);
199 length = abs(new_x2 - new_x1);
201 /* if we've clipped the endpoint, always draw the full length
202 * of the segment, because then the capstyle doesn't matter
209 /* must calculate new error terms */
210 clipdx = abs(new_x1 - x1);
211 clipdy = abs(new_y1 - y1);
212 e += (clipdy * e2) + ((clipdx - clipdy) * e1);
216 /* draw the segment */
226 MI_OUTPUT_POINT(x, y);
236 else /* Y major line */
239 e2 = e1 - (ady << 1);
241 length = ady; /* don't draw endpoint in main loop */
243 SetYMajorOctant(octant);
244 FIXUP_ERROR(e, octant, bias);
253 if ((oc1 | oc2) != 0)
255 result = miZeroClipLine(xleft, ytop, xright, ybottom,
256 &new_x1, &new_y1, &new_x2, &new_y2,
258 &pt1_clipped, &pt2_clipped,
259 octant, bias, oc1, oc2);
263 length = abs(new_y2 - new_y1);
265 /* if we've clipped the endpoint, always draw the full length
266 * of the segment, because then the capstyle doesn't matter
273 /* must calculate new error terms */
274 clipdx = abs(new_x1 - x1);
275 clipdy = abs(new_y1 - y1);
276 e += (clipdx * e2) + ((clipdy - clipdx) * e1);
280 /* draw the segment */
290 MI_OUTPUT_POINT(x, y);
302 /* only do the capnotlast check on the last segment
303 * and only if the endpoint wasn't clipped. And then, if the last
304 * point is the same as the first point, do not draw it, unless the
307 if ( (! pt2_clipped) && (GDK_GC_FBDATA(pGC)->values.cap_style != GDK_CAP_NOT_LAST) &&
308 (((xstart != x2) || (ystart != y2)) || (ppt == pptInit + 1)))
310 MI_OUTPUT_POINT(x, y);
314 gdk_fb_fill_spans(pDraw, pGC, pspanInit, Nspans, FALSE);
316 DEALLOCATE_LOCAL(pspanInit);
320 miZeroDashLine(dst, pgc, mode, nptInit, pptInit)
324 int nptInit; /* number of points in polyline */
325 GdkPoint *pptInit; /* points in the polyline */
327 /* XXX kludge until real zero-width dash code is written */
328 GDK_GC_FBDATA(pgc)->values.line_width = 1;
329 miWideDash (dst, pgc, mode, nptInit, pptInit);
330 GDK_GC_FBDATA(pgc)->values.line_width = 0;