14 typedef struct wl_Line
25 typedef struct wl_Rectangle
29 int x, y, width, height;
40 int x, y, width, height, startangle, arcangle;
47 typedef struct wl_String
59 typedef struct wl_GraphicClosure
66 typedef struct wl_PostScriptClosure
74 typedef struct wl_Polygon
85 typedef union wl_DisplayElt
95 typedef DisplayElt *RefDisplayElt;
101 static ListLinks *x_get_links_of_display_list (elt)
106 return &((Line *) elt)->links;
122 void x_set_gc (display, gc,
function, color, linewidth, font)
133 unsigned long valuemask;
136 gcvalues.function =
function;
137 gcvalues.foreground = color;
138 valuemask = GCFunction | GCForeground;
142 gcvalues.line_width = linewidth;
143 valuemask |= GCLineWidth;
148 gcvalues.font = font;
152 XChangeGC (display, gc, valuemask, &gcvalues);
158 #define AllocDisplayElt() malloc (sizeof (DisplayElt))
159 #define FreeDisplayElt(E) free (E)
162 void x_record_line (displaylist, action, x0, y0, x1, y1,
163 function, color, linewidth)
168 unsigned long function, color, linewidth;
173 elt = (Line *) AllocDisplayElt ();
174 elt->action = action;
179 elt->function =
function;
181 elt->linewidth = linewidth;
189 void x_record_arc (displaylist, action, x, y, width, height,
190 startangle, arcangle,
191 function, color, linewidth)
195 long x, y, width, height, startangle, arcangle;
196 unsigned long function, color, linewidth;
201 elt = (Arc *) AllocDisplayElt ();
202 elt->action = action;
206 elt->height = height;
207 elt->startangle = startangle;
208 elt->arcangle = arcangle;
209 elt->function =
function;
211 elt->linewidth = linewidth;
218 void x_record_rectangle (displaylist, action, x, y, width, height,
219 function, color, linewidth)
223 long x, y, width, height;
224 unsigned long function, color, linewidth;
229 elt = (Rectangle *) AllocDisplayElt ();
230 elt->action = action;
234 elt->height = height;
235 elt->function =
function;
237 elt->linewidth = linewidth;
244 void x_record_polygon (displaylist, action, points, npoints,
245 function, color, linewidth)
251 unsigned long function, color, linewidth;
258 elt = (Polygon *) AllocDisplayElt ();
259 elt->action = action;
260 elt->npoints = npoints;
261 elt->points = p = (XPoint *) malloc (npoints*2*
sizeof(
short));
262 for (; npoints > 0; npoints--, p++, points++)
264 elt->function =
function;
266 elt->linewidth = linewidth;
273 void x_record_string (displaylist, action, x, y, str, font,
281 unsigned long function, color;
286 elt = (String *) AllocDisplayElt ();
287 elt->action = action;
290 elt->str = (
char *) malloc (strlen (str)+1);
291 strcpy (elt->str, str);
292 *(elt->str+strlen(str)) =
'\0';
293 elt->function =
function;
302 static long x_draw_elt (elt, g)
310 Rectangle *rectangle;
319 x_set_gc (g->display, g->gc, line->function,
321 XDrawLine (g->display, g->drawable, g->gc,
322 line->x0, line->y0, line->x1, line->y1);
328 x_set_gc (g->display, g->gc, arc->function,
330 if (arc->action == DRAW_ARC)
331 XDrawArc (g->display, g->drawable, g->gc,
333 arc->width, arc->height,
334 arc->startangle, arc->arcangle);
336 XFillArc (g->display, g->drawable, g->gc,
338 arc->width, arc->height,
339 arc->startangle, arc->arcangle);
344 rectangle = (Rectangle *) elt;
345 x_set_gc (g->display, g->gc, rectangle->function,
347 if (rectangle->action == DRAW_RECTANGLE)
348 XDrawRectangle (g->display, g->drawable, g->gc,
349 rectangle->x, rectangle->y,
350 rectangle->width, rectangle->height);
352 XFillRectangle (g->display, g->drawable, g->gc,
353 rectangle->x, rectangle->y,
354 rectangle->width, rectangle->height);
358 case DRAW_IMAGE_STRING:
360 x_set_gc (g->display, g->gc, s->function,
362 if (s->action == DRAW_STRING)
363 XDrawString (g->display, g->drawable, g->gc,
365 s->str, strlen (s->str));
367 XDrawImageString (g->display, g->drawable, g->gc,
369 s->str, strlen (s->str));
374 polygon = (Polygon *) elt;
375 x_set_gc (g->display, g->gc, polygon->function,
377 if (polygon->action == FILL_POLYGON)
378 XFillPolygon (g->display, g->drawable, g->gc,
379 polygon->points, polygon->npoints,
380 Complex, CoordModeOrigin);
382 XDrawLines (g->display, g->drawable, g->gc,
383 polygon->points, polygon->npoints,
399 void x_refresh_window (display, window, pixmap, pixmapgc, displaylist)
408 XWindowAttributes attr;
413 XSetGraphicsExposures (display, pixmapgc, False);
416 XGetWindowAttributes (display, window, &attr);
420 XClearArea (display, pixmap, 0, 0,
421 attr.width, attr.height, False);
424 x_set_gc (display, pixmapgc, GXcopy, attr.backing_pixel,
427 XFillRectangle (display, pixmap, pixmapgc,
428 0, 0, attr.width, attr.height);
437 if (window != pixmap)
438 XCopyArea (display, pixmap, window, pixmapgc, 0, 0,
439 attr.width, attr.height, 0, 0);
446 static long x_free_elt (elt, closure)
454 Rectangle *rectangle;
477 case DRAW_IMAGE_STRING:
484 polygon = (Polygon *) elt;
485 free (polygon->points);
491 FreeDisplayElt (elt);
498 void x_free_display_list (displaylist)
508 static char *prolog[] = {
510 "/mt {moveto} def /lt {lineto} def /slw {setlinewidth} def\n",
511 "/np {newpath} def /st {stroke} def /fi {fill} def /cp {closepath} def\n",
512 "1 setlinecap 1 setlinejoin\n",
513 "/line {/lw exch def /b exch def /g exch def /r exch def\n",
514 " /y1 exch def /x1 exch def \n",
515 " /y0 exch def /x0 exch def\n",
516 " r 65535 div g 65535 div b 65535 div setrgbcolor\n",
517 " np lw slw x0 y0 mt x1 y1 lt st} def\n",
518 "/rect {/sf exch def /lw exch def\n",
519 " /b exch def /g exch def /r exch def\n",
520 " /h exch def /w exch def \n",
521 " /y exch def /x exch def\n",
522 " r 65535 div g 65535 div b 65535 div setrgbcolor\n",
523 " np lw slw x y mt x w add y lt x w add y h sub lt\n",
524 " x y h sub lt cp sf {st} {fi} ifelse} def\n",
525 "/earcdict 100 dict def\n",
526 "earcdict /mtrx matrix put\n",
527 "/earc {earcdict begin\n",
528 " /sf exch def /lw exch def\n",
529 " /b exch def /g exch def /r exch def\n",
530 " r 65535 div g 65535 div b 65535 div setrgbcolor\n",
531 " /ea exch def /sa exch def\n",
532 " /yr exch def /xr exch def /y exch def /x exch def\n",
533 " /savematrix mtrx currentmatrix def\n",
534 " np x y translate xr yr scale 0 0 1 sa ea arc\n",
535 " savematrix setmatrix lw slw sf {st} {fi} ifelse\n",
537 "/Helvetica findfont 18 scalefont setfont\n",
538 "/dstr {/sf exch def\n",
539 " /b exch def /g exch def /r exch def\n",
540 " /str exch def /y exch def /x exch def\n",
541 " r 65535 div g 65535 div b 65535 div setrgbcolor\n",
542 " x y mt str show} def\n",
547 static void x_postscript_prolog (f)
555 for (i = 0; prolog[i] != 0; i++)
556 ret = write (f, prolog[i], strlen (prolog[i]));
563 static char nstr[BUF_SIZE];
565 static char *add_number (buf, n)
574 for (m=n, i=1; m>=10; i++)
577 if (i < BUF_SIZE && strlen (buf) + i < BUF_SIZE)
579 sprintf (nstr,
"%ld ", n);
587 static char *add_string (buf, s)
592 if (strlen (buf) + strlen(s) < BUF_SIZE)
599 static void x_get_rgb_values (display, window, color, rgb)
607 XWindowAttributes windowAttributes;
609 XGetWindowAttributes (display, window, &windowAttributes);
611 XQueryColor (display, windowAttributes.colormap, rgb);
615 static long x_postscript_elt (elt, psc)
618 PostScriptClosure *psc;
623 Rectangle *rectangle;
642 pbuf = add_number (pbuf, line->x0);
643 pbuf = add_number (pbuf, psc->height - line->y0);
644 pbuf = add_number (pbuf, line->x1);
645 pbuf = add_number (pbuf, psc->height - line->y1);
646 x_get_rgb_values (psc->display, psc->window, line->color, &color);
647 pbuf = add_number (pbuf, color.red);
648 pbuf = add_number (pbuf, color.green);
649 pbuf = add_number (pbuf, color.blue);
650 pbuf = add_number (pbuf, line->linewidth);
651 pbuf = add_string (pbuf,
"line\n");
652 ret = write (psc->f, pbuf, strlen (pbuf));
657 rectangle = (Rectangle *) elt;
659 pbuf = add_number (pbuf, rectangle->x);
660 pbuf = add_number (pbuf, psc->height - rectangle->y);
661 pbuf = add_number (pbuf, rectangle->width);
662 pbuf = add_number (pbuf, rectangle->height);
663 x_get_rgb_values (psc->display, psc->window, rectangle->color, &color);
664 pbuf = add_number (pbuf, color.red);
665 pbuf = add_number (pbuf, color.green);
666 pbuf = add_number (pbuf, color.blue);
668 if (rectangle->action == DRAW_RECTANGLE)
670 pbuf = add_number (pbuf, rectangle->linewidth);
671 pbuf = add_string (pbuf,
"true ");
675 pbuf = add_number (pbuf, 1);
676 pbuf = add_string (pbuf,
"false ");
679 pbuf = add_string (pbuf,
"rect\n");
680 ret = write (psc->f, pbuf, strlen (pbuf));
686 pbuf = add_number (pbuf, arc->x+arc->width/2);
687 pbuf = add_number (pbuf, psc->height - (arc->y+arc->height/2));
688 pbuf = add_number (pbuf, arc->width/2);
689 pbuf = add_number (pbuf, arc->height/2);
690 pbuf = add_number (pbuf, arc->startangle);
691 pbuf = add_number (pbuf, (arc->startangle+arc->arcangle)/64);
692 x_get_rgb_values (psc->display, psc->window, arc->color, &color);
693 pbuf = add_number (pbuf, color.red);
694 pbuf = add_number (pbuf, color.green);
695 pbuf = add_number (pbuf, color.blue);
697 if (arc->action == DRAW_ARC)
699 pbuf = add_number (pbuf, arc->linewidth);
700 pbuf = add_string (pbuf,
"true ");
704 pbuf = add_number (pbuf, 1);
705 pbuf = add_string (pbuf,
"false ");
708 pbuf = add_string (pbuf,
"earc\n");
709 ret = write (psc->f, pbuf, strlen (pbuf));
713 case DRAW_IMAGE_STRING:
715 pbuf = add_number (pbuf, s->x);
716 pbuf = add_number (pbuf, psc->height - s->y);
717 pbuf = add_string (pbuf,
"(");
718 pbuf = add_string (pbuf, s->str);
719 pbuf = add_string (pbuf,
") ");
720 x_get_rgb_values (psc->display, psc->window, s->color, &color);
721 pbuf = add_number (pbuf, color.red);
722 pbuf = add_number (pbuf, color.green);
723 pbuf = add_number (pbuf, color.blue);
725 if (s->action == DRAW_STRING)
726 pbuf = add_string (pbuf,
"true ");
728 pbuf = add_string (pbuf,
"false ");
730 pbuf = add_string (pbuf,
"dstr\n");
731 ret = write (psc->f, pbuf, strlen (pbuf));
735 polygon = (Polygon *) elt;
737 x_get_rgb_values (psc->display, psc->window, polygon->color, &color);
738 pbuf = add_number (pbuf, color.red);
739 pbuf = add_string (pbuf,
"65535 div ");
740 pbuf = add_number (pbuf, color.green);
741 pbuf = add_string (pbuf,
"65535 div ");
742 pbuf = add_number (pbuf, color.blue);
743 pbuf = add_string (pbuf,
"65535 div ");
744 pbuf = add_string (pbuf,
"setrgbcolor ");
747 pbuf = add_string (pbuf,
"np ");
748 pbuf = add_number (pbuf, p->x);
749 pbuf = add_number (pbuf, psc->height - p->y);
750 pbuf = add_string (pbuf,
"mt\n");
752 for (i=1; i<polygon->npoints; i++, p++)
754 pbuf = add_number (pbuf, p->x);
755 pbuf = add_number (pbuf, psc->height - p->y);
756 pbuf = add_string (pbuf,
"lt ");
758 pbuf = add_string (pbuf,
"\n");
761 pbuf = add_string (pbuf,
"cp fi\n");
762 ret = write (psc->f, pbuf, strlen (pbuf));
772 long x_postscript_window (display, window, displaylist, filename)
779 XWindowAttributes windowAttributes;
780 PostScriptClosure psc;
785 psc.display =(long)display;
787 if ((psc.f = open (filename, O_CREAT|O_WRONLY|O_TRUNC,
788 S_IRUSR|S_IWUSR|S_IRWXG)) == -1)
790 Errorline (
"\n*** Error: cannot open file %s.\n", filename);
794 XGetWindowAttributes (display, window, &windowAttributes);
795 psc.height = windowAttributes.height;
796 x_postscript_prolog (psc.f);
798 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,...)
void List_SetLinkProc(RefListHeader header, RefListGetLinksProc getLinks)
List_SetLinkProc.
long List_Enum(RefListHeader header, RefListEnumProc proc, Ref closure)
List_Enum.