(no message)
authorMark Opperman <opcode@ucbvax.Berkeley.EDU>
Fri, 4 Jan 1985 11:35:00 +0000 (03:35 -0800)
committerMark Opperman <opcode@ucbvax.Berkeley.EDU>
Fri, 4 Jan 1985 11:35:00 +0000 (03:35 -0800)
SCCS-vsn: local/ditroff/ditroff.old.okeeffe/sunsrc/gremlin/db.c 1.2
SCCS-vsn: local/ditroff/ditroff.old.okeeffe/sunsrc/gremlin/display.c 1.2
SCCS-vsn: local/ditroff/ditroff.old.okeeffe/sunsrc/gremlin/graphics.c 1.2
SCCS-vsn: local/ditroff/ditroff.old.okeeffe/sunsrc/gremlin/graphics2.c 1.2

usr/src/local/ditroff/ditroff.old.okeeffe/sunsrc/gremlin/db.c
usr/src/local/ditroff/ditroff.old.okeeffe/sunsrc/gremlin/display.c
usr/src/local/ditroff/ditroff.old.okeeffe/sunsrc/gremlin/graphics.c
usr/src/local/ditroff/ditroff.old.okeeffe/sunsrc/gremlin/graphics2.c

index 0925301..1ab7f87 100644 (file)
@@ -1,5 +1,5 @@
 /*
 /*
- * @(#)db.c    1.1     %G%
+ * @(#)db.c    1.2     %G%
  *
  * This file contains routines for database manipulation for the
  * SUN Gremlin picture editor.
  *
  * This file contains routines for database manipulation for the
  * SUN Gremlin picture editor.
@@ -40,19 +40,6 @@ extern TOOLINSTALLED;
 
 ELT *cset;
 
 
 ELT *cset;
 
-#ifdef oldway
-/*
- * This routine returns a pointer to an initialized database element
- * which would be the only element in an empty list.
- */
-ELT *
-DBInit()
-{
-    return((ELT *) NULL);
-}
-#endif
-
-
 /*
  * This routine creates a new element with the specified attributes and
  * links it into database db.
 /*
  * This routine creates a new element with the specified attributes and
  * links it into database db.
index 5332dd7..bcd92d6 100644 (file)
@@ -1,5 +1,5 @@
 /*
 /*
- * @(#)display.c       1.1     %G%
+ * @(#)display.c       1.2     %G%
  *
  * This file contains routines to implement the higher level display
  * driver routines for the SUN Gremlin picture editor.
  *
  * This file contains routines to implement the higher level display
  * driver routines for the SUN Gremlin picture editor.
@@ -53,7 +53,6 @@ int minsunx, maxsunx, minsuny, maxsuny;
  * This routine displays an arbitrary element type 
  * using the parameters stored with the element.  
  * Elements are drawn by Exclusive Oring the screen.
  * This routine displays an arbitrary element type 
  * using the parameters stored with the element.  
  * Elements are drawn by Exclusive Oring the screen.
- * mro 7/13/84
  */
 DISScreenAdd(element, mask)
 register ELT *element;
  */
 DISScreenAdd(element, mask)
 register ELT *element;
@@ -70,8 +69,9 @@ int mask;
     pr_rop(scratch_pr, 0, 0, pix_size.r_width, pix_size.r_height,
                                                PIX_SRC, NULL, 0, 0);
 
     pr_rop(scratch_pr, 0, 0, pix_size.r_width, pix_size.r_height,
                                                PIX_SRC, NULL, 0, 0);
 
-    minsunx = minsuny = dbx_to_win(element->ptlist->x);
-    maxsunx = maxsuny = dby_to_win(element->ptlist->y);
+    /* determine bounds for this element */
+    minsunx = maxsunx = dbx_to_win(element->ptlist->x);
+    minsuny = maxsuny = dby_to_win(element->ptlist->y);
 
     if (TEXT(element->type)) {
        GRSetTextPos(element->textpt, element->type, element->brushf,
 
     if (TEXT(element->type)) {
        GRSetTextPos(element->textpt, element->type, element->brushf,
@@ -138,18 +138,10 @@ int mask;
        }
     }
 
        }
     }
 
-/*
-printf("minsunx=%d maxsunx=%d minsuny=%d maxsuny=%d\n",
-minsunx, maxsunx, minsuny, maxsuny);
-*/
-
     x = minsunx - 8;
     x = minsunx - 8;
-    width = maxsunx + 8 - x;
     y = minsuny - 8;
     y = minsuny - 8;
+    width = maxsunx + 8 - x;
     height = maxsuny + 8 - y;
     height = maxsuny + 8 - y;
-/*
-printf("x=%d y=%d width=%d height=%d\n", x, y, width, height);
-*/
 
     if (mask & pixmask)
        pw_write(pix_pw, x, y, width, height, PIX_SRC ^ PIX_DST, 
 
     if (mask & pixmask)
        pw_write(pix_pw, x, y, width, height, PIX_SRC ^ PIX_DST, 
@@ -158,24 +150,12 @@ printf("x=%d y=%d width=%d height=%d\n", x, y, width, height);
     if (mask & csetmask)
        pr_rop(cset_pr, x, y, width, height, PIX_SRC ^ PIX_DST, 
                                                    scratch_pr, x, y);
     if (mask & csetmask)
        pr_rop(cset_pr, x, y, width, height, PIX_SRC ^ PIX_DST, 
                                                    scratch_pr, x, y);
-
-#ifdef oldway
-    if (mask & pixmask)
-       pw_write(pix_pw, 0, 0, pix_size.r_width, pix_size.r_height,
-           PIX_SRC ^ PIX_DST, scratch_pr, 0, 0);
-    if (mask & csetmask)
-       pr_rop(cset_pr, 0, 0, pix_size.r_width, pix_size.r_height,
-           PIX_SRC ^ PIX_DST, scratch_pr, 0, 0);
-#endif
-for (x=0;x<10000;x++);
 }  /* end DISScreenAdd */
 
 
 /*
  * This routine erases an arbitrary element type by redrawing the 
  * element with XOR.  This is the same as drawing the element.
 }  /* end DISScreenAdd */
 
 
 /*
  * This routine erases an arbitrary element type by redrawing the 
  * element with XOR.  This is the same as drawing the element.
- * mro 7/13/84
  */
 DISScreenErase(element, mask)
 register ELT *element;
  */
 DISScreenErase(element, mask)
 register ELT *element;
@@ -187,7 +167,6 @@ register mask;
 
 /*
  * This routine clears the current set pixrect.
 
 /*
  * This routine clears the current set pixrect.
- * mro 7/31/84
  */
 DISClearSetDisplay()
 {
  */
 DISClearSetDisplay()
 {
@@ -207,4 +186,3 @@ DISClearSetDisplay()
 
     GRClear(csetmask);
 }  /* end DISClearSetDisplay */
 
     GRClear(csetmask);
 }  /* end DISClearSetDisplay */
-
index a8dcb39..9d2b2e2 100644 (file)
@@ -1,5 +1,5 @@
 /*
 /*
- * @(#)graphics.c      1.1     %G%
+ * @(#)graphics.c      1.2     %G%
  *
  * Graphics routines for the SUN Gremlin picture editor.
  *
  *
  * Graphics routines for the SUN Gremlin picture editor.
  *
@@ -71,6 +71,12 @@ struct pixrect *stipple_prs[NSTIPPLES] = {
 /* ... and the corresponding images (32 x 32 bits) from the vfont file */
 char stipple_patterns[NSTIPPLES][128];
 
 /* ... and the corresponding images (32 x 32 bits) from the vfont file */
 char stipple_patterns[NSTIPPLES][128];
 
+/* data used in graphics2.c for drawing polygons */
+int rasterlength;              /* real # horizontal bits in scratch_pr */
+int bytesperline;              /* rasterlength / 8 */
+int nlines;                    /* # horizontal bits defined by scratch_pr */
+char *fill;                    /* pointer to scratch_pr image */
+
 /* 
  *  This matrix points to the DISPATCH data for each font/size pair
  *  if an unsuccesful attempt is made to open a particular font/size pair,
 /* 
  *  This matrix points to the DISPATCH data for each font/size pair
  *  if an unsuccesful attempt is made to open a particular font/size pair,
@@ -758,6 +764,13 @@ GRStippleInit()
 
     /* bit maps are all in core now */
     free(stipple_info);
 
     /* bit maps are all in core now */
     free(stipple_info);
+
+    /* set up parameters for drawing polygons */
+    mpr_data = (struct mpr_data *) scratch_pr->pr_data;
+    bytesperline = mpr_data->md_linebytes;
+    fill = (char *) mpr_data->md_image;
+    rasterlength = bytesperline << 3;
+    nlines = scratch_pr->pr_size.x;
 } /* end GRStippleInit */;
 
 
 } /* end GRStippleInit */;
 
 
index a2b531c..0124f2d 100644 (file)
@@ -1,5 +1,5 @@
 /*
 /*
- * @(#)graphics2.c     1.1     %G%
+ * @(#)graphics2.c     1.2     %G%
  *
  * Line drawing and polygon fill routines for the SUN Gremlin
  * picture editor.  Line drawing courtesy of dsun.c and polygon
  *
  * Line drawing and polygon fill routines for the SUN Gremlin
  * picture editor.  Line drawing courtesy of dsun.c and polygon
 #include <suntool/tool_hs.h>
 #include "gremlin.h"
 
 #include <suntool/tool_hs.h>
 #include "gremlin.h"
 
-#ifdef maybefaster
-extern char *_image;
-extern int _bytesperline, _maxx, _maxy;
-#else
 #define point(sun_x, sun_y)  pr_put(scratch_pr, (sun_x), (sun_y), 1)
 #define point(sun_x, sun_y)  pr_put(scratch_pr, (sun_x), (sun_y), 1)
-#endif
 
 /* imports from main.c */
 
 
 /* imports from main.c */
 
@@ -41,6 +36,10 @@ extern int HiStipple[];
 /* imports from graphics.c */
 
 extern char stipple_patterns[NSTIPPLES][128];
 /* imports from graphics.c */
 
 extern char stipple_patterns[NSTIPPLES][128];
+extern rasterlength;
+extern bytesperline;
+extern nlines;                 /* scratch_pr->pr_size.x */
+extern char *fill;             /* zero origin in filling buffer */
 
 /* imports from C */
 
 
 /* imports from C */
 
@@ -48,14 +47,8 @@ extern char *calloc();
 
 /* locals */
 
 
 /* locals */
 
-static RASTER_LENGTH;
-static BYTES_PER_LINE;
-static NLINES;
-static char *fill;             /* Zero origin in filling buffer */
 static char *stipplebits;
 
 static char *stipplebits;
 
-#define pv(x)  ((polyvector *)x)
-
 typedef struct poly {
     struct poly *next;         /* doubly-linked lists of vectors */
     struct poly *prev;
 typedef struct poly {
     struct poly *next;         /* doubly-linked lists of vectors */
     struct poly *prev;
@@ -66,25 +59,12 @@ typedef struct poly {
     short endx;                        /* where vector ends */
 } polyvector;
 
     short endx;                        /* where vector ends */
 } polyvector;
 
-#ifdef maybefaster
-static char bm[] = { 128, 64, 32, 16, 8, 4, 2, 1};
-point(x, y)
-register x, y;
-{
-    if (x<0 || x>=_maxx || y<0 || y>= _maxy)
-       return;
-    
-    *(_image + (y * _bytesperline) + (x >> 3)) |= bm[x&7];
-}
-#endif
-    
 
 /*
  * Vector from (x1, y1) to (x2, y2) using global linemod and linethickness.
  * Parameters in database coordinates system.
  * Always write to scratch_pr.
 
 /*
  * Vector from (x1, y1) to (x2, y2) using global linemod and linethickness.
  * Parameters in database coordinates system.
  * Always write to scratch_pr.
- * Stolen from dsun.
- * mro 7/21/84
+ * Borrowed from dsun.
  */
 GRVector(dbx1, dby1, dbx2, dby2)
 float dbx1, dby1, dbx2, dby2;
  */
 GRVector(dbx1, dby1, dbx2, dby2)
 float dbx1, dby1, dbx2, dby2;
@@ -278,7 +258,7 @@ float dbx1, dby1, dbx2, dby2;
  * Plots a filled (if requested) circle of the specified radius
  * centered about (x, y).
  * Coordinates are window relative.
  * Plots a filled (if requested) circle of the specified radius
  * centered about (x, y).
  * Coordinates are window relative.
- * Stolen from dsun.
+ * Modified from dsun source.
  */
 RoundEnd(x, y, radius, filled)
 register x;
  */
 RoundEnd(x, y, radius, filled)
 register x;
@@ -334,21 +314,12 @@ int radius, filled;
 GRSetStippleStyle(style)
 int style;
 {
 GRSetStippleStyle(style)
 int style;
 {
-    struct mpr_data *md;
-    struct pixrect *pr;
-
     if ((style <= 0) || (style > NSTIPPLES)) {
        fprintf(stderr, "GRSetStippleStyle: bad stipple #%d\n", style);
        return;
     }
 
     stipplebits = stipple_patterns[style-1];
     if ((style <= 0) || (style > NSTIPPLES)) {
        fprintf(stderr, "GRSetStippleStyle: bad stipple #%d\n", style);
        return;
     }
 
     stipplebits = stipple_patterns[style-1];
-
-    md = (struct mpr_data *) scratch_pr->pr_data;
-    BYTES_PER_LINE = md->md_linebytes;
-    fill = (char *) md->md_image;
-    RASTER_LENGTH = BYTES_PER_LINE << 3;
-    NLINES = scratch_pr->pr_size.x;
 }
 
 /* >>> stipple fonts must be 32 x 32 bits <<< */
 }
 
 /* >>> stipple fonts must be 32 x 32 bits <<< */
@@ -358,13 +329,20 @@ int style;
 
 
 /*
 
 
 /*
- *  Fill polygon defined by points in plist using parameters set by
- *  previous call to GRSetStippleStyle().
+ * Fill polygon defined by points in plist using parameters set by
+ * previous call to GRSetStippleStyle().
+ *
+ * This routine was modified from source for the varian driver.
+ * Because the varian rotates everything 90 degrees before printing,
+ * the x and y coordinates from the window are reversed before
+ * computing the region.  This is just a kludge to get the code
+ * to work as soon as possible.  Better to change this at some point,
+ * but I don't have time now.
  *
  *
- *  The scan-line algorithm implemented scans from left to right 
- *  (low x to high x).  It also scans, within a line, from bottom to top 
- *  (high y to low y).  Stipple patterns MUST be a power of two bytes wide
- *  and square (in fact, they must be 32 x 32 bits).
+ * The scan-line algorithm implemented scans from left to right 
+ * (low x to high x).  It also scans, within a line, from bottom to top 
+ * (high y to low y).  Stipple patterns MUST be a power of two bytes wide
+ * and square (in fact, they must be 32 x 32 bits).
  */
 GRStippleFill(plist)
 POINT *plist;
  */
 GRStippleFill(plist)
 POINT *plist;
@@ -388,18 +366,22 @@ POINT *plist;
     p1 = plist;
     npts = 0;
 
     p1 = plist;
     npts = 0;
 
-    /* convert coordinates to arrays of integers */
+    /*
+     * convert coordinates to arrays of integers exchanging x and y,
+     * and making origin upper right.
+     */
     while (!Nullpoint(p1)) {
        npts++;
        x[npts] = dby_to_win(p1->y) - 1;
     while (!Nullpoint(p1)) {
        npts++;
        x[npts] = dby_to_win(p1->y) - 1;
-       y[npts] = RASTER_LENGTH - 1 - dbx_to_win(p1->x);
+       y[npts] = rasterlength - 1 - dbx_to_win(p1->x);
        p1 = PTNextPoint(p1);
     }
 
     topstipple = stipplebits;          /* start of stipple pattern */
 
     /* allocate space for raster-fill algorithm */
        p1 = PTNextPoint(p1);
     }
 
     topstipple = stipplebits;          /* start of stipple pattern */
 
     /* allocate space for raster-fill algorithm */
-    if ((vectptr = pv(calloc(sizeof(polyvector), npts + 6))) == NULL) {
+    if ((vectptr = (polyvector *) calloc(sizeof(polyvector), npts + 6)) == 
+                                                       (polyvector *) NULL) {
        fprintf(stderr, "unable to allocate space for polygon");
        return;
     }
        fprintf(stderr, "unable to allocate space for polygon");
        return;
     }
@@ -407,7 +389,7 @@ POINT *plist;
     waitinghead = vectptr;
     minx = maxx = x[1];
     miny = maxy = y[1];
     waitinghead = vectptr;
     minx = maxx = x[1];
     miny = maxy = y[1];
-    (vectptr++)->prev = pv(NULL);      /* put dummy entry at start */
+    (vectptr++)->prev = (polyvector *) NULL;   /* put dummy entry at start */
     waitinghead->next = vectptr;
     vectptr->prev = waitinghead;
 
     waitinghead->next = vectptr;
     vectptr->prev = waitinghead;
 
@@ -422,14 +404,9 @@ POINT *plist;
        register int j;                         /* indexes to work off of */
        register int k;
 
        register int j;                         /* indexes to work off of */
        register int k;
 
-       if (miny > y[i])                        /* remember limits */
-           miny = y[i];
-       else if (maxy < y[i]) 
-           maxy = y[i];
-       if (maxx < x[i]) 
-           maxx = x[i];
-       else if (minx > x[i]) 
-           minx = x[i];
+       /* remember limits */
+       MINMAX(miny, maxy, y[i]);
+       MINMAX(minx, maxx, x[i]);
 
        j = i;                  /* j points to the higher (lesser) point */
        k = ++i;
 
        j = i;                  /* j points to the higher (lesser) point */
        k = ++i;
@@ -449,9 +426,16 @@ POINT *plist;
        vectptr->prev = vectptr - 1;
     }
 
        vectptr->prev = vectptr - 1;
     }
 
+    /*
+     * keep polygon within bounds of scratch pixrect 
+     * width is checked when actual drawing is done
+     */
+    if (maxx >= scratch_pr->pr_size.y)
+       maxx = scratch_pr->pr_size.y - 1;
+
     /* set now because we didn't know minx before */
     leftstipple = topstipple + (minx & MASK) * BYTEWIDTH;
     /* set now because we didn't know minx before */
     leftstipple = topstipple + (minx & MASK) * BYTEWIDTH;
-    bottompage = fill + minx * BYTES_PER_LINE;
+    bottompage = fill + minx * bytesperline;
     waitinghead->param = minx - 1;
 
     /* if no useable vectors, quit */
     waitinghead->param = minx - 1;
 
     /* if no useable vectors, quit */
@@ -461,7 +445,7 @@ POINT *plist;
     }
 
     vectptr->param = maxx + 1;         /* dummy entry at end, too */
     }
 
     vectptr->param = maxx + 1;         /* dummy entry at end, too */
-    vectptr->next = pv(NULL);
+    vectptr->next = (polyvector *) NULL;
 
     activehead = ++vectptr;            /* two dummy entries for active list */
     vectptr->curry = maxy + 1;         /* head */
 
     activehead = ++vectptr;            /* two dummy entries for active list */
     vectptr->curry = maxy + 1;         /* head */
@@ -483,7 +467,7 @@ POINT *plist;
      */
     while (minx <= maxx) {
        i = maxx + 1;           /* this is the NEXT time to get a new vector */
      */
     while (minx <= maxx) {
        i = maxx + 1;           /* this is the NEXT time to get a new vector */
-       for (vectptr=waitinghead->next; vectptr!=pv(NULL); ) {
+       for (vectptr=waitinghead->next; vectptr!=(polyvector *) NULL; ) {
            if (minx == vectptr->param) {
                /* 
                 * The entry in waiting list (vectptr) is ready to go into 
            if (minx == vectptr->param) {
                /* 
                 * The entry in waiting list (vectptr) is ready to go into 
@@ -535,7 +519,7 @@ POINT *plist;
            } while ((vectptr = vectptr->next) != activehead);
 
            /* draw the span */
            } while ((vectptr = vectptr->next) != activehead);
 
            /* draw the span */
-           if (((unsigned) minx) < NLINES) {
+           if (((unsigned) minx) < nlines) {
              vectptr = activehead->next;
              while (vectptr->next != activehead) {
                register int start;             /* get the beginning */
              vectptr = activehead->next;
              while (vectptr->next != activehead) {
                register int start;             /* get the beginning */
@@ -543,18 +527,18 @@ POINT *plist;
                register char *glyph;
                register char *raster;
 
                register char *glyph;
                register char *raster;
 
-               start = (RASTER_LENGTH - 1) - vectptr->curry;
+               start = (rasterlength - 1) - vectptr->curry;
                vectptr = vectptr->next;
                vectptr = vectptr->next;
-               length = RASTER_LENGTH - vectptr->curry;
+               length = rasterlength - vectptr->curry;
                vectptr = vectptr->next;
 
                /* bound the polygon to the page */
                vectptr = vectptr->next;
 
                /* bound the polygon to the page */
-               if (start >= RASTER_LENGTH)
+               if (start >= rasterlength)
                    break;
                if (start < 0) 
                    start = 0;
                    break;
                if (start < 0) 
                    start = 0;
-               if (length > RASTER_LENGTH
-                   length = RASTER_LENGTH;
+               if (length > rasterlength
+                   length = rasterlength;
                length -= start;                /* length is in pixels */
 
                i = start & 7;
                length -= start;                /* length is in pixels */
 
                i = start & 7;
@@ -640,7 +624,7 @@ POINT *plist;
            } else {
                leftstipple = topstipple;
            }
            } else {
                leftstipple = topstipple;
            }
-           bottompage += BYTES_PER_LINE;
+           bottompage += bytesperline;
        } /* while (minx < nextx) */
     } /* while (minx <= maxx) */
 
        } /* while (minx < nextx) */
     } /* while (minx <= maxx) */