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