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