1 | /* hpgl.cc |
---|
2 | * Export from Aven as HPGL. |
---|
3 | */ |
---|
4 | /* Copyright (C) 1993-2003,2005,2010,2014 Olly Betts |
---|
5 | * |
---|
6 | * This program is free software; you can redistribute it and/or modify |
---|
7 | * it under the terms of the GNU General Public License as published by |
---|
8 | * the Free Software Foundation; either version 2 of the License, or |
---|
9 | * (at your option) any later version. |
---|
10 | * |
---|
11 | * This program is distributed in the hope that it will be useful, |
---|
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
14 | * GNU General Public License for more details. |
---|
15 | * |
---|
16 | * You should have received a copy of the GNU General Public License |
---|
17 | * along with this program; if not, write to the Free Software |
---|
18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
---|
19 | */ |
---|
20 | |
---|
21 | #ifdef HAVE_CONFIG_H |
---|
22 | # include <config.h> |
---|
23 | #endif |
---|
24 | |
---|
25 | #include <stdio.h> |
---|
26 | |
---|
27 | #include "hpgl.h" |
---|
28 | #include "useful.h" |
---|
29 | |
---|
30 | # define HPGL_USE_UC |
---|
31 | /*# define HPGL_USE_SR */ /* for text sized relative to page size */ |
---|
32 | |
---|
33 | # define HPGL_UNITS_PER_MM 40 |
---|
34 | # define HPGL_EOL "\003" /* terminates labelling commands: LB<string>\003 */ |
---|
35 | |
---|
36 | # ifndef HPGL_USE_UC |
---|
37 | # define HPGL_SO "\016" /* shift in & shift out of extended character set */ |
---|
38 | # define HPGL_SI "\017" |
---|
39 | # endif |
---|
40 | |
---|
41 | # define HPGL_CROSS_SIZE 28 /* length of cross arms (in HPGL units) */ |
---|
42 | |
---|
43 | static long xpPageWidth, ypPageDepth; |
---|
44 | |
---|
45 | static long x_org = 0, y_org = 0; |
---|
46 | static bool fNewLines = fTrue; |
---|
47 | static bool fOriginInCentre = fFalse; |
---|
48 | |
---|
49 | /* Check if this line intersects the current page */ |
---|
50 | /* Initialise HPGL routines. */ |
---|
51 | void HPGL::header(const char *, const char *, time_t) |
---|
52 | { |
---|
53 | // FIXME: mm_across_page, mm_down_page, origin_in_centre, scale |
---|
54 | double PaperWidth = 9999999, PaperDepth = 9999999; |
---|
55 | fOriginInCentre = true; |
---|
56 | |
---|
57 | xpPageWidth = (long)(HPGL_UNITS_PER_MM * (double)PaperWidth); |
---|
58 | ypPageDepth = (long)(HPGL_UNITS_PER_MM * (double)PaperDepth); |
---|
59 | |
---|
60 | /* SR scales characters relative to P1 and P2 */ |
---|
61 | /* SI scales characters to size given (in cm) */ |
---|
62 | /* INitialise; Select Pen 1; */ |
---|
63 | /* Either: Scale chars Relative to P1 & P2 0.5,1.0 (2/3 deflt size) */ |
---|
64 | /* Or: Scale chars absolute to 2/3 of default size on A4 page */ |
---|
65 | fputs("IN;SP1;" |
---|
66 | #ifndef HPGL_USE_UC |
---|
67 | "CA-1;GM0,800;" /* Char set Alternate -1; Get Memory; */ |
---|
68 | #endif |
---|
69 | #ifdef HPGL_USE_SR |
---|
70 | "SR0.5,1.0;" |
---|
71 | #else |
---|
72 | "SI0.125,.179;" |
---|
73 | #endif |
---|
74 | , fh); |
---|
75 | if (fNewLines) PUTC('\n', fh); |
---|
76 | |
---|
77 | #ifndef HPGL_USE_UC |
---|
78 | /* define degree and copyright symbols */ |
---|
79 | fputs("DL32,10,30,12,30,13,29,13,27,12,26,10,26,9,27,9,29," |
---|
80 | "10,30;DL40,0,0;", fh); /* Hope this works! Seems to for BP */ |
---|
81 | if (fNewLines) PUTC('\n', fh); |
---|
82 | |
---|
83 | fputs("DL67,16,14,16,18,17,22,19,25,22,28,26,30,31,31,37,32," |
---|
84 | "43,32,49,31,53,30,58,28,61,25,63,22,64,18,64,14,63,10," |
---|
85 | "61,7,58,4,53,2,49,1,43,0,37,0,31,1,26,2,22,4,19,7,17,10," |
---|
86 | "16,14;", fh); |
---|
87 | if (fNewLines) PUTC('\n', fh); |
---|
88 | |
---|
89 | fputs("DL41,4,20,3,19,0,23,-4,24,-9,24,-14,23,-17,22,-20,19," |
---|
90 | "-21,16,-20,13,-17,10,-14,9,-9,8,-4,8,0,9,3,11,4,12;", fh); |
---|
91 | if (fNewLines) PUTC('\n', fh); |
---|
92 | #endif |
---|
93 | #if 0 |
---|
94 | /* and set clipping (Input Window!) on plotter (left,bottom,right,top) */ |
---|
95 | fprintf(fh, "IW%ld,%ld,%ld,%ld;", clip.x_min - x_org, clip.y_min - y_org, |
---|
96 | clip.x_min - x_org + xpPageWidth, clip.y_min - y_org + ypPageDepth); |
---|
97 | #endif |
---|
98 | } |
---|
99 | |
---|
100 | void |
---|
101 | HPGL::line(const img_point *p1, const img_point *p, bool /*fSurface*/, bool fPending) |
---|
102 | { |
---|
103 | if (fPending) { |
---|
104 | fprintf(fh, "PU%ld,%ld;", long(p1->x - x_org), long(p1->y - y_org)); |
---|
105 | } |
---|
106 | fprintf(fh, "PD%ld,%ld;", long(p->x - x_org), long(p->y - y_org)); |
---|
107 | } |
---|
108 | |
---|
109 | #define CS HPGL_CROSS_SIZE |
---|
110 | #define CS2 (2 * HPGL_CROSS_SIZE) |
---|
111 | void |
---|
112 | HPGL::cross(const img_point *p, bool /*fSurface*/) |
---|
113 | { |
---|
114 | fprintf(fh, "PU%ld,%ld;", long(p->x - x_org), long(p->y - y_org)); |
---|
115 | /* SM plots a symbol at each point, but it isn't very convenient here */ |
---|
116 | /* We can write PDPR%d,%dPR%d,%d... but the HP7475A manual doesn't say */ |
---|
117 | /* clearly if this will work on older plotters (such as the HP9872) */ |
---|
118 | fprintf(fh, "PD;PR%d,%d;PR%d,%d;PU%d,0;PD%d,%d;PU%d,%d;PA;", |
---|
119 | CS, CS, -CS2, -CS2, CS2, /*0,*/ -CS2, CS2, CS, -CS); |
---|
120 | if (fNewLines) PUTC('\n', fh); |
---|
121 | } |
---|
122 | #undef CS |
---|
123 | #undef CS2 |
---|
124 | |
---|
125 | void |
---|
126 | HPGL::label(const img_point *p, const char *s, bool /*fSurface*/, int) |
---|
127 | { |
---|
128 | /* LB is a text label, terminated with a ^C */ |
---|
129 | fprintf(fh, "PU%ld,%ld;LB", long(p->x - x_org), long(p->y - y_org)); |
---|
130 | while (*s) { |
---|
131 | switch (*s) { |
---|
132 | case '\xB0': |
---|
133 | #ifdef HPGL_USE_UC |
---|
134 | /* draw a degree sign */ |
---|
135 | fputs(HPGL_EOL";UC1.25,7.5,99,.25,0,.125,-.25,0,-.5," |
---|
136 | "-.125,-.25,-.25,0,-.125,.25,0,.5,.125,.25;LB", fh); |
---|
137 | #else |
---|
138 | /* KLUDGE: this prints the degree sign if the plotter supports |
---|
139 | * extended chars or a space if not, since we tried to redefine |
---|
140 | * space. Nifty, eh? */ |
---|
141 | fputs(HPGL_SO" "HPGL_SI, fh); |
---|
142 | #endif |
---|
143 | break; |
---|
144 | case '\xA9': |
---|
145 | #ifdef HPGL_USE_UC |
---|
146 | /* (C) needs two chars to look right! */ |
---|
147 | /* This bit does the circle of the (C) symbol: */ |
---|
148 | fputs(HPGL_EOL";", fh); |
---|
149 | if (fNewLines) PUTC('\n', fh); |
---|
150 | fputs("UC2,3.5,99,0,1,0.125,1,0.25,.75,0.375,.75," |
---|
151 | ".5,.5,.625,.25,.75,.25,.75,0,.75,-.25,.625,-.25," |
---|
152 | ".5,-.5,.375,-.75,.25,-.75,.125,-1,0,-1,-0.125,-1," |
---|
153 | "-0.25,-.75,-0.375,-.75,-.5,-.5,-.625,-.25,-.75,-.25," |
---|
154 | "-.75,0,-.75,.25,-.625,.25,-.5,.5,-.375,.75,-.25,.75," |
---|
155 | "-.125,1;", fh); |
---|
156 | if (fNewLines) PUTC('\n', fh); |
---|
157 | /* And this bit's the c in the middle: */ |
---|
158 | fputs("UC.5,5,99,-.125,.25,-.375,.5,-.5,.25,-.625,0," |
---|
159 | "-.625,-.25,-.375,-.25,-.375,-.75,-.125,-.75,.125,-.75," |
---|
160 | ".375,-.75,.375,-.25,.625,-.25,.625,0,.5,.25,.375,.5," |
---|
161 | ".125,.25;", fh); |
---|
162 | if (fNewLines) PUTC('\n', fh); |
---|
163 | fputs("LB", fh); |
---|
164 | #else |
---|
165 | fputs(HPGL_SO"(C)"HPGL_SI, fh); |
---|
166 | #endif |
---|
167 | break; |
---|
168 | default: |
---|
169 | PUTC(*s, fh); |
---|
170 | } |
---|
171 | s++; |
---|
172 | } |
---|
173 | fputs(HPGL_EOL";", fh); |
---|
174 | if (fNewLines) PUTC('\n', fh); |
---|
175 | } |
---|
176 | |
---|
177 | void |
---|
178 | HPGL::footer() |
---|
179 | { |
---|
180 | /* Clear clipping window; New page. NB PG is a no-op on the HP7475A */ |
---|
181 | fputs("IW;PG;", fh); |
---|
182 | if (fNewLines) PUTC('\n', fh); |
---|
183 | } |
---|