PLplot  5.10.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
hpgl.c
Go to the documentation of this file.
1 // File: hpgl.c
2 //
3 // Descript: hp7470, hp7580, and lj_hpgl drivers
4 //
5 // Library: ---
6 //
7 // Requires: ---
8 //
9 // Public: plD_init_hp7470()
10 // plD_init_hp7580()
11 // plD_init_lj_hpgl()
12 // plD_line_hpgl()
13 // plD_polyline_hpgl()
14 // plD_eop_hpgl()
15 // plD_bop_hpgl()
16 // plD_tidy_hpgl()
17 // plD_state_hpgl()
18 // plD_esc_hpgl()
19 //
20 // pldummy_hpgl()
21 //
22 // Private: initialize_hpgl_pls()
23 //
24 // Notes: ---
25 //
26 //--------------------------------------------------------------------------
27 
28 #include "plDevs.h"
29 
30 #if defined ( PLD_hp7470 ) || defined ( PLD_hp7580 ) || defined ( PLD_lj_hpgl )
31 
32 #include "plplotP.h"
33 #include <stdio.h>
34 #include <string.h>
35 #include "drivers.h"
36 
37 // Device info
38 PLDLLIMPEXP_DRIVER const char* plD_DEVICE_INFO_hpgl =
39 #if defined ( PLD_hp7470 )
40  "hp7470:HP 7470 Plotter File (HPGL Cartridge, Small Plotter):0:hpgl:34:hp7470\n"
41 #endif
42 #if defined ( PLD_hp7580 )
43  "hp7580:HP 7580 Plotter File (Large Plotter):0:hpgl:35:hp7580\n"
44 #endif
45 #if defined ( PLD_lj_hpgl )
46  "lj_hpgl:HP Laserjet III, HPGL emulation mode:0:hpgl:36:lj_hpgl\n"
47 #endif
48 ;
49 
50 
51 void plD_line_hpgl( PLStream *, short, short, short, short );
52 void plD_polyline_hpgl( PLStream *, short *, short *, PLINT );
53 void plD_eop_hpgl( PLStream * );
54 void plD_bop_hpgl( PLStream * );
55 void plD_tidy_hpgl( PLStream * );
56 void plD_state_hpgl( PLStream *, PLINT );
57 void plD_esc_hpgl( PLStream *, PLINT, void * );
58 
59 // top level declarations
60 
61 // Plotter sizes
62 
63 #define HP7470_XMIN 0
64 #define HP7470_XMAX 10299
65 #define HP7470_YMIN 0
66 #define HP7470_YMAX 7649
67 
68 #define HP7580_XMIN -4500
69 #define HP7580_XMAX 4500
70 #define HP7580_YMIN -2790
71 #define HP7580_YMAX 2790
72 
73 #define LJIII_XMIN 0
74 #define LJIII_XMAX 11000
75 #define LJIII_YMIN 500
76 #define LJIII_YMAX 7700
77 
78 #define OF pls->OutFile
79 #define MIN_WIDTH 1. // Minimum pen width
80 #define MAX_WIDTH 10. // Maximum pen width
81 #define DEF_WIDTH 1. // Default pen width
82 
83 static void hpgl_dispatch_init_helper( PLDispatchTable *pdt,
84  char *menustr, char *devnam,
85  int type, int seq, plD_init_fp init )
86 {
87 #ifndef ENABLE_DYNDRIVERS
88  pdt->pl_MenuStr = menustr;
89  pdt->pl_DevName = devnam;
90 #endif
91  pdt->pl_type = type;
92  pdt->pl_seq = seq;
93  pdt->pl_init = init;
94  pdt->pl_line = (plD_line_fp) plD_line_hpgl;
95  pdt->pl_polyline = (plD_polyline_fp) plD_polyline_hpgl;
96  pdt->pl_eop = (plD_eop_fp) plD_eop_hpgl;
97  pdt->pl_bop = (plD_bop_fp) plD_bop_hpgl;
98  pdt->pl_tidy = (plD_tidy_fp) plD_tidy_hpgl;
99  pdt->pl_state = (plD_state_fp) plD_state_hpgl;
100  pdt->pl_esc = (plD_esc_fp) plD_esc_hpgl;
101 }
102 
103 //--------------------------------------------------------------------------
104 // initialize_hpgl_pls()
105 //
106 // Initialize plot stream
107 //--------------------------------------------------------------------------
108 
109 static void
110 initialize_hpgl_pls( PLStream *pls )
111 {
112  PLDev *dev = (PLDev *) pls->dev;
113 
114  if ( pls->width == 0 ) // Is 0 if uninitialized
115  pls->width = 1;
116 
117  plFamInit( pls ); // Initialize family file info
118  plOpenFile( pls ); // get file name if not already set
119 
120  dev->xold = PL_UNDEFINED;
121  dev->yold = PL_UNDEFINED;
122  dev->xlen = dev->xmax - dev->xmin;
123  dev->ylen = dev->ymax - dev->ymin;
124 
125  plP_setpxl( (PLFLT) 40., (PLFLT) 40. );
126  plP_setphy( dev->xmin, dev->xmax, dev->ymin, dev->ymax );
127 }
128 
129 //--------------------------------------------------------------------------
130 // plD_init_hp7470()
131 //
132 // Initialize device.
133 //--------------------------------------------------------------------------
134 
135 #ifdef PLD_hp7470
136 void plD_init_hp7470( PLStream * );
137 
139 {
140  hpgl_dispatch_init_helper( pdt,
141  "HP 7470 Plotter File (HPGL Cartridge, Small Plotter)",
142  "hp7470",
144  (plD_init_fp) plD_init_hp7470 );
145 }
146 
147 void
148 plD_init_hp7470( PLStream *pls )
149 {
150  PLDev *dev;
151 
152  pls->color = 1;
153  dev = plAllocDev( pls ); // Allocate device-specific data
154  dev->xmin = HP7470_XMIN;
155  dev->xmax = HP7470_XMAX;
156  dev->ymin = HP7470_YMIN;
157  dev->ymax = HP7470_YMAX;
158 
159  initialize_hpgl_pls( pls ); // initialize plot stream
160 
161  fputs( "\x1b.I200;;17:\x1b.N;19:\x1b.M;;;10:IN;\n", OF );
162 }
163 #endif // PLD_hp7470
164 
165 //--------------------------------------------------------------------------
166 // plD_init_hp7580()
167 //
168 // Initialize device.
169 //--------------------------------------------------------------------------
170 
171 #ifdef PLD_hp7580
172 void plD_init_hp7580( PLStream * );
173 
175 {
176  hpgl_dispatch_init_helper( pdt,
177  "HP 7580 Plotter File (Large Plotter)", "hp7580",
179  (plD_init_fp) plD_init_hp7580 );
180 }
181 
182 void
183 plD_init_hp7580( PLStream *pls )
184 {
185  PLDev *dev;
186 
187  pls->color = 1;
188  dev = plAllocDev( pls ); // Allocate device-specific data
189  dev->xmin = HP7580_XMIN;
190  dev->xmax = HP7580_XMAX;
191  dev->ymin = HP7580_YMIN;
192  dev->ymax = HP7580_YMAX;
193 
194  initialize_hpgl_pls( pls ); // initialize plot stream
195 
196  fputs( "\x1b.I200;;17:\x1b.N;19:\x1b.M;;;10:IN;\n", OF );
197  fputs( "RO90;IP;SP4;PA;\n", OF );
198 }
199 #endif // PLD_hp7580
200 
201 //--------------------------------------------------------------------------
202 // plD_init_lj_hpgl()
203 //
204 // Initialize device.
205 //--------------------------------------------------------------------------
206 
207 #ifdef PLD_lj_hpgl
208 void plD_init_lj_hpgl( PLStream * );
209 
211 {
212  hpgl_dispatch_init_helper( pdt,
213  "HP Laserjet III, HPGL emulation mode", "lj_hpgl",
215  (plD_init_fp) plD_init_lj_hpgl );
216 }
217 
218 void
219 plD_init_lj_hpgl( PLStream *pls )
220 {
221  PLDev *dev;
222 
223  dev = plAllocDev( pls ); // Allocate device-specific data
224  dev->xmin = LJIII_XMIN;
225  dev->xmax = LJIII_XMAX;
226  dev->ymin = LJIII_YMIN;
227  dev->ymax = LJIII_YMAX;
228 
229  initialize_hpgl_pls( pls ); // initialize plot stream
230 
231 // HP III changes here up to .I200 puts printer in HPGL/2 emulation
232 // with 300DPI printing.
233 // Next line : added pw 0.2 for pen width 0.2 (of an inch ?)
234 //
235  fputs( "\x1b*T300R\x1b%1B;\x1b.I200;;17:\x1b.N;19:\x1b.M;;;10:IN;\n", OF );
236  fputs( "RO90;IP;PW 0.2;SP 1;PA;", OF );
237 }
238 #endif // PLD_lj_hpgl
239 
240 //--------------------------------------------------------------------------
241 // plD_line_hpgl()
242 //
243 // Draw a line in the current color from (x1,y1) to (x2,y2).
244 //--------------------------------------------------------------------------
245 
246 void
247 plD_line_hpgl( PLStream *pls, short x1a, short y1a, short x2a, short y2a )
248 {
249  PLDev *dev = (PLDev *) pls->dev;
250  int x1 = x1a, y1 = y1a, x2 = x2a, y2 = y2a;
251 
252 // Write out old path
253 
254  if ( x1 != dev->xold || y1 != dev->yold )
255  pls->bytecnt += fprintf( OF, "PU%d %d;", x1, y1 );
256 
257 // Add new point to path
258 
259  pls->bytecnt += fprintf( OF, "PD%d %d\n", x2, y2 );
260 
261  dev->xold = x2;
262  dev->yold = y2;
263 }
264 
265 //--------------------------------------------------------------------------
266 // plD_polyline_hpgl()
267 //
268 // Draw a polyline in the current color.
269 //--------------------------------------------------------------------------
270 
271 void
272 plD_polyline_hpgl( PLStream *pls, short *xa, short *ya, PLINT npts )
273 {
274  register PLINT i;
275  PLDev *dev = (PLDev *) pls->dev;
276 
277 // Write out old path
278 
279  if ( xa[0] != dev->xold || ya[0] != dev->yold )
280  pls->bytecnt += fprintf( OF, "PU%d %d;", xa[0], ya[0] );
281 
282 // Add new point to path
283 
284  for ( i = 1; i < npts; i++ )
285  pls->bytecnt += fprintf( OF, "PD%d %d\n", xa[i], ya[i] );
286 
287  dev->xold = xa[ npts - 1 ];
288  dev->yold = ya[ npts - 1 ];
289 }
290 
291 //--------------------------------------------------------------------------
292 // plD_eop_hpgl()
293 //
294 // End of page.
295 //--------------------------------------------------------------------------
296 
297 void
298 plD_eop_hpgl( PLStream *pls )
299 {
300 }
301 
302 //--------------------------------------------------------------------------
303 // plD_bop_hpgl()
304 //
305 // Set up for the next page.
306 // Advance to next family file if necessary (file output).
307 //--------------------------------------------------------------------------
308 
309 void
310 plD_bop_hpgl( PLStream *pls )
311 {
312  PLDev *dev = (PLDev *) pls->dev;
313 
314  dev->xold = PL_UNDEFINED;
315  dev->yold = PL_UNDEFINED;
316 
317  fputs( "PG;\n", OF );
318  if ( !pls->termin )
319  plGetFam( pls );
320 
321  pls->page++;
322 }
323 
324 //--------------------------------------------------------------------------
325 // plD_tidy_hpgl()
326 //
327 // Close graphics file or otherwise clean up.
328 //--------------------------------------------------------------------------
329 
330 void
331 plD_tidy_hpgl( PLStream *pls )
332 {
333  fputs( "SP0\n", OF );
334  plCloseFile( pls );
335 }
336 
337 //--------------------------------------------------------------------------
338 // plD_state_hpgl()
339 //
340 // Handle change in PLStream state (color, pen width, fill attribute, etc).
341 //--------------------------------------------------------------------------
342 
343 void
344 plD_state_hpgl( PLStream *pls, PLINT op )
345 {
346  switch ( op )
347  {
348  case PLSTATE_WIDTH:
349  case PLSTATE_COLOR0: {
350  int width = (int) (
351  ( pls->width < MIN_WIDTH ) ? DEF_WIDTH :
352  ( pls->width > MAX_WIDTH ) ? MAX_WIDTH : pls->width );
353 
354  if ( pls->icol0 < 1 || pls->icol0 > 8 )
355  fputs( "\nInvalid pen selection.", stderr );
356  else
357  fprintf( OF, "SP%d %d\n", pls->icol0, width );
358 
359  break;
360  }
361  case PLSTATE_COLOR1:
362  break;
363  }
364 }
365 
366 //--------------------------------------------------------------------------
367 // plD_esc_hpgl()
368 //
369 // Escape function.
370 //--------------------------------------------------------------------------
371 
372 void
373 plD_esc_hpgl( PLStream *pls, PLINT op, void *ptr )
374 {
375 }
376 
377 #else
378 int
380 {
381  return 0;
382 }
383 
384 #endif // PLD_hp7470 || PLD_hp7580 || PLD_lj_hpgl