Annotation of researchv9/X11/src/X.V11R1/server/ddx/mi/midash.c, revision 1.1.1.1

1.1       root        1: /***********************************************************
                      2: Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts,
                      3: and the Massachusetts Institute of Technology, Cambridge, Massachusetts.
                      4: 
                      5:                         All Rights Reserved
                      6: 
                      7: Permission to use, copy, modify, and distribute this software and its 
                      8: documentation for any purpose and without fee is hereby granted, 
                      9: provided that the above copyright notice appear in all copies and that
                     10: both that copyright notice and this permission notice appear in 
                     11: supporting documentation, and that the names of Digital or MIT not be
                     12: used in advertising or publicity pertaining to distribution of the
                     13: software without specific, written prior permission.  
                     14: 
                     15: DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
                     16: ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
                     17: DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
                     18: ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
                     19: WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
                     20: ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
                     21: SOFTWARE.
                     22: 
                     23: ******************************************************************/
                     24: /* $Header: midash.c,v 1.7 87/09/10 09:48:55 rws Exp $ */
                     25: #include "miscstruct.h"
                     26: #include "mistruct.h"
                     27: 
                     28: miDashPtr CheckDashStorage();
                     29: 
                     30: /* return a list of DashRec.  there will be an extra
                     31: entry at the end holding the last point of the polyline.
                     32:    this means that the code that actually draws dashes can
                     33: get a pair of points for every dash.  only the point in the last
                     34: dash record is useful; the other fields are not used.
                     35:    nseg is the number of segments, not the number of points.
                     36: 
                     37: example:
                     38: 
                     39:    dash1.start
                     40:    dash2.start
                     41:    dash3.start
                     42:    last-point
                     43: 
                     44: defines a list of segments
                     45:    (dash1.pt, dash2.pt)
                     46:    (dash2.pt, dash3.pt)
                     47:    (dash3.pt, last-point)
                     48: and nseg == 3.
                     49: 
                     50: NOTE:
                     51:     EVEN_DASH == ~ODD_DASH
                     52: */
                     53: 
                     54: miDashPtr
                     55: miDashLine(npt, ppt, nDash, pDash, offset, pnseg)
                     56: int npt;
                     57: DDXPointPtr ppt;
                     58: int nDash;
                     59: unsigned char *pDash;
                     60: int offset;
                     61: int *pnseg;
                     62: {
                     63:     DDXPointRec pt1, pt2;
                     64:     int lenCur;                /* npt used from this dash */
                     65:     int lenMax;                /* npt in this dash */
                     66:     int iDash = 0;     /* index of current dash */
                     67:     int which;         /* EVEN_DASH or ODD_DASH */
                     68:     miDashPtr pseg;    /* list of dash segments */
                     69:     miDashPtr psegBase;        /* start of list */
                     70:     int nseg = 0;      /* number of dashes so far */
                     71:     int nsegMax = 0;   /* num segs we can fit in this list */
                     72: 
                     73:     int x, y, len;
                     74:     int adx, ady, signdx, signdy;
                     75:     int du, dv, e1, e2, e;
                     76: 
                     77:     lenCur = offset;
                     78:     which = EVEN_DASH;
                     79:     while(lenCur > pDash[iDash])
                     80:     {
                     81:        lenCur -= pDash[iDash];
                     82:        iDash++;
                     83:        if (iDash >= nDash)
                     84:            iDash = 0;
                     85:        which = ~which;
                     86:     }
                     87:     lenMax = pDash[iDash];
                     88: 
                     89:     psegBase = (miDashPtr)NULL;
                     90: 
                     91:     while(--npt)
                     92:     {
                     93:        pt1 = *ppt++;
                     94:        pt2 = *ppt;
                     95: 
                     96:        adx = pt2.x - pt1.x;
                     97:        ady = pt2.y - pt1.y;
                     98:        signdx = sign(adx);
                     99:        signdy = sign(ady);
                    100:        adx = abs(adx);
                    101:        ady = abs(ady);
                    102: 
                    103:        if (adx > ady)
                    104:        {
                    105:            du = adx;
                    106:            dv = ady;
                    107:            len = adx;
                    108:        }
                    109:        else
                    110:        {
                    111:            du = ady;
                    112:            dv = adx;
                    113:            len = ady;
                    114:        }
                    115: 
                    116:        e1 = dv * 2;
                    117:        e2 = e1 - 2*du;
                    118:        e = e1 - du;
                    119:        x = pt1.x;
                    120:        y = pt1.y;
                    121: 
                    122:        nseg++;
                    123:        pseg = CheckDashStorage(&psegBase, nseg, &nsegMax);
                    124:        pseg->pt = pt1;
                    125:        pseg->e1 = e1;
                    126:        pseg->e2 = e2;
                    127:        pseg->e = e;
                    128:        pseg->which = which;
                    129:        pseg->newLine = 1;
                    130: 
                    131:        while (len--)
                    132:        {
                    133:            if (adx > ady)
                    134:            {
                    135:                /* X_AXIS */
                    136:                if (((signdx > 0) && (e < 0)) ||
                    137:                    ((signdx <=0) && (e <=0))
                    138:                   )
                    139:                {
                    140:                    e += e1;
                    141:                }
                    142:                else
                    143:                {
                    144:                    y += signdy;
                    145:                    e += e2;
                    146:                }
                    147:                x += signdx;
                    148:            }
                    149:            else
                    150:            {
                    151:                /* Y_AXIS */
                    152:                if (((signdx > 0) && (e < 0)) ||
                    153:                    ((signdx <=0) && (e <=0))
                    154:                   )
                    155:                {
                    156:                    e +=e1;
                    157:                }
                    158:                else
                    159:                {
                    160:                    x += signdx;
                    161:                    e += e2;
                    162:                }
                    163:                y += signdy;
                    164:            }
                    165: 
                    166:            lenCur++;
                    167:            if (lenCur >= lenMax)
                    168:            {
                    169:                nseg++;
                    170:                pseg = CheckDashStorage(&psegBase, nseg, &nsegMax);
                    171:                pseg->pt.x = x;
                    172:                pseg->pt.y = y;
                    173:                pseg->e1 = e1;
                    174:                pseg->e2 = e2;
                    175:                pseg->e = e;
                    176:                which = ~which;
                    177:                pseg->which = which;
                    178:                pseg->newLine = 0;
                    179: 
                    180:                /* move on to next dash */
                    181:                iDash++;
                    182:                if (iDash >= nDash)
                    183:                    iDash = 0;
                    184:                lenMax = pDash[iDash];
                    185:                lenCur = 0;
                    186:            }
                    187:        } /* while len-- */
                    188:     } /* while --npt */
                    189: 
                    190:     *pnseg = nseg;
                    191:     pseg = CheckDashStorage(&psegBase, nseg+1, &nsegMax);
                    192:     pseg->pt = pt2;
                    193:     return psegBase;
                    194: } 
                    195: 
                    196: 
                    197: #define NSEGDELTA 16
                    198: 
                    199: /* returns a pointer to the pseg[nseg-1], growing the storage as
                    200: necessary.  this interface seems unnecessarily cumbersome.
                    201: 
                    202: */
                    203: 
                    204: static
                    205: miDashPtr
                    206: CheckDashStorage(ppseg, nseg, pnsegMax)
                    207: miDashPtr *ppseg;              /* base pointer */
                    208: int nseg;                      /* number of segment we want to write to */
                    209: int *pnsegMax;                 /* size (in segments) of list so far */
                    210: {
                    211:     if (nseg > *pnsegMax)
                    212:     {
                    213:        *pnsegMax += NSEGDELTA;
                    214:        *ppseg = (miDashPtr)Xrealloc(*ppseg, 
                    215:                                     (*pnsegMax)*sizeof(miDashRec));
                    216:     }
                    217:     return(*ppseg+(nseg-1));
                    218: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.