summaryrefslogtreecommitdiff
path: root/graphics/hpgl2ps
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2019-09-02 13:46:59 +0900
committerNorbert Preining <norbert@preining.info>2019-09-02 13:46:59 +0900
commite0c6872cf40896c7be36b11dcc744620f10adf1d (patch)
tree60335e10d2f4354b0674ec22d7b53f0f8abee672 /graphics/hpgl2ps
Initial commit
Diffstat (limited to 'graphics/hpgl2ps')
-rw-r--r--graphics/hpgl2ps/Makefile49
-rw-r--r--graphics/hpgl2ps/README38
-rw-r--r--graphics/hpgl2ps/changesizes.c75
-rw-r--r--graphics/hpgl2ps/circle.c92
-rw-r--r--graphics/hpgl2ps/defn.h115
-rw-r--r--graphics/hpgl2ps/dxy2ps.c90
-rw-r--r--graphics/hpgl2ps/dxy2ps.man89
-rw-r--r--graphics/hpgl2ps/dxycom.c151
-rw-r--r--graphics/hpgl2ps/end_draw.c14
-rw-r--r--graphics/hpgl2ps/foo.ps219
-rw-r--r--graphics/hpgl2ps/getval.c45
-rw-r--r--graphics/hpgl2ps/hpgl2ps.c90
-rw-r--r--graphics/hpgl2ps/hpgl2ps.man83
-rw-r--r--graphics/hpgl2ps/hpglcom.c577
-rw-r--r--graphics/hpgl2ps/linesize.c16
-rw-r--r--graphics/hpgl2ps/linetype.c161
-rw-r--r--graphics/hpgl2ps/manualfeed.c24
-rw-r--r--graphics/hpgl2ps/plotcoords.c47
-rw-r--r--graphics/hpgl2ps/plotdot.c39
-rw-r--r--graphics/hpgl2ps/plotinit.c57
-rw-r--r--graphics/hpgl2ps/plotps.c64
-rw-r--r--graphics/hpgl2ps/ps_macros.c121
-rw-r--r--graphics/hpgl2ps/rectangle.c29
-rw-r--r--graphics/hpgl2ps/test1.dxy17
-rw-r--r--graphics/hpgl2ps/test1.hpgl38
-rw-r--r--graphics/hpgl2ps/textps.c116
-rw-r--r--graphics/hpgl2ps/viewport.c38
27 files changed, 2494 insertions, 0 deletions
diff --git a/graphics/hpgl2ps/Makefile b/graphics/hpgl2ps/Makefile
new file mode 100644
index 0000000000..dbf3dd3c01
--- /dev/null
+++ b/graphics/hpgl2ps/Makefile
@@ -0,0 +1,49 @@
+# 1.0 dxy2ps and hpgl2ps (Copyright) D McCormick
+# Commercial reproduction prohibited.
+#
+FILTER1= dxy2ps
+FILTER2= hpgl2ps
+INSDIR= /usr/local/bin
+INCLUDE= defn.h
+LOCALLIB= libroland.a
+AR= ar
+ARFLAGS= ru
+LOADLIBES= -lm
+CFLAGS= -g
+
+OBJ1= dxy2ps.o
+
+OBJ2= hpgl2ps.o
+
+OBJC= changesizes.o circle.o dxycom.o end_draw.o\
+ getval.o hpglcom.o linesize.o linetype.o\
+ manualfeed.o plotdot.o plotinit.o plotps.o\
+ ps_macros.o rectangle.o textps.o viewport.o\
+ plotcoords.o
+
+all: $(FILTER1) $(FILTER2)
+
+$(FILTER1): $(LOCALLIB) $(OBJ1)
+ $(CC) $(CFLAGS) -o $@ $(OBJ1) $(LOCALLIB) $(LOADLIBES)
+
+$(FILTER2): $(LOCALLIB) $(OBJ2)
+ $(CC) $(CFLAGS) -o $@ $(OBJ2) $(LOCALLIB) $(LOADLIBES)
+
+$(LOCALLIB): $(OBJC)
+ $(AR) $(ARFLAGS) $@ $(OBJC)
+ ranlib $(LOCALLIB)
+
+$(OBJC): $(INCLUDE)
+
+$(OBJ1): $(INCLUDE)
+
+$(OBJ2): $(INCLUDE)
+
+install: $(FILTER1)
+ install -s $(FILTER1) $(INSDIR)
+
+install2: $(FILTER2)
+ install -s $(FILTER2) $(INSDIR)
+
+clean:
+ -rm -f *.o a.out core libroland.a
diff --git a/graphics/hpgl2ps/README b/graphics/hpgl2ps/README
new file mode 100644
index 0000000000..636450ce2e
--- /dev/null
+++ b/graphics/hpgl2ps/README
@@ -0,0 +1,38 @@
+There are two filters in this package which are based on the Roland
+plotter command set.
+
+1. DXY: A simple command set which is used with all DXY plotters
+
+2. RD-GL: This command set is a superset of the HP (Hewlet Packard)
+ graphics language.
+
+Not all the commands of DXY or RD-GL (HPGL) are implemented (approx 95%
+are) and those commands that are not are skipped and a warning given.
+It is very easy to add to this filter if a particular unimplemented
+command is desired.
+
+If you wish to implement a command go to the relevant portion in the
+command switch "dxycom.c" or "hpglcom.c" and call an appropriate user
+written procedure. (You will need a good knowledge of writing
+PostScript programs)
+
+The filters use the the procedure "getopt" which is used to interpret
+command line options and arguments and is normally available on 4.3 bsd
+and Sys V Unix. For those sites running 4.1 or 4.2 it may be available
+as a local library and must be written into the Makefile.
+
+IF YOU DONT HAVE GETOPT YOU WILL HAVE REWRITE THE CODE THAT INTERPRETS
+COMMAND LINE OPTIONS AND ARGUMENTS.
+
+NOTE 1: The method of writing text is not fully compatible with HPGL
+and will be changed at a later date.
+
+NOTE 2: The PostScript macros are written into a C procedure to allow
+each filter to be a single stand alone program. These macros can easily
+be incorporated into other filter programs.
+
+I have written some test procedures for the testing of each filter they
+are "test1.hpgl" for hpgl2ps and "test1.dxy" for dxy2ps.
+
+Don McCormick.
+
diff --git a/graphics/hpgl2ps/changesizes.c b/graphics/hpgl2ps/changesizes.c
new file mode 100644
index 0000000000..113f866655
--- /dev/null
+++ b/graphics/hpgl2ps/changesizes.c
@@ -0,0 +1,75 @@
+/*
+ * This utility will take a string of real numbers seperated by commas and
+ * put them in an array.
+ *
+ * Don McCormick
+ */
+#include "defn.h"
+
+#define ERROR1 "Only 9 line sizes allowed"
+#define ERROR2 "Too many decimal points in number"
+#define ERROR3 "line size specification incorrect"
+#define ERROR4 "Max no of characters for each line size is 5"
+
+changesizes(sizebuf)
+char sizebuf[50];
+{
+ int i;
+ int j = 0;
+ int k = 0;
+ int DECIMAL = 0;
+ float number;
+ char numbuf[5];
+
+ for (i = 0; i < 50; i++)
+ {
+ if (sizebuf[i] == ',' || sizebuf[i] == NULL)
+ {
+ if ((number = atof(numbuf)) >= 0.01 && number <= 10)
+ pen_size[j] = number; /* Put number in array */
+ else
+ fprintf(stderr, "Warning: line size too large ignored \n");
+
+ if (sizebuf[i] == NULL) return;
+
+ if (j++ > 8)
+ {
+ fprintf(stderr, "Error: %s\n", ERROR1);
+ exit(1);
+ }
+ for (k = 0; k < 5; k++)
+ numbuf[k] = NULL; /* Clear number buffer */
+
+ k = 0;
+ DECIMAL = 0; /* One decimal per number */
+
+ while (sizebuf[i + 1] == ',' && sizebuf[i + 1] != NULL)
+ i++; /* Get rid of extra commas */
+ } else
+ {
+ if ((sizebuf[i] >= '0' && sizebuf[i] <= '9')
+ || sizebuf[i] == '.')
+ {
+ if (sizebuf[i] == '.')
+ {
+ if (DECIMAL == 1)
+ {
+ fprintf(stderr, "Error: %s\n", ERROR2);
+ exit(1);
+ }
+ DECIMAL = 1;
+ }
+ numbuf[k] = sizebuf[i];
+ } else
+ {
+ fprintf(stderr, "Error: %s\n", ERROR3);
+ exit(1);
+ }
+ if (k++ > 5)
+ {
+ fprintf(stderr, "Error: %s\n", ERROR4);
+ exit(1);
+ }
+ }
+ }
+}
diff --git a/graphics/hpgl2ps/circle.c b/graphics/hpgl2ps/circle.c
new file mode 100644
index 0000000000..bfa164b452
--- /dev/null
+++ b/graphics/hpgl2ps/circle.c
@@ -0,0 +1,92 @@
+#include "defn.h"
+
+circle(type)
+int type;
+{
+ float radius;
+ float start_angle = 0;
+ float end_angle = 360;
+ float chord_angle = 0;
+ float Xc, Yc;
+ float percent;
+ float distance;
+ float length;
+ float angle;
+
+ end_draw();
+
+ switch (type)
+ {
+ case RDGLCIRCLE:
+ if (SIGNED_NUMERIC)
+ radius = getval() * XSCALE;
+ if (SIGNED_NUMERIC)
+ chord_angle = getval();
+ Xc = absX;
+ Yc = absY;
+ break;
+
+ case CIRCLE:
+ if (SIGNED_NUMERIC)
+ absX = Xc = getval() * XSCALE;
+ if (SIGNED_NUMERIC)
+ absY = Yc = getval() * YSCALE;
+ if (SIGNED_NUMERIC)
+ radius = getval() * XSCALE;
+ if (SIGNED_NUMERIC)
+ start_angle = getval();
+ if (SIGNED_NUMERIC)
+ end_angle = getval();
+ if (SIGNED_NUMERIC)
+ chord_angle = getval();
+ break;
+
+ case RCIRCLE:
+ if (SIGNED_NUMERIC)
+ radius = getval() * XSCALE;
+ if (SIGNED_NUMERIC)
+ start_angle = getval();
+ if (SIGNED_NUMERIC)
+ end_angle = getval();
+ if (SIGNED_NUMERIC)
+ chord_angle = getval();
+ angle = deg_rad * (90.0 - start_angle);
+ Xc = absX - radius * cos(angle);
+ angle = deg_rad * (90.0 - start_angle);
+ Yc = absY + radius * sin(angle);
+ break;
+
+ case CCIRCLE:
+ if (SIGNED_NUMERIC)
+ absX = getval() * XSCALE;
+ if (SIGNED_NUMERIC)
+ absY = getval() * YSCALE;
+ break;
+
+ case ACIRCLE:
+ Xc = absX;
+ Yc = absY;
+ if (SIGNED_NUMERIC)
+ radius = getval() * XSCALE;
+ if (SIGNED_NUMERIC)
+ start_angle = getval();
+ if (SIGNED_NUMERIC)
+ end_angle = getval();
+ if (SIGNED_NUMERIC)
+ chord_angle = getval();
+ break;
+
+ case SCIRCLE:
+ if (SIGNED_NUMERIC)
+ percent = getval();
+ if (SIGNED_NUMERIC)
+ distance = getval();
+ if (SIGNED_NUMERIC)
+ length = getval();
+ fprintf("Warning: segment and indication lines not available yet\n");
+ break;
+ }
+
+ printf("%g %g %g %g %g %g Ellipse\n",
+ Xc, Yc, radius, radius, start_angle, end_angle);
+}
diff --git a/graphics/hpgl2ps/defn.h b/graphics/hpgl2ps/defn.h
new file mode 100644
index 0000000000..613db33454
--- /dev/null
+++ b/graphics/hpgl2ps/defn.h
@@ -0,0 +1,115 @@
+/*
+ *
+ * The following definations allow for the efficient
+ * translation of DXY and RD-GL codes to PostScript code
+ *
+ */
+
+#include <stdio.h>
+#include <math.h>
+#include <ctype.h>
+
+#define CR '\015'
+#define LF '\012'
+#define SPACE '\040'
+
+#define SIGNED_NUMERIC (ungetc(( ch = getc(stream)),stream) != EOF ) &&\
+ (((ch>='0') && (ch<='9')) || (ch=='-') || (ch=='+')\
+ || (ch==' ') || (ch==',') || (ch == '.'))
+
+#define CIRCLE 21 /* DXY Circle */
+#define RCIRCLE 22 /* DXY Relative Circle */
+#define CCIRCLE 23 /* DXY Centered Circle */
+#define ACIRCLE 24 /* DXY Arc plus Circle */
+#define SCIRCLE 25 /* DXY Segment Circle */
+#define RDGLCIRCLE 26 /* RD-GL Circle */
+
+#define TEXT 31
+#define MARK 32
+
+#define LINETYPE 41
+#define LINESCALE 42
+#define LINE_TYPE_SCALE 43
+/*
+ * Files to open if any
+ */
+FILE *stream;
+FILE *fopen();
+/*
+ * Plotting Parameters that will contain the necessary PostScript
+ * commands to plot (see dxy2ps.c for the initialisation) and
+ * ps_macros.c for the plotting macros).
+ */
+char *MOVE;
+char *RMOVE;
+char *DRAW;
+char *RDRAW;
+/*
+ * Definition of "ch" used in SIGNED_NUMERIC
+ */
+char ch;
+/*
+ * Define the function getval() which returns a real number.
+ */
+float getval();
+/*
+ * Scaling parameters used for translation from DXY and RD-GL
+ * coordinate sytem to the PostScript coordinate system which
+ * has been defined in millimeters. (See above)
+ */
+float SCALE;
+float XSCALE;
+float YSCALE;
+float xmax, xmin;
+float ymax, ymin;
+/*
+ * End of line terminator (RD-GL / HP-GL)
+ */
+char EOL;
+/*
+ * PostScript Coordinate parameters
+ */
+float lastXmove;
+float lastYmove;
+float absX;
+float absY;
+float xval;
+float yval;
+float xoffset, yoffset;
+/*
+ * Extra parameters
+ */
+float char_angle;
+float char_height;
+float char_width;
+float char_space;
+float char_slant;
+
+char font[60];
+
+char symbol;
+
+int dcount;
+/*
+ * Degree radian conversion parameter ie: deg_rad = asin(1) / 90.0;
+ * ( Defined in dxy2ps.c or rdgl2ps.c )
+ */
+float deg_rad;
+/*
+ * Line / pen size parameter (max 9 sizes)
+ */
+float pen_size[9];
+/*
+ * Paper size (ie A3 or A4) and Mode (HPGL or DXY)
+ */
+char *PaperSize;
+char *Mode;
+/*
+ * Flags
+ */
+int LANDSCAPE;
+int DRAW_FLAG;
+int PLOTABS;
+int PENDOWN;
+int SETDOT; /* HP-GL commands only */
+int SYMBOL; /* HP-GL commands only */
diff --git a/graphics/hpgl2ps/dxy2ps.c b/graphics/hpgl2ps/dxy2ps.c
new file mode 100644
index 0000000000..89e20a6aa9
--- /dev/null
+++ b/graphics/hpgl2ps/dxy2ps.c
@@ -0,0 +1,90 @@
+#include "defn.h"
+
+#define USAGE "Usage: dxy2ps [-amr] [-l line sizes] [-s scale] [-x offset] [-y offset] [file]\n"
+
+main(argc, argv)
+int argc;
+char *argv[];
+{
+ extern int optind;
+ extern char *optarg;
+
+ char op;
+ int MANUAL_FEED = 0; /* DEFAULT: No manual feed */
+
+ PaperSize = "A3";
+ Mode = "DXY";
+ plotcoords(); /* Set up plotter coordinates */
+
+ plotinit(); /* Get other initialisations */
+
+ while ((ch = getopt(argc, argv, "al:ms:x:y:r")) != EOF)
+ {
+ switch (ch)
+ {
+ case 'a': /* DXY ISO A4 297mm * 210mm */
+ PaperSize = "A4";
+ plotcoords();
+ break;
+
+ case 'l':
+ changesizes(optarg);
+ break;
+
+ case 'm':
+ MANUAL_FEED = 1;
+ break;
+
+ case 'r':
+ LANDSCAPE = 0;
+ break;
+
+ case 's':
+ SCALE = atof(optarg);
+ if (SCALE < 0.1)
+ SCALE = 0.1;
+ else
+ if (SCALE > 3)
+ SCALE = 3;
+ break;
+
+ case 'x':
+ xoffset = atof(optarg);
+ break;
+
+ case 'y':
+ yoffset = atof(optarg);
+ break;
+
+ default:
+ fprintf(stderr, "%s\n", USAGE);
+ exit(1);
+ }
+ }
+ if (optind == argc)
+ stream = stdin;
+ else if ((stream = fopen(argv[optind], "r")) == NULL)
+ {
+ fprintf(stderr, "ERROR: cannot open \"%s\"\n", argv[optind]);
+ exit(1);
+ }
+ ps_macros(); /* Output PostScript Macros */
+
+ viewport(); /* Scale the viewport for the plot */
+
+ printf("/%s %g Font\n", font, char_height);
+
+ if (MANUAL_FEED)
+ manualfeed(1);
+
+ while ((op = getc(stream)) != EOF)
+ if ((isalpha(op) > 0) || op == '^')
+ dxycom(op);
+
+ end_draw();
+
+ printf("showpage\n");
+
+ if (MANUAL_FEED)
+ manualfeed(0);
+}
diff --git a/graphics/hpgl2ps/dxy2ps.man b/graphics/hpgl2ps/dxy2ps.man
new file mode 100644
index 0000000000..f27dda4853
--- /dev/null
+++ b/graphics/hpgl2ps/dxy2ps.man
@@ -0,0 +1,89 @@
+.TH DXY2PS (1L) "25 September 1987"
+.SH NAME
+dxy2ps - A Roland DXY plot command filter to PostScript
+.SH SYNOPSIS
+\fBdxy2ps\fR
+[\fB-amr\fR]
+[\fB-l \fIline sizes\fR]
+[\fB-s \fIscale\fR]
+[\fB-x \fIoffset\fR]
+[\fB-y \fIoffset\fR]
+[\fIplotfile\fR]
+.SH DESCRIPTION
+This filter is used to convert the Roland DXY and the Roland
+Graphics Language (RD-GL) (which is a superset of the Hewlet Packard
+Graphics Language (HP-GL)) commands to PostScript.
+.PP
+The RD-GL commands are only operated on if each command is prefixed with
+a "^", therfore if your plotfile only contains HP-GL or RD-GL commands
+use the filter \fBhpgl2ps\fR.
+.PP
+The default conditions for \fBdxy2ps\fR are:
+.TP
+.B 1.
+The plot translation is from ISO A3 (420mm x 297mm) to ISO A4
+(297mm x 210mm) on the LaserWriter.
+.TP
+.B 2.
+Line thicknesses are in millimeters and are for lines (pens) 1 to 9:
+( 0.1, 0.2, 0.3, 0.4, 0.5, 0.7, 1.0, 1.25, 1.5 )
+.TP
+.B Note:
+If the plotfile is not specified then standard input is assumed.
+.SH ARGUMENTS
+.TP
+.B -a
+Draw on an A4 ISO (297mm x 210mm) sheet of paper. This will give an
+aproximate 1:1 translation to the LaserWriter.
+.TP
+\fB-l \fIline sizes\fR
+This option allows the default line sizes to be replaced with different
+sizes starting from line (pen) one through nine. The new sizes (real or
+integer) are entered in a comma seperated string (\fIline size\fR) and
+are in millimeters. Only the sizes entered in the string will be
+changed with respect to lines (pens) one to nine while nonentered line
+(pen) sizes will retain the default sizes.
+.sp
+In the following example only the first three sizes will be changed.
+.sp
+eg: dxy2ps -l 0.4,0.3,1 file | lpr -Plaser1
+.TP
+.B -m
+Enable the manual feed on the LaserWriter (cutoff time 3 minutes).
+.TP
+.B -r
+Rotate plot(s) through 90 degrees. (The plot is made smaller)
+.TP
+\fB-s\fI scale\fR Scale the plot from 0.1 to 3 times its original
+size.
+.TP
+\fB-x\fI offset\fR Place an X offset (in mm) in the plot.
+.TP
+\fB-y\fI offset\fR Place an Y offset (in mm) in the plot.
+.PP
+\fBNote:\fR Offsets are with respect to the 0, 0 (origin) of the HP-GL
+/ RD-GL plotting commands, thus if the minimum plotting coordinates are
+below either the X and/or Y zero axis then a positive offset is
+applied. Similarly if the minimum plot coordinates are above the X
+and/or Y zero axis then a negative offset is applied.
+.SH FILES
+/usr/local/bin/dxy2ps
+.br
+/usr/local/bin/hpgl2ps
+.SH AUTHOR
+Don McCormick
+.br
+CSIRO
+.br
+Division of Applied Physics
+.br
+PO 218, Lindfield, N.S.W., 2070
+.br
+Australia
+.SH BUGS
+Some of the graphics commands are unimplemented and a warning will be
+displayed. If this command is vital then it must be written into the code.
+.PP
+No interactive command is suported.
+.PP
+If any bugs are found notify damc@natmlab or damc@nifty or root.
diff --git a/graphics/hpgl2ps/dxycom.c b/graphics/hpgl2ps/dxycom.c
new file mode 100644
index 0000000000..124be81915
--- /dev/null
+++ b/graphics/hpgl2ps/dxycom.c
@@ -0,0 +1,151 @@
+#include "defn.h"
+
+dxycom(op)
+char op;
+{
+ int intval;
+
+ switch (op)
+ {
+ case 'H': /* HOME */
+ case 'h':
+ break;
+
+ case 'D': /* DRAW */
+ case 'd':
+ plotps(DRAW);
+ break;
+
+ case 'M': /* MOVE */
+ case 'm':
+ plotps(MOVE);
+ break;
+
+ case 'I': /* RELATIVE DRAW */
+ case 'i':
+ plotps(RDRAW);
+ break;
+
+ case 'R': /* RELATIVE MOVE */
+ case 'r':
+ plotps(RMOVE);
+ break;
+
+ case 'L': /* LINE TYPE */
+ case 'l':
+ linetype(LINETYPE);
+ break;
+
+ case 'B': /* LINE SCALE */
+ case 'b':
+ linetype(LINESCALE);
+ break;
+
+ case 'X': /* AXIS */
+ case 'x':
+ {
+ int p, q, r;
+
+ p = rint(getval());
+ q = rint(getval());
+ r = rint(getval());
+ fprintf(stderr, "Warning %c not implemented yet\n", op);
+ }
+ break;
+
+ case 'P': /* PRINT */
+ case 'p':
+ textps(TEXT);
+ break;
+
+ case 'S': /* ALPHA SCALE */
+ case 's':
+ {
+ int n;
+
+ if (SIGNED_NUMERIC)
+ n = rint(getval());
+ else
+ n = 3;
+ char_height = (n + 1) * 0.8 * SCALE;
+ char_width = (n + 1) * 0.4 * SCALE;
+ char_space = (n + 1) * 0.2 * SCALE;
+ }
+ printf("/%s %g %g %g DefFont\n",
+ font, char_width, char_height, char_slant);
+ break;
+
+ case 'Q': /* ALPHA ROTATE */
+ case 'q':
+ intval = rint(getval());
+ switch (intval)
+ {
+ case 0:
+ char_angle = 0.0;
+ break;
+
+ case 1:
+ char_angle = 90.0;
+ break;
+
+ case 2:
+ char_angle = 180.0;
+ break;
+
+ case 3:
+ char_angle = 270.0;
+ break;
+ }
+ break;
+
+ case 'N': /* MARK */
+ case 'n':
+ textps(MARK);
+ break;
+
+ case 'J': /* PEN CHANGE */
+ case 'j':
+ linesize();
+ break;
+
+ case 'C': /* CIRCLE */
+ case 'c':
+ circle(CIRCLE);
+ break;
+
+ case 'E': /* RELATIVE CIRCLE */
+ case 'e':
+ circle(RCIRCLE);
+ break;
+
+ case 'A': /* CIRCLE CENTER */
+ case 'a':
+ circle(CCIRCLE);
+ break;
+
+ case 'G': /* ARC + CIRCLE */
+ case 'g':
+ circle(ACIRCLE);
+ break;
+
+ case 'K': /* SEGMENT AND INDICATION LINES FOR CIRCLES */
+ case 'k':
+ circle(SCIRCLE);
+ break;
+
+ case 'T': /* HATCHING */
+ case 't':
+ rectangle();
+ break;
+
+ case '^': /* CALL HP-GL / RD-GL COMMANDS */
+ end_draw();
+ if ((ch = getc(stream)) != EOF)
+ hpglcom(ch);
+ break;
+
+ default:
+ fprintf(stderr, "Warning: %c Unknown DXY command\n", op);
+ break;
+ }
+}
diff --git a/graphics/hpgl2ps/end_draw.c b/graphics/hpgl2ps/end_draw.c
new file mode 100644
index 0000000000..265cf81b64
--- /dev/null
+++ b/graphics/hpgl2ps/end_draw.c
@@ -0,0 +1,14 @@
+#include "defn.h"
+
+end_draw()
+{
+ if (DRAW_FLAG)
+ {
+ if (lastXmove == absX && lastYmove == absY)
+ printf("closepath\n");
+
+ printf("stroke\n");
+ DRAW_FLAG = 0;
+ }
+ dcount = 0;
+}
diff --git a/graphics/hpgl2ps/foo.ps b/graphics/hpgl2ps/foo.ps
new file mode 100644
index 0000000000..3355314f22
--- /dev/null
+++ b/graphics/hpgl2ps/foo.ps
@@ -0,0 +1,219 @@
+%! PS-Adobe-1.0: For Apple LaserWriter
+% default font is 10 pt. Helvetica
+/basefont {/Helvetica findfont 10 scalefont setfont} def
+/mm {72.27 mul 25.4 div} def
+/M
+{
+ /Ymove exch def
+ /Xmove exch def
+ Xmove mm Ymove mm moveto
+} def
+/R
+{
+ /Yrmove exch def
+ /Xrmove exch def
+ Xrmove mm Yrmove mm rmoveto
+} def
+/D
+{
+ /Ydraw exch def
+ /Xdraw exch def
+ Xdraw mm Ydraw mm lineto
+} def
+/I
+{
+ /Yrdraw exch def
+ /Xrdraw exch def
+ Xrdraw mm Yrdraw mm rlineto
+} def
+/Font
+{
+ /Height exch def
+ /FontName exch def
+ FontName findfont Height mm scalefont setfont
+} def
+/DefFont
+{
+ /Slant exch def
+ /Height exch def
+ /Width exch def
+ /FontName exch def
+ FontName findfont [ Width mm 0 Slant mm Height mm 0 0] makefont setfont
+} def
+/Text
+{
+ /String exch def
+ /Angle exch def
+ /Position exch def
+ /Ymove exch def
+ /Xmove exch def
+ Position 1 lt {/hpf 0 def /lpf 0 def} if
+ Position 1 eq {/hpf 0 def /lpf 0 def} if
+ Position 2 eq {/hpf 0 def /lpf 0.5 def} if
+ Position 3 eq {/hpf 0 def /lpf 1 def} if
+ Position 4 eq {/hpf 0.5 def /lpf 0 def} if
+ Position 5 eq {/hpf 0.5 def /lpf 0.5 def} if
+ Position 6 eq {/hpf 0.5 def /lpf 1 def} if
+ Position 7 eq {/hpf 1 def /lpf 0 def} if
+ Position 8 eq {/hpf 1 def /lpf 0.5 def} if
+ Position 9 eq {/hpf 1 def /lpf 1 def} if
+ Position 9 gt {/hpf 1 def /lpf 1 def} if
+ /StrLen String stringwidth pop lpf mul def
+ /StrHt Height mm hpf mul def
+ /Xdiff StrHt Angle sin mul StrLen Angle cos mul sub def
+ /Ydiff StrHt Angle cos mul StrLen Angle sin mul add def
+ Xmove mm Xdiff add Ymove mm Ydiff sub moveto
+ gsave
+ Angle rotate
+ String show
+ grestore
+ /PosterOnly 0 def
+} def
+/EllipseDict 8 dict def
+EllipseDict /mtrx matrix put
+/Ellipse
+{ EllipseDict begin
+ /endangle exch def
+ /startangle exch def
+ /yradius exch def
+ /xradius exch def
+ /ycenter exch def
+ /xcenter exch def
+ /savematrix mtrx currentmatrix def
+ xcenter mm ycenter mm translate
+ xradius mm yradius mm div 1 scale
+ newpath
+ 0 0 xradius mm startangle endangle arc
+ stroke
+ savematrix setmatrix
+ end
+} def
+basefont
+1 setlinecap
+1 setlinejoin
+3 setmiterlimit
+90 rotate
+15.9522 mm -196.902 mm translate
+/ 2.7 Font
+/ 1.95072 2.77207 0 DefFont
+/ 1.95072 2.77207 0 DefFont
+[] 0 setdash
+newpath
+ 17.1115 17.1115 M
+ 34.2231 17.1115 D
+ 34.2231 34.2231 D
+ 17.1115 34.2231 D
+ 17.1115 17.1115 D
+ -1.71115 0 I
+ 0 -1.71115 I
+ 1.71115 0 I
+ 0 1.71115 I
+closepath
+stroke
+newpath
+ 0 0 M
+ 184.805 0 D
+ 184.805 131.417 D
+ 0 131.417 D
+ 0 0 D
+closepath
+stroke
+[2.55252 mm 1.91439 mm 1.91439 mm 1.91439 mm] 0 setdash
+newpath
+ 68.4462 23.9562 M
+ 68.4462 0 I
+stroke
+[3.82878 mm 1.27626 mm 1.91439 mm 1.27626 mm] 0 setdash
+newpath
+ 68.4462 22.245 M
+ 68.4462 0 I
+stroke
+[5.10504 mm 0.957195 mm 1.27626 mm 0.957195 mm] 0 setdash
+newpath
+ 68.4462 20.5339 M
+ 68.4462 0 I
+stroke
+[6.3813 mm 1.27626 mm 0.63813 mm 1.27626 mm] 0 setdash
+newpath
+ 68.4462 18.8227 M
+ 68.4462 0 I
+stroke
+[7.01943 mm 1.27626 mm 0 mm 0 mm] 0 setdash
+newpath
+ 68.4462 17.1115 M
+ 68.4462 0 I
+stroke
+[6.3813 mm 1.91439 mm 0 mm 0 mm] 0 setdash
+newpath
+ 68.4462 15.4004 M
+ 68.4462 0 I
+stroke
+[] 0 setdash
+newpath
+ 68.4462 13.6892 M 68.4462 13.6892 D
+stroke
+newpath
+ 136.892 13.6892 M 136.892 13.6892 D
+stroke
+[1.91439 mm 4.46691 mm 1.91439 mm 0 mm] 0 setdash
+newpath
+ 68.4462 11.9781 M
+ 68.4462 0 I
+stroke
+[2.55252 mm 3.19065 mm 2.55252 mm 0 mm] 0 setdash
+newpath
+ 68.4462 10.2669 M
+ 68.4462 0 I
+stroke
+[3.19065 mm 2.23345 mm 0.63813 mm 2.23345 mm] 0 setdash
+newpath
+ 68.4462 8.55577 M
+ 68.4462 0 I
+stroke
+[3.19065 mm 1.91439 mm 1.91439 mm 1.91439 mm] 0 setdash
+newpath
+ 68.4462 6.84462 M
+ 68.4462 0 I
+stroke
+[2.55252 mm 1.59532 mm 2.55252 mm 1.59532 mm] 0 setdash
+newpath
+ 68.4462 5.13346 M
+ 68.4462 0 I
+stroke
+[2.23345 mm 1.91439 mm 2.23345 mm 1.91439 mm] 0 setdash
+newpath
+ 68.4462 3.42231 M
+ 68.4462 0 I
+stroke
+34.2231 68.4462 1 0 ( -- 0deg --) Text
+34.2231 68.4462 1 45 ( -- 45deg --) Text
+34.2231 68.4462 1 90 ( -- 90deg --) Text
+34.2231 68.4462 1 135 ( -- 135deg --) Text
+34.2231 68.4462 1 180 ( -- 180deg --) Text
+34.2231 68.4462 1 -135 ( -- 225deg --) Text
+34.2231 68.4462 1 -90 ( -- 270deg --) Text
+34.2231 68.4462 1 -45 ( -- 315deg --) Text
+/ 1.95072 2.77207 2.77207 DefFont
+68.4462 68.4462 1 0 ( SLANT of 45deg) Text
+/ 1.95072 2.77207 -2.77207 DefFont
+68.4462 61.6016 1 0 ( SLANT of -45deg) Text
+/ 1.95072 2.77207 0 DefFont
+/ 1.95072 2.77207 0 DefFont
+34.2231 102.669 1 0 ( Size is relative) Text
+/ 2.7 1.9 0 DefFont
+34.2231 94.1135 1 0 ( DEFAULT sizes) Text
+/ 8 10 0 DefFont
+34.2231 85.5577 1 0 (LARGE size (w=8mm, h=10mm)) Text
+[] 0 setdash
+154.004 17.1115 8.55577 8.55577 0 360 Ellipse
+154.004 17.1115 6.84462 6.84462 0 360 Ellipse
+154.004 17.1115 5.13346 5.13346 0 360 Ellipse
+154.004 17.1115 3.42231 3.42231 0 360 Ellipse
+154.004 17.1115 1.71115 1.71115 0 360 Ellipse
+154.004 17.1115 0.855577 0.855577 0 360 Ellipse
+/ 1.95072 2.77207 0 DefFont
+154.004 17.1115 5 0 (+) Text
+171.115 17.1115 5 0 (+) Text
+171.115 25.6673 5 0 (%) Text
+171.115 8.55577 5 0 (%) Text
+showpage
diff --git a/graphics/hpgl2ps/getval.c b/graphics/hpgl2ps/getval.c
new file mode 100644
index 0000000000..3c4f3fcfc9
--- /dev/null
+++ b/graphics/hpgl2ps/getval.c
@@ -0,0 +1,45 @@
+/*
+ * Returns a real number
+ */
+
+#include "defn.h"
+
+#define ERROR "Two or more decimal places in a number"
+
+float
+getval()
+{
+ char valbuf[10];
+ float value;
+ int DECIMAL = 0;
+ int i;
+
+ /* Null the value buffer "valbuf" */
+ for (i = 0; i < 10; i++)
+ valbuf[i] = NULL;
+
+ i = 0;
+
+ ch = getc(stream);
+
+ while ((ch == ' ') || (ch == ','))
+ ch = getc(stream);
+
+ while ((ch >= '0' && ch <= '9') || ch == '.' || ch == '-' || ch == '+')
+ {
+ if (ch == '.')
+ {
+ if (DECIMAL)
+ {
+ fprintf(stderr,"Error: %s\n", ERROR);
+ exit(1);
+ }
+ DECIMAL = 1;
+ }
+ valbuf[i++] = ch;
+ ch = getc(stream);
+ }
+ ungetc(ch, stream); /* Put non numeric char back */
+ value = atof (valbuf);
+ return (value);
+}
diff --git a/graphics/hpgl2ps/hpgl2ps.c b/graphics/hpgl2ps/hpgl2ps.c
new file mode 100644
index 0000000000..6460248044
--- /dev/null
+++ b/graphics/hpgl2ps/hpgl2ps.c
@@ -0,0 +1,90 @@
+#include "defn.h"
+
+#define USAGE "Usage: hpgl2ps [-amr] [-l line sizes] [-s scale] [-x offset] [-y offset] [file]\n"
+
+main(argc, argv)
+int argc;
+char *argv[];
+{
+ extern int optind;
+ extern char *optarg;
+
+ char op;
+ int MANUAL_FEED = 0; /* DEFAULT: No manual feed */
+
+ PaperSize = "A3";
+ Mode = "HPGL";
+ plotcoords();
+
+ plotinit(); /* Get other initialiasations */
+
+ while ((ch = getopt(argc, argv, "al:ms:x:y:r")) != EOF)
+ {
+ switch (ch)
+ {
+ case 'a': /* HP-GL ISO A4 297mm * 210mm */
+ PaperSize = "A4";
+ plotcoords();
+ break;
+
+ case 'l':
+ changesizes(optarg);
+ break;
+
+ case 'm':
+ MANUAL_FEED = 1;
+ break;
+
+ case 'r':
+ LANDSCAPE = 0;
+ break;
+
+ case 's':
+ SCALE = atof(optarg);
+ if (SCALE < 0.1)
+ SCALE = 0.1;
+ else
+ if (SCALE > 3)
+ SCALE = 3;
+ break;
+
+ case 'x':
+ xoffset = atof(optarg);
+ break;
+
+ case 'y':
+ yoffset = atof(optarg);
+ break;
+
+ default:
+ fprintf(stderr, "%s\n", USAGE);
+ exit(1);
+ }
+ }
+ if (optind == argc)
+ stream = stdin;
+ else if ((stream = fopen(argv[optind], "r")) == NULL)
+ {
+ fprintf(stderr, "ERROR: cannot open \"%s\"\n", argv[optind]);
+ exit(1);
+ }
+ ps_macros(); /* Output PostScript Macros */
+
+ viewport(); /* Scale the viewport for the plot */
+
+ printf("/%s %g Font\n", font, char_height);
+
+ if (MANUAL_FEED)
+ manualfeed(1);
+
+ while ((op = getc(stream)) != EOF)
+ if (isalpha(op) > 0)
+ hpglcom(op);
+
+ end_draw();
+
+ printf("showpage\n");
+
+ if (MANUAL_FEED)
+ manualfeed(0);
+}
diff --git a/graphics/hpgl2ps/hpgl2ps.man b/graphics/hpgl2ps/hpgl2ps.man
new file mode 100644
index 0000000000..a333c9f4cc
--- /dev/null
+++ b/graphics/hpgl2ps/hpgl2ps.man
@@ -0,0 +1,83 @@
+.TH HPGL2PS (1L) "25 September 1987"
+.SH NAME
+hpgl2ps - A HP (Hewlet Packard) plot command filter to PostScript
+.SH SYNOPSIS
+\fBhpgl2ps\fR
+[\fB-amr\fR]
+[\fB-l \fIline sizes\fR]
+[\fB-s \fIscale\fR]
+[\fB-x \fIoffset\fR]
+[\fB-y \fIoffset\fR]
+[\fIplotfile\fR]
+.SH DESCRIPTION
+This filter is used to convert the Hewlet Packard Graphic Language (HP-GL)
+9873C plotter commands to PostScript. The HP-GL commands are a subset of the
+Roland plotter command set (RD-GL).
+.PP
+The default conditions for \fBhpgl2ps\fR are:
+.TP
+.B 1.
+The plot translation is from ISO A3 (420mm x 297mm) to ISO A4
+(297mm x 210mm) on the LaserWriter.
+.TP
+.B 2.
+Line thicknesses are in millimeters and are for lines (pens) 1 to 9:
+( 0.1, 0.2, 0.3, 0.4, 0.5, 0.7, 1.0, 1.25, 1.5 )
+.TP
+.B Note:
+If the plotfile is not specified then standard input is assumed.
+.SH ARGUMENTS
+.TP
+.B -a
+Draw on an A4 ISO (297mm x 210mm) sheet of paper. This will give an
+aproximate 1:1 translation to the LaserWriter.
+.TP
+\fB-l \fIline sizes\fR
+This option allows the default line sizes to be replaced with different
+sizes starting from line (pen) one through nine. The new sizes (real or
+integer) are entered in a comma seperated string (\fIline size\fR) and
+are in millimeters. Only the sizes entered in the string will be
+changed with respect to lines (pens) one to nine while nonentered line
+(pen) sizes will retain the default sizes.
+.sp
+In the following example only the first three sizes will be changed.
+.sp
+eg: hpgl2ps -l 0.4,0.3,1 file | lpr -Plaser1
+.TP
+.B -m
+Enable the manual feed on the LaserWriter (cutoff time 3 minutes).
+.TP
+.B -r
+Rotate plot(s) through 90 degrees. (The plot is made smaller)
+.TP
+\fB-s\fI scale\fR Scale the plot from 0.1 to 3 times its original
+size.
+.TP
+\fB-x\fI offset\fR Place an X offset (in mm) in the plot.
+.TP
+\fB-y\fI offset\fR Place an Y offset (in mm) in the plot.
+.PP
+\fBNote:\fR Offsets are with respect to the 0, 0 (origin) of the HP-GL
+/ RD-GL plotting commands, thus if the minimum plotting coordinates are
+below either the X and/or Y zero axis then a positive offset is
+applied. Similarly if the minimum plot coordinates are above the X
+and/or Y zero axis then a negative offset is applied.
+.SH FILES
+/usr/local/bin/hpgl2ps
+.SH AUTHOR
+Don McCormick
+.br
+CSIRO
+.br
+Division of Applied Physics
+.br
+PO 218, Lindfield, N.S.W., 2070
+.br
+Australia
+.SH BUGS
+Some of the graphics commands are unimplemented and a warning will be
+displayed. If this command is vital then it must be written into the code.
+.PP
+No interactive command is suported.
+.PP
+If any bugs are found notify damc@natmlab or damc@nifty or root.
diff --git a/graphics/hpgl2ps/hpglcom.c b/graphics/hpgl2ps/hpglcom.c
new file mode 100644
index 0000000000..1e58f366b0
--- /dev/null
+++ b/graphics/hpgl2ps/hpglcom.c
@@ -0,0 +1,577 @@
+/*
+ * This procedure translates RD-GL (Roland DG Graphic Language) into the
+ * equivalent PostScript language.
+ *
+ * The RD-GL is a superset equivalent to HP-GL
+ *
+ * Don McCormick
+ */
+
+#include "defn.h"
+
+/* The folowing defaults should be 0.5% and 1.0% for the respective character
+ * width and height, however this is too small when scaled to Postcript
+ * charcter sizes.
+ */
+float DEFWIDTH = 0.0075; /* 0.75 % of P2x - P1x for default char width */
+float DEFHEIGHT = 0.015; /* 1.5 % of P2y - P1y for default char height */
+
+hpglcom(op1)
+char op1;
+{
+ char op2;
+ int no_op; /* No operation value */
+
+ switch (op1)
+ {
+ case 'A':
+ case 'a':
+ op2 = getc(stream);
+ switch (op2)
+ {
+ case 'A': /* Arc Absolute (not HP-GL) */
+ case 'a':
+ break;
+
+ case 'P': /* Automatic Pen Lift (HP-GL only) */
+ case 'p':
+ while (((ch = getc(stream)) != EOF) && ch != ';');
+ break;
+
+ case 'R': /* Arc Relative (not HP-GL) */
+ case 'r':
+ break;
+
+ default:
+ fprintf(stderr, "Warning: %c%c Unknown HP-GL Command\n\n", op1, op2);
+ }
+ break;
+
+ case 'C':
+ case 'c':
+ op2 = getc(stream);
+ switch (op2)
+ {
+ case 'A': /* Alternate Character Set (Not Used) */
+ case 'a':
+ while (((ch = getc(stream)) != EOF) && ch != ';');
+ fprintf(stderr, "Warning: Alt character set not implemented yet\n");
+ break;
+
+ case 'I': /* Circle */
+ case 'i':
+ circle(RDGLCIRCLE);
+ break;
+
+ case 'P': /* Character Plot */
+ case 'p':
+ {
+ float xspace, yspace;
+
+ xspace = getval() * XSCALE * SCALE * (char_width + char_space);
+ yspace = getval() * YSCALE * SCALE * (char_width + char_space);
+ end_draw();
+ printf(" %g mm %g mm %s\n", xspace, yspace, RMOVE);
+ }
+ break;
+
+ case 'S': /* Standard Character Set */
+ case 's':
+ while (((ch = getc(stream)) != EOF) && ch != ';');
+ break;
+
+ default:
+ fprintf(stderr, "Warning: %c%c Unknown HP-GL Command\n", op1, op2);
+ }
+ break;
+
+ case 'D':
+ case 'd':
+ op2 = getc(stream);
+ switch (op2)
+ {
+ case 'C': /* Digitize Clear (Not Used) */
+ case 'c':
+ break;
+
+ case 'F': /* Default */
+ case 'f':
+ SETDOT = 0;
+ SYMBOL = 0;
+ PENDOWN = 0;
+ EOL = '\003';
+ char_angle = 0;
+ char_slant = 0;
+ char_width = DEFWIDTH * (xmax - xmin) * XSCALE * SCALE;
+ char_height = DEFHEIGHT * (ymax - ymin) * YSCALE * SCALE;
+ char_space = char_width * (1/.67 - 1);
+ printf("/%s %g %g %g DefFont\n",
+ font, char_width, char_height, char_slant);
+ break;
+
+ case 'I': /* Absolute Direction */
+ case 'i':
+ {
+ float run, rise;
+
+ if (SIGNED_NUMERIC)
+ {
+ run = getval() * XSCALE;
+ rise = getval() * YSCALE;
+ char_angle = atan2(rise, run) / deg_rad;
+ }
+ else
+ char_angle = 0;
+ }
+ break;
+
+ case 'P': /* Digitize Point (Not Used) */
+ case 'p':
+ break;
+
+ case 'R': /* Relative Direction */
+ case 'r':
+ {
+ float run, rise;
+
+ if (SIGNED_NUMERIC)
+ {
+ run = getval() * XSCALE;
+ rise = getval() * YSCALE;
+ char_angle += atan2(rise, run) / deg_rad;
+ }
+ else
+ char_angle = 0;
+ }
+ break;
+
+ case 'T': /* Define Terminator */
+ case 't':
+ if ((ch = getc(stream)) != EOF)
+ EOL = ch; /* End of label terminator */
+ break;
+
+ default:
+ fprintf(stderr, "Warning: %c%c Unknown HP-GL Command\n", op1, op2);
+ }
+ break;
+
+ case 'E': /* NOT HP-GL */
+ case 'e':
+ op2 = getc(stream);
+ switch (op2)
+ {
+ case 'A': /* Edge Rectangle Absolute */
+ case 'a':
+ break;
+
+ case 'R': /* Edge Rectangle Relative */
+ case 'r':
+ break;
+
+ case 'W': /* Edge Wedge */
+ case 'w':
+ break;
+
+ default:
+ fprintf(stderr, "Warning: %c%c Unknown RD-GL Command\n", op1, op2);
+ }
+ break;
+
+ case 'F': /* NOT HP-GL */
+ case 'f':
+ op2 = getc(stream);
+ switch (op2)
+ {
+ case 'T': /* Fill Type */
+ case 't':
+ break;
+
+ default:
+ fprintf(stderr, "Warning: %c%c Unknown HP-GL Command\n", op1, op2);
+ }
+ break;
+
+ case 'I':
+ case 'i':
+ op2 = getc(stream);
+ switch (op2)
+ {
+ case 'M': /* Input Mask (Not Used) */
+ case 'm':
+ break;
+
+ case 'N': /* Initialize */
+ case 'n':
+ plotcoords();
+ SETDOT = 0;
+ SYMBOL = 0;
+ PENDOWN = 0;
+ EOL = '\003';
+ char_angle = 0;
+ char_slant = 0;
+ char_width = DEFWIDTH * (xmax - xmin) * XSCALE * SCALE;
+ char_height = DEFHEIGHT * (ymax - ymin) * YSCALE * SCALE;
+ char_space = char_width * (1/0.67 - 1);
+ printf("/%s %g %g %g DefFont\n",
+ font, char_width, char_height, char_slant);
+ break;
+
+ case 'P': /* Input P1 and P2 (Not Used) */
+ case 'p':
+ while (((ch = getc(stream)) != EOF) && ch != ';');
+ fprintf(stderr,"Warning: IP command not implemented\n");
+ break;
+
+ case 'W': /* Input Window */
+ case 'w':
+ while (((ch = getc(stream)) != EOF) && ch != ';');
+ fprintf(stderr,"Warning: IW command not implemented\n");
+ break;
+
+ default:
+ fprintf(stderr, "Warning: %c%c Unknown HP-GL Command\n", op1, op2);
+ }
+ break;
+
+ case 'L':
+ case 'l':
+ op2 = getc(stream);
+ switch (op2)
+ {
+ case 'B': /* Label */
+ case 'b':
+ textps(TEXT);
+ break;
+
+ case 'T': /* Line Type */
+ case 't':
+ linetype(LINE_TYPE_SCALE);
+ break;
+
+ default:
+ fprintf(stderr, "Warning: %c%c Unknown HP-GL Command\n", op1, op2);
+ }
+ break;
+
+ case 'O': /* NOT USED */
+ case 'o':
+ op2 = getc(stream);
+ switch (op2)
+ {
+ case 'A': /* Output Actual Position (Not HP-GL) */
+ case 'a':
+ break;
+
+ case 'C': /* Output Commanded Position */
+ case 'c':
+ break;
+
+ case 'D': /* Output Digitise */
+ case 'd':
+ break;
+
+ case 'E': /* Output Error */
+ case 'e':
+ break;
+
+ case 'P': /* Output P1 and P2 */
+ case 'p':
+ break;
+
+ case 'S': /* Output Status */
+ case 's':
+ break;
+
+ case 'W': /* Output Window (Not HP-GL) */
+ case 'w':
+ break;
+
+ default:
+ fprintf(stderr, "Warning: %c%c Unknown HP-GL Command\n", op1, op2);
+ }
+ break;
+
+ case 'P':
+ case 'p':
+ op2 = getc(stream);
+ switch (op2)
+ {
+ case 'A': /* Plot Absolute */
+ case 'a':
+ PLOTABS = 1;
+ if (SIGNED_NUMERIC)
+ if (SETDOT || SYMBOL)
+ plotdot(MOVE);
+ else if (PENDOWN)
+ plotps(DRAW);
+ else
+ plotps(MOVE);
+ break;
+
+ case 'D': /* Pen Down */
+ case 'd':
+ PENDOWN = 1;
+ if (SIGNED_NUMERIC)
+ if (SETDOT)
+ plotdot(MOVE);
+ else if (PLOTABS)
+ plotps(DRAW);
+ else
+ plotps(RDRAW);
+ break;
+
+ case 'R': /* Plot Relative */
+ case 'r':
+ PLOTABS = 0;
+ if (SIGNED_NUMERIC)
+ if (SETDOT || SYMBOL)
+ plotdot(RMOVE);
+ else if (PENDOWN)
+ plotps(RDRAW);
+ else
+ plotps(RMOVE);
+ break;
+
+ case 'T': /* Pen Thickness (Not HP-GL) */
+ case 't':
+ {
+ float linewidth;
+
+ linewidth = getval() * SCALE; /* In mm */
+ printf("%g mm setlinewidth\n", linewidth);
+ }
+ break;
+
+ case 'U': /* Pen Up */
+ case 'u':
+ PENDOWN = 0;
+ if (SIGNED_NUMERIC)
+ if (SETDOT)
+ plotdot(MOVE);
+ else if (PLOTABS)
+ plotps(MOVE);
+ else
+ plotps(RMOVE);
+ break;
+
+ default:
+ fprintf(stderr, "Warning: %c%c Unknown HP-GL Command\n", op1, op2);
+ }
+ break;
+
+ case 'R': /* Not HP-GL */
+ case 'r':
+ op2 = getc(stream);
+ switch (op2)
+ {
+ case 'A': /* Shade Rectange Absolute */
+ case 'a':
+ break;
+
+ case 'R': /* Shade Rectangle Relative */
+ case 'r':
+ break;
+
+ default:
+ fprintf(stderr, "Warning: %c%c Unknown RD-GL Command\n", op1, op2);
+ }
+ break;
+
+ case 'S':
+ case 's':
+ op2 = getc(stream);
+ switch (op2)
+ {
+ case 'A': /* Select Alternate Set (Not Used) */
+ case 'a':
+ break;
+
+ case 'C': /* Scale */
+ case 'c':
+ if (SIGNED_NUMERIC)
+ xmin = getval();
+ else
+ break;
+
+ if (SIGNED_NUMERIC)
+ xmax = getval();
+ if (SIGNED_NUMERIC)
+ ymin = getval();
+ if (SIGNED_NUMERIC)
+ ymax = getval();
+ fprintf(stderr, "Warning: Scaling not implemented yet\n");
+ break;
+
+ case 'I': /* Absolute Character Size */
+ case 'i':
+ if (SIGNED_NUMERIC)
+ {
+ char_width = getval() * 10 * SCALE; /* In mm */
+ char_height = getval() * 10 * SCALE; /* In mm */
+ } else
+ {
+ if ((ch = getc(stream)) == ';')
+ {
+ char_width = 2.7 * SCALE;
+ char_height = 1.9 * SCALE;
+ }
+ }
+ char_space = char_width * (1/.67 - 1);
+ printf("/%s %g %g %g DefFont\n",
+ font, char_width, char_height, char_slant);
+ break;
+
+ case 'L': /* Character Slant */
+ case 'l':
+ if (SIGNED_NUMERIC)
+ char_slant = char_height * getval();
+ else
+ char_slant = 0;
+
+ char_space = char_width * (1/.67 - 1);
+ printf("/%s %g %g %g DefFont\n",
+ font, char_width, char_height, char_slant);
+ break;
+
+ case 'M': /* Symbol Mode */
+ case 'm':
+ if ((ch = getc(stream)) != EOF && ch != ';' && isgraph(ch) > 0)
+ {
+ symbol = ch;
+ SYMBOL = 1;
+ }
+ else
+ SYMBOL = 0;
+ break;
+
+ case 'P': /* Pen Select */
+ case 'p':
+ linesize();
+ break;
+
+ case 'R': /* Relative Character Size */
+ case 'r':
+ {
+ float pwidth, pheight;
+
+ if (SIGNED_NUMERIC)
+ {
+ pwidth = getval() * SCALE; /* Percent */
+ pheight = getval() * SCALE; /* Percent */
+ } else
+ {
+ pwidth = DEFWIDTH * 100 * SCALE;
+ pheight = DEFHEIGHT * 100 * SCALE;
+ }
+ char_width = (xmax - xmin) * XSCALE * pwidth / 100.0;
+ char_height = (ymax - ymin) * YSCALE * pheight / 100.0;
+ char_space = char_width * (1/.67 - 1);
+ }
+ printf("/%s %g %g %g DefFont\n",
+ font, char_width, char_height, char_slant);
+ break;
+
+ default:
+ fprintf(stderr, "Warning: %c%c Unknown HP-GL Command\n", op1, op2);
+ }
+ break;
+
+ case 'T':
+ case 't':
+ op2 = getc(stream);
+ switch (op2)
+ {
+ case 'L': /* Tick Length */
+ case 'l':
+ while (((ch = getc(stream)) != EOF) && ch != ';');
+ fprintf(stderr, "Warning: Tick length not implemented yet\n");
+ break;
+
+ default:
+ fprintf(stderr, "Warning: %c%c Unknown HP-GL Command\n", op1, op2);
+ }
+ break;
+
+ case 'U':
+ case 'u':
+ op2 = getc(stream);
+ switch (op2)
+ {
+ case 'C': /* User Defined Character */
+ case 'c':
+ while (((ch = getc(stream)) != EOF) && ch != ';');
+ fprintf(stderr, "Warning: User defined character not implemented yet\n");
+ break;
+
+ default:
+ fprintf(stderr, "Warning: %c%c Unknown HP-GL Command\n", op1, op2);
+ }
+ break;
+
+ case 'V':
+ case 'v':
+ op2 = getc(stream);
+ switch (op2)
+ {
+ case 'S': /* Velocity Select */
+ case 's':
+ while (((ch = getc(stream)) != EOF) && ch != ';');
+ break;
+
+ default:
+ fprintf(stderr, "Warning: %c%c Unknown HP-GL Command\n", op1, op2);
+ }
+ break;
+
+ case 'W': /* Not HP-GL */
+ case 'w':
+ op2 = getc(stream);
+ switch (op2)
+ {
+ case 'G': /* Shade Wedge */
+ case 'g':
+ break;
+
+ default:
+ fprintf(stderr, "Warning: %c%c Unknown RD-GL Command\n", op1, op2);
+ }
+ break;
+
+ case 'X':
+ case 'x':
+ op2 = getc(stream);
+ switch (op2)
+ {
+ case 'T': /* X Tick */
+ case 't':
+ while (((ch = getc(stream)) != EOF) && ch != ';');
+ fprintf(stderr, "Warning: X tick not implemented yet\n");
+ break;
+
+ default:
+ fprintf(stderr, "Warning: %c%c Unknown HP-GL Command\n", op1, op2);
+ }
+ break;
+
+ case 'Y':
+ case 'y':
+ op2 = getc(stream);
+ switch (op2)
+ {
+ case 'T': /* Y Tick */
+ case 't':
+ while (((ch = getc(stream)) != EOF) && ch != ';');
+ fprintf(stderr, "Warning: Y tick not implemented yet\n");
+ break;
+
+ default:
+ fprintf(stderr, "Warning: %c%c Unknown HP-GL Command\n", op1, op2);
+ }
+ break;
+
+ default:
+ fprintf(stderr, "Warning: %c Unknown HP-GL First Op Command\n", op1);
+ break;
+ }
+}
diff --git a/graphics/hpgl2ps/linesize.c b/graphics/hpgl2ps/linesize.c
new file mode 100644
index 0000000000..c773479602
--- /dev/null
+++ b/graphics/hpgl2ps/linesize.c
@@ -0,0 +1,16 @@
+#include "defn.h"
+
+linesize()
+{
+ int ipen = 0;
+ float linewidth;
+
+ if (SIGNED_NUMERIC)
+ ipen = getval() - 1;
+
+ if (ipen < 0 || ipen > 8)
+ ipen = 0;
+
+ linewidth = pen_size[ipen] * SCALE; /* In mm */
+ printf("%g mm setlinewidth\n", linewidth);
+}
diff --git a/graphics/hpgl2ps/linetype.c b/graphics/hpgl2ps/linetype.c
new file mode 100644
index 0000000000..909b55c436
--- /dev/null
+++ b/graphics/hpgl2ps/linetype.c
@@ -0,0 +1,161 @@
+/*
+ * Sets the line type and the scaling of the line pattern
+ *
+ * Don McCormick CSIRO Division of Applied Physics National Measurements
+ * Laboritory Bradfield Road Lindfield 2018 N.S.W.
+ *
+ * NOTE: default length for a line pattern is approx 6.5 mm on A4 size paper.
+ */
+#include "defn.h"
+
+float linescale;
+int linestyle;
+
+linetype(line)
+int line;
+{
+ float down1, down2;
+ float up1, up2;
+ float diagonal;
+
+ end_draw();
+
+ if (line == LINE_TYPE_SCALE) /* HP-GL only */
+ {
+ if (SIGNED_NUMERIC)
+ {
+ if ((linestyle = rint(getval())) > 6)
+ linestyle = 6;
+ else if (linestyle < -6)
+ linestyle = -6;
+ }
+ else
+ {
+ SETDOT = 0;
+ printf("[] 0 setdash\n");
+ return;
+ }
+
+ diagonal = pow((xmax - xmin),2.0) + pow((ymax - ymin),2.0);
+ diagonal = pow(diagonal,0.5);
+ if (SIGNED_NUMERIC)
+ linescale = getval() * 0.01 * diagonal * XSCALE * SCALE * 0.2;
+ else
+ linescale = 0.015 * diagonal * XSCALE * SCALE * 0.2;
+ } else
+ if (line == LINESCALE) /* DXY commands only */
+ {
+ if (SIGNED_NUMERIC)
+ linescale = getval() / 80 * SCALE;
+ else
+ return;
+ } else
+ if (line == LINETYPE) /* DXY commands only */
+ {
+ if (SIGNED_NUMERIC)
+ {
+ if ((linestyle = rint(getval())) > 5)
+ linestyle = 5;
+ else if (linestyle < -5)
+ linestyle = -5;
+ }
+ else
+ return;
+ } else
+ {
+ fprintf(stderr, "Error: Unknown line flag in linetype.c\n");
+ exit(1);
+ }
+ /*
+ * select a line style/type and scale/pitch
+ */
+ switch (linestyle)
+ {
+ case 6:
+ down1 = 2.0;
+ up1 = up2 = 1.5;
+ down2 = 1.5;
+ break;
+
+ case 5:
+ down1 = 3.0;
+ up1 = up2 = 1.0;
+ down2 = 1.5;
+ break;
+
+ case 4:
+ down1 = 4.0;
+ up1 = up2 = 0.75;
+ down2 = 1.0;
+ break;
+
+ case 3:
+ down1 = 5.0;
+ up1 = up2 = 1.0;
+ down2 = 0.5;
+ break;
+
+ case 2:
+ down1 = 5.5;
+ up1 = 1.0;
+ up2 = down2 = 0.0;
+ break;
+
+ case 1:
+ down1 = 5.0;
+ up1 = 1.5;
+ up2 = down2 = 0.0;
+ break;
+
+ case -1:
+ down1 = 1.5;
+ up1 = 3.5;
+ down2 = 1.5;
+ up2 = 0.0;
+ break;
+
+ case -2:
+ down1 = 2.0;
+ up1 = 2.5;
+ down2 = 2.0;
+ up2 = 0.0;
+ break;
+
+ case -3:
+ down1 = 2.5;
+ up1 = up2 = 1.75;
+ down2 = 0.5;
+ break;
+
+ case -4:
+ down1 = 2.5;
+ up1 = up2 = 1.5;
+ down2 = 1.5;
+ break;
+
+ case -5:
+ down1 = down2 = 2.0;
+ up1 = up2 = 1.25;
+ break;
+
+ case -6:
+ down1 = down2 = 1.75;
+ up1 = up2 = 1.5;
+ break;
+ }
+ if (linestyle == 0)
+ {
+ SETDOT = 1; /* For HP-GL only */
+ printf("[] 0 setdash\n"); /* For DXY commands */
+ } else
+ {
+ SETDOT = 0; /* For HP-GL only */
+ if (linescale <= 0) linescale = SCALE;
+ down1 *= linescale;
+ up2 *= linescale;
+ up1 *= linescale;
+ down2 *= linescale;
+ printf("[%g mm %g mm %g mm %g mm] 0 setdash\n",
+ down1, up1, down2, up2);
+ }
+}
diff --git a/graphics/hpgl2ps/manualfeed.c b/graphics/hpgl2ps/manualfeed.c
new file mode 100644
index 0000000000..e4976fa317
--- /dev/null
+++ b/graphics/hpgl2ps/manualfeed.c
@@ -0,0 +1,24 @@
+/*
+ * A procedure to allow the user to use the manual feed on
+ * the LaserWriter.
+ * The default wait before timeout is 3 minutes however this
+ * is easily changed.
+ *
+ * argument: 1. Enable manual feed.
+ * 0. Disable manual feed.
+ *
+ * Don McCormick
+ */
+manualfeed(arg)
+int arg;
+{
+ if (arg == 1)
+ {
+ printf("statusdict /manualfeed true put\n");
+ printf("statusdict /manualfeedtimeout 180 put\n"); /* 3 minute wait */
+ } else
+ printf("statusdict /manualfeed false put\n");
+
+ printf("usertime 5000 add\n");
+ printf("{dup usertime lt {pop exit} if} loop\n");
+}
diff --git a/graphics/hpgl2ps/plotcoords.c b/graphics/hpgl2ps/plotcoords.c
new file mode 100644
index 0000000000..f985222cef
--- /dev/null
+++ b/graphics/hpgl2ps/plotcoords.c
@@ -0,0 +1,47 @@
+/*
+ * Define default maximum and minimum plotting coordinates.
+ * P1 (xmin, ymin), P2 (xmax, ymax)
+ *
+ * PaperSize can be:
+ * "A3" ISO (420mm by 297mm)
+ * "A4" ISO (297mm by 210mm)
+ * "A" ANSI (11" by 8.5")
+ * "B" ANSI (17" by 11")
+ *
+ * Mode can be: "HPGL" or "DXY"
+ *
+ * Don McCormick
+ */
+
+#include "defn.h"
+
+plotcoords()
+{
+ if (strcmp(Mode, "HPGL") == 0)
+ {
+ if (strcmp(PaperSize, "A3") == 0) /* HP-GL ISO A3 420mm * 297mm */
+ {
+ xmax = 15200;
+ ymax = 10800;
+ }
+ else /* HP-GL ISO A4 297mm * 210mm */
+ {
+ xmax = 10800;
+ ymax = 7680;
+ }
+ }
+ else
+ {
+ if (strcmp(PaperSize, "A3") == 0) /* DXY ISO A3 420mm * 297mm */
+ {
+ xmax = 3800;
+ ymax = 2700;
+ }
+ else /* DXY ISO A4 297mm * 210mm */
+ {
+ xmax = 2700;
+ ymax = 1920;
+ }
+ }
+ xmin = ymin = 0.0;
+}
diff --git a/graphics/hpgl2ps/plotdot.c b/graphics/hpgl2ps/plotdot.c
new file mode 100644
index 0000000000..d35b09a868
--- /dev/null
+++ b/graphics/hpgl2ps/plotdot.c
@@ -0,0 +1,39 @@
+/*
+ * Plot a dot or symbol on the paper
+ */
+#include "defn.h"
+
+plotdot(type)
+char *type;
+{
+ end_draw();
+
+ while (SIGNED_NUMERIC)
+ {
+ xval = getval() * XSCALE;
+ yval = getval() * YSCALE;
+ if (type == RMOVE)
+ {
+ absX += xval;
+ absY += yval;
+ } else
+ if (type == MOVE)
+ {
+ absX = xval;
+ absY = yval;
+ } else
+ {
+ fprintf(stderr, "Error: expecting move command not %s\n", type);
+ exit(1);
+ }
+
+ if (SYMBOL)
+ printf("%g %g 5 %g (%c) Text\n", absX, absY, char_angle, symbol);
+ else if (SETDOT)
+ {
+ printf("newpath\n");
+ printf(" %g %g %s %g %g %s\n", absX, absY, MOVE, absX, absY, DRAW);
+ printf("stroke\n");
+ }
+ }
+}
diff --git a/graphics/hpgl2ps/plotinit.c b/graphics/hpgl2ps/plotinit.c
new file mode 100644
index 0000000000..326ffb648a
--- /dev/null
+++ b/graphics/hpgl2ps/plotinit.c
@@ -0,0 +1,57 @@
+#include "defn.h"
+
+plotinit()
+{
+ /*
+ * Initialisation of PostScript plot macros
+ */
+ MOVE = "M";
+ RMOVE = "R";
+ DRAW = "D";
+ RDRAW = "I";
+
+ LANDSCAPE = 1; /* Display plot in Landscape mode */
+
+ SCALE = 1; /* Default Scale */
+
+ PLOTABS = 1; /* Absolute plot coordinates */
+
+ PENDOWN = 0; /* Penup */
+
+ SETDOT = 0; /* HP-GL only for linetype = 0 */
+
+ SYMBOL = 0; /* HP-GL only */
+ /*
+ * Default line/pen sizes (in mm)
+ */
+ pen_size[0] = 0.1;
+ pen_size[1] = 0.2;
+ pen_size[2] = 0.3;
+ pen_size[3] = 0.4;
+ pen_size[4] = 0.5;
+ pen_size[5] = 0.7;
+ pen_size[6] = 1.0;
+ pen_size[7] = 1.25;
+ pen_size[8] = 1.5;
+
+ strcpy("Helvetica",font); /* Default font */
+
+ EOL = '\003'; /* End of line terminator default */
+
+ /*
+ * Default character specifications
+ */
+ char_angle = 0; /* Degrees */
+ char_slant = 0; /* tan(angle) */
+ char_height = 2.7; /* mm */
+ char_space = 0.8; /* mm */
+ char_width = 1.9; /* mm */
+ /*
+ * Page offsets set to zero
+ */
+ xoffset = yoffset = 0;
+ /*
+ * Define degree to radian parameter
+ */
+ deg_rad = asin(1.0) / 90.0;
+}
diff --git a/graphics/hpgl2ps/plotps.c b/graphics/hpgl2ps/plotps.c
new file mode 100644
index 0000000000..9f6db9d20a
--- /dev/null
+++ b/graphics/hpgl2ps/plotps.c
@@ -0,0 +1,64 @@
+#include "defn.h"
+
+#define MAXDRAWPOINTS 100
+
+plotps(type)
+char *type;
+{
+ if (type == MOVE || type == RMOVE)
+ {
+ while (SIGNED_NUMERIC)
+ {
+ if (type == MOVE)
+ {
+ end_draw();
+ absX = lastXmove = getval() * XSCALE;
+ absY = lastYmove = getval() * YSCALE;
+ } else
+ if (type == RMOVE)
+ {
+ end_draw();
+ lastXmove = absX += getval() * XSCALE;
+ lastYmove = absY += getval() * YSCALE;
+ }
+ }
+ }
+ else /* Must be a DRAW or RDRAW */
+ {
+ while (SIGNED_NUMERIC)
+ {
+ if (dcount++ >= MAXDRAWPOINTS)
+ {
+ end_draw();
+ printf("newpath\n");
+ printf(" %g %g %s\n", absX, absY, MOVE);
+ DRAW_FLAG = 1;
+ fprintf(stderr, "Warning exceeded 100 draw points\n");
+ }
+ xval = getval() * XSCALE;
+ yval = getval() * YSCALE;
+ if (!DRAW_FLAG)
+ {
+ printf("newpath\n");
+ printf(" %g %g %s\n", absX, absY, MOVE);
+ DRAW_FLAG = 1;
+ }
+ if (type == RDRAW)
+ {
+ absX += xval;
+ absY += yval;
+ printf(" %g %g %s\n", xval, yval, RDRAW);
+ } else
+ if (type == DRAW)
+ {
+ absX = xval;
+ absY = yval;
+ printf(" %g %g %s\n", absX, absY, DRAW);
+ } else
+ {
+ fprintf(stderr, "Error: expecting draw command not %s\n", type);
+ exit(1);
+ }
+ }
+ }
+}
diff --git a/graphics/hpgl2ps/ps_macros.c b/graphics/hpgl2ps/ps_macros.c
new file mode 100644
index 0000000000..c0096dbe83
--- /dev/null
+++ b/graphics/hpgl2ps/ps_macros.c
@@ -0,0 +1,121 @@
+ps_macros()
+{
+ printf("%%! PS-Adobe-1.0: For Apple LaserWriter\n");
+ printf("%% default font is 10 pt. Helvetica\n");
+ printf("/basefont {/Helvetica findfont 10 scalefont setfont} def\n");
+
+ printf("/mm {72.27 mul 25.4 div} def\n"); /* Specify millimeters */
+
+ printf("/M\n"); /* Move macro */
+ printf("{\n");
+ printf(" /Ymove exch def\n");
+ printf(" /Xmove exch def\n");
+ printf(" Xmove mm Ymove mm moveto\n");
+ printf("} def\n");
+
+ printf("/R\n"); /* Relative move macro */
+ printf("{\n");
+ printf(" /Yrmove exch def\n");
+ printf(" /Xrmove exch def\n");
+ printf(" Xrmove mm Yrmove mm rmoveto\n");
+ printf("} def\n");
+
+ printf("/D\n"); /* Draw macro */
+ printf("{\n");
+ printf(" /Ydraw exch def\n");
+ printf(" /Xdraw exch def\n");
+ printf(" Xdraw mm Ydraw mm lineto\n");
+ printf("} def\n");
+
+ printf("/I\n"); /* Relative draw macro */
+ printf("{\n");
+ printf(" /Yrdraw exch def\n");
+ printf(" /Xrdraw exch def\n");
+ printf(" Xrdraw mm Yrdraw mm rlineto\n");
+ printf("} def\n");
+ /*
+ * Procedure to change font and size of font
+ * ----> font size Font <----
+ */
+ printf("/Font\n");
+ printf("{\n");
+ printf(" /Height exch def\n");
+ printf(" /FontName exch def\n");
+ printf(" FontName findfont Height mm scalefont setfont\n");
+ printf("} def\n");
+ /*
+ * Procedure to change font, width, slant and height
+ * ----> font width height slant DefFont <----
+ *
+ * Note: slant = height * tan( slant_angle )
+ */
+ printf("/DefFont\n");
+ printf("{\n");
+ printf(" /Slant exch def\n");
+ printf(" /Height exch def\n");
+ printf(" /Width exch def\n");
+ printf(" /FontName exch def\n");
+ printf(" FontName findfont [ Width mm 0 Slant mm Height mm 0 0] makefont setfont\n");
+ printf("} def\n");
+ /*
+ * General Text Layout Procedure
+ * ----> x y pos_num angle (text) Text <----
+ */
+ printf("/Text\n");
+ printf("{\n");
+ printf(" /String exch def\n");
+ printf(" /Angle exch def\n");
+ printf(" /Position exch def\n");
+ printf(" /Ymove exch def\n");
+ printf(" /Xmove exch def\n");
+ printf(" Position 1 lt {/hpf 0 def /lpf 0 def} if\n");
+ printf(" Position 1 eq {/hpf 0 def /lpf 0 def} if\n");
+ printf(" Position 2 eq {/hpf 0 def /lpf 0.5 def} if\n");
+ printf(" Position 3 eq {/hpf 0 def /lpf 1 def} if\n");
+ printf(" Position 4 eq {/hpf 0.5 def /lpf 0 def} if\n");
+ printf(" Position 5 eq {/hpf 0.5 def /lpf 0.5 def} if\n");
+ printf(" Position 6 eq {/hpf 0.5 def /lpf 1 def} if\n");
+ printf(" Position 7 eq {/hpf 1 def /lpf 0 def} if\n");
+ printf(" Position 8 eq {/hpf 1 def /lpf 0.5 def} if\n");
+ printf(" Position 9 eq {/hpf 1 def /lpf 1 def} if\n");
+ printf(" Position 9 gt {/hpf 1 def /lpf 1 def} if\n");
+ printf(" /StrLen String stringwidth pop lpf mul def\n");
+ printf(" /StrHt Height mm hpf mul def\n");
+ printf(" /Xdiff StrHt Angle sin mul StrLen Angle cos mul sub def\n");
+ printf(" /Ydiff StrHt Angle cos mul StrLen Angle sin mul add def\n");
+ printf(" Xmove mm Xdiff add Ymove mm Ydiff sub moveto\n");
+ printf(" gsave\n");
+ printf(" Angle rotate\n");
+ printf(" String show\n");
+ printf(" grestore\n");
+ printf(" /PosterOnly 0 def\n");
+ printf("} def\n");
+ /*
+ * Ellipse and Circle procedure.
+ * ----> xcen ycen xrad yrad start_angle end_angle Ellipse <----
+ */
+ printf("/EllipseDict 8 dict def\n");
+ printf("EllipseDict /mtrx matrix put\n");
+ printf("/Ellipse \n");
+ printf("{ EllipseDict begin\n");
+ printf(" /endangle exch def\n");
+ printf(" /startangle exch def\n");
+ printf(" /yradius exch def\n");
+ printf(" /xradius exch def\n");
+ printf(" /ycenter exch def\n");
+ printf(" /xcenter exch def\n");
+ printf(" /savematrix mtrx currentmatrix def\n");
+ printf(" xcenter mm ycenter mm translate\n");
+ printf(" xradius mm yradius mm div 1 scale\n");
+ printf(" newpath\n");
+ printf(" 0 0 xradius mm startangle endangle arc\n");
+ printf(" stroke\n");
+ printf(" savematrix setmatrix\n");
+ printf(" end\n");
+ printf("} def\n");
+
+ printf("basefont\n"); /* Set the default font */
+ printf("1 setlinecap\n"); /* Use round caps */
+ printf("1 setlinejoin\n"); /* Use round joins */
+ printf("3 setmiterlimit\n"); /* Bevel small angle miters */
+}
diff --git a/graphics/hpgl2ps/rectangle.c b/graphics/hpgl2ps/rectangle.c
new file mode 100644
index 0000000000..3035b1f350
--- /dev/null
+++ b/graphics/hpgl2ps/rectangle.c
@@ -0,0 +1,29 @@
+#include "defn.h"
+
+rectangle()
+{
+ int hatch;
+ float width, height;
+ float hatch_spacing;
+ float hatch_angle;
+
+ if (SIGNED_NUMERIC)
+ hatch = getval();
+ if (SIGNED_NUMERIC)
+ width = getval() * XSCALE;
+ if (SIGNED_NUMERIC)
+ height = getval() * YSCALE;
+ if (SIGNED_NUMERIC)
+ hatch_spacing = getval() * XSCALE;
+ if (SIGNED_NUMERIC)
+ hatch_angle = getval();
+
+ end_draw();
+ printf("%g %g M\n", xval, yval);
+ printf("%g 0 I\n", width);
+ printf("0 %g I\n", height);
+ printf("-%g 0 I\n", width);
+ printf("closepath stroke\n");
+ if (hatch != 2)
+ fprintf(stderr, "Warning: Cross hatching not implemented yet\n");
+}
diff --git a/graphics/hpgl2ps/test1.dxy b/graphics/hpgl2ps/test1.dxy
new file mode 100644
index 0000000000..b688e42fbc
--- /dev/null
+++ b/graphics/hpgl2ps/test1.dxy
@@ -0,0 +1,17 @@
+J1
+M 1000, 1000
+I 100, 0, -200,0, 100, 0, 0,100,0, -200
+P Hi There
+C 1000, 1000, 500, 0, 250
+M 2000,1000
+I 100, 0, -200,0, 100, 0, 0,100,0, -200
+L 2
+J5
+C 2000, 1000, 500, 250, 0
+J3
+M 0 0
+I 3800,0,0,2700,-3800,0,0,-2700
+M 500,2000
+^SL1;S50PDXY-880
+^SL;S3
+
diff --git a/graphics/hpgl2ps/test1.hpgl b/graphics/hpgl2ps/test1.hpgl
new file mode 100644
index 0000000000..688194ccb4
--- /dev/null
+++ b/graphics/hpgl2ps/test1.hpgl
@@ -0,0 +1,38 @@
+DF;IN;LT;PU1000,1000;PD2000,1000,2000,2000,1000,2000,1000,1000;
+PR-100,0,0,-100,100,0,0,100;
+PU;PA0,0;PD10800,0,10800,7680,0,7680,0,0;PU;
+LT6,2;PA;PU4000,1400;PD;PR4000,0;
+LT5,2;PA;PU4000,1300;PD;PR4000,0;
+LT4,2;PA;PU4000,1200;PD;PR4000,0;
+LT3,2;PA;PU4000,1100;PD;PR4000,0;
+LT2,2;PA;PU4000,1000;PD;PR4000,0;
+LT1,2;PA;PU4000,900;PD;PR4000,0;
+LT0;PA;PU4000,800;PD;PR4000,0;
+LT-1,2;PA;PU4000,700;PD;PR4000,0;
+LT-2,2;PA;PU4000,600;PD;PR4000,0;
+LT-3,2;PA;PU4000,500;PD;PR4000,0;
+LT-4,2;PA;PU4000,400;PD;PR4000,0;
+LT-5,2;PA;PU4000,300;PD;PR4000,0;
+LT-6,2;PA;PU4000,200;PD;PR4000,0;
+PU;PA2000,4000;
+DI;LB -- 0deg --
+DI1,1;LB -- 45deg --
+DI0,1;LB -- 90deg --
+DI-1,1;LB -- 135deg --
+DI-1,0;LB -- 180deg --
+DI-1,-1;LB -- 225deg --
+DI0,-1;LB -- 270deg --
+DI1,-1;LB -- 315deg --
+PA4000,4000;
+DI;SL1;LB SLANT of 45deg
+PA4000,3600;
+SL-1;LB SLANT of -45deg
+PA2000,6000;
+SL;SR;LB Size is relative
+PA2000,5500;
+SI;LB DEFAULT sizes
+PA2000,5000;
+SI.8,1;LBLARGE size (w=8mm, h=10mm)
+LT; PA 9000,1000;CI500,20;CI400;CI300;CI200,1;CI100;CI50;
+IN;SM+;PA9000,1000,10000,1000;SM%;PR0,500,0,-1000;
+SM;
diff --git a/graphics/hpgl2ps/textps.c b/graphics/hpgl2ps/textps.c
new file mode 100644
index 0000000000..035df13cbb
--- /dev/null
+++ b/graphics/hpgl2ps/textps.c
@@ -0,0 +1,116 @@
+#include "defn.h"
+
+#define MAXBUFSIZE 100
+
+textps(type)
+int type;
+{
+ char string[4];
+ char buffer[MAXBUFSIZE];
+ float Xch, Ych;
+ int intval;
+ int i;
+
+ end_draw();
+
+ if (type == TEXT)
+ {
+ for (i = 0 ; i < MAXBUFSIZE; i++) /* Clear buffer */
+ buffer[i] = NULL;
+
+ i = 0; /* Reset buffer counter */
+
+ while (((ch = getc(stream)) != EOF)
+ && ch != CR && ch != LF && ch != EOL)
+ {
+ buffer[i++] = ch;
+/* printf("%g %g 1 %g (%c) Text\n", absX, absY, char_angle, ch);
+ * absX += (char_width + char_space) * cos(char_angle * deg_rad);
+ * absY += (char_width + char_space) * sin(char_angle * deg_rad);
+ */
+ }
+ printf("%g %g 1 %g (%s) Text\n", absX, absY, char_angle, buffer);
+ } else /* Must be a MARK */
+ {
+ int symb_num;
+
+ if (SIGNED_NUMERIC)
+ symb_num = getval();
+ else
+ {
+ fprintf(stderr,
+ "Error: expecting a symbol number not %c (%d)",
+ symb_num, symb_num);
+ exit(1);
+ }
+ intval = (int)(getval() + 0.5);
+ switch (intval)
+ {
+ case 0:
+ strcpy(string, "*");
+ break;
+
+ case 1:
+ strcpy(string, "+");
+ break;
+
+ case 2:
+ strcpy(string, "#");
+ break;
+
+ case 3:
+ strcpy(string, "@");
+ break;
+
+ case 4:
+ strcpy(string, "%");
+ break;
+
+ case 5:
+ strcpy(string, "|");
+ break;
+
+ case 6:
+ strcpy(string, "=");
+ break;
+
+ case 7:
+ strcpy(string, "&");
+ break;
+
+ case 9:
+ strcpy(string, "O");
+ break;
+
+ case 10:
+ strcpy(string, "0");
+ break;
+
+ case 11:
+ strcpy(string, "Y");
+ break;
+
+ case 12:
+ strcpy(string, "X");
+ break;
+
+ case 13:
+ strcpy(string, "Z");
+ break;
+
+ case 14:
+ strcpy(string, "S");
+ break;
+
+ case 15:
+ strcpy(string, "Q");
+ break;
+
+ default:
+ fprintf(stderr, "Warning symbol number is %d\n", symb_num);
+ strcpy(string, "*");
+ break;
+ }
+ printf("%g %g 5 %g (%s) Text\n", absX, absY, char_angle, string);
+ }
+}
diff --git a/graphics/hpgl2ps/viewport.c b/graphics/hpgl2ps/viewport.c
new file mode 100644
index 0000000000..ac34586842
--- /dev/null
+++ b/graphics/hpgl2ps/viewport.c
@@ -0,0 +1,38 @@
+/*
+ * This procedure sets up the variables for the translation of plotter
+ * coordinates to PostScript coordinates.
+ *
+ * Note: the procedure "defaults" may be incorporated here, however
+ * I have not had the time to work it out properly.
+ *
+ * Don McCormick
+ */
+#include "defn.h"
+
+viewport()
+{
+ float pagewidth = 197.0; /* Page width for Laser Printer */
+ float pageheight = 280.0; /* Page height for Laser Printer */
+ float pwoffset = 12;
+ float phoffset = 12;
+
+ float psxmax, psymax; /* Sizes scaled to the viewport */
+
+ if (LANDSCAPE) /* Default mode */
+ {
+ psymax = pagewidth * 0.938095;
+ psxmax = psymax * (xmax - xmin)/ (ymax - ymin);
+ xoffset += (pageheight + phoffset - psxmax) / 2.0;
+ yoffset -= (pagewidth + pwoffset + psymax) / 2.0;
+ printf("90 rotate\n");
+ } else
+ {
+ psxmax = pagewidth * 0.938095;
+ psymax = psxmax * (ymax - ymin) / (xmax - xmin);
+ xoffset += (pagewidth + pwoffset - psxmax) / 2.0;
+ yoffset += (pageheight + phoffset - psymax) / 2.0;
+ }
+ printf("%g mm %g mm translate\n", xoffset, yoffset);
+ XSCALE = psxmax / xmax * SCALE;
+ YSCALE = psymax / ymax * SCALE;
+}