1 /***********************************************************
3 Copyright 1987, 1998 The Open Group
7 The above copyright notice and this permission notice shall be included in
8 all copies or substantial portions of the Software.
10 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
11 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
12 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
13 OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
14 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
15 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
17 Except as contained in this notice, the name of The Open Group shall not be
18 used in advertising or otherwise to promote the sale, use or other dealings
19 in this Software without prior written authorization from The Open Group.
22 Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
26 Permission to use, copy, modify, and distribute this software and its
27 documentation for any purpose and without fee is hereby granted,
28 provided that the above copyright notice appear in all copies and that
29 both that copyright notice and this permission notice appear in
30 supporting documentation, and that the name of Digital not be
31 used in advertising or publicity pertaining to distribution of the
32 software without specific, written prior permission.
34 DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
35 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
36 DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
37 ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
38 WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
39 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
42 ******************************************************************/
43 /* $TOG: midash.c /main/14 1998/02/09 14:46:34 kaleb $ */
47 static miDashPtr CheckDashStorage();
49 /* return a list of DashRec. there will be an extra
50 entry at the end holding the last point of the polyline.
51 this means that the code that actually draws dashes can
52 get a pair of points for every dash. only the point in the last
53 dash record is useful; the other fields are not used.
54 nseg is the number of segments, not the number of points.
63 defines a list of segments
66 (dash3.pt, last-point)
70 EVEN_DASH == ~ODD_DASH
73 miDashLines may return 0 segments, going from pt[0] to pt[0] with one dash.
76 enum { EVEN_DASH=0, ODD_DASH=1 };
78 #define sign(x) ((x)>0)?1:( ((x)<0)?-1:0 )
81 miDashLine(npt, ppt, nDash, pDash, offset, pnseg)
90 int lenCur; /* npt used from this dash */
91 int lenMax; /* npt in this dash */
92 int iDash = 0; /* index of current dash */
93 int which; /* EVEN_DASH or ODD_DASH */
94 miDashPtr pseg; /* list of dash segments */
95 miDashPtr psegBase; /* start of list */
96 int nseg = 0; /* number of dashes so far */
97 int nsegMax = 0; /* num segs we can fit in this list */
100 int adx, ady, signdx, signdy;
101 int du, dv, e1, e2, e, base_e = 0;
105 while(lenCur >= pDash[iDash])
107 lenCur -= pDash[iDash];
113 lenMax = pDash[iDash];
115 psegBase = (miDashPtr)NULL;
116 pt2 = ppt[0]; /* just in case there is only one point */
120 if (PtEqual(ppt[0], ppt[1]))
123 continue; /* no duplicated points in polyline */
155 pseg = CheckDashStorage(&psegBase, nseg, &nsegMax);
157 return (miDashPtr)NULL;
161 base_e = pseg->e = e;
170 if (((signdx > 0) && (e < 0)) ||
171 ((signdx <=0) && (e <=0))
186 if (((signdx > 0) && (e < 0)) ||
187 ((signdx <=0) && (e <=0))
201 if (lenCur >= lenMax && (len || npt <= 1))
204 pseg = CheckDashStorage(&psegBase, nseg, &nsegMax);
206 return (miDashPtr)NULL;
216 /* move on to next dash */
220 lenMax = pDash[iDash];
226 if (lenCur == 0 && nseg != 0)
232 pseg = CheckDashStorage(&psegBase, nseg+1, &nsegMax);
234 return (miDashPtr)NULL;
245 /* returns a pointer to the pseg[nseg-1], growing the storage as
246 necessary. this interface seems unnecessarily cumbersome.
252 CheckDashStorage(ppseg, nseg, pnsegMax)
253 miDashPtr *ppseg; /* base pointer */
254 int nseg; /* number of segment we want to write to */
255 int *pnsegMax; /* size (in segments) of list so far */
257 if (nseg > *pnsegMax)
261 *pnsegMax += NSEGDELTA;
262 newppseg = (miDashPtr)g_realloc(*ppseg,
263 (*pnsegMax)*sizeof(miDashRec));
267 return (miDashPtr)NULL;
271 return(*ppseg+(nseg-1));
275 miStepDash (dist, pDashIndex, pDash, numInDashList, pDashOffset)
276 int dist; /* distance to step */
277 int *pDashIndex; /* current dash */
278 unsigned char *pDash; /* dash list */
279 int numInDashList; /* total length of dash list */
280 int *pDashOffset; /* offset into current dash */
282 int dashIndex, dashOffset;
286 dashIndex = *pDashIndex;
287 dashOffset = *pDashOffset;
288 if (dist < pDash[dashIndex] - dashOffset)
290 *pDashOffset = dashOffset + dist;
293 dist -= pDash[dashIndex] - dashOffset;
294 if (++dashIndex == numInDashList)
297 for (i = 0; i < numInDashList; i++)
298 totallen += pDash[i];
299 if (totallen <= dist)
300 dist = dist % totallen;
301 while (dist >= pDash[dashIndex])
303 dist -= pDash[dashIndex];
304 if (++dashIndex == numInDashList)
307 *pDashIndex = dashIndex;