PLplot  5.10.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
ljii.c
Go to the documentation of this file.
1 // PLplot Laser Jet II device driver.
2 //
3 // Note only the 150 dpi mode is supported. The others (75,100,300)
4 // should work by just changing the value of DPI and changing the
5 // values passed to plP_setphy().
6 //
7 #include "plDevs.h"
8 
9 #ifdef PLD_ljii
10 
11 #include "plplotP.h"
12 #include "drivers.h"
13 #include <math.h>
14 #include <string.h>
15 
16 #ifdef __GO32__ // dos386/djgpp
17 #ifdef MSDOS
18 #undef MSDOS
19 #endif
20 #endif
21 
22 // Device info
23 PLDLLIMPEXP_DRIVER const char* plD_DEVICE_INFO_ljii =
24  "ljii:LaserJet II Bitmap File (150 dpi):0:ljii:33:ljii\n";
25 
26 // Function prototypes
27 
29 
30 void plD_init_ljii( PLStream * );
31 void plD_line_ljii( PLStream *, short, short, short, short );
32 void plD_polyline_ljii( PLStream *, short *, short *, PLINT );
33 void plD_eop_ljii( PLStream * );
34 void plD_bop_ljii( PLStream * );
35 void plD_tidy_ljii( PLStream * );
36 void plD_state_ljii( PLStream *, PLINT );
37 void plD_esc_ljii( PLStream *, PLINT, void * );
38 
39 static void setpoint( PLINT, PLINT );
40 
41 // top level declarations
42 
43 #define JETX 1103
44 #define JETY 1409
45 
46 #define OF pls->OutFile
47 #define DPI 150 // Resolution Dots per Inch
48 #define CURX 51
49 #define CURY 61
50 #define XDOTS 1104L // # dots across
51 #define YDOTS 1410L // # dots down
52 #define BPROW XDOTS / 8L // # bytes across
53 #define NBYTES BPROW * YDOTS // total number of bytes
54 
55 // Graphics control characters.
56 
57 #define ESC 0x1b
58 #define FF 0x0c
59 
60 static char mask[8] =
61 { '\200', '\100', '\040', '\020', '\010', '\004', '\002', '\001' };
62 
63 #ifndef MSDOS
64 #define _HUGE
65 #else
66 #define _HUGE _huge
67 #endif
68 
69 static char _HUGE *bitmap; // points to memory area NBYTES in size
70 
72 {
73 #ifndef ENABLE_DYNDRIVERS
74  pdt->pl_MenuStr = "LaserJet II Bitmap File (150 dpi)";
75  pdt->pl_DevName = "ljii";
76 #endif
78  pdt->pl_seq = 33;
79  pdt->pl_init = (plD_init_fp) plD_init_ljii;
80  pdt->pl_line = (plD_line_fp) plD_line_ljii;
81  pdt->pl_polyline = (plD_polyline_fp) plD_polyline_ljii;
82  pdt->pl_eop = (plD_eop_fp) plD_eop_ljii;
83  pdt->pl_bop = (plD_bop_fp) plD_bop_ljii;
84  pdt->pl_tidy = (plD_tidy_fp) plD_tidy_ljii;
85  pdt->pl_state = (plD_state_fp) plD_state_ljii;
86  pdt->pl_esc = (plD_esc_fp) plD_esc_ljii;
87 }
88 
89 //--------------------------------------------------------------------------
90 // plD_init_ljii()
91 //
92 // Initialize device.
93 //--------------------------------------------------------------------------
94 
95 void
96 plD_init_ljii( PLStream *pls )
97 {
98  PLDev *dev;
99 
100 // Initialize family file info
101 
102  plFamInit( pls );
103 
104 // Prompt for a file name if not already set
105 
106  plOpenFile( pls );
107 
108 // Allocate and initialize device-specific data
109 
110  dev = plAllocDev( pls );
111 
112  dev->xold = PL_UNDEFINED;
113  dev->yold = PL_UNDEFINED;
114  dev->xmin = 0;
115  dev->ymin = 0;
116 
117  plP_setpxl( (PLFLT) 5.905, (PLFLT) 5.905 );
118 
119 // Rotate by 90 degrees since portrait mode addressing is used
120 
121  dev->xmin = 0;
122  dev->ymin = 0;
123  dev->xmax = JETY;
124  dev->ymax = JETX;
125  dev->xlen = dev->xmax - dev->xmin;
126  dev->ylen = dev->ymax - dev->ymin;
127 
128  plP_setphy( dev->xmin, dev->xmax, dev->ymin, dev->ymax );
129 
130 // If portrait mode is specified, then set up an additional rotation
131 // transformation with aspect ratio allowed to adjust via freeaspect.
132 // Default orientation is landscape (ORIENTATION == 3 or 90 deg rotation
133 // counter-clockwise from portrait). (Legacy PLplot used seascape
134 // which was equivalent to ORIENTATION == 1 or 90 deg clockwise rotation
135 // from portrait.)
136 
137  if ( pls->portrait )
138  {
139  plsdiori( (PLFLT) ( 4 - ORIENTATION ) );
140  pls->freeaspect = 1;
141  }
142 
143 // Allocate storage for bit map matrix
144 
145 #ifdef MSDOS
146  if ( ( bitmap = (char _HUGE *) halloc( (long) NBYTES, sizeof ( char ) ) ) == NULL )
147  plexit( "Out of memory in call to calloc" );
148 #else
149  if ( ( bitmap = (void *) calloc( NBYTES, sizeof ( char ) ) ) == NULL )
150  plexit( "Out of memory in call to calloc" );
151 #endif
152 
153 // Reset Printer
154 
155  fprintf( OF, "%cE", ESC );
156 }
157 
158 //--------------------------------------------------------------------------
159 // plD_line_ljii()
160 //
161 // Draw a line in the current color from (x1,y1) to (x2,y2).
162 //--------------------------------------------------------------------------
163 
164 void
165 plD_line_ljii( PLStream *pls, short x1a, short y1a, short x2a, short y2a )
166 {
167  PLDev *dev = (PLDev *) pls->dev;
168  int i;
169  int x1 = x1a, y1 = y1a, x2 = x2a, y2 = y2a;
170  PLINT x1b, y1b, x2b, y2b;
171  PLFLT length, fx, fy, dx, dy;
172 
173 // Take mirror image, since PCL expects (0,0) to be at top left
174 
175  y1 = dev->ymax - ( y1 - dev->ymin );
176  y2 = dev->ymax - ( y2 - dev->ymin );
177 
178 // Rotate by 90 degrees
179 
180  plRotPhy( ORIENTATION, dev->xmin, dev->ymin, dev->xmax, dev->ymax, &x1, &y1 );
181  plRotPhy( ORIENTATION, dev->xmin, dev->ymin, dev->xmax, dev->ymax, &x2, &y2 );
182 
183  x1b = x1, x2b = x2, y1b = y1, y2b = y2;
184  length = (PLFLT) sqrt( (double)
185  ( ( x2b - x1b ) * ( x2b - x1b ) + ( y2b - y1b ) * ( y2b - y1b ) ) );
186 
187  if ( length == 0. )
188  length = 1.;
189  dx = ( x2 - x1 ) / length;
190  dy = ( y2 - y1 ) / length;
191 
192  fx = x1;
193  fy = y1;
194  setpoint( (PLINT) x1, (PLINT) y1 );
195  setpoint( (PLINT) x2, (PLINT) y2 );
196 
197  for ( i = 1; i <= (int) length; i++ )
198  setpoint( (PLINT) ( fx += dx ), (PLINT) ( fy += dy ) );
199 }
200 
201 //--------------------------------------------------------------------------
202 // plD_polyline_ljii()
203 //
204 // Draw a polyline in the current color.
205 //--------------------------------------------------------------------------
206 
207 void
208 plD_polyline_ljii( PLStream *pls, short *xa, short *ya, PLINT npts )
209 {
210  PLINT i;
211 
212  for ( i = 0; i < npts - 1; i++ )
213  plD_line_ljii( pls, xa[i], ya[i], xa[i + 1], ya[i + 1] );
214 }
215 
216 //--------------------------------------------------------------------------
217 // plD_eop_ljii()
218 //
219 // End of page.(prints it here).
220 //--------------------------------------------------------------------------
221 
222 void
223 plD_eop_ljii( PLStream *pls )
224 {
225  PLINT i, j;
226 
227 // First move cursor to origin
228 
229  fprintf( OF, "%c*p%dX", ESC, CURX );
230  fprintf( OF, "%c*p%dY", ESC, CURY );
231 
232 // Then put Laser Printer in 150 dpi mode
233 
234  fprintf( OF, "%c*t%dR", ESC, DPI );
235  fprintf( OF, "%c*r1A", ESC );
236 
237 // Write out raster data
238 
239  for ( j = 0; j < YDOTS; j++ )
240  {
241  fprintf( OF, "%c*b%ldW", ESC, BPROW );
242  for ( i = 0; i < BPROW; i++ )
243  putc( *( bitmap + i + j * BPROW ), OF );
244  }
245  pls->bytecnt += NBYTES;
246 
247 // End raster graphics and send Form Feed
248 
249  fprintf( OF, "%c*rB", ESC );
250  fprintf( OF, "%c", FF );
251 
252 // Finally, clear out bitmap storage area
253 
254  memset( bitmap, '\0', NBYTES );
255 }
256 
257 //--------------------------------------------------------------------------
258 // plD_bop_ljii()
259 //
260 // Set up for the next page.
261 // Advance to next family file if necessary (file output).
262 //--------------------------------------------------------------------------
263 
264 void
265 plD_bop_ljii( PLStream *pls )
266 {
267  if ( !pls->termin )
268  plGetFam( pls );
269 
270  pls->page++;
271 }
272 
273 //--------------------------------------------------------------------------
274 // plD_tidy_ljii()
275 //
276 // Close graphics file or otherwise clean up.
277 //--------------------------------------------------------------------------
278 
279 void
280 plD_tidy_ljii( PLStream *pls )
281 {
282 // Reset Printer
283 
284  fprintf( OF, "%cE", ESC );
285  plCloseFile( pls );
286  free( (void *) bitmap );
287 }
288 
289 //--------------------------------------------------------------------------
290 // plD_state_ljii()
291 //
292 // Handle change in PLStream state (color, pen width, fill attribute, etc).
293 //--------------------------------------------------------------------------
294 
295 void
296 plD_state_ljii( PLStream *pls, PLINT op )
297 {
298 }
299 
300 //--------------------------------------------------------------------------
301 // plD_esc_ljii()
302 //
303 // Escape function.
304 //--------------------------------------------------------------------------
305 
306 void
307 plD_esc_ljii( PLStream *pls, PLINT op, void *ptr )
308 {
309 }
310 
311 //--------------------------------------------------------------------------
312 // setpoint()
313 //
314 // Sets a bit in the bitmap.
315 //--------------------------------------------------------------------------
316 
317 static void
318 setpoint( PLINT x, PLINT y )
319 {
320  PLINT index;
321  index = x / 8 + y * BPROW;
322  *( bitmap + index ) = *( bitmap + index ) | mask[x % 8];
323 }
324 
325 #else
326 int
328 {
329  return 0;
330 }
331 
332 #endif // PLD_ljii