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
*
* 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.
-#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.
- * @(#)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.
* 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.
*/
DISScreenAdd(element, mask)
register ELT *element;
*/
DISScreenAdd(element, mask)
register ELT *element;
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,
-/*
-printf("minsunx=%d maxsunx=%d minsuny=%d maxsuny=%d\n",
-minsunx, maxsunx, minsuny, maxsuny);
-*/
-
- width = maxsunx + 8 - x;
+ 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,
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.
*/
DISScreenErase(element, mask)
register ELT *element;
*/
DISScreenErase(element, mask)
register ELT *element;
/*
* This routine clears the current set pixrect.
/*
* This routine clears the current set pixrect.
*/
DISClearSetDisplay()
{
*/
DISClearSetDisplay()
{
GRClear(csetmask);
} /* end DISClearSetDisplay */
GRClear(csetmask);
} /* end DISClearSetDisplay */
- * @(#)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.
*
/* ... 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,
/* 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 */;
- * @(#)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)
/* imports from main.c */
/* imports from main.c */
/* 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 */
-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;
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
*/
GRVector(dbx1, dby1, dbx2, dby2)
float dbx1, dby1, dbx2, dby2;
*/
GRVector(dbx1, dby1, dbx2, dby2)
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.
+ * Modified from dsun source.
*/
RoundEnd(x, y, radius, filled)
register x;
*/
RoundEnd(x, y, radius, filled)
register x;
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 <<< */
- * 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;
- /* 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;
}
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;
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;
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 */
}
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 */
*/
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
} 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 */
register char *glyph;
register char *raster;
register char *glyph;
register char *raster;
- start = (RASTER_LENGTH - 1) - vectptr->curry;
+ start = (rasterlength - 1) - vectptr->curry;
- 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;
} else {
leftstipple = topstipple;
}
} else {
leftstipple = topstipple;
}
- bottompage += BYTES_PER_LINE;
+ bottompage += bytesperline;
} /* while (minx < nextx) */
} /* while (minx <= maxx) */
} /* while (minx < nextx) */
} /* while (minx <= maxx) */