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 $ */
48 static miDashPtr CheckDashStorage();
50 /* return a list of DashRec. there will be an extra
51 entry at the end holding the last point of the polyline.
52 this means that the code that actually draws dashes can
53 get a pair of points for every dash. only the point in the last
54 dash record is useful; the other fields are not used.
55 nseg is the number of segments, not the number of points.
64 defines a list of segments
67 (dash3.pt, last-point)
71 EVEN_DASH == ~ODD_DASH
74 miDashLines may return 0 segments, going from pt[0] to pt[0] with one dash.
77 enum { EVEN_DASH=0, ODD_DASH=1 };
79 #define sign(x) ((x)>0)?1:( ((x)<0)?-1:0 )
82 miDashLine(npt, ppt, nDash, pDash, offset, pnseg)
91 int lenCur; /* npt used from this dash */
92 int lenMax; /* npt in this dash */
93 int iDash = 0; /* index of current dash */
94 int which; /* EVEN_DASH or ODD_DASH */
95 miDashPtr pseg; /* list of dash segments */
96 miDashPtr psegBase; /* start of list */
97 int nseg = 0; /* number of dashes so far */
98 int nsegMax = 0; /* num segs we can fit in this list */
101 int adx, ady, signdx, signdy;
102 int du, dv, e1, e2, e, base_e = 0;
106 while(lenCur >= pDash[iDash])
108 lenCur -= pDash[iDash];
114 lenMax = pDash[iDash];
116 psegBase = (miDashPtr)NULL;
117 pt2 = ppt[0]; /* just in case there is only one point */
121 if (PtEqual(ppt[0], ppt[1]))
124 continue; /* no duplicated points in polyline */
156 pseg = CheckDashStorage(&psegBase, nseg, &nsegMax);
158 return (miDashPtr)NULL;
162 base_e = pseg->e = e;
171 if (((signdx > 0) && (e < 0)) ||
172 ((signdx <=0) && (e <=0))
187 if (((signdx > 0) && (e < 0)) ||
188 ((signdx <=0) && (e <=0))
202 if (lenCur >= lenMax && (len || npt <= 1))
205 pseg = CheckDashStorage(&psegBase, nseg, &nsegMax);
207 return (miDashPtr)NULL;
217 /* move on to next dash */
221 lenMax = pDash[iDash];
227 if (lenCur == 0 && nseg != 0)
233 pseg = CheckDashStorage(&psegBase, nseg+1, &nsegMax);
235 return (miDashPtr)NULL;
246 /* returns a pointer to the pseg[nseg-1], growing the storage as
247 necessary. this interface seems unnecessarily cumbersome.
253 CheckDashStorage(ppseg, nseg, pnsegMax)
254 miDashPtr *ppseg; /* base pointer */
255 int nseg; /* number of segment we want to write to */
256 int *pnsegMax; /* size (in segments) of list so far */
258 if (nseg > *pnsegMax)
262 *pnsegMax += NSEGDELTA;
263 newppseg = (miDashPtr)g_realloc(*ppseg,
264 (*pnsegMax)*sizeof(miDashRec));
268 return (miDashPtr)NULL;
272 return(*ppseg+(nseg-1));
276 miStepDash (dist, pDashIndex, pDash, numInDashList, pDashOffset)
277 int dist; /* distance to step */
278 int *pDashIndex; /* current dash */
279 unsigned char *pDash; /* dash list */
280 int numInDashList; /* total length of dash list */
281 int *pDashOffset; /* offset into current dash */
283 int dashIndex, dashOffset;
287 dashIndex = *pDashIndex;
288 dashOffset = *pDashOffset;
289 if (dist < pDash[dashIndex] - dashOffset)
291 *pDashOffset = dashOffset + dist;
294 dist -= pDash[dashIndex] - dashOffset;
295 if (++dashIndex == numInDashList)
298 for (i = 0; i < numInDashList; i++)
299 totallen += pDash[i];
300 if (totallen <= dist)
301 dist = dist % totallen;
302 while (dist >= pDash[dashIndex])
304 dist -= pDash[dashIndex];
305 if (++dashIndex == numInDashList)
308 *pDashIndex = dashIndex;