diff options
Diffstat (limited to 'src/graph/Gdraws')
-rw-r--r-- | src/graph/Gdraws/ChangeLog | 49 | ||||
-rwxr-xr-x | src/graph/Gdraws/Gdraws0.h | 102 | ||||
-rw-r--r-- | src/graph/Gdraws/Gfun.c.pamphlet | 1350 | ||||
-rw-r--r-- | src/graph/Gdraws/Makefile.in | 77 | ||||
-rw-r--r-- | src/graph/Gdraws/Makefile.pamphlet | 229 | ||||
-rw-r--r-- | src/graph/Gdraws/data.c.pamphlet | 256 | ||||
-rw-r--r-- | src/graph/Gdraws/loadFont.c.pamphlet | 71 | ||||
-rw-r--r-- | src/graph/Gdraws/main.c.pamphlet | 215 | ||||
-rw-r--r-- | src/graph/Gdraws/menu.c.pamphlet | 82 | ||||
-rw-r--r-- | src/graph/Gdraws/psFiles.pamphlet | 635 | ||||
-rw-r--r-- | src/graph/Gdraws/yesORno.c.pamphlet | 67 |
11 files changed, 3133 insertions, 0 deletions
diff --git a/src/graph/Gdraws/ChangeLog b/src/graph/Gdraws/ChangeLog new file mode 100644 index 00000000..fb486345 --- /dev/null +++ b/src/graph/Gdraws/ChangeLog @@ -0,0 +1,49 @@ +2007-07-29 Gabriel Dos Reis <gdr@cs.tamu.edu> + + * Makefile.pamphlet: Propagate libtoolization changes. + * Makefile.in: Regenerate. + +2006-11-26 Gabriel Dos Reis <gdr@cs.tamu.edu> + + * Makefile.pamphlet: Add support for OS that require extension for + executable binary files. + * Makefile.in: Regenerate. + + * Gdraws0.h: Include axiom-c-macros.h + +2006-11-24 Gabriel Dos Reis <gdr@cs.tamu.edu> + + * Makefile.pamphlet: Introduce implicit rules for extracting + PostScript files. Remove replicated special case rules. + (AXIOM_CFLAGS): New variable. + (Gfun.$(OBJEXT)): Use it. + (.SUFFIXES): New target. + (all-Gdraws): Likewise. + * Makefile.in: Regenerate. + + * Gfun.c.pamphlet: Remove K&R C style function declaration. + +2006-10-08 Gabriel Dos Reis <gdr@cs.tamu.edu> + + * Makefile.pamphlet: Remove references to ${MNT} throughout. + +2006-10-04 Gabriel Dos Reis <gdr@cs.tamu.edu> + + * Makefile.pamphlet (pamphlets): New. + (DCOFILES): Remove. + +2006-09-18 Gabriel Dos Reis <gdr@cs.tamu.edu> + + * Makefile.pamphlet: Tidy. + (subdir): New. + +2006-09-11 Gabriel Dos Reis <gdr@cs.tamu.edu> + + * Makefile.pamphlet: Use $(axiom_build_document) to tangle + pamphlets. Add support for out-of-source build. + * Makefile.in: Regenerate. + +2006-09-03 Gabriel Dos Reis <gdr@cs.tamu.edu> + + * Makefile.in: New. + diff --git a/src/graph/Gdraws/Gdraws0.h b/src/graph/Gdraws/Gdraws0.h new file mode 100755 index 00000000..62066b69 --- /dev/null +++ b/src/graph/Gdraws/Gdraws0.h @@ -0,0 +1,102 @@ +/* +Copyright (c) 1991-2002, The Numerical ALgorithms Group Ltd. +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + + - Neither the name of The Numerical ALgorithms Group Ltd. nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS +IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A +PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER +OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#ifndef _GDRAWS0_H_ +#define _GDRAWS0_H_ 1 + +#include <X11/Xlib.h> +#include "axiom-c-macros.h" + + +#define yes 1 +#define no 0 + +/* + * Indices for PostScript draw procedures. + * + * The order of these defined variables are very important; they are used + * to create the OUTPUT file. Essentially, PSCreateFile() loops through the + * index of 0 to psDrawNo and checks if the file/procedure is used. If so, + * the file is copied to the output file. + */ + +#define output 0 /* output file */ +#define headerps 1 /* postscript header file */ +#define drawps 2 /* draw procedure */ +#define drawarcps 3 /* draw arc procedure */ +#define drawfilledps 4 /* draw filled procedure */ +#define drawcolorps 5 /* draw color filled procedure */ +#define drawpointps 6 /* draw point procedure */ +#define fillpolyps 7 /* polygon filled procedure */ +#define fillwolps 8 /* polygon filled with outline proc */ +#define colorpolyps 9 /* polygon fill with color procedure */ +#define colorwolps 10 /* polygon fill with color procedure */ +#define drawlineps 11 /* draw line procedure */ +#define drawlinesps 12 /* draw lines procedure */ +#define drawIstrps 13 /* draw image string procedure */ +#define drawstrps 14 /* draw string procedure */ +#define drawrectps 15 /* draw rectangle procedure */ +#define fillarcps 16 /* filled arc procedure */ +#define setupps 17 /* setup, or pre-script */ +#define GCdictps 18 /* grahphics context definition file */ +#define scriptps 19 /* script file */ +#define endps 20 /* wrap up, close down, procedure */ + +#define psDrawNo 21 /* for use in createPSfile() */ + + +/* + * PostScript structures + */ + +typedef struct _psStruct { /* data structure for ps routines info */ + int flag; + char filename[200]; +} psStruct; + +psStruct psData[psDrawNo]; /* need psDrawNo of them */ + + +/* + * These variables are expected to be declared in within client programs, eg, + * main.c in view2D and view3D. + */ + +extern int scrn; /* screen */ +extern Display *dsply; /* display */ +extern char *envAXIOM; /* environment variable AXIOM or DEVE */ + + +#endif + + diff --git a/src/graph/Gdraws/Gfun.c.pamphlet b/src/graph/Gdraws/Gfun.c.pamphlet new file mode 100644 index 00000000..7a42f762 --- /dev/null +++ b/src/graph/Gdraws/Gfun.c.pamphlet @@ -0,0 +1,1350 @@ +\documentclass{article} +\usepackage{axiom} +\begin{document} +\title{\$SPAD/src/graph Gfun.c} +\author{The Axiom Team} +\maketitle +\begin{abstract} +\end{abstract} +\eject +\tableofcontents +\eject +\section{License} +<<license>>= +/* +Copyright (c) 1991-2002, The Numerical ALgorithms Group Ltd. +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + + - Neither the name of The Numerical ALgorithms Group Ltd. nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS +IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A +PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER +OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ +@ +<<*>>= +<<license>> + + +#define _GFUN_C +#include "useproto.h" + +#include <stdio.h> +#include <unistd.h> +#include <stdlib.h> +#include <string.h> + +#include "Gdraws0.h" +#include "G.h" +#include "hash.h" + +#include "hash.H1" +#include "Gfun.H1" + + +/* + * Given 2 file pointers, this function copies file ifp to file ofp + */ + +static void +filecopy(FILE * ifp, FILE * ofp) +{ + + int c; + + while ((c = getc(ifp)) != EOF) + putc(c, ofp); +} + + +/* + * PSCreateFile generates the output file by using the order of defined + * variables; they are used to create the OUTPUT file. Essentially, + * PSCreateFile() loop through the index of 0 to psDrawNo and checks if the + * file/procedure is used. If so, the file is included into the output + * file. + */ + +int +PSCreateFile( + int bWidth, /* border width of picture frame */ + Window vw, Window tw, /* viewWindow, and titleWindow */ + char *title) /* title of picture to be drawn in title bar */ +{ + FILE *ifp, *ofp, *fp; /* input, output and temp file pointer */ + int i; /* index */ + + /* last things to add to the script file */ + + fp = fopen(psData[scriptps].filename, "a"); + fprintf(fp, "\n grestore\t%% restore graphics state\n\n"); + fclose(fp); + +#if 0 + /* Make frame drawing optional. */ + + Gdraws_drawFrame(bWidth, vw, tw, title); +#endif + + /* put procedures and script together into OUTPUT.ps */ + + if ((ofp = fopen(psData[output].filename, "w")) == NULL) { + fprintf(stderr, "Cannot open %s to write.\n", psData[output].filename); + return (psError); + } + else { + i = 1; + while (i < psDrawNo) { /* loops through each file/procedure */ + if (psData[i].flag) { /* if set, procedure/file is used */ + if ((ifp = fopen(psData[i].filename, "r")) == NULL) { + if (i == GCdictps) { /* GC dictionaries */ + fprintf(stderr, "Warning: missing GCdictionary.\n"); + } + else { + fprintf(stderr, "Cannot open %s to read.\n", + psData[i].filename); + fclose(ofp); + return (psError); + } + } + else { + filecopy(ifp, ofp); + fclose(ifp); + } + } + i++; + } + } + + /* remove script file in tmp */ + + unlink(psData[scriptps].filename); + +#if 0 + /* remove GCdict file in tmp */ + unlink(psData[GCdictps].filename); +#endif + + return (fclose(ofp)); +} + + + +/* + * This function draws the frame of the picture, which corresponds to the + * picture frame on the X display. In addition, it draws the title window as + * well as the title of the picture. + */ + +int +Gdraws_drawFrame( + int borderW, /* border width */ + Window viewWindow, Window titleWindow, + char *title) /* title of picture */ +{ + FILE *fp; + XWindowAttributes vwInfo, twInfo; + + /* choose 2 and "frameDict" for frame dictionary: can be anything else */ + + PSCreateContext((GC)2, "frameDict", borderW, psButtCap, psMiterJoin, + psWhite, psBlack); + + fp = fopen(psData[scriptps].filename, "a"); + + XGetWindowAttributes(dsply, viewWindow, &vwInfo); + + /* draw title window */ + + XGetWindowAttributes(dsply, titleWindow, &twInfo); + fprintf(fp, "\t%s\t%d\t%d\t%d\t%d\ttitle\n", "frameDict", + twInfo.height - vwInfo.height, twInfo.width, 0, vwInfo.height); + + /* draw viewport window */ + + fprintf(fp, "\t%s\tdrawFrame\n", "frameDict"); /* using Gdraws_setDimension() */ + + /* draw title text */ + + psData[drawIstrps].flag = yes; + fprintf(fp, "\t%s\tloadFont\n\t%d\t(%s) stringwidth pop sub 2 div\n", + "frameDict", twInfo.width, title); + fprintf(fp, "\t%d\t(%s)\t(%s)\tpsDrawIStr\n", 15, title, "title"); + + return (fclose(fp)); +} + + +/* setDimension sets the dimension of the picture */ + +int +Gdraws_setDimension( + Window viewWindow, + Window titleWindow) +{ + FILE *fp; + XWindowAttributes vwInfo, twInfo; + float pageWidth, pageHeight, width; + + fp = fopen(psData[scriptps].filename, "w"); + + XGetWindowAttributes(dsply, titleWindow, &twInfo); + XGetWindowAttributes(dsply, viewWindow, &vwInfo); + pageWidth = 575.0; + pageHeight = 750.0; + +#if 0 + pageWidth = (float) (DisplayWidth(dsply, scrn) / DisplayWidthMM(dsply, scrn)); + pageWidth *= 160.0; + pageHeight = (float) (DisplayHeight(dsply, scrn) / DisplayHeightMM(dsply, scrn)); + pageHeight *= 210.0; + fprintf(stderr, "%f, %f\n", pageWidth, pageHeight); +#endif + + fprintf(fp, "\n gsave\t%% save graphics state for clipping path\n\n"); + if ((vwInfo.height > pageWidth) || (vwInfo.height > pageHeight)) { + width = (float) vwInfo.width; + if (vwInfo.height > pageWidth) { + width = pageWidth / width; + fprintf(fp, "\t%f\t%f", width, width); + } + else { + if (vwInfo.height > pageHeight) + fprintf(fp, "\t%f\t%f", width, pageHeight / width); + } + } + else { + fprintf(fp, "\t%f\t%f", 1.0, 1.0); + } + fprintf(fp, "\tscale\n\n"); + + fprintf(fp, "\t%d\t%d\t%d\tsetDim\n", twInfo.height - vwInfo.height, + vwInfo.height, vwInfo.width); + + /* Write a Bounding Box for psfig etc. */ + + fprintf(fp, "%%%%BoundingBox: 0 0 %d %d\n", vwInfo.height, vwInfo.width); + + fprintf(fp, "\tmaxX maxY\t0 0\trectangle\tclip\t%% set clip path\n\n"); + return (fclose(fp)); +} +/* + * GDrawImageString draws an image text string + */ + +int +GDrawImageString( + GC gc, /* graphics context */ + Window wid, /* window id */ + int x, int y, + char *string, + int length, int dFlag) +{ + int s; + + switch (dFlag) { + case Xoption: + s = XDrawImageString(dsply, wid, gc, x, y, string, length); + break; + case PSoption: + { + FILE *fp; + + if ((fp = fopen(psData[scriptps].filename, "a")) == NULL) { + fprintf(stderr, "GDrawImageString cannot open %s\n", + psData[scriptps].filename); + return (psError); + } + + psData[drawIstrps].flag = yes; /* set procedure flag */ + fprintf(fp, "\t%s\t%d\t%d\t(%s)\t(%s)\tpsDrawIStr\n", + PSfindGC(gc), x, y, string, "window"); + s = fclose(fp); + } + break; + default: + fprintf(stderr, "GdrawImagestring request (%d) not implemented yet.\n", dFlag); + return (psError); + } + return (s); +} + +/* Draws an arc; see XDrawArc */ + +int +GDrawArc( + GC gc, /* graphics context */ + Window wid, /* window id */ + int x, int y, + unsigned int wdth, unsigned int hght, + int ang1, int ang2, int dFlag) +{ + int s = 0; + + switch (dFlag) { + case Xoption: + XDrawArc(dsply, wid, gc, x, y, wdth, hght, ang1, ang2); + break; + case PSoption: + { + FILE *fp; + + if ((fp = fopen(psData[scriptps].filename, "a")) == NULL) { + fprintf(stderr, "GDrawArc cannot open %s\n", + psData[scriptps].filename); + return (psError); + } + + psData[drawarcps].flag = yes; + fprintf(fp, "\t%s\t%d\t%d\t%d\t%d\t%d\t%d\tpsDrawArc\n", + PSfindGC(gc), x, y, hght, wdth, ang1 / 64, ang2 / 64); + s = fclose(fp); + } + break; + default: + fprintf(stderr, "Gdrawarc request (%d) not implemented yet.\n", + dFlag); + return (psError); + } + return (s); +} +/* + * GDrawLine draws a line, see XDrawLine + */ + +int +GDrawLine( + GC gc, /* graphics context */ + Window wid, /* window id */ + int x0, int y0, int x1, int y1, int dFlag) +{ + int s = 0; + + switch (dFlag) { + case Xoption: + XDrawLine(dsply, wid, gc, x0, y0, x1, y1); + break; + case PSoption: + { + FILE *fp; + + if ((fp = fopen(psData[scriptps].filename, "a")) == NULL) { + fprintf(stderr, "GDrawLine cannot open %s\n", + psData[scriptps].filename); + return (psError); + } + + psData[drawlineps].flag = yes; /* sets procedure flag */ + fprintf(fp, "\t%s\t%d\t%d\t%d\t%d\tpsDrawLine\n", + PSfindGC(gc), x1, y1, x0, y0); + s = fclose(fp); + } + break; + default: + fprintf(stderr, "Gdrawline request (%d) not implemented yet.\n", + dFlag); + return (psError); + } + return (s); +} + + + + + +/* + * GDrawLines draws lines; see XDrawLines + */ + +int +GDrawLines( + GC gc, /* graphics context */ + Window wid, /* window id */ + XPoint * points, /* points */ + int numberOfPoints, int mode, int dFlag) + /* number of points, mode and display flag */ +{ + int s = 0; + + switch (dFlag) { + case Xoption: + XDrawLines(dsply, wid, gc, points, numberOfPoints, mode); + break; + case PSoption: + { + FILE *fp; /* not dealing with modes yet */ + int i = 0; + + if ((fp = fopen(psData[scriptps].filename, "a")) == NULL) { + fprintf(stderr, "GDrawLines cannot open %s\n", + psData[scriptps].filename); + return (psError); + } + + psData[drawlinesps].flag = yes; /* set procedure flag */ + fprintf(fp, "\t%s\n", PSfindGC(gc)); + i = numberOfPoints - 1; + while (i > 0) + { fprintf(fp, "\t%d\t%d\n", points[i].x, points[i].y); + i = i-1; + } + + fprintf(fp, "\t%d\t%d\t%d\tpsDrawLines\n", + numberOfPoints, points[i].x, points[i].y); + s = fclose(fp); + } + break; + default: + fprintf(stderr, "Gdrawlines request (%d) not implemented yet\n", + dFlag); + return (psError); + } + return (s); +} + +/* + * GDrawPoint draws a point, see XDrawPoint + */ + +int +GDrawPoint( + Window wid, /* window id */ + GC gc, /* graphics context */ + int x0, int y0, int dFlag) +{ + int s = 0; + + switch (dFlag) { + case Xoption: + XDrawPoint(dsply, wid, gc, x0, y0); + break; + case PSoption: + { + FILE *fp; + + if ((fp = fopen(psData[scriptps].filename, "a")) == NULL) { + fprintf(stderr, "GDrawPoint cannot open %s\n", + psData[scriptps].filename); + return (psError); + } + + psData[drawpointps].flag = yes; /* sets procedure flag */ + fprintf(fp, "\t%s\t%d\t%d\t%d\t%d\tpsDrawPoint\n", + PSfindGC(gc), x0, y0, x0 + 1, y0 + 1); + s = fclose(fp); + } + break; + default: + fprintf(stderr, "Gdrawpoint request (%d) not implemented yet\n", + dFlag); + return (psError); + } + return (s); +} + +/* + * GDrawRectangle draws a rectangle; see XDrawRectangle + */ + +int +GDrawRectangle( + GC gc, + Window windowId, + short int x,short int y,short int width,short int height, + int dFlag) +{ + int s = 0; + + switch (dFlag) { + case Xoption: + XDrawRectangle(dsply, windowId, gc, x, y, width, height); + break; + case PSoption: + { + FILE *fp; + + if ((fp = fopen(psData[scriptps].filename, "a")) == NULL) { + fprintf(stderr, "GDrawRect cannot open %s\n", + psData[scriptps].filename); + return (psError); + } + + psData[drawrectps].flag = yes; + fprintf(fp, "\t%s\t%d\t%d\t%d\t%d\tpsDrawRect\n", + PSfindGC(gc), width, height, x, y); + s = fclose(fp); + } + break; + default: + fprintf(stderr, "Gdrawrect request (%d) not implemented yet\n", + dFlag); + return (psError); + } + return (s); +} + +/* + * GDraw3DButtonOut draws a rectangle with 3D shading on rhs and bottom + */ + +int +GDraw3DButtonOut( + GC gc, + Window windowId, + short int x,short int y,short int width,short int height, + int dFlag) +{ + /* draw regular rectangle */ + + int s = GDrawRectangle(gc, windowId, x, y, width - 1, height - 1, dFlag); + + /* add extra line down rhs */ + + GDrawLine(gc, windowId, + x + width, y + 1, x + width, y + height, + dFlag); + + /* add extra line across bottom */ + + GDrawLine(gc, windowId, + x + 1, y + height, x + width, y + height, + dFlag); + + return (s); +} + +/* + * GDraw3DButtonIn draws a rectangle with 3D shading on lhs and top + */ + +int +GDraw3DButtonIn( + GC gc, + Window windowId, + short int x,short int y,short int width,short int height, + int dFlag) +{ + /* draw regular rectangle */ + + int s = GDrawRectangle(gc, windowId, x + 1, y + 1, width - 1, height - 1, dFlag); + + /* add extra line down lhs */ + + GDrawLine(gc, windowId, + x, y, x, y + height - 1, + dFlag); + + /* add extra line across top */ + + GDrawLine(gc, windowId, + x, y, x + width - 1, y, + dFlag); + + return (s); +} + +/* + * GDrawPushButton draws a push button whose appearance depends on "isOn." + */ + +int +GDrawPushButton( + Display * display, + GC gc1, GC gc2, GC gc3, + Window windowId, + short int x,short int y,short int width,short int height, + int isOn, char *text, + unsigned long buttonColor, unsigned long color, + int dFlag) +{ + int len = strlen(text); + + if (dFlag == Xoption) + XClearArea(display, windowId, x, y, width + 1, height + 1, False); + + GSetForeground(gc1, (float) buttonColor, dFlag); + + if (isOn) + GDraw3DButtonIn(gc1, windowId, x, y, width, height, dFlag); + else + GDraw3DButtonOut(gc1, windowId, x, y, width, height, dFlag); + + GSetForeground(gc2, (float) color, dFlag); + + return GDrawString(gc2, windowId, + x + (isOn ? 2 : 0) + centerX(gc3, text, len, width), + y + (isOn ? 2 : 0) + centerY(gc3, height), + text, len, dFlag); +} + + + +/* + * Draws a string; see XDrawString + */ + +int +GDrawString( + GC gc, /* graphics context */ + Window wid, /* window id */ + int x, int y, + char *string, /* string to be drawn */ + int length, int dFlag) +{ + int s; + + switch (dFlag) { + case Xoption: + s = XDrawString(dsply, wid, gc, x, y, string, length); + break; + case PSoption: + { + FILE *fp; + + if ((fp = fopen(psData[scriptps].filename, "a")) == NULL) { + fprintf(stderr, "GDrawString cannot open %s\n", + psData[scriptps].filename); + return (psError); + } + + psData[drawstrps].flag = yes; /* sets procedure flag */ + fprintf(fp, "\t%s\t(%s)\t%d\t%d\tpsDrawStr\n", + PSfindGC(gc), string, x, y); + + s = fclose(fp); + } + break; + default: + fprintf(stderr, "Gdrawstring request (%d) not implemented yet\n", + dFlag); + return (psError); + } + return (s); +} + +/* + * Draws and fills an arc with foreground color; see XFillArc + */ + +int +GFillArc( + GC gc, /* graphics context */ + Window wid, /* window id */ + int x, int y, + unsigned int wdth, unsigned int hght, + int ang1, int ang2, int dFlag) +{ + int s = 0; + + switch (dFlag) { + case Xoption: /* angle: times 64 already */ + XFillArc(dsply, wid, gc, x, y, wdth, hght, ang1, ang2); + break; + case PSoption: + { + FILE *fp; + + if ((fp = fopen(psData[scriptps].filename, "a")) == NULL) { + fprintf(stderr, "GFillArc cannot open %s\n", + psData[scriptps].filename); + return (psError); + } + + psData[fillarcps].flag = yes; /* sets procedure flag */ + fprintf(fp, "\t%s\t%d %d\t%d %d\t%d %d\t%d %d\tpsFillArc\n", + PSfindGC(gc), x, y, hght, wdth, ang1 / 64, ang2 / 64, + x + wdth / 2, y + hght / 2); + s = fclose(fp); + } + break; + default: + fprintf(stderr, "GFillArc request (%d) not implemented yet\n", + dFlag); + return (psError); + } + return (s); +} + +/* + * Initializes the path and files to be used. + */ + +int +PSGlobalInit(void) +{ /* This needs to be called only once each + * session. */ + char *tmp; + + /* path-independent global file name */ + psData[GCdictps].flag = yes; + tmp = tempnam(NULL, "axPS"); + sprintf(psData[GCdictps].filename, "%s", tmp); + free(tmp); + psData[setupps].flag = yes; + psData[scriptps].flag = yes;/* new script file name */ + psData[endps].flag = yes; + + /* path specific file names */ + + if ((envAXIOM = getenv("DEVE")) != NULL) { /* get env var AXIOM */ + + psData[headerps].flag = yes; + sprintf(psData[headerps].filename, "%s%s", envAXIOM, "/Gdraws/PS/header.ps"); + sprintf(psData[drawps].filename, "%s%s", envAXIOM, "/Gdraws/PS/draw.ps"); + sprintf(psData[drawarcps].filename, "%s%s", envAXIOM, + "/Gdraws/PS/drawarc.ps"); + sprintf(psData[drawfilledps].filename, "%s%s", envAXIOM, + "/Gdraws/PS/drwfilled.ps"); + sprintf(psData[drawcolorps].filename, "%s%s", envAXIOM, + "/Gdraws/PS/drawcolor.ps"); + sprintf(psData[fillpolyps].filename, "%s%s", envAXIOM, + "/Gdraws/PS/fillpoly.ps"); + sprintf(psData[colorpolyps].filename, "%s%s", envAXIOM, + "/Gdraws/PS/colorpoly.ps"); + sprintf(psData[fillwolps].filename, "%s%s", envAXIOM, + "/Gdraws/PS/fillwol.ps"); + sprintf(psData[colorwolps].filename, "%s%s", envAXIOM, + "/Gdraws/PS/colorwol.ps"); + sprintf(psData[drawpointps].filename, "%s%s", envAXIOM, + "/Gdraws/PS/drawpoint.ps"); + sprintf(psData[drawlineps].filename, "%s%s", envAXIOM, + "/Gdraws/PS/drawline.ps"); + sprintf(psData[drawlinesps].filename, "%s%s", envAXIOM, + "/Gdraws/PS/drawlines.ps"); + sprintf(psData[drawrectps].filename, "%s%s", envAXIOM, + "/Gdraws/PS/drawrect.ps"); + sprintf(psData[drawstrps].filename, "%s%s", envAXIOM, + "/Gdraws/PS/drawstr.ps"); + sprintf(psData[drawIstrps].filename, "%s%s", envAXIOM, + "/Gdraws/PS/drawIstr.ps"); + sprintf(psData[fillarcps].filename, "%s%s", envAXIOM, + "/Gdraws/PS/fillarc.ps"); + sprintf(psData[setupps].filename, "%s%s", envAXIOM, "/Gdraws/PS/setup.ps"); + sprintf(psData[endps].filename, "%s%s", envAXIOM, "/Gdraws/PS/end.ps"); + } + else if ((envAXIOM = getenv("AXIOM")) != NULL) { + psData[headerps].flag = yes; + sprintf(psData[headerps].filename, "%s%s", envAXIOM, + "/lib/graph/header.ps"); + sprintf(psData[drawps].filename, "%s%s", envAXIOM, + "/lib/graph/draw.ps"); + sprintf(psData[drawarcps].filename, "%s%s", envAXIOM, + "/lib/graph/drawarc.ps"); + sprintf(psData[drawfilledps].filename, "%s%s", envAXIOM, + "/lib/graph/drwfilled.ps"); + sprintf(psData[drawcolorps].filename, "%s%s", envAXIOM, + "/lib/graph/drawcolor.ps"); + sprintf(psData[fillpolyps].filename, "%s%s", envAXIOM, + "/lib/graph/fillpoly.ps"); + sprintf(psData[colorpolyps].filename, "%s%s", envAXIOM, + "/lib/graph/colorpoly.ps"); + sprintf(psData[fillwolps].filename, "%s%s", envAXIOM, + "/lib/graph/fillwol.ps"); + sprintf(psData[colorwolps].filename, "%s%s", envAXIOM, + "/lib/graph/colorwol.ps"); + sprintf(psData[drawpointps].filename, "%s%s", envAXIOM, + "/lib/graph/drawpoint.ps"); + sprintf(psData[drawlineps].filename, "%s%s", envAXIOM, + "/lib/graph/drawline.ps"); + sprintf(psData[drawlinesps].filename, "%s%s", envAXIOM, + "/lib/graph/drawlines.ps"); + sprintf(psData[drawrectps].filename, "%s%s", envAXIOM, + "/lib/graph/drawrect.ps"); + sprintf(psData[drawstrps].filename, "%s%s", envAXIOM, + "/lib/graph/drawstr.ps"); + sprintf(psData[drawIstrps].filename, "%s%s", envAXIOM, + "/lib/graph/drawIstr.ps"); + sprintf(psData[fillarcps].filename, "%s%s", envAXIOM, + "/lib/graph/fillarc.ps"); + sprintf(psData[setupps].filename, "%s%s", envAXIOM, + "/lib/graph/setup.ps"); + sprintf(psData[endps].filename, "%s%s", envAXIOM, + "/lib/graph/end.ps"); + } + else { + fprintf(stderr, " need environment variable AXIOM or DEVE; process aborted\n"); + return (psError); + } + + return (psInit = yes); +} + + +/* + * This needs to be called for every postscript file generated. It + * initializes the procedure flags. + */ + +int +PSInit(Window vw, Window tw) +{ + if (!psInit) { + /* must have PSGlobalInit() called before this */ + fprintf(stderr, "Error: need initialization for ps data files: call PSGlobalInit().\n"); + return (psError); + } + + sprintf(psData[output].filename, "%s", PSfilename); /* output file name */ + + psData[drawps].flag = no; /* ps procedures flags */ + psData[drawarcps].flag = no; + psData[drawfilledps].flag = no; + psData[drawcolorps].flag = no; + psData[fillpolyps].flag = no; + psData[fillwolps].flag = no; + psData[colorpolyps].flag = no; + psData[colorwolps].flag = no; + psData[drawpointps].flag = no; + psData[drawlineps].flag = no; + psData[drawlinesps].flag = no; + psData[drawrectps].flag = no; + psData[drawstrps].flag = no; + psData[drawIstrps].flag = no; + psData[fillarcps].flag = no; + + sprintf(psData[scriptps].filename, "%s", tmpnam(NULL)); /* script file */ + return (Gdraws_setDimension(vw, tw)); +} + +/* + * This procedure sets the line attributes; notice that lineWidth is not set + * for PS, this is because lineWidth of 0, the thinest line on the ps device, + * is device-dependent, thus, we'll leave it and use default. Also lineStyle + * is solid in ps by default, thus we don't need to set it. We'll leave out + * line style here since we really never used anything other than line solid + * which is the default line style in postscript. + */ + +int +PSCreateContext( + GC gc, /* graphics context */ + char *C_gc, /* GC name to be used as postscript variable */ + int lineWidth, int capStyle, int joinStyle, + float bg, float fg) +{ + FILE *fp; + GCptr newGC, curGC; + + /* get memory for new GC cell */ + + if (!(newGC = (GCptr) malloc(sizeof(GCstruct)))) { + fprintf(stderr, "Ran out of memory(malloc) trying to create a ps GC.\n"); + exit(-1); + } + + /* attach newGC to chain */ + + if (GChead == NULL) + GChead = newGC; + else { /* attach newGC to end of linked list */ + curGC = GChead; + while (curGC->next != NULL) + curGC = curGC->next; + curGC->next = newGC; + } + + /* fill newGC with information */ + + newGC->GCint = gc; + sprintf(newGC->GCchar, "%s", C_gc); + newGC->next = NULL; + + if ((fp = fopen(psData[GCdictps].filename, "a")) == NULL) { + fprintf(stderr, "PSCreateContext cannot open %s\n", + psData[GCdictps].filename); + return (psError); + } + + fprintf(fp, "\t%d\t%d\t%d\n\t%f\t%f\t/%s\tmakeDict\n", joinStyle, + capStyle, lineWidth, bg, fg, C_gc); + + return (fclose(fp)); +} + +/* + * Looks into GC linked list with gc (unsigned long) as index to find the + * character name. + */ + +char * +PSfindGC(GC gc) +{ + GCptr curGC; + + curGC = GChead; + while ((curGC != NULL) && (curGC->GCint != gc)) + curGC = curGC->next; + + if (curGC == NULL) { + fprintf(stderr, "PSfindGC cannot find gc: %p.\n",gc); + return (NULL); + } + else + return (curGC->GCchar); +} + +/* + * Sets foreground color; see XSetForeground + */ + +int +GSetForeground( + GC gc, /* graphics context */ + float color, /* foreground color to be set */ + int dFlag) /* display flag: PS, X,... */ +{ + int s = 0; + + switch (dFlag) { + case Xoption: + XSetForeground(dsply, gc, (unsigned long) color); + break; + case PSoption: + { + FILE *fp; + + if ((fp = fopen(psData[scriptps].filename, "a")) == NULL) { + fprintf(stderr, "GSetForeground cannot open %s\n", + psData[scriptps].filename); + return (0); + } + fprintf(fp, "\t%s\t%f\tsetForeground\n", PSfindGC(gc), color); + s = fclose(fp); + break; + } + default: + fprintf(stderr, "GSetForeground request (%d) not implemented yet\n", dFlag); + return (0); + } + return (s); +} + +/* + * Sets background color; see XSetBackground + */ + +int +GSetBackground( + GC gc, /* graphics context */ + float color, /* background color to be set */ + int dFlag) /* display flag: PS, X,... */ +{ + int s = 0; + + switch (dFlag) { + case Xoption: + XSetBackground(dsply, gc, (unsigned long) color); + break; + case PSoption: + { + FILE *fp; + + if ((fp = fopen(psData[scriptps].filename, "a")) == NULL) { + fprintf(stderr, "GSetBackground cannot open %s\n", + psData[scriptps].filename); + return (0); + } + fprintf(fp, "\t%s\t%f\tsetBackground\n", PSfindGC(gc), color); + s = fclose(fp); + break; + } + default: + fprintf(stderr, "GSetBackground request (%d) not implemented yet\n", dFlag); + return (0); + } + return (s); +} + +/* + * See XSetLineAttributes. Notice that we'll not setting line style for + * postscript. This is because solid is the ls in ps and in view3D and 2D, + * we really don't use anything else than solid. + */ + +int +GSetLineAttributes( + GC gc, + int lineWidth, int lineStyle, int capStyle, int joinStyle, + int dFlag) +{ + int s = 0; + + switch (dFlag) { + case Xoption: + XSetLineAttributes(dsply, gc, lineWidth, lineStyle, + capStyle, joinStyle); + break; + case PSoption: + { + FILE *fp; + int psCap, psJoin; + + switch (capStyle) { + case 0: /* CapNotLast is not implemented in ps */ + case 1: + psCap = psButtCap; + break; + case 2: + psCap = psRoundCap; + break; + case 3: + psCap = psPSqCap; + break; + default: + fprintf(stderr, "cap style: %d unknown, using default.\n", capStyle); + psCap = psButtCap; + } + + switch (joinStyle) { + case 0: + psJoin = psMiterJoin; + break; + case 1: + psJoin = psRoundJoin; + break; + case 2: + psJoin = psBevelJoin; + break; + default: + fprintf(stderr, "join style: %d unknown, using default.\n", joinStyle); + psJoin = psMiterJoin; + } + + /* + * width of zero is machine-dependent and is not recom- mended, + * we'll use 1 as the thinest line available if (lineWidth < 1) + * lineWidth = 1; + */ + + if ((fp = fopen(psData[scriptps].filename, "a")) == NULL) { + fprintf(stderr, "GSetLineAttributes cannot open %s\n", + psData[scriptps].filename); + return (0); + } + + fprintf(fp, "\t%d\t%d\t%d\t%s\tsetLineAttributes\n", + lineWidth, psCap, psJoin, PSfindGC(gc)); + s = fclose(fp); + } + break; + default: + fprintf(stderr, "GSetLineAttributes request (%d) not implemented yet\n", dFlag); + return (0); + } + return (s); +} + +/* + * This procedure frees the data structure used for GC information, and also + * unlinks the GC dictionary file. + */ + +int +PSClose(void) +{ + if (GChead != NULL) { + + /* free memory used by GC struct */ + + GCptr curGC = GChead; + + while (curGC != NULL) { + GCptr freeGC = curGC; + + curGC = curGC->next; + free(freeGC); + } + } + + /* remove GC dictionary file */ + + return (unlink(psData[GCdictps].filename)); +} + + + + +int +centerX (GC viewGCx,char * theString,int strlength,int windowWidth) +{ + XFontStruct *fontStruct; + GContext con; + int result; + + + con=XGContextFromGC(viewGCx); + fontStruct = XQueryFont(dsply,con); + if(fontStruct == NULL) return(0); + result = (windowWidth - XTextWidth(fontStruct,theString,strlength))/2 - + fontStruct->min_bounds.lbearing; + XFreeFontInfo(NULL,fontStruct,1); + return(result); +} + + +int +centerY (GC viewGCy,int windowHeight) +{ + + XFontStruct *fontStruct; + GContext con; + int result; + + con=XGContextFromGC(viewGCy); + fontStruct = XQueryFont(dsply,con); + if (fontStruct == NULL) return(0); + result = (windowHeight - + (fontStruct->max_bounds.ascent + fontStruct->max_bounds.descent))/2 + + fontStruct->max_bounds.ascent; + XFreeFontInfo(NULL,fontStruct,1); + return(result); + +} + + +/* + * PSColorPolygon draws and fills a polygon given data in XPoint; see + * XFillPolygon + */ + +int +PSColorPolygon( + float r, float g, float b, /* red, green and blue color + * components */ + XPoint * points, /* vertices of polygon */ + int numberOfPoints) /* number of points */ +{ + int i = 0; + FILE *fp; + + if ((fp = fopen(psData[scriptps].filename, "a")) == NULL) { + fprintf(stderr, "PSColorPolygon cannot open %s\n", + psData[scriptps].filename); + return (psError); + } + + psData[colorpolyps].flag = yes; /* sets procedure flag */ + + fprintf(fp, "\t%f\t%f\t%f\tsetrgbcolor\n", r, g, b); + + i = numberOfPoints - 1; + while (i > 0) + { fprintf(fp, "\t%d\t%d\n", points[i].x, points[i].y); + i = i-1; + } + + fprintf(fp, "\t%d\t%d\t%d\tpsColorPoly\n", numberOfPoints, points[i].x, points[i].y); + + return (fclose(fp)); +} + + +/* + * PSColorwOutline draws and also outlines the colored polygon. + */ + +int +PSColorwOutline( + float r, float g, float b, /* red, green and blue color + * components */ + XPoint * points, /* vertices of polygon */ + int numberOfPoints) /* number of points */ +{ + int i = 0; + FILE *fp; + + if ((fp = fopen(psData[scriptps].filename, "a")) == NULL) { + fprintf(stderr, "PSDrawFOL cannot open %s\n", psData[scriptps].filename); + return (psError); + } + + psData[colorwolps].flag = yes; /* sets procedure flag */ + + fprintf(fp, "\t%f\t%f\t%f\tsetrgbcolor\n", r, g, b); + + i = numberOfPoints - 1; + while (i > 0) + { fprintf(fp, "\t%d\t%d\n", points[i].x, points[i].y); + i = i-1; + } + + fprintf(fp, "\t%d\t%d\t%d\tpsFillwOutline\n", + numberOfPoints, points[i].x, points[i].y); + + return (fclose(fp)); +} +/* + * This function does what XDraw would do, notice that only a subset of + * attributes in GC is implemented -- adequate for our purpose now + */ + +int +PSDrawColor( + float r, float g, float b, /* red, green and blue color + * components */ + XPoint *points, /* point list */ + int numberOfPoints) /* vertex count and display flag (X, PS,...) */ +{ + int i = 0; + FILE *fp; + + if ((fp = fopen(psData[scriptps].filename, "a")) == NULL) { + fprintf(stderr, "GDraw cannot open %s\n", + psData[scriptps].filename); + return (psError); + } + + psData[drawcolorps].flag = yes; /* set procedure flag */ + + fprintf(fp, "\t%f\t%f\t%f\tsetrgbcolor\n", r, g, b); + + i = numberOfPoints - 1; + while (i > 0) + { fprintf(fp, "\t%d\t%d\n", points[i].x, points[i].y); + i=i-1; + } + + fprintf(fp, "\t%d\t%d\t%d\tpsDrawColor\n", numberOfPoints, points[i].x, points[i].y); + + return (fclose(fp)); +} +/* + * PSFillPolygon draws and fills a polygon given data in XPoint; see + * XFillPolygon. + */ + +int +PSFillPolygon( + GC gc, /* graphics context */ + XPoint * points, /* vertices of polygon */ + int numberOfPoints) /* number of points */ +{ + int i = 0; + FILE *fp; + + if ((fp = fopen(psData[scriptps].filename, "a")) == NULL) { + fprintf(stderr, "PSFillPolygon cannot open %s\n", + psData[scriptps].filename); + return (psError); + } + + psData[fillpolyps].flag = yes; /* sets procedure flag */ + fprintf(fp, "\t%s\n", PSfindGC(gc)); + + i = numberOfPoints - 1; + while (i > 0) + { fprintf(fp, "\t%d\t%d\n", points[i].x, points[i].y); + i = i-1; + } + + fprintf(fp, "\t%d\t%d\t%d\tpsFillPoly\n", numberOfPoints, points[i].x, points[i].y); + + return (fclose(fp)); +} + +/* + * PSFillwOutline draws and also outlines the filled polygon. + */ + +int +PSFillwOutline( + GC gc, /* graphics context */ + XPoint * points, /* vertices of polygon */ + int numberOfPoints) + /* number of points */ +{ + int i = 0; + FILE *fp; + + if ((fp = fopen(psData[scriptps].filename, "a")) == NULL) { + fprintf(stderr, "PSDrawFOL cannot open %s\n", psData[scriptps].filename); + return (psError); + } + + psData[fillwolps].flag = yes; /* sets procedure flag */ + fprintf(fp, "\t%s\n", PSfindGC(gc)); + + i = numberOfPoints - 1; + while (i > 0) + { fprintf(fp, "\t%d\t%d\n", points[i].x, points[i].y); + i = i-1; + } + + fprintf(fp, "\t%d\t%d\t%d\tpsFillwOutline\n", + numberOfPoints, points[i].x, points[i].y); + + return (fclose(fp)); +} + +static int +TrivEqual(Window s1,Window s2) +{ + return ( s1 == s2); +} + +static int +TrivHash_code(Window s,int size) +{ + return (s % size); +} + + +HashTable * +XCreateAssocTable(int size) +{ + HashTable * table; + table = (HashTable *) malloc(sizeof(HashTable)); + hash_init(table,size,(EqualFunction)TrivEqual,(HashcodeFunction)TrivHash_code); + return table; +} + +void +XMakeAssoc(Display * dsp, HashTable *table, Window w, int * p) +{ + hash_insert(table,(char *) p, (char *) w); +} + +int * +XLookUpAssoc(Display * dsp, HashTable *table,Window w) +{ + return (int *) hash_find(table,(char *)w); +} + +void +XDeleteAssoc(Display * dsp,HashTable * table, Window w) +{ + hash_delete(table,(char *) w); +} + + + + + +@ +\eject +\begin{thebibliography}{99} +\bibitem{1} nothing +\end{thebibliography} +\end{document} diff --git a/src/graph/Gdraws/Makefile.in b/src/graph/Gdraws/Makefile.in new file mode 100644 index 00000000..2c053558 --- /dev/null +++ b/src/graph/Gdraws/Makefile.in @@ -0,0 +1,77 @@ +IN= $(axiom_src_srcdir)/graph/Gdraws +OUT= $(axiom_target_libdir) +PS= $(axiom_target_libdir)/graph +DOC= $(axiom_target_docdir)/src/graph + +# local include files shared by graphics +LINC= $(axiom_src_srcdir)/graph/include + +# global include files shared by everyone +GINC= $(axiom_src_srcdir)/include + +# include files in Hyperdoc +HINC= $(axiom_src_srcdir)/hyper + +# bitmaps for cursors +BIT= $(axiom_src_srcdir)/graph/include/bitmaps + +# a .h file stuck in a really wierd place +DOTH= $(axiom_src_srcdir)/graph/viewman + +# a .c file in the library subdirectory +DOTC= $(axiom_src_srcdir)/lib + +pamphlets = Gfun.c.pamphlet psFiles.pamphlet Makefile.pamphlet + +AXIOM_CFLAGS = ${CCF} -I${LINC} -I${GINC} -I$(srcdir) -I${HINC} \ + $(axiom_includes) ${AXIOM_X11_CFLAGS} + + +subdir = src/graph/Gdraws/ + +pamphlets = Makefile.pamphlet Gfun.c.pamphlet psFiles.pamphlet + +HEADERS = ${IN}/Gdraws0.h ${LINC}/G.h ${LINC}/Gfun.H1 \ + ${GINC}/hash.h ${GINC}/hash.H1 ${GINC}/useproto.h \ + $(axiom_c_macros_h) + +PSFiles= ${PS}/colorpoly.ps ${PS}/colorwol.ps ${PS}/draw.ps \ + ${PS}/drawIstr.ps ${PS}/drawarc.ps ${PS}/drawcolor.ps \ + ${PS}/drawline.ps ${PS}/drawlines.ps ${PS}/drawpoint.ps \ + ${PS}/drawrect.ps ${PS}/drawstr.ps ${PS}/drwfilled.ps \ + ${PS}/end.ps ${PS}/fillarc.ps ${PS}/fillpoly.ps \ + ${PS}/fillwol.ps ${PS}/header.ps ${PS}/setup.ps + +.SUFFIXES: +.SUFFIXES: .c .lo .h .ps + +.PHONY: all all-ax all-Gdraws +all: all-ax +all-ax all-Gdraws: stamp + @ echo finished making $(axiom_src_srcdir)/Gdraws + +.PHONY: PSfiles.post +stamp: Gfun.$(OBJEXT) $(PSfiles) + @rm -f stamp + $(STAMP) stamp + +$(PS)/%.ps: $(srcdir)/psFiles.pamphlet + $(axiom_build_document) --tangle=$* --output=$@ $< + +Gfun.c: $(srcdir)/Gfun.c.pamphlet + $(axiom_build_document) --tangle --output=$@ $< + +Gfun.$(OBJEXT): ${HEADERS} + +Gfun.$(OBJEXT): $(builddir)/Gfun.c + ${COMPILE} -o $@ $(CFLAGS) $(AXIOM_CFLAGS) $< + + +mostlyclean-local: + @rm -f Gfun.$(OBJEXT) + +clean-local: mostlyclean-local + @rm -f $(PSFiles) + +distclean-local: clean-local + diff --git a/src/graph/Gdraws/Makefile.pamphlet b/src/graph/Gdraws/Makefile.pamphlet new file mode 100644 index 00000000..40b013c6 --- /dev/null +++ b/src/graph/Gdraws/Makefile.pamphlet @@ -0,0 +1,229 @@ +%% Oh Emacs, this is a -*- Makefile -*-, so give me tabs. +\documentclass{article} +\usepackage{axiom} + +\title{\$SPAD/src/graph/Gdraws Makefile} +\author{Timothy Daly \and Gabriel Dos~Reis} + +\begin{document} +\maketitle + +\begin{abstract} +\end{abstract} +\eject + +\tableofcontents +\eject + +\section{Gdraws} + +This directory consists of all the Gdraw functions along with a local +testing protocol to test out these functions. +The subdirectory PS contains all the ps drawing functions in support of +the Gdraw functions. + +\subsection{GDRAW} + +A Gdraw function, using a draw option dFlsg as input, provides drawings +capability on different output devices. Currently, Gdraw supports routines +both in Xwindows functions, and in postscript functions on +a postscript printer/interpreter. + +The general drawing functions are (see file for description of functionality) +\begin{verbatim} + 1. Gdrawarc.c + 2. Gdrawstring.c + 3. Gdraw.c + 4. Gdrawline.c + 5. Gdrfilled.c + 6. GdrawFrame.c + 7. Gdrawlines.c + 8. Gfillarc.c + 9. GdrawIstr.c + 10. Gdrawrect.c + 11. Gmisc.c + 12. GinitPS.c + 13. GCreatePS.c + 14. PSFill.c + 15. ../include/G.h + header information needed by all the Gdraw routines and + view3D/view2D as well. + 16. ps.h + header information needed by only the Gdraw routines. + +\subsection{POSTSCRIPT} + +A PostScript file can be generated by using a button on the control +panel of a viewAlone picture, or in Axiom, with the command write, +option Postscript. This file can be submitted to the postsctipt +printer to be printed, or viewed using the postscript interpreter. +It will draw a window, title, and picture clipped to fit inside of the +window. + +In order to generate a postscript output, we first initializ file names and +paths to be used by our program by using +\begin{verbatim} + InitPs(viewWindow, titleWindow) [in GinitPS.c] +\end{verbatim} +then call the G draw routines with option "PS", which would generate postscript +drawing commands. Then create the output file (OUTPUT.ps by default) by using +\begin{verbatim} + makePSfile(viewWindow, titleWindow, title) [in GcreatePS.c] +\end{verbatim} + +The output file would be in local directory, i.e., the directory where Axiom +or viewAlone, etc., was started up. + +The following routines are used to test out the Gdraw functions: +\begin{verbatim} +1. main.c creates windows, and titles and processes Xwindow events. +2. data.c creates data for drawing and call Gdraw routines. +3. menu.c draws menu when mouse clicks in viewWindow +4. yesORno.c determines if mouse click in menu means "yes" or "no". +5. loadFont.c loads font for display +\end{verbatim} + +The Gdraw routines have been written in such a way that they are usable by +both view3D and view2D. + +\subsection{TO USE G FUNCTIONS} + +In order to draw in postscript, use GSetForeground to set the foreground +colors for the drawing (and fill) functions. Use GSetLineAttributes +to set line attributes. And finally, replace the XDraw commands with the +corresponding GDraw commands with the appropriate parameters. In addition, +we need to: draw frame, set GC variable names, create GCs, initialize +postscript data structures, cat all the procedures used together. + +{\bf IMPORTANT}:\\ +In order to create postscript command file, we need environment +variable DEVE (i.e., setenv DEVE /u/jimwen/3D/version28) or AXIOM (e.g., setenv +AXIOM /spad/mnt/rt in case Gdraws directory has been installed on the server). +Without this path, the program would not know where the postscript files (in +Gdraws/PS) are. + +{\bf LIMITATIONS} of current implementation:\\ +A picture is printed with 1 inch x direction, and 1 inch y direction +offset, and the largest complete picutre is the size of the page +with the offest. + +{\bf BUGS}:\\ +The region box is not drawn correctly when perspective is altered. + + +{\bf FUTURE DIRECTIONS}: +\begin{itemize} +\item for view3D color rendering, may want to convert LINE drawing color +to the appropriate grayscale. Right now, they're all drawn in black. +\item for view3D's routines for color rendering, may want to implement +color drawing for postscript functions just in case someone does +have access to a color postscript printer. +\item implement more functionality for attributes used in GC, i.e., dashed +line, dotted line etc. +\item implement a display postscript menu to set things like picture size, +landscape/portrait orientation, picture centered, left, right, up, +down, etc., reversed video. +\item make font an attribute in postscripts's graphics context so the +font can be set in user program. Right now, it uses only 1 font. +\item for view2D's stuff, implement a smaller font for the drawing the +units on the axes. +\end{itemize} + +\section{environment variables} +<<environment>>= +IN= $(axiom_src_srcdir)/graph/Gdraws +OUT= $(axiom_target_libdir) +PS= $(axiom_target_libdir)/graph +DOC= $(axiom_target_docdir)/src/graph + +# local include files shared by graphics +LINC= $(axiom_src_srcdir)/graph/include + +# global include files shared by everyone +GINC= $(axiom_src_srcdir)/include + +# include files in Hyperdoc +HINC= $(axiom_src_srcdir)/hyper + +# bitmaps for cursors +BIT= $(axiom_src_srcdir)/graph/include/bitmaps + +# a .h file stuck in a really wierd place +DOTH= $(axiom_src_srcdir)/graph/viewman + +# a .c file in the library subdirectory +DOTC= $(axiom_src_srcdir)/lib + +pamphlets = Gfun.c.pamphlet psFiles.pamphlet Makefile.pamphlet + +AXIOM_CFLAGS = ${CCF} -I${LINC} -I${GINC} -I$(srcdir) -I${HINC} \ + $(axiom_includes) ${AXIOM_X11_CFLAGS} + +@ +\section{Gdraw code} +\subsection{Gfun} +<<Gfun.c>>= +Gfun.c: $(srcdir)/Gfun.c.pamphlet + $(axiom_build_document) --tangle --output=$@ $< + +@ + +<<Gfun.o>>= +Gfun.$(OBJEXT): ${HEADERS} + +Gfun.$(OBJEXT): $(builddir)/Gfun.c + ${COMPILE} -o $@ $(CFLAGS) $(AXIOM_CFLAGS) $< + +@ + +<<*>>= +<<environment>> + +subdir = src/graph/Gdraws/ + +pamphlets = Makefile.pamphlet Gfun.c.pamphlet psFiles.pamphlet + +HEADERS = ${IN}/Gdraws0.h ${LINC}/G.h ${LINC}/Gfun.H1 \ + ${GINC}/hash.h ${GINC}/hash.H1 ${GINC}/useproto.h \ + $(axiom_c_macros_h) + +PSFiles= ${PS}/colorpoly.ps ${PS}/colorwol.ps ${PS}/draw.ps \ + ${PS}/drawIstr.ps ${PS}/drawarc.ps ${PS}/drawcolor.ps \ + ${PS}/drawline.ps ${PS}/drawlines.ps ${PS}/drawpoint.ps \ + ${PS}/drawrect.ps ${PS}/drawstr.ps ${PS}/drwfilled.ps \ + ${PS}/end.ps ${PS}/fillarc.ps ${PS}/fillpoly.ps \ + ${PS}/fillwol.ps ${PS}/header.ps ${PS}/setup.ps + +.SUFFIXES: +.SUFFIXES: .c .lo .h .ps + +.PHONY: all all-ax all-Gdraws +all: all-ax +all-ax all-Gdraws: stamp + @ echo finished making $(axiom_src_srcdir)/Gdraws + +.PHONY: PSfiles.post +stamp: Gfun.$(OBJEXT) $(PSfiles) + @rm -f stamp + $(STAMP) stamp + +$(PS)/%.ps: $(srcdir)/psFiles.pamphlet + $(axiom_build_document) --tangle=$* --output=$@ $< + +<<Gfun.c>> +<<Gfun.o>> + +mostlyclean-local: + @rm -f Gfun.$(OBJEXT) + +clean-local: mostlyclean-local + @rm -f $(PSFiles) + +distclean-local: clean-local + +@ +\eject +\begin{thebibliography}{99} +\bibitem{1} nothing +\end{thebibliography} +\end{document} diff --git a/src/graph/Gdraws/data.c.pamphlet b/src/graph/Gdraws/data.c.pamphlet new file mode 100644 index 00000000..70c113b6 --- /dev/null +++ b/src/graph/Gdraws/data.c.pamphlet @@ -0,0 +1,256 @@ +\documentclass{article} +\usepackage{axiom} +\begin{document} +\title{\$SPAD/src/graph data.c} +\author{The Axiom Team} +\maketitle +\begin{abstract} +\end{abstract} +\eject +\tableofcontents +\eject +\section{License} +<<license>>= +/* +Copyright (c) 1991-2002, The Numerical ALgorithms Group Ltd. +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + + - Neither the name of The Numerical ALgorithms Group Ltd. nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS +IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A +PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER +OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ +@ +<<*>>= +<<license>> + +/* Data file to test out Gdraw functions */ + +#include "Gdraws0.h" +#include "../view3D/header.h" +#include "noX10.h" + +extern GC gc, gc1; + +int +Gdraws_data(int dFlag) +{ + static Vertex vlist[5]; + static int vcount = 5; + static int x0, y0, x1, y1; + static char *str = "This is a text string."; + static int x, y; + static int FirstTime = yes; + static int Rx, Ry, Rwidth, Rheight; + static int Ix, Iy; + static char *Istr = "Image text string."; + static XPoint points[7]; + static XPoint p1[7]; + static int np1 = 7; + static int npoints, mode; + static int ax, ay, angle1, angle2; + static unsigned int awidth, aheight; + static Vertex dfvlist[7]; + static int dfvcount = 7; + static XPoint dfvl1[7]; + static int dfvc = 7; + + if (FirstTime) { + + vlist[0].x = 10; + vlist[0].y = 10; + vlist[0].flags = 0; + + vlist[1].x = 250; + vlist[1].y = 10; + vlist[1].flags = 0; + + vlist[2].x = 250; + vlist[2].y = 140; + vlist[2].flags = 0; + + vlist[3].x = 10; + vlist[3].y = 140; + vlist[3].flags = 0; + + vlist[4].x = 10; + vlist[4].y = 10; + vlist[4].flags = 0; + + x0 = y0 = 12; + x1 = 248; + y1 = 138; + + x = 25; + y = 50; + + Ix = 20; + Iy = 180; + + Rx = 160; + Ry = 40; + Rwidth = 30; + Rheight = 80; + + points[0].x = 80; + points[0].y = 95; + points[1].x = 30; + points[1].y = 15; + points[2].x = 120; + points[2].y = 70; + points[3].x = 25; + points[3].y = 180; + points[4].x = 43; + points[4].y = 56; + points[5].x = 270; + points[6].y = 0; + points[6].x = 0; + points[5].y = 160; + + p1[0].x = 2; + p1[0].y = 155; + p1[1].x = 99; + p1[1].y = 39; + p1[2].x = 260; + p1[2].y = 75; + p1[3].x = 33; + p1[3].y = 170; + p1[4].x = 4; + p1[4].y = 111; + p1[5].x = 203; + p1[6].y = 33; + p1[6].x = 170; + p1[5].y = 200; + + npoints = 7; + mode = CoordModeOrigin; /* there's also CoordModePrevious */ + + ax = 130; + ay = 100; + awidth = 165; + aheight = 95; + angle1 = 165; + angle2 = -330; + + dfvlist[0].x = 300; + dfvlist[0].y = 0; + dfvlist[0].flags = 0; + + dfvlist[1].x = 200; + dfvlist[1].y = 0; + dfvlist[1].flags = 0; + + dfvlist[2].x = 200; + dfvlist[2].y = 100; + dfvlist[2].flags = 0; + + dfvlist[3].x = 100; + dfvlist[3].y = 100; + dfvlist[3].flags = 0; + + dfvlist[4].x = 100; + dfvlist[4].y = 200; + dfvlist[4].flags = 0; + + dfvlist[5].x = 0; + dfvlist[5].y = 200; + dfvlist[5].flags = 0; + + dfvlist[6].x = 300; + dfvlist[6].y = 0; + dfvlist[6].flags = 0; + + dfvl1[0].x = 0; + dfvl1[0].y = 300; + dfvl1[1].x = 0; + dfvl1[1].y = 200; + dfvl1[2].x = 100; + dfvl1[2].y = 200; + dfvl1[3].x = 100; + dfvl1[3].y = 100; + dfvl1[4].x = 200; + dfvl1[4].y = 100; + dfvl1[5].x = 200; + dfvl1[5].y = 0; + dfvl1[6].x = 0; + dfvl1[6].y = 300; + + FirstTime = no; + } + + if (dFlag == PS) { + GSetForeground(gc1, 0.3125, PS); + if (PSFillwOutline(gc1, dfvl1, dfvc) == psError) + return (psError); + } + + if (GDrawString(gc, viewport->viewWindow, x, y, str, strlen(str), dFlag) + == psError) + return (psError); + + + if (GDrawLine(gc, viewport->viewWindow, x0, y0, x1, y1, dFlag) == psError) + return (psError); + + if (GDrawRectangle(gc, viewport->viewWindow, Rx, Ry, Rwidth, Rheight, dFlag) + == psError) + return (psError); + + if (GDrawLines(gc, viewport->viewWindow, points, npoints, mode, dFlag) + == psError) + return (psError); + + if (GDrawArc(gc, viewport->viewWindow, ax, ay, awidth, aheight, angle1 * 64, + angle2 * 64, dFlag) == psError) + return (psError); + + GSetForeground(gc1, (float) psBlack, dFlag); + GSetBackground(gc1, (float) psWhite, dFlag); + if (GFillArc(gc1, viewport->viewWindow, 20, ay - 20, awidth / 2, aheight / 2, + angle1 * 64, angle2 * 64, dFlag) == psError) + return (psError); + + + GSetForeground(gc1, (float) psWhite, dFlag); + GSetBackground(gc1, (float) psBlack, dFlag); + if (GDrawImageString(gc1, viewport->viewWindow, Ix, Iy, + Istr, strlen(Istr), dFlag) == psError) + return (psError); + + if (dFlag == PS) { + GSetForeground(gc1, 0.8, dFlag); + PSFillPolygon(gc1, p1, np1); + PSColorPolygon(0.2, 0.4, 0.8, p1, np1); + } + + return (1); +} +@ +\eject +\begin{thebibliography}{99} +\bibitem{1} nothing +\end{thebibliography} +\end{document} diff --git a/src/graph/Gdraws/loadFont.c.pamphlet b/src/graph/Gdraws/loadFont.c.pamphlet new file mode 100644 index 00000000..72484e13 --- /dev/null +++ b/src/graph/Gdraws/loadFont.c.pamphlet @@ -0,0 +1,71 @@ +\documentclass{article} +\usepackage{axiom} +\begin{document} +\title{\$SPAD/src/graph loadFont.c} +\author{The Axiom Team} +\maketitle +\begin{abstract} +\end{abstract} +\eject +\tableofcontents +\eject +\section{License} +<<license>>= +/* +Copyright (c) 1991-2002, The Numerical ALgorithms Group Ltd. +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + + - Neither the name of The Numerical ALgorithms Group Ltd. nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS +IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A +PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER +OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ +@ +<<*>>= +<<license>> + + +/* load_font for display to test out Gdraw functions in this directory */ + +#include "Gdraws0.h" +#include "../include/G.h" + +#include <stdio.h> + +void +Gdraws_load_font(XFontStruct **font_info, char *fontname) +{ + if ((*font_info = XLoadQueryFont(dsply, fontname)) == NULL) { + fprintf(stderr, "cannot open font %s\n", fontname); + exit(-1); + } +} +@ +\eject +\begin{thebibliography}{99} +\bibitem{1} nothing +\end{thebibliography} +\end{document} diff --git a/src/graph/Gdraws/main.c.pamphlet b/src/graph/Gdraws/main.c.pamphlet new file mode 100644 index 00000000..838b4bbb --- /dev/null +++ b/src/graph/Gdraws/main.c.pamphlet @@ -0,0 +1,215 @@ +\documentclass{article} +\usepackage{axiom} +\begin{document} +\title{\$SPAD/src/graph main.c} +\author{The Axiom Team} +\maketitle +\begin{abstract} +\end{abstract} +\eject +\tableofcontents +\eject +\section{License} +<<license>>= +/* +Copyright (c) 1991-2002, The Numerical ALgorithms Group Ltd. +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + + - Neither the name of The Numerical ALgorithms Group Ltd. nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS +IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A +PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER +OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ +@ +<<*>>= +<<license>> + + +/* main procedure to test out Gdraw functions in this directory */ +#include <stdio.h> +#include "Gdraws0.h" +#include "../view3D/header.h" + +GC gc, gc1; +Display *dsply; +int scrn; +viewPoints *viewport; + +int psInit=no; +GCptr GChead=NULL; +char *PSfilename="OUTPUT.ps"; +char *envAXIOM; + +int +main(int argc, char **argv) +{ + + XGCValues values; + + XEvent report; + int x0=0, y0=0, width=300, height=200, border=3; + + char *fontname = "6x13"; + XFontStruct *dsp_font; + + Window menu; + char *str1 = " Print out the PostScript file? ", + *str0 = "Generate a PostScript file (OUTPUT.ps)?"; + int m_width, m_height, flag=yes; + + /* open display */ + if ((dsply = XOpenDisplay(NULL)) == NULL) { + printf("Can't open display NULL\n"); + exit(-1); + } + + scrn = DefaultScreen(dsply); + + /* access font */ + Gdraws_load_font(&dsp_font, fontname); + + values.background = WhitePixel(dsply, scrn); + values.foreground = BlackPixel(dsply, scrn); + + gc = XCreateGC(dsply, RootWindow(dsply, scrn), + (GCForeground | GCBackground), &values); + PSGlobalInit(); /* must initiate before using G/PS functions */ + PSCreateContext(gc, "gc", psNormalWidth, psButtCap, + psMiterJoin, psWhite, psBlack); + XSetFont(dsply, gc, dsp_font->fid); + gc1 = XCreateGC(dsply, RootWindow(dsply, scrn), + (GCForeground | GCBackground), &values); + PSCreateContext(gc1, "gc1", psNormalWidth, psButtCap, psMiterJoin, + psWhite, psBlack); + XSetFont(dsply, gc1, dsp_font->fid); + + if (!(viewport = (viewPoints *)malloc(sizeof(viewPoints)))) { + fprintf(stderr,"Ran out of memory (malloc) trying to create a viewport.\n"); + exit(-1); + } + + viewport->titleWindow = XCreateSimpleWindow(dsply, RootWindow(dsply,scrn), + x0, y0, width+6, + height+32+height/4, border, + BlackPixel(dsply, scrn), + WhitePixel(dsply, scrn)); + + viewport->viewWindow = XCreateSimpleWindow(dsply, viewport->titleWindow, + x0, y0+20, width, height, border, + BlackPixel(dsply, scrn), + WhitePixel(dsply, scrn)); + + strcpy(viewport->title, "what is a test title?"); + + m_width = width; m_height = height/4; + menu = XCreateSimpleWindow(dsply, viewport->titleWindow, x0, y0+20+height+6, + m_width, m_height, border, + BlackPixel(dsply,scrn), WhitePixel(dsply,scrn)); + + XSelectInput(dsply, viewport->viewWindow, + KeyPressMask|ButtonPressMask|ExposureMask); + XSelectInput(dsply, viewport->titleWindow, KeyPressMask|ExposureMask); + XSelectInput(dsply, menu, KeyPressMask|ButtonPressMask|ExposureMask); + + XMapWindow(dsply, viewport->viewWindow); + XMapWindow(dsply, viewport->titleWindow); + XFlush(dsply); + + while (yes) { + XNextEvent(dsply, &report); + switch (report.type) { + + case Expose: + if (report.xexpose.window==viewport->titleWindow) { + if (GDrawImageString(gc, viewport->titleWindow, + 20, 15, viewport->title, + strlen(viewport->title),X) == psError) + printf("screen draw image string failed.\n"); + if (Gdraws_data(X) == psError) + printf("screen Gdraws_data failed.\n"); + } + if (report.xexpose.window==viewport->viewWindow) { + if (Gdraws_data(X) == psError) + printf("screen Gdraws_data failed.\n"); + } + else if (report.xexpose.window==menu) { + if (flag) + Gdraws_draw_menu(menu, str0, m_width, m_height); + else + Gdraws_draw_menu(menu, str1, m_width, m_height); + } + break; + + case ButtonPress: + if (report.xbutton.window==viewport->viewWindow) { + XMapWindow(dsply, menu); + XFlush(dsply); + } + else if (report.xbutton.window==menu && flag) { + XUnmapWindow(dsply, menu); + if (Gdraws_pressed_yes(m_width, m_height, report.xbutton.x, + report.xbutton.y)) { + flag=no; + XMapWindow(dsply, menu); + PSInit(viewport->viewWindow, viewport->titleWindow); + if (Gdraws_data(PS) != psError) + PSCreateFile(3,viewport->viewWindow, + viewport->titleWindow,viewport->title); + else printf("PS Gdraws_data failed.\n"); + } + } + else if (report.xbutton.window==menu && !flag) { + XUnmapWindow(dsply, menu); + if (Gdraws_pressed_yes(m_width, m_height, report.xbutton.x, + report.xbutton.y)) + system("print OUTPUT.ps"); + flag = yes; + } + break; + + case KeyPress: + if (report.xkey.window==viewport->viewWindow || + report.xkey.window==viewport->titleWindow) { + XFreeGC(dsply, gc); + XFreeGC(dsply, gc1); + XCloseDisplay(dsply); + PSClose(); + exit(1); + } + else if (report.xkey.window==menu) XUnmapWindow(dsply, menu); + + default: + break; + } + } + return 0; +} +@ +\eject +\begin{thebibliography}{99} +\bibitem{1} nothing +\end{thebibliography} +\end{document} diff --git a/src/graph/Gdraws/menu.c.pamphlet b/src/graph/Gdraws/menu.c.pamphlet new file mode 100644 index 00000000..7219f8d6 --- /dev/null +++ b/src/graph/Gdraws/menu.c.pamphlet @@ -0,0 +1,82 @@ +\documentclass{article} +\usepackage{axiom} +\begin{document} +\title{\$SPAD/src/graph menu.c} +\author{The Axiom Team} +\maketitle +\begin{abstract} +\end{abstract} +\eject +\tableofcontents +\eject +\section{License} +<<license>>= +/* +Copyright (c) 1991-2002, The Numerical ALgorithms Group Ltd. +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + + - Neither the name of The Numerical ALgorithms Group Ltd. nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS +IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A +PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER +OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ +@ +<<*>>= +<<license>> + +/* menu of display used for testing out Gdraw functions in this directory */ +#include "Gdraws0.h" +#include "../include/G.h" + +extern GC gc; + +void +Gdraws_draw_menu(Window menu, char *str, int width, int height) +{ + char *str1 = "y e s", *str2 = "n o"; + int x0=0, y0=0; + + XDrawString(dsply, menu, gc, 30, height/4+3, str, strlen(str)); + + XFillArc(dsply, menu, gc, 35, height/3+5, width/2-50, height/3*2-10, + 0*64, 360*64); + + XFillArc(dsply, menu, gc, width/2+5, height/3+5, width/2-50, height/3*2-10, + 0*64, 360*64); + + XSetForeground(dsply, gc, WhitePixel(dsply, scrn)); + XDrawString(dsply, menu, gc, width/4-5, height/3*2+3, str1, strlen(str1)); + XDrawString(dsply, menu, gc, width/4*3-28,height/3*2+3, str2, strlen(str2)); + XSetForeground(dsply, gc, BlackPixel(dsply, scrn)); + + XFlush(dsply); +} +@ +\eject +\begin{thebibliography}{99} +\bibitem{1} nothing +\end{thebibliography} +\end{document} diff --git a/src/graph/Gdraws/psFiles.pamphlet b/src/graph/Gdraws/psFiles.pamphlet new file mode 100644 index 00000000..80799360 --- /dev/null +++ b/src/graph/Gdraws/psFiles.pamphlet @@ -0,0 +1,635 @@ +\documentclass{article} +\usepackage{axiom} +\begin{document} +\title{\$SPAD/src/graph/Gdraws psFiles} +\author{Timothy Daly} +\maketitle +\begin{abstract} +\end{abstract} +\eject +\tableofcontents +\eject +\section{The postscript command definitions} +\subsection{colorpoly} +\begin{verbatim} +operand stack configuration in order to use psColorPoly: + psFillPoly + XPoint[0].y + XPoint[0].x + n + ... + XPoint[n].y + XPoint[n].x + graphics-context dictionary +this draws a polygon by connecting all the points and fills the +region with foreground color +\end{verbatim} +<<colorpoly>>= +/psColorPoly + { gsave + newpath + yVal moveto + 1 sub { + yVal lineto + } repeat + closepath + fill %% fills with foreground color + grestore } + def + +@ +\subsection{colorwol} +\begin{verbatim} +operand stack configuration in order to use psDrawFilled: + psFillwOL + XPoint[0].y + XPoint[0].x + n + ... + XPoint[n].y + XPoint[n].x + graphics-context dictionary +this draws lines connecting all the points and fills the +region with background color (default: 1, or white). +\end{verbatim} +<<colorwol>>= +/psColorwOutline + { gsave + newpath + yVal moveto + 1 sub { + yVal lineto + } repeat + closepath + begin gsave fill grestore %% fills with foreground color + 0 setgray stroke grestore end } %% outline it with black + def + +@ +\subsection{drawarc} +\begin{verbatim} +operand stack configuration in order to use psDrawArc: + psDrawArc + angle2 + angle1 + width + height + y + x + graphics-context dictionary +this draws an arc whose origin is at x, y, and whose width +and height specifies the rectangle which encases the arc. +Origin is at upper left corner of rectangle. +This function uses "scale" to make cricles and ellipses. +\end{verbatim} +<<drawarc>>= +/psDrawArc + { gsave + newpath + /sfactor 4 index 4 index div def %% scale factor + 1 sfactor scale + 6 5 roll %% x on top of stack + 3 index 2 div add %% define x origin + 6 5 roll %% y on top of stack + 6 5 roll %% h on top of stack + 2 div add yVal sfactor div %% define y origin + 5 4 roll %% w on top of stack + 2 div %% define radius + 5 3 roll %% a1 a2 on top of stack + 1 index add + arcn %% draw clockwise arc + begin installGC stroke end + grestore } + def + +@ +\subsection{drawcolor} +\begin{verbatim} +operand stack configuration in order to use psDrawColor: + psDraw + vlist[0].y + vlist[0].x + n + ... + vlist[n].y + vlist[n].x + graphics-context dictionary +to draw lines connecting points in vlist[0] to vlist[n] +\end{verbatim} +<<drawcolor>>= +/psDrawColor + { gsave + newpath + yVal moveto %% set currentpoint + 1 sub { %% loop to draw lines. + yVal lineto + } repeat + stroke %% draw in foreground color + grestore } + def + +@ +\subsection{drawIstr} +\begin{verbatim} +operand stack configuration in order to use psDrawIStr: + psDrawIStr + window type: title or window + string + y + x + graphics-context dictionary +it draws a text string in foreground color on top of bounding box of +string, which is in background color. +\end{verbatim} +<<drawIstr>>= +/psDrawIStr + { gsave + newpath %% for rectangle + loadFont + + /window exch def %% get window type + + %% draw bounding box with background color + /str exch def %% get text string + str stringwidth pop 1 sub %% width + FontHeight 1 sub %% height + currentfont begin %% get font height + FontBBox + end + /ypos exch def pop %% define ypos + neg ypos add /offset exch def pop + /offset ypos offset div FontHeight mul def %% define offset + /h exch def /w exch def %% define h + /y0 exch def %% define y0 + /x0 exch def %% define x0 + w h x0 y0 offset sub + window (title) eq + {hVal moveto drawRect} %% draws in title window + {rectangle} ifelse %% draws in view window + begin + BGcolor setgray fill %% set background box color + + x0 y0 + window (title) eq + {hVal} %% print title text + {yVal} ifelse %% print window text + moveto str + FGcolor setgray show %% set text color + end + grestore } + def + +@ +\subsection{drawline} +\begin{verbatim} +operand stack configuration in order to use psDrawLine: + psDrawLine + y0 + x0 + y1 + x1 + graphics-context dictionary +this draws a line from (x0, y0) to (x1, y1). +\end{verbatim} +<<drawline>>= +/psDrawLine + { gsave + newpath + yVal moveto + yVal lineto + begin installGC stroke end + grestore } + def + +@ +\subsection{drawlines} +\begin{verbatim} +operand stack configuration in order to use psDrawLines: + psDrawLines + points[0].y + points[0].x + n + ... + points[n].y + points[n].x + graphics-context dictionary +this draws lines connecting all the points. +\end{verbatim} +<<drawlines>>= +/psDrawLines + { gsave + newpath + yVal moveto + 1 sub { + yVal lineto + } repeat + begin installGC stroke end + grestore } + def + +@ +\subsection{drawpoint} +\begin{verbatim} +operand stack configuration in order to use psDrawPoint: + psDrawPoint + y0 + x0 + graphics-context dictionary +this draws a point at (x0, y0). +\end{verbatim} +<<drawpoint>>= +/psDrawPoint + { gsave + newpath + yVal moveto + yVal lineto + begin installGC stroke end %%fills with foreground color + grestore } + def + +@ +\subsection{draw} +\begin{verbatim} +operand stack configuration in order to use psDraw: + psDraw + vlist[0].y + vlist[0].x + n + ... + vlist[n].y + vlist[n].x + graphics-context dictionary +to draw lines connecting points in vlist[0] to vlist[n] +\end{verbatim} +<<draw>>= +/psDraw + { gsave + newpath + yVal moveto %% set currentpoint + 1 sub { %% loop to draw lines. + yVal lineto + } repeat + begin installGC stroke end %% draw in foreground color + grestore } + def + +@ +\subsection{drawrect} +\begin{verbatim} +operand stack configuration in order to use psDrawRect: + psDrawRect + y + x + height + width + graphics-context dictionary +this draws an outline of a rectangle whose origin is at (x,y) and is width ++ 1 wide and height + 1 tall. +\end{verbatim} +<<drawrect>>= +/psDrawRect + { gsave + newpath + rectangle + begin installGC stroke end + grestore } + def + +@ +\subsection{drawstr} +\begin{verbatim} +operand stack configuration in order to use psDrawStr: + psDrawStr + y + x + string + graphics-context dictionary +this function draws a text string at (x,y). +\end{verbatim} +<<drawstr>>= +/psDrawStr + { gsave + newpath + loadFont + yVal moveto + exch begin installGC show end + grestore } + def + +@ +\subsection{drwfilled} +\begin{verbatim} +operand stack configuration in order to use psDrawFilled: + psDrawFilled + vlist[0].y + vlist[0].x + n + ... + vlist[n].y + vlist[n].x + graphics-context dictionary +this draws lines connecting all the points and fills the +region with background color (default: 1, or white). +\end{verbatim} +<<drwfilled>>= +/psDrawFilled + { gsave + newpath + yVal moveto + 1 sub { + yVal lineto + } repeat + begin installGC fill end %% fills with foreground color + grestore } + def + +@ +\subsection{end} +\begin{verbatim} +\end{verbatim} +<<end>>= + + cleartomark %% clearing operand stack + +end %% pops mainDict from dictionary stack + +showpage + +%-------------------------- end --------------------------% +@ +\subsection{fillarc} +\begin{verbatim} +operand stack configuration in order to use psFillArc: + psFillArc + y center of rectangle + x center of rectangle + angle2 + angle1 + width + height + y + x + graphics-context dictionary +this draws and fills an arc whose origin is at x, y, and whose width +and height specifies the rectangle which encases the arc. +Origin is at upper left corner of rectangle. +This function uses "scale" to make cricles and ellipses. +\end{verbatim} +<<fillarc>>= +/psFillArc + { gsave + yVal moveto + newpath + /sfactor 4 index 4 index div def + 1 sfactor scale + 6 5 roll %% x on top of stack + 3 index 2 div add %% define x origin + 6 5 roll %% y on top of stack + 6 5 roll %% h on top of stack + 2 div add yVal sfactor div %% define y origin + 5 4 roll %% w on top of stack + 2 div %% define radius + 5 3 roll %% a1 a2 now on top + 1 index add + arc %% draw clockwise arc + begin installGC fill end %% fills with foreground color + grestore } + def + +@ +\subsection{fillpoly} +\begin{verbatim} +operand stack configuration in order to use psDrawFilled: + psFillPoly + XPoint[0].y + XPoint[0].x + n + ... + XPoint[n].y + XPoint[n].x + graphics-context dictionary +this draws a polygon by connecting all the points and fills the +region with foreground color +\end{verbatim} +<<fillpoly>>= +/psFillPoly + { gsave + newpath + yVal moveto + 1 sub { + yVal lineto + } repeat + closepath + begin installGC fill end %% fills with foreground color + grestore } + def + +@ +\subsection{fillwol} +\begin{verbatim} +operand stack configuration in order to use psDrawFilled: + psFillwOL + XPoint[0].y + XPoint[0].x + n + ... + XPoint[n].y + XPoint[n].x + graphics-context dictionary +this draws lines connecting all the points and fills the +region with background color (default: 1, or white). +\end{verbatim} +<<fillwol>>= +/psFillwOutline + { gsave + newpath + yVal moveto + 1 sub { + yVal lineto + } repeat + closepath + begin installGC + gsave fill grestore %% fills with foreground color + 0 setgray stroke grestore end } %% outline it with black + def + +@ +\subsection{header} +\begin{verbatim} +\end{verbatim} +<<header>>= +%!PS-Adobe-2.0 +%%DocumentFonts: Times-Roman +%%Creator: AXIOM +%%CreationDate: today +%%Pages: 1 +%%processing (hard) limit: 250 pts or 500 values for the operand stack. +%%EndComments + +%------------------------------- prologue -------------------------------% +%-------------------------- support procedures --------------------------% + +%--------- first create user dictionary with 100 entries max ------------% +% (number can be changed to accomodate definitions) % + +100 dict begin %% using 100 entries in top level dictionary + +/FontHeight 12 def + +/inch + { 72 mul } + def + +% yVal and hVal are necessary because the Xwindow display origin +% is at the upper left corner, while the postscript display +% origin is at the lower left hand corner. + +/yVal %% get Y value -- make upper left corner origin + { maxY exch sub } %% maxY is viewWindow height + def + +/hVal %% get H value -- used for displaying title text + { maxH sub abs } %% maxH is viewWindow height+titleWindow height + def + +% loads in the font + +/loadFont + { /Times-Roman findfont FontHeight scalefont setfont } + def + +% draws a rectangle with input operand: +% height +% width +% notice that this function does not "draw" or ink the rectangle. +/drawRect + { 1 index 1 add 0 rlineto %% draw first side + 0 exch 1 add neg rlineto %% draw second side + 1 add neg 0 rlineto %% draw third side + closepath } %% draw fourth side + def + +% create a rectangle with input operand in the view window: +% y +% x +% height +% width +% notice that this function does not "draw" or ink the rectangle. +/rectangle + { yVal moveto %% set currentpoint for line + drawRect } %% draws the rectangle + def + +% These are global variables that every draw procedure uses +% THe operand should be as follows: +% viewWindow width +% viewWindow height +% title height +/setDim + { /maxX exch def %% width of display + /maxY exch def %% height of display + /titleH exch def %% height of title + /maxH maxY titleH add def %% height of display + title + } def + +%-------------------------- major procedures --------------------------% + +/title %% draws a rectangle around the title of picture + { gsave + newpath + moveto %% lower left of title + titleH 1 add 0 exch rlineto %% draw first side + 1 add 0 rlineto %% draw second side + 1 add neg 0 exch rlineto + begin installGC stroke end %% draw third side + grestore } + def + +/drawFrame %% draw display frame + { gsave + newpath + maxX maxY 0 0 rectangle + begin installGC stroke end + grestore } + def + +% updates the foreground color of existing graphics-context dictionary: +% foreground color +% dictionary name +/setForeground + { /FGcolor exch put } + def + +% updates the background color of existing graphics-context dictionary: +% background color +% dictionary name +/setBackground + { /BGcolor exch put } + def + +% updates the line width, line style, cap style, join style of +% existing graphics-context dictionary: +% dictionary name +% join style +% cap style +% line width +/setLineAttributes + { begin + /JoinStyle exch def + /CapStyle exch def + /LineWidth exch def + end } + def + +% creates a graphics context dictionary with the following information: +% /dictionary name +% foreground color +% background color +% line width +% cap style +% join style +% this creates different graphical contexts for different drawing functions. +/makeDict + { 5 dict 2 copy def begin pop %% with dict name on top of stack + /FGcolor exch def %% define drawing attributes + /BGcolor exch def %% not heavily used + /LineWidth exch def + /CapStyle exch def + /JoinStyle exch def + end } + def + +% makes the current dictionary attributes effective +% this function takes the values in the current dictionary to set the context +% these are the values currently being used: foreground, cap, join, and width +/installGC + { + FGcolor currentgray ne + {FGcolor setgray} if %% foreground color + CapStyle currentlinecap ne + {CapStyle setlinecap} if %% cap style + JoinStyle currentlinejoin ne + {JoinStyle setlinejoin} if %% join style + LineWidth currentlinewidth ne + {LineWidth setlinewidth} if } %% line width + def + +@ +\subsection{setup} +\begin{verbatim} +\end{verbatim} +<<setup>>= +%-------------------------- script --------------------------% + +% 1 inch 1 inch translate + + mark %% mark bottom of our stack + +@ +<<*>>= +@ +\eject +\begin{thebibliography}{99} +\bibitem{1} nothing +\end{thebibliography} +\end{document} diff --git a/src/graph/Gdraws/yesORno.c.pamphlet b/src/graph/Gdraws/yesORno.c.pamphlet new file mode 100644 index 00000000..daed4bca --- /dev/null +++ b/src/graph/Gdraws/yesORno.c.pamphlet @@ -0,0 +1,67 @@ +\documentclass{article} +\usepackage{axiom} +\begin{document} +\title{\$SPAD/src/graph yesORno.c} +\author{The Axiom Team} +\maketitle +\begin{abstract} +\end{abstract} +\eject +\tableofcontents +\eject +\section{License} +<<license>>= +/* +Copyright (c) 1991-2002, The Numerical ALgorithms Group Ltd. +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + + - Neither the name of The Numerical ALgorithms Group Ltd. nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS +IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A +PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER +OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ +@ +<<*>>= +<<license>> + +/* + * Decides if mouse click was in yes or no region; used by program to test + * out Gdraw functions in this directory. + */ + +#include "Gdraws0.h" + +int +Gdraws_pressed_yes(int win_width, int win_height, int x, int y) +{ + return (x < win_width / 2) ? yes : no; +} +@ +\eject +\begin{thebibliography}{99} +\bibitem{1} nothing +\end{thebibliography} +\end{document} |