18 typedef struct wl_Line
29 typedef struct wl_Rectangle
33 int x, y, width, height;
44 int x, y, width, height, startangle, arcangle;
51 typedef struct wl_String
63 typedef struct wl_GraphicClosure
70 typedef struct wl_PostScriptClosure
78 typedef struct wl_Polygon
89 typedef union wl_DisplayElt
99 typedef DisplayElt *RefDisplayElt;
110 static ListLinks *x_get_links_of_display_list (DisplayElt *elt)
112 return &((Line *) elt)->links;
142 void x_set_gc (Display *display, GC gc,
long function,
unsigned long color,
long linewidth, Font font)
145 unsigned long valuemask;
148 gcvalues.function =
function;
149 gcvalues.foreground = color;
150 valuemask = GCFunction | GCForeground;
154 gcvalues.line_width = linewidth;
155 valuemask |= GCLineWidth;
160 gcvalues.font = font;
164 XChangeGC (display, gc, valuemask, &gcvalues);
169 #define AllocDisplayElt() malloc (sizeof (DisplayElt))
170 #define FreeDisplayElt(E) free (E)
186 void x_record_line (
ListHeader *displaylist, Action action,
long x0,
long y0,
long x1,
long y1,
unsigned long function,
unsigned long color,
unsigned long linewidth)
190 elt = (Line *) AllocDisplayElt ();
191 elt->action = action;
196 elt->function =
function;
198 elt->linewidth = linewidth;
221 void x_record_arc (
ListHeader *displaylist, Action action,
long x,
long y,
long width,
long height,
long startangle,
long arcangle,
unsigned long function,
unsigned long color,
unsigned long linewidth)
225 elt = (Arc *) AllocDisplayElt ();
226 elt->action = action;
230 elt->height = height;
231 elt->startangle = startangle;
232 elt->arcangle = arcangle;
233 elt->function =
function;
235 elt->linewidth = linewidth;
255 void x_record_rectangle (
ListHeader *displaylist, Action action,
long x,
long y,
long width,
long height,
unsigned long function,
unsigned long color,
unsigned long linewidth)
259 elt = (Rectangle *) AllocDisplayElt ();
260 elt->action = action;
264 elt->height = height;
265 elt->function =
function;
267 elt->linewidth = linewidth;
285 void x_record_polygon (
ListHeader *displaylist, Action action, XPoint *points,
long npoints,
unsigned long function,
unsigned long color,
unsigned long linewidth)
291 elt = (Polygon *) AllocDisplayElt ();
292 elt->action = action;
293 elt->npoints = npoints;
294 elt->points = p = (XPoint *) malloc (npoints*2*
sizeof(
short));
295 for (; npoints > 0; npoints--, p++, points++)
297 elt->function =
function;
299 elt->linewidth = linewidth;
318 void x_record_string (
ListHeader *displaylist, Action action,
long x,
long y,
char *str, Font font,
unsigned long function,
unsigned long color)
322 elt = (String *) AllocDisplayElt ();
323 elt->action = action;
326 elt->str = (
char *) malloc (strlen (str)+1);
327 strcpy (elt->str, str);
328 *(elt->str+strlen(str)) =
'\0';
329 elt->function =
function;
344 static long x_draw_elt (DisplayElt *elt, GraphicClosure *g)
348 Rectangle *rectangle;
357 x_set_gc (g->display, g->gc, line->function,
359 XDrawLine (g->display, g->drawable, g->gc,
360 line->x0, line->y0, line->x1, line->y1);
366 x_set_gc (g->display, g->gc, arc->function,
368 if (arc->action == DRAW_ARC)
369 XDrawArc (g->display, g->drawable, g->gc,
371 arc->width, arc->height,
372 arc->startangle, arc->arcangle);
374 XFillArc (g->display, g->drawable, g->gc,
376 arc->width, arc->height,
377 arc->startangle, arc->arcangle);
382 rectangle = (Rectangle *) elt;
383 x_set_gc (g->display, g->gc, rectangle->function,
385 if (rectangle->action == DRAW_RECTANGLE)
386 XDrawRectangle (g->display, g->drawable, g->gc,
387 rectangle->x, rectangle->y,
388 rectangle->width, rectangle->height);
390 XFillRectangle (g->display, g->drawable, g->gc,
391 rectangle->x, rectangle->y,
392 rectangle->width, rectangle->height);
396 case DRAW_IMAGE_STRING:
398 x_set_gc (g->display, g->gc, s->function,
400 if (s->action == DRAW_STRING)
401 XDrawString (g->display, g->drawable, g->gc,
403 s->str, strlen (s->str));
405 XDrawImageString (g->display, g->drawable, g->gc,
407 s->str, strlen (s->str));
412 polygon = (Polygon *) elt;
413 x_set_gc (g->display, g->gc, polygon->function,
415 if (polygon->action == FILL_POLYGON)
416 XFillPolygon (g->display, g->drawable, g->gc,
417 polygon->points, polygon->npoints,
418 Complex, CoordModeOrigin);
420 XDrawLines (g->display, g->drawable, g->gc,
421 polygon->points, polygon->npoints,
447 void x_refresh_window (Display *display, Window window, Pixmap pixmap, GC pixmapgc,
ListHeader *displaylist)
449 XWindowAttributes attr;
454 XSetGraphicsExposures (display, pixmapgc, False);
457 XGetWindowAttributes (display, window, &attr);
461 XClearArea (display, pixmap, 0, 0,
462 attr.width, attr.height, False);
465 x_set_gc (display, pixmapgc, GXcopy, attr.backing_pixel,
468 XFillRectangle (display, pixmap, pixmapgc,
469 0, 0, attr.width, attr.height);
478 if (window != pixmap)
479 XCopyArea (display, pixmap, window, pixmapgc, 0, 0,
480 attr.width, attr.height, 0, 0);
494 static long x_free_elt (DisplayElt *elt,
long *closure)
498 Rectangle *rectangle;
521 case DRAW_IMAGE_STRING:
528 polygon = (Polygon *) elt;
529 free (polygon->points);
535 FreeDisplayElt (elt);
548 void x_free_display_list (
ListHeader *displaylist)
555 static char *prolog[] = {
557 "/mt {moveto} def /lt {lineto} def /slw {setlinewidth} def\n",
558 "/np {newpath} def /st {stroke} def /fi {fill} def /cp {closepath} def\n",
559 "1 setlinecap 1 setlinejoin\n",
560 "/line {/lw exch def /b exch def /g exch def /r exch def\n",
561 " /y1 exch def /x1 exch def \n",
562 " /y0 exch def /x0 exch def\n",
563 " r 65535 div g 65535 div b 65535 div setrgbcolor\n",
564 " np lw slw x0 y0 mt x1 y1 lt st} def\n",
565 "/rect {/sf exch def /lw exch def\n",
566 " /b exch def /g exch def /r exch def\n",
567 " /h exch def /w exch def \n",
568 " /y exch def /x exch def\n",
569 " r 65535 div g 65535 div b 65535 div setrgbcolor\n",
570 " np lw slw x y mt x w add y lt x w add y h sub lt\n",
571 " x y h sub lt cp sf {st} {fi} ifelse} def\n",
572 "/earcdict 100 dict def\n",
573 "earcdict /mtrx matrix put\n",
574 "/earc {earcdict begin\n",
575 " /sf exch def /lw exch def\n",
576 " /b exch def /g exch def /r exch def\n",
577 " r 65535 div g 65535 div b 65535 div setrgbcolor\n",
578 " /ea exch def /sa exch def\n",
579 " /yr exch def /xr exch def /y exch def /x exch def\n",
580 " /savematrix mtrx currentmatrix def\n",
581 " np x y translate xr yr scale 0 0 1 sa ea arc\n",
582 " savematrix setmatrix lw slw sf {st} {fi} ifelse\n",
584 "/Helvetica findfont 18 scalefont setfont\n",
585 "/dstr {/sf exch def\n",
586 " /b exch def /g exch def /r exch def\n",
587 " /str exch def /y exch def /x exch def\n",
588 " r 65535 div g 65535 div b 65535 div setrgbcolor\n",
589 " x y mt str show} def\n",
599 static void x_postscript_prolog (
long f)
604 for (i = 0; prolog[i] != 0; i++)
605 ret = write (f, prolog[i], strlen (prolog[i]));
612 static char nstr[BUF_SIZE];
621 static char *add_number (
char *buf,
long n)
626 for (m=n, i=1; m>=10; i++)
629 if (i < BUF_SIZE && strlen (buf) + i < BUF_SIZE)
631 sprintf (nstr,
"%ld ", n);
645 static char *add_string (
char *buf,
char * s)
647 if (strlen (buf) + strlen(s) < BUF_SIZE)
662 static void x_get_rgb_values (Display *display, Window window,
unsigned long color, XColor *rgb)
664 XWindowAttributes windowAttributes;
666 XGetWindowAttributes (display, window, &windowAttributes);
668 XQueryColor (display, windowAttributes.colormap, rgb);
678 static long x_postscript_elt (DisplayElt *elt, PostScriptClosure *psc)
682 Rectangle *rectangle;
701 pbuf = add_number (pbuf, line->x0);
702 pbuf = add_number (pbuf, psc->height - line->y0);
703 pbuf = add_number (pbuf, line->x1);
704 pbuf = add_number (pbuf, psc->height - line->y1);
705 x_get_rgb_values ((Display *)psc->display, psc->window, line->color, &color);
706 pbuf = add_number (pbuf, color.red);
707 pbuf = add_number (pbuf, color.green);
708 pbuf = add_number (pbuf, color.blue);
709 pbuf = add_number (pbuf, line->linewidth);
710 pbuf = add_string (pbuf,
"line\n");
711 ret = write (psc->f, pbuf, strlen (pbuf));
716 rectangle = (Rectangle *) elt;
718 pbuf = add_number (pbuf, rectangle->x);
719 pbuf = add_number (pbuf, psc->height - rectangle->y);
720 pbuf = add_number (pbuf, rectangle->width);
721 pbuf = add_number (pbuf, rectangle->height);
722 x_get_rgb_values ((Display *) psc->display, psc->window, rectangle->color, &color);
723 pbuf = add_number (pbuf, color.red);
724 pbuf = add_number (pbuf, color.green);
725 pbuf = add_number (pbuf, color.blue);
727 if (rectangle->action == DRAW_RECTANGLE)
729 pbuf = add_number (pbuf, rectangle->linewidth);
730 pbuf = add_string (pbuf,
"true ");
734 pbuf = add_number (pbuf, 1);
735 pbuf = add_string (pbuf,
"false ");
738 pbuf = add_string (pbuf,
"rect\n");
739 ret = write (psc->f, pbuf, strlen (pbuf));
745 pbuf = add_number (pbuf, arc->x+arc->width/2);
746 pbuf = add_number (pbuf, psc->height - (arc->y+arc->height/2));
747 pbuf = add_number (pbuf, arc->width/2);
748 pbuf = add_number (pbuf, arc->height/2);
749 pbuf = add_number (pbuf, arc->startangle);
750 pbuf = add_number (pbuf, (arc->startangle+arc->arcangle)/64);
751 x_get_rgb_values ((Display *)psc->display, psc->window, arc->color, &color);
752 pbuf = add_number (pbuf, color.red);
753 pbuf = add_number (pbuf, color.green);
754 pbuf = add_number (pbuf, color.blue);
756 if (arc->action == DRAW_ARC)
758 pbuf = add_number (pbuf, arc->linewidth);
759 pbuf = add_string (pbuf,
"true ");
763 pbuf = add_number (pbuf, 1);
764 pbuf = add_string (pbuf,
"false ");
767 pbuf = add_string (pbuf,
"earc\n");
768 ret = write (psc->f, pbuf, strlen (pbuf));
772 case DRAW_IMAGE_STRING:
774 pbuf = add_number (pbuf, s->x);
775 pbuf = add_number (pbuf, psc->height - s->y);
776 pbuf = add_string (pbuf,
"(");
777 pbuf = add_string (pbuf, s->str);
778 pbuf = add_string (pbuf,
") ");
779 x_get_rgb_values ((Display *)psc->display, psc->window, s->color, &color);
780 pbuf = add_number (pbuf, color.red);
781 pbuf = add_number (pbuf, color.green);
782 pbuf = add_number (pbuf, color.blue);
784 if (s->action == DRAW_STRING)
785 pbuf = add_string (pbuf,
"true ");
787 pbuf = add_string (pbuf,
"false ");
789 pbuf = add_string (pbuf,
"dstr\n");
790 ret = write (psc->f, pbuf, strlen (pbuf));
794 polygon = (Polygon *) elt;
796 x_get_rgb_values ((Display *)psc->display, psc->window, polygon->color, &color);
797 pbuf = add_number (pbuf, color.red);
798 pbuf = add_string (pbuf,
"65535 div ");
799 pbuf = add_number (pbuf, color.green);
800 pbuf = add_string (pbuf,
"65535 div ");
801 pbuf = add_number (pbuf, color.blue);
802 pbuf = add_string (pbuf,
"65535 div ");
803 pbuf = add_string (pbuf,
"setrgbcolor ");
806 pbuf = add_string (pbuf,
"np ");
807 pbuf = add_number (pbuf, p->x);
808 pbuf = add_number (pbuf, psc->height - p->y);
809 pbuf = add_string (pbuf,
"mt\n");
811 for (i=1; i<polygon->npoints; i++, p++)
813 pbuf = add_number (pbuf, p->x);
814 pbuf = add_number (pbuf, psc->height - p->y);
815 pbuf = add_string (pbuf,
"lt ");
817 pbuf = add_string (pbuf,
"\n");
820 pbuf = add_string (pbuf,
"cp fi\n");
821 ret = write (psc->f, pbuf, strlen (pbuf));
839 long x_postscript_window (Display *display, Window window,
ListHeader *displaylist,
char *filename)
841 XWindowAttributes windowAttributes;
842 PostScriptClosure psc;
847 psc.display = (
GENERIC)display;
849 if ((psc.f = open (filename, O_CREAT|O_WRONLY|O_TRUNC,
850 S_IRUSR|S_IWUSR|S_IRWXG)) == -1)
852 Errorline (
"\n*** Error: cannot open file %s.\n", filename);
856 XGetWindowAttributes (display, window, &windowAttributes);
857 psc.height = windowAttributes.height;
858 x_postscript_prolog (psc.f);
860 ret = write (psc.f,
"showpage\n", strlen (
"showpage\n"));
#define xDefaultLineWidth
void List_Append(RefListHeader header, Ref atom)
void List_Append
void Errorline(char *format,...)
Errorline.
unsigned long * GENERIC
unsigned long *GENERIC
#define TRUE
Standard boolean.
#define FALSE
Standard boolean.
void List_SetLinkProc(RefListHeader header, RefListGetLinksProc getLinks)
List_SetLinkProc.
long List_Enum(RefListHeader header, RefListEnumProc proc, Ref closure)
List_Enum.