00001
00002
00003
00004
00005
00006
00007
00008
00009 #include "plDevs.h"
00010
00011 #ifdef PLD_ljii
00012
00013 #include "plplotP.h"
00014 #include "drivers.h"
00015 #include <math.h>
00016 #include <string.h>
00017
00018 #ifdef __GO32__ // dos386/djgpp
00019 #ifdef MSDOS
00020 #undef MSDOS
00021 #endif
00022 #endif
00023
00024
00025 PLDLLIMPEXP_DRIVER const char* plD_DEVICE_INFO_ljii =
00026 "ljii:LaserJet II Bitmap File (150 dpi):0:ljii:33:ljii\n";
00027
00028
00029
00030 void plD_dispatch_init_ljii( PLDispatchTable *pdt );
00031
00032 void plD_init_ljii( PLStream * );
00033 void plD_line_ljii( PLStream *, short, short, short, short );
00034 void plD_polyline_ljii( PLStream *, short *, short *, PLINT );
00035 void plD_eop_ljii( PLStream * );
00036 void plD_bop_ljii( PLStream * );
00037 void plD_tidy_ljii( PLStream * );
00038 void plD_state_ljii( PLStream *, PLINT );
00039 void plD_esc_ljii( PLStream *, PLINT, void * );
00040
00041 static void setpoint( PLINT, PLINT );
00042
00043
00044
00045 #define JETX 1103
00046 #define JETY 1409
00047
00048 #define OF pls->OutFile
00049 #define DPI 150 // Resolution Dots per Inch
00050 #define CURX 51
00051 #define CURY 61
00052 #define XDOTS 1104L // # dots across
00053 #define YDOTS 1410L // # dots down
00054 #define BPROW XDOTS / 8L // # bytes across
00055 #define NBYTES BPROW * YDOTS // total number of bytes
00056
00057
00058
00059 #define ESC 0x1b
00060 #define FF 0x0c
00061
00062 static char mask[8] =
00063 { '\200', '\100', '\040', '\020', '\010', '\004', '\002', '\001' };
00064
00065 #ifndef MSDOS
00066 #define _HUGE
00067 #else
00068 #define _HUGE _huge
00069 #endif
00070
00071 static char _HUGE *bitmap;
00072
00073 void plD_dispatch_init_ljii( PLDispatchTable *pdt )
00074 {
00075 #ifndef ENABLE_DYNDRIVERS
00076 pdt->pl_MenuStr = "LaserJet II Bitmap File (150 dpi)";
00077 pdt->pl_DevName = "ljii";
00078 #endif
00079 pdt->pl_type = plDevType_FileOriented;
00080 pdt->pl_seq = 33;
00081 pdt->pl_init = (plD_init_fp) plD_init_ljii;
00082 pdt->pl_line = (plD_line_fp) plD_line_ljii;
00083 pdt->pl_polyline = (plD_polyline_fp) plD_polyline_ljii;
00084 pdt->pl_eop = (plD_eop_fp) plD_eop_ljii;
00085 pdt->pl_bop = (plD_bop_fp) plD_bop_ljii;
00086 pdt->pl_tidy = (plD_tidy_fp) plD_tidy_ljii;
00087 pdt->pl_state = (plD_state_fp) plD_state_ljii;
00088 pdt->pl_esc = (plD_esc_fp) plD_esc_ljii;
00089 }
00090
00091
00092
00093
00094
00095
00096
00097 void
00098 plD_init_ljii( PLStream *pls )
00099 {
00100 PLDev *dev;
00101
00102
00103
00104 plFamInit( pls );
00105
00106
00107
00108 plOpenFile( pls );
00109
00110
00111
00112 dev = plAllocDev( pls );
00113
00114 dev->xold = PL_UNDEFINED;
00115 dev->yold = PL_UNDEFINED;
00116 dev->xmin = 0;
00117 dev->ymin = 0;
00118
00119 plP_setpxl( (PLFLT) 5.905, (PLFLT) 5.905 );
00120
00121
00122
00123 dev->xmin = 0;
00124 dev->ymin = 0;
00125 dev->xmax = JETY;
00126 dev->ymax = JETX;
00127 dev->xlen = dev->xmax - dev->xmin;
00128 dev->ylen = dev->ymax - dev->ymin;
00129
00130 plP_setphy( dev->xmin, dev->xmax, dev->ymin, dev->ymax );
00131
00132
00133
00134
00135
00136
00137
00138
00139 if ( pls->portrait )
00140 {
00141 plsdiori( (PLFLT) ( 4 - ORIENTATION ) );
00142 pls->freeaspect = 1;
00143 }
00144
00145
00146
00147 #ifdef MSDOS
00148 if ( ( bitmap = (char _HUGE *) halloc( (long) NBYTES, sizeof ( char ) ) ) == NULL )
00149 plexit( "Out of memory in call to calloc" );
00150 #else
00151 if ( ( bitmap = (void *) calloc( NBYTES, sizeof ( char ) ) ) == NULL )
00152 plexit( "Out of memory in call to calloc" );
00153 #endif
00154
00155
00156
00157 fprintf( OF, "%cE", ESC );
00158 }
00159
00160
00161
00162
00163
00164
00165
00166 void
00167 plD_line_ljii( PLStream *pls, short x1a, short y1a, short x2a, short y2a )
00168 {
00169 PLDev *dev = (PLDev *) pls->dev;
00170 int i;
00171 int x1 = x1a, y1 = y1a, x2 = x2a, y2 = y2a;
00172 PLINT x1b, y1b, x2b, y2b;
00173 PLFLT length, fx, fy, dx, dy;
00174
00175
00176
00177 y1 = dev->ymax - ( y1 - dev->ymin );
00178 y2 = dev->ymax - ( y2 - dev->ymin );
00179
00180
00181
00182 plRotPhy( ORIENTATION, dev->xmin, dev->ymin, dev->xmax, dev->ymax, &x1, &y1 );
00183 plRotPhy( ORIENTATION, dev->xmin, dev->ymin, dev->xmax, dev->ymax, &x2, &y2 );
00184
00185 x1b = x1, x2b = x2, y1b = y1, y2b = y2;
00186 length = (PLFLT) sqrt( (double)
00187 ( ( x2b - x1b ) * ( x2b - x1b ) + ( y2b - y1b ) * ( y2b - y1b ) ) );
00188
00189 if ( length == 0. )
00190 length = 1.;
00191 dx = ( x2 - x1 ) / length;
00192 dy = ( y2 - y1 ) / length;
00193
00194 fx = x1;
00195 fy = y1;
00196 setpoint( (PLINT) x1, (PLINT) y1 );
00197 setpoint( (PLINT) x2, (PLINT) y2 );
00198
00199 for ( i = 1; i <= (int) length; i++ )
00200 setpoint( (PLINT) ( fx += dx ), (PLINT) ( fy += dy ) );
00201 }
00202
00203
00204
00205
00206
00207
00208
00209 void
00210 plD_polyline_ljii( PLStream *pls, short *xa, short *ya, PLINT npts )
00211 {
00212 PLINT i;
00213
00214 for ( i = 0; i < npts - 1; i++ )
00215 plD_line_ljii( pls, xa[i], ya[i], xa[i + 1], ya[i + 1] );
00216 }
00217
00218
00219
00220
00221
00222
00223
00224 void
00225 plD_eop_ljii( PLStream *pls )
00226 {
00227 PLINT i, j;
00228
00229
00230
00231 fprintf( OF, "%c*p%dX", ESC, CURX );
00232 fprintf( OF, "%c*p%dY", ESC, CURY );
00233
00234
00235
00236 fprintf( OF, "%c*t%dR", ESC, DPI );
00237 fprintf( OF, "%c*r1A", ESC );
00238
00239
00240
00241 for ( j = 0; j < YDOTS; j++ )
00242 {
00243 fprintf( OF, "%c*b%ldW", ESC, BPROW );
00244 for ( i = 0; i < BPROW; i++ )
00245 putc( *( bitmap + i + j * BPROW ), OF );
00246 }
00247 pls->bytecnt += NBYTES;
00248
00249
00250
00251 fprintf( OF, "%c*rB", ESC );
00252 fprintf( OF, "%c", FF );
00253
00254
00255
00256 memset( bitmap, '\0', NBYTES );
00257 }
00258
00259
00260
00261
00262
00263
00264
00265
00266 void
00267 plD_bop_ljii( PLStream *pls )
00268 {
00269 if ( !pls->termin )
00270 plGetFam( pls );
00271
00272 pls->page++;
00273 }
00274
00275
00276
00277
00278
00279
00280
00281 void
00282 plD_tidy_ljii( PLStream *pls )
00283 {
00284
00285
00286 fprintf( OF, "%cE", ESC );
00287 plCloseFile( pls );
00288 free( (void *) bitmap );
00289 }
00290
00291
00292
00293
00294
00295
00296
00297 void
00298 plD_state_ljii( PLStream *pls, PLINT op )
00299 {
00300 }
00301
00302
00303
00304
00305
00306
00307
00308 void
00309 plD_esc_ljii( PLStream *pls, PLINT op, void *ptr )
00310 {
00311 }
00312
00313
00314
00315
00316
00317
00318
00319 static void
00320 setpoint( PLINT x, PLINT y )
00321 {
00322 PLINT index;
00323 index = x / 8 + y * BPROW;
00324 *( bitmap + index ) = *( bitmap + index ) | mask[x % 8];
00325 }
00326
00327 #else
00328 int
00329 pldummy_ljii()
00330 {
00331 return 0;
00332 }
00333
00334 #endif // PLD_ljii