PLplot  5.10.0
ljii.c
Go to the documentation of this file.
00001 //      PLplot Laser Jet II device driver.
00002 //
00003 //      Note only the 150 dpi mode is supported.  The others (75,100,300)
00004 //      should work by just changing the value of DPI and changing the
00005 //      values passed to plP_setphy().
00006 //
00007 #include "plDevs.h"
00008 
00009 #ifdef PLD_ljii
00010 
00011 #include "plplotP.h"
00012 #include "drivers.h"
00013 #include <math.h>
00014 #include <string.h>
00015 
00016 #ifdef __GO32__                 // dos386/djgpp
00017 #ifdef MSDOS
00018 #undef MSDOS
00019 #endif
00020 #endif
00021 
00022 // Device info
00023 PLDLLIMPEXP_DRIVER const char* plD_DEVICE_INFO_ljii =
00024     "ljii:LaserJet II Bitmap File (150 dpi):0:ljii:33:ljii\n";
00025 
00026 // Function prototypes
00027 
00028 void plD_dispatch_init_ljii( PLDispatchTable *pdt );
00029 
00030 void plD_init_ljii( PLStream * );
00031 void plD_line_ljii( PLStream *, short, short, short, short );
00032 void plD_polyline_ljii( PLStream *, short *, short *, PLINT );
00033 void plD_eop_ljii( PLStream * );
00034 void plD_bop_ljii( PLStream * );
00035 void plD_tidy_ljii( PLStream * );
00036 void plD_state_ljii( PLStream *, PLINT );
00037 void plD_esc_ljii( PLStream *, PLINT, void * );
00038 
00039 static void setpoint( PLINT, PLINT );
00040 
00041 // top level declarations
00042 
00043 #define JETX      1103
00044 #define JETY      1409
00045 
00046 #define OF        pls->OutFile
00047 #define DPI       150           // Resolution Dots per Inch
00048 #define CURX      51
00049 #define CURY      61
00050 #define XDOTS     1104L         // # dots across
00051 #define YDOTS     1410L         // # dots down
00052 #define BPROW     XDOTS / 8L    // # bytes across
00053 #define NBYTES    BPROW * YDOTS // total number of bytes
00054 
00055 // Graphics control characters.
00056 
00057 #define ESC    0x1b
00058 #define FF     0x0c
00059 
00060 static char mask[8] =
00061 { '\200', '\100', '\040', '\020', '\010', '\004', '\002', '\001' };
00062 
00063 #ifndef MSDOS
00064 #define _HUGE
00065 #else
00066 #define _HUGE    _huge
00067 #endif
00068 
00069 static char _HUGE *bitmap;      // points to memory area NBYTES in size
00070 
00071 void plD_dispatch_init_ljii( PLDispatchTable *pdt )
00072 {
00073 #ifndef ENABLE_DYNDRIVERS
00074     pdt->pl_MenuStr = "LaserJet II Bitmap File (150 dpi)";
00075     pdt->pl_DevName = "ljii";
00076 #endif
00077     pdt->pl_type     = plDevType_FileOriented;
00078     pdt->pl_seq      = 33;
00079     pdt->pl_init     = (plD_init_fp) plD_init_ljii;
00080     pdt->pl_line     = (plD_line_fp) plD_line_ljii;
00081     pdt->pl_polyline = (plD_polyline_fp) plD_polyline_ljii;
00082     pdt->pl_eop      = (plD_eop_fp) plD_eop_ljii;
00083     pdt->pl_bop      = (plD_bop_fp) plD_bop_ljii;
00084     pdt->pl_tidy     = (plD_tidy_fp) plD_tidy_ljii;
00085     pdt->pl_state    = (plD_state_fp) plD_state_ljii;
00086     pdt->pl_esc      = (plD_esc_fp) plD_esc_ljii;
00087 }
00088 
00089 //--------------------------------------------------------------------------
00090 // plD_init_ljii()
00091 //
00092 // Initialize device.
00093 //--------------------------------------------------------------------------
00094 
00095 void
00096 plD_init_ljii( PLStream *pls )
00097 {
00098     PLDev *dev;
00099 
00100 // Initialize family file info
00101 
00102     plFamInit( pls );
00103 
00104 // Prompt for a file name if not already set
00105 
00106     plOpenFile( pls );
00107 
00108 // Allocate and initialize device-specific data
00109 
00110     dev = plAllocDev( pls );
00111 
00112     dev->xold = PL_UNDEFINED;
00113     dev->yold = PL_UNDEFINED;
00114     dev->xmin = 0;
00115     dev->ymin = 0;
00116 
00117     plP_setpxl( (PLFLT) 5.905, (PLFLT) 5.905 );
00118 
00119 // Rotate by 90 degrees since portrait mode addressing is used
00120 
00121     dev->xmin = 0;
00122     dev->ymin = 0;
00123     dev->xmax = JETY;
00124     dev->ymax = JETX;
00125     dev->xlen = dev->xmax - dev->xmin;
00126     dev->ylen = dev->ymax - dev->ymin;
00127 
00128     plP_setphy( dev->xmin, dev->xmax, dev->ymin, dev->ymax );
00129 
00130 // If portrait mode is specified, then set up an additional rotation
00131 // transformation with aspect ratio allowed to adjust via freeaspect.
00132 // Default orientation is landscape (ORIENTATION == 3 or 90 deg rotation
00133 // counter-clockwise from portrait).  (Legacy PLplot used seascape
00134 // which was equivalent to ORIENTATION == 1 or 90 deg clockwise rotation
00135 // from portrait.)
00136 
00137     if ( pls->portrait )
00138     {
00139         plsdiori( (PLFLT) ( 4 - ORIENTATION ) );
00140         pls->freeaspect = 1;
00141     }
00142 
00143 // Allocate storage for bit map matrix
00144 
00145 #ifdef MSDOS
00146     if ( ( bitmap = (char _HUGE *) halloc( (long) NBYTES, sizeof ( char ) ) ) == NULL )
00147         plexit( "Out of memory in call to calloc" );
00148 #else
00149     if ( ( bitmap = (void *) calloc( NBYTES, sizeof ( char ) ) ) == NULL )
00150         plexit( "Out of memory in call to calloc" );
00151 #endif
00152 
00153 // Reset Printer
00154 
00155     fprintf( OF, "%cE", ESC );
00156 }
00157 
00158 //--------------------------------------------------------------------------
00159 // plD_line_ljii()
00160 //
00161 // Draw a line in the current color from (x1,y1) to (x2,y2).
00162 //--------------------------------------------------------------------------
00163 
00164 void
00165 plD_line_ljii( PLStream *pls, short x1a, short y1a, short x2a, short y2a )
00166 {
00167     PLDev *dev = (PLDev *) pls->dev;
00168     int   i;
00169     int   x1 = x1a, y1 = y1a, x2 = x2a, y2 = y2a;
00170     PLINT x1b, y1b, x2b, y2b;
00171     PLFLT length, fx, fy, dx, dy;
00172 
00173 // Take mirror image, since PCL expects (0,0) to be at top left
00174 
00175     y1 = dev->ymax - ( y1 - dev->ymin );
00176     y2 = dev->ymax - ( y2 - dev->ymin );
00177 
00178 // Rotate by 90 degrees
00179 
00180     plRotPhy( ORIENTATION, dev->xmin, dev->ymin, dev->xmax, dev->ymax, &x1, &y1 );
00181     plRotPhy( ORIENTATION, dev->xmin, dev->ymin, dev->xmax, dev->ymax, &x2, &y2 );
00182 
00183     x1b    = x1, x2b = x2, y1b = y1, y2b = y2;
00184     length = (PLFLT) sqrt( (double)
00185         ( ( x2b - x1b ) * ( x2b - x1b ) + ( y2b - y1b ) * ( y2b - y1b ) ) );
00186 
00187     if ( length == 0. )
00188         length = 1.;
00189     dx = ( x2 - x1 ) / length;
00190     dy = ( y2 - y1 ) / length;
00191 
00192     fx = x1;
00193     fy = y1;
00194     setpoint( (PLINT) x1, (PLINT) y1 );
00195     setpoint( (PLINT) x2, (PLINT) y2 );
00196 
00197     for ( i = 1; i <= (int) length; i++ )
00198         setpoint( (PLINT) ( fx += dx ), (PLINT) ( fy += dy ) );
00199 }
00200 
00201 //--------------------------------------------------------------------------
00202 // plD_polyline_ljii()
00203 //
00204 // Draw a polyline in the current color.
00205 //--------------------------------------------------------------------------
00206 
00207 void
00208 plD_polyline_ljii( PLStream *pls, short *xa, short *ya, PLINT npts )
00209 {
00210     PLINT i;
00211 
00212     for ( i = 0; i < npts - 1; i++ )
00213         plD_line_ljii( pls, xa[i], ya[i], xa[i + 1], ya[i + 1] );
00214 }
00215 
00216 //--------------------------------------------------------------------------
00217 // plD_eop_ljii()
00218 //
00219 // End of page.(prints it here).
00220 //--------------------------------------------------------------------------
00221 
00222 void
00223 plD_eop_ljii( PLStream *pls )
00224 {
00225     PLINT i, j;
00226 
00227 // First move cursor to origin
00228 
00229     fprintf( OF, "%c*p%dX", ESC, CURX );
00230     fprintf( OF, "%c*p%dY", ESC, CURY );
00231 
00232 // Then put Laser Printer in 150 dpi mode
00233 
00234     fprintf( OF, "%c*t%dR", ESC, DPI );
00235     fprintf( OF, "%c*r1A", ESC );
00236 
00237 // Write out raster data
00238 
00239     for ( j = 0; j < YDOTS; j++ )
00240     {
00241         fprintf( OF, "%c*b%ldW", ESC, BPROW );
00242         for ( i = 0; i < BPROW; i++ )
00243             putc( *( bitmap + i + j * BPROW ), OF );
00244     }
00245     pls->bytecnt += NBYTES;
00246 
00247 // End raster graphics and send Form Feed
00248 
00249     fprintf( OF, "%c*rB", ESC );
00250     fprintf( OF, "%c", FF );
00251 
00252 // Finally, clear out bitmap storage area
00253 
00254     memset( bitmap, '\0', NBYTES );
00255 }
00256 
00257 //--------------------------------------------------------------------------
00258 // plD_bop_ljii()
00259 //
00260 // Set up for the next page.
00261 // Advance to next family file if necessary (file output).
00262 //--------------------------------------------------------------------------
00263 
00264 void
00265 plD_bop_ljii( PLStream *pls )
00266 {
00267     if ( !pls->termin )
00268         plGetFam( pls );
00269 
00270     pls->page++;
00271 }
00272 
00273 //--------------------------------------------------------------------------
00274 // plD_tidy_ljii()
00275 //
00276 // Close graphics file or otherwise clean up.
00277 //--------------------------------------------------------------------------
00278 
00279 void
00280 plD_tidy_ljii( PLStream *pls )
00281 {
00282 // Reset Printer
00283 
00284     fprintf( OF, "%cE", ESC );
00285     plCloseFile( pls );
00286     free( (void *) bitmap );
00287 }
00288 
00289 //--------------------------------------------------------------------------
00290 // plD_state_ljii()
00291 //
00292 // Handle change in PLStream state (color, pen width, fill attribute, etc).
00293 //--------------------------------------------------------------------------
00294 
00295 void
00296 plD_state_ljii( PLStream *pls, PLINT op )
00297 {
00298 }
00299 
00300 //--------------------------------------------------------------------------
00301 // plD_esc_ljii()
00302 //
00303 // Escape function.
00304 //--------------------------------------------------------------------------
00305 
00306 void
00307 plD_esc_ljii( PLStream *pls, PLINT op, void *ptr )
00308 {
00309 }
00310 
00311 //--------------------------------------------------------------------------
00312 // setpoint()
00313 //
00314 // Sets a bit in the bitmap.
00315 //--------------------------------------------------------------------------
00316 
00317 static void
00318 setpoint( PLINT x, PLINT y )
00319 {
00320     PLINT index;
00321     index = x / 8 + y * BPROW;
00322     *( bitmap + index ) = *( bitmap + index ) | mask[x % 8];
00323 }
00324 
00325 #else
00326 int
00327 pldummy_ljii()
00328 {
00329     return 0;
00330 }
00331 
00332 #endif                          // PLD_ljii
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines