From ed9de1280341db3879323b6e3bee945ef0099044 Mon Sep 17 00:00:00 2001 From: John Honniball Date: Tue, 3 Jul 2018 23:06:59 +0100 Subject: [PATCH] Change use of HPGL-2 command 'EA' into 'PA' so that older plotters and HPGL conversion programs will work properly. In particular, HPGL-to-PostScript was failing to recognise 'EA', which led to rectangles being omitted from the converted drawings. --- hpgllib.c | 38 ++++++++++++++++++++------------------ hpgllib.h | 4 ++-- spiro.cpp | 2 ++ 3 files changed, 24 insertions(+), 20 deletions(-) diff --git a/hpgllib.c b/hpgllib.c index 9aa9451..0bfc678 100644 --- a/hpgllib.c +++ b/hpgllib.c @@ -409,29 +409,31 @@ void closelinesequence (int closePoly) } -void rectangle (double x1, double y1, double x2, double y2) +void rectangle (const double x1, const double y1, const double x2, const double y2) { - int ix1, iy1, ix2, iy2; - - ix1 = (int)(x1 + Minx); - iy1 = (int)(y1 + Miny); - ix2 = (int)(x2 + Minx); - iy2 = (int)(y2 + Miny); - - fprintf (Plt, "PU%d,%d;EA%d,%d;\n", ix1, iy1, ix2, iy2); +/* Use 'PA' here instead of 'EA' (available in HPGL-2) because + some conversion programs (notably HPGL-to-PostScript) fail + to recognise 'EA'. */ + const int ix1 = (int)(x1 + Minx); + const int iy1 = (int)(y1 + Miny); + const int ix2 = (int)(x2 + Minx); + const int iy2 = (int)(y2 + Miny); + + fprintf (Plt, "PU%d,%d;PD;PA%d,%d,%d,%d,%d,%d,%d,%d;\n", ix1, iy1, + ix1, iy2, ix2, iy2, ix2, iy1, ix1, iy1); } -void fillrectangle (double x1, double y1, double x2, double y2) +void fillrectangle (const double x1, const double y1, const double x2, const double y2) { - int ix1, iy1, ix2, iy2; - - ix1 = (int)(x1 + Minx); - iy1 = (int)(y1 + Miny); - ix2 = (int)(x2 + Minx); - iy2 = (int)(y2 + Miny); - - fprintf (Plt, "PU%d,%d;RA%d,%d;\n", ix1, iy1, ix2, iy2); +/* Note that 'RA' is an HPGL-2 command and may not be recognised + by all plotters and all HPGL conversion programs */ + const int ix1 = (int)(x1 + Minx); + const int iy1 = (int)(y1 + Miny); + const int ix2 = (int)(x2 + Minx); + const int iy2 = (int)(y2 + Miny); + + fprintf (Plt, "PU%d,%d;RA%d,%d;\n", ix1, iy1, ix2, iy2); } diff --git a/hpgllib.h b/hpgllib.h index b6ddcb9..abc1070 100644 --- a/hpgllib.h +++ b/hpgllib.h @@ -15,8 +15,8 @@ void lineto (double x, double y); void openlinesequence (double x, double y); void linesegmentto (double x, double y); void closelinesequence (int closePoly); -void rectangle (double x1, double y1, double x2, double y2); -void fillrectangle (double x1, double y1, double x2, double y2); +void rectangle (const double x1, const double y1, const double x2, const double y2); +void fillrectangle (const double x1, const double y1, const double x2, const double y2); void circle (double x, double y, double r); void circle2 (double x, double y, double r, double tol); void arc (double x, double y, double a); diff --git a/spiro.cpp b/spiro.cpp index 47e6969..3454b8f 100644 --- a/spiro.cpp +++ b/spiro.cpp @@ -18,6 +18,8 @@ void Spiro::setup() // printf ("LBhttp://www.dorkbot.org/dorkbotbristol%c;\n", 3); printf ("LBBristol Hackspace%c;\n", 3); printf ("PU%d,%d;EA%d,%d\n", MINX, MINY, MAXX, MAXY); + printf ("PU%d,%d;PD;PA%d,%d,%d,%d,%d,%d,%d,%d\n", MINX, MINY, + MINX, MAXY, MAXX, MAXY, MAXX, MINY, MINX, MINY); } void Spiro::close()