1 /***********************************************************
3 Copyright (c) 1987 X Consortium
5 Permission is hereby granted, free of charge, to any person obtaining a copy
6 of this software and associated documentation files (the "Software"), to deal
7 in the Software without restriction, including without limitation the rights
8 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 copies of the Software, and to permit persons to whom the Software is
10 furnished to do so, subject to the following conditions:
12 The above copyright notice and this permission notice shall be included in
13 all copies or substantial portions of the Software.
15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
19 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 Except as contained in this notice, the name of the X Consortium shall not be
23 used in advertising or otherwise to promote the sale, use or other dealings
24 in this Software without prior written authorization from the X Consortium.
27 Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
31 Permission to use, copy, modify, and distribute this software and its
32 documentation for any purpose and without fee is hereby granted,
33 provided that the above copyright notice appear in all copies and that
34 both that copyright notice and this permission notice appear in
35 supporting documentation, and that the name of Digital not be
36 used in advertising or publicity pertaining to distribution of the
37 software without specific, written prior permission.
39 DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
40 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
41 DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
42 ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
43 WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
44 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
47 ******************************************************************/
48 /* $XConsortium: midash.c,v 5.5 94/04/17 20:27:27 dpw Exp $ */
49 #include "miscstruct.h"
53 static miDashPtr CheckDashStorage();
55 /* return a list of DashRec. there will be an extra
56 entry at the end holding the last point of the polyline.
57 this means that the code that actually draws dashes can
58 get a pair of points for every dash. only the point in the last
59 dash record is useful; the other fields are not used.
60 nseg is the number of segments, not the number of points.
69 defines a list of segments
72 (dash3.pt, last-point)
76 EVEN_DASH == ~ODD_DASH
79 miDashLines may return 0 segments, going from pt[0] to pt[0] with one dash.
83 miDashLine(npt, ppt, nDash, pDash, offset, pnseg)
92 int lenCur; /* npt used from this dash */
93 int lenMax; /* npt in this dash */
94 int iDash = 0; /* index of current dash */
95 int which; /* EVEN_DASH or ODD_DASH */
96 miDashPtr pseg; /* list of dash segments */
97 miDashPtr psegBase; /* start of list */
98 int nseg = 0; /* number of dashes so far */
99 int nsegMax = 0; /* num segs we can fit in this list */
102 int adx, ady, signdx, signdy;
103 int du, dv, e1, e2, e, base_e = 0;
107 while(lenCur >= pDash[iDash])
109 lenCur -= pDash[iDash];
115 lenMax = pDash[iDash];
117 psegBase = (miDashPtr)NULL;
118 pt2 = ppt[0]; /* just in case there is only one point */
122 if (PtEqual(ppt[0], ppt[1]))
125 continue; /* no duplicated points in polyline */
157 pseg = CheckDashStorage(&psegBase, nseg, &nsegMax);
159 return (miDashPtr)NULL;
163 base_e = pseg->e = e;
172 if (((signdx > 0) && (e < 0)) ||
173 ((signdx <=0) && (e <=0))
188 if (((signdx > 0) && (e < 0)) ||
189 ((signdx <=0) && (e <=0))
203 if (lenCur >= lenMax && (len || npt <= 1))
206 pseg = CheckDashStorage(&psegBase, nseg, &nsegMax);
208 return (miDashPtr)NULL;
218 /* move on to next dash */
222 lenMax = pDash[iDash];
228 if (lenCur == 0 && nseg != 0)
234 pseg = CheckDashStorage(&psegBase, nseg+1, &nsegMax);
236 return (miDashPtr)NULL;
247 /* returns a pointer to the pseg[nseg-1], growing the storage as
248 necessary. this interface seems unnecessarily cumbersome.
254 CheckDashStorage(ppseg, nseg, pnsegMax)
255 miDashPtr *ppseg; /* base pointer */
256 int nseg; /* number of segment we want to write to */
257 int *pnsegMax; /* size (in segments) of list so far */
259 if (nseg > *pnsegMax)
263 *pnsegMax += NSEGDELTA;
264 newppseg = (miDashPtr)xrealloc(*ppseg,
265 (*pnsegMax)*sizeof(miDashRec));
269 return (miDashPtr)NULL;
273 return(*ppseg+(nseg-1));
277 miStepDash (dist, pDashIndex, pDash, numInDashList, pDashOffset)
278 int dist; /* distance to step */
279 int *pDashIndex; /* current dash */
280 unsigned char *pDash; /* dash list */
281 int numInDashList; /* total length of dash list */
282 int *pDashOffset; /* offset into current dash */
284 int dashIndex, dashOffset;
288 dashIndex = *pDashIndex;
289 dashOffset = *pDashOffset;
290 if (dist < pDash[dashIndex] - dashOffset)
292 *pDashOffset = dashOffset + dist;
295 dist -= pDash[dashIndex] - dashOffset;
296 if (++dashIndex == numInDashList)
299 for (i = 0; i < numInDashList; i++)
300 totallen += pDash[i];
301 if (totallen <= dist)
302 dist = dist % totallen;
303 while (dist >= pDash[dashIndex])
305 dist -= pDash[dashIndex];
306 if (++dashIndex == numInDashList)
309 *pDashIndex = dashIndex;