PLplot  5.10.0
hpgl.c
Go to the documentation of this file.
00001 //  File:       hpgl.c
00002 //
00003 //  Descript:   hp7470, hp7580, and lj_hpgl drivers
00004 //
00005 //  Library:    ---
00006 //
00007 //  Requires:   ---
00008 //
00009 //  Public:     plD_init_hp7470()
00010 //              plD_init_hp7580()
00011 //              plD_init_lj_hpgl()
00012 //              plD_line_hpgl()
00013 //              plD_polyline_hpgl()
00014 //              plD_eop_hpgl()
00015 //              plD_bop_hpgl()
00016 //              plD_tidy_hpgl()
00017 //              plD_state_hpgl()
00018 //              plD_esc_hpgl()
00019 //
00020 //              pldummy_hpgl()
00021 //
00022 //  Private:    initialize_hpgl_pls()
00023 //
00024 //  Notes:      ---
00025 //
00026 //--------------------------------------------------------------------------
00027 
00028 #include "plDevs.h"
00029 
00030 #if defined ( PLD_hp7470 ) || defined ( PLD_hp7580 ) || defined ( PLD_lj_hpgl )
00031 
00032 #include "plplotP.h"
00033 #include <stdio.h>
00034 #include <string.h>
00035 #include "drivers.h"
00036 
00037 // Device info
00038 PLDLLIMPEXP_DRIVER const char* plD_DEVICE_INFO_hpgl =
00039 #if defined ( PLD_hp7470 )
00040     "hp7470:HP 7470 Plotter File (HPGL Cartridge, Small Plotter):0:hpgl:34:hp7470\n"
00041 #endif
00042 #if defined ( PLD_hp7580 )
00043     "hp7580:HP 7580 Plotter File (Large Plotter):0:hpgl:35:hp7580\n"
00044 #endif
00045 #if defined ( PLD_lj_hpgl )
00046     "lj_hpgl:HP Laserjet III, HPGL emulation mode:0:hpgl:36:lj_hpgl\n"
00047 #endif
00048 ;
00049 
00050 
00051 void plD_line_hpgl( PLStream *, short, short, short, short );
00052 void plD_polyline_hpgl( PLStream *, short *, short *, PLINT );
00053 void plD_eop_hpgl( PLStream * );
00054 void plD_bop_hpgl( PLStream * );
00055 void plD_tidy_hpgl( PLStream * );
00056 void plD_state_hpgl( PLStream *, PLINT );
00057 void plD_esc_hpgl( PLStream *, PLINT, void * );
00058 
00059 // top level declarations
00060 
00061 // Plotter sizes
00062 
00063 #define HP7470_XMIN    0
00064 #define HP7470_XMAX    10299
00065 #define HP7470_YMIN    0
00066 #define HP7470_YMAX    7649
00067 
00068 #define HP7580_XMIN    -4500
00069 #define HP7580_XMAX    4500
00070 #define HP7580_YMIN    -2790
00071 #define HP7580_YMAX    2790
00072 
00073 #define LJIII_XMIN     0
00074 #define LJIII_XMAX     11000
00075 #define LJIII_YMIN     500
00076 #define LJIII_YMAX     7700
00077 
00078 #define OF             pls->OutFile
00079 #define MIN_WIDTH      1.  // Minimum pen width
00080 #define MAX_WIDTH      10. // Maximum pen width
00081 #define DEF_WIDTH      1.  // Default pen width
00082 
00083 static void hpgl_dispatch_init_helper( PLDispatchTable *pdt,
00084                                        char *menustr, char *devnam,
00085                                        int type, int seq, plD_init_fp init )
00086 {
00087 #ifndef ENABLE_DYNDRIVERS
00088     pdt->pl_MenuStr = menustr;
00089     pdt->pl_DevName = devnam;
00090 #endif
00091     pdt->pl_type     = type;
00092     pdt->pl_seq      = seq;
00093     pdt->pl_init     = init;
00094     pdt->pl_line     = (plD_line_fp) plD_line_hpgl;
00095     pdt->pl_polyline = (plD_polyline_fp) plD_polyline_hpgl;
00096     pdt->pl_eop      = (plD_eop_fp) plD_eop_hpgl;
00097     pdt->pl_bop      = (plD_bop_fp) plD_bop_hpgl;
00098     pdt->pl_tidy     = (plD_tidy_fp) plD_tidy_hpgl;
00099     pdt->pl_state    = (plD_state_fp) plD_state_hpgl;
00100     pdt->pl_esc      = (plD_esc_fp) plD_esc_hpgl;
00101 }
00102 
00103 //--------------------------------------------------------------------------
00104 // initialize_hpgl_pls()
00105 //
00106 // Initialize plot stream
00107 //--------------------------------------------------------------------------
00108 
00109 static void
00110 initialize_hpgl_pls( PLStream *pls )
00111 {
00112     PLDev *dev = (PLDev *) pls->dev;
00113 
00114     if ( pls->width == 0 )      // Is 0 if uninitialized
00115         pls->width = 1;
00116 
00117     plFamInit( pls );             // Initialize family file info
00118     plOpenFile( pls );            // get file name if not already set
00119 
00120     dev->xold = PL_UNDEFINED;
00121     dev->yold = PL_UNDEFINED;
00122     dev->xlen = dev->xmax - dev->xmin;
00123     dev->ylen = dev->ymax - dev->ymin;
00124 
00125     plP_setpxl( (PLFLT) 40., (PLFLT) 40. );
00126     plP_setphy( dev->xmin, dev->xmax, dev->ymin, dev->ymax );
00127 }
00128 
00129 //--------------------------------------------------------------------------
00130 // plD_init_hp7470()
00131 //
00132 // Initialize device.
00133 //--------------------------------------------------------------------------
00134 
00135 #ifdef PLD_hp7470
00136 void plD_init_hp7470( PLStream * );
00137 
00138 void plD_dispatch_init_hp7470( PLDispatchTable *pdt )
00139 {
00140     hpgl_dispatch_init_helper( pdt,
00141         "HP 7470 Plotter File (HPGL Cartridge, Small Plotter)",
00142         "hp7470",
00143         plDevType_FileOriented, 34,
00144         (plD_init_fp) plD_init_hp7470 );
00145 }
00146 
00147 void
00148 plD_init_hp7470( PLStream *pls )
00149 {
00150     PLDev *dev;
00151 
00152     pls->color = 1;
00153     dev        = plAllocDev( pls ); // Allocate device-specific data
00154     dev->xmin  = HP7470_XMIN;
00155     dev->xmax  = HP7470_XMAX;
00156     dev->ymin  = HP7470_YMIN;
00157     dev->ymax  = HP7470_YMAX;
00158 
00159     initialize_hpgl_pls( pls );   // initialize plot stream
00160 
00161     fputs( "\x1b.I200;;17:\x1b.N;19:\x1b.M;;;10:IN;\n", OF );
00162 }
00163 #endif          // PLD_hp7470
00164 
00165 //--------------------------------------------------------------------------
00166 // plD_init_hp7580()
00167 //
00168 // Initialize device.
00169 //--------------------------------------------------------------------------
00170 
00171 #ifdef PLD_hp7580
00172 void plD_init_hp7580( PLStream * );
00173 
00174 void plD_dispatch_init_hp7580( PLDispatchTable *pdt )
00175 {
00176     hpgl_dispatch_init_helper( pdt,
00177         "HP 7580 Plotter File (Large Plotter)", "hp7580",
00178         plDevType_FileOriented, 35,
00179         (plD_init_fp) plD_init_hp7580 );
00180 }
00181 
00182 void
00183 plD_init_hp7580( PLStream *pls )
00184 {
00185     PLDev *dev;
00186 
00187     pls->color = 1;
00188     dev        = plAllocDev( pls ); // Allocate device-specific data
00189     dev->xmin  = HP7580_XMIN;
00190     dev->xmax  = HP7580_XMAX;
00191     dev->ymin  = HP7580_YMIN;
00192     dev->ymax  = HP7580_YMAX;
00193 
00194     initialize_hpgl_pls( pls );   // initialize plot stream
00195 
00196     fputs( "\x1b.I200;;17:\x1b.N;19:\x1b.M;;;10:IN;\n", OF );
00197     fputs( "RO90;IP;SP4;PA;\n", OF );
00198 }
00199 #endif  // PLD_hp7580
00200 
00201 //--------------------------------------------------------------------------
00202 // plD_init_lj_hpgl()
00203 //
00204 // Initialize device.
00205 //--------------------------------------------------------------------------
00206 
00207 #ifdef PLD_lj_hpgl
00208 void plD_init_lj_hpgl( PLStream * );
00209 
00210 void plD_dispatch_init_hpgl( PLDispatchTable *pdt )
00211 {
00212     hpgl_dispatch_init_helper( pdt,
00213         "HP Laserjet III, HPGL emulation mode", "lj_hpgl",
00214         plDevType_FileOriented, 36,
00215         (plD_init_fp) plD_init_lj_hpgl );
00216 }
00217 
00218 void
00219 plD_init_lj_hpgl( PLStream *pls )
00220 {
00221     PLDev *dev;
00222 
00223     dev       = plAllocDev( pls ); // Allocate device-specific data
00224     dev->xmin = LJIII_XMIN;
00225     dev->xmax = LJIII_XMAX;
00226     dev->ymin = LJIII_YMIN;
00227     dev->ymax = LJIII_YMAX;
00228 
00229     initialize_hpgl_pls( pls );   // initialize plot stream
00230 
00231 // HP III changes here up to .I200 puts printer in HPGL/2 emulation
00232 // with 300DPI printing.
00233 // Next line : added pw 0.2 for pen width 0.2 (of an inch ?)
00234 //
00235     fputs( "\x1b*T300R\x1b%1B;\x1b.I200;;17:\x1b.N;19:\x1b.M;;;10:IN;\n", OF );
00236     fputs( "RO90;IP;PW 0.2;SP 1;PA;", OF );
00237 }
00238 #endif  // PLD_lj_hpgl
00239 
00240 //--------------------------------------------------------------------------
00241 // plD_line_hpgl()
00242 //
00243 // Draw a line in the current color from (x1,y1) to (x2,y2).
00244 //--------------------------------------------------------------------------
00245 
00246 void
00247 plD_line_hpgl( PLStream *pls, short x1a, short y1a, short x2a, short y2a )
00248 {
00249     PLDev *dev = (PLDev *) pls->dev;
00250     int   x1   = x1a, y1 = y1a, x2 = x2a, y2 = y2a;
00251 
00252 // Write out old path
00253 
00254     if ( x1 != dev->xold || y1 != dev->yold )
00255         pls->bytecnt += fprintf( OF, "PU%d %d;", x1, y1 );
00256 
00257 // Add new point to path
00258 
00259     pls->bytecnt += fprintf( OF, "PD%d %d\n", x2, y2 );
00260 
00261     dev->xold = x2;
00262     dev->yold = y2;
00263 }
00264 
00265 //--------------------------------------------------------------------------
00266 // plD_polyline_hpgl()
00267 //
00268 // Draw a polyline in the current color.
00269 //--------------------------------------------------------------------------
00270 
00271 void
00272 plD_polyline_hpgl( PLStream *pls, short *xa, short *ya, PLINT npts )
00273 {
00274     register PLINT i;
00275     PLDev          *dev = (PLDev *) pls->dev;
00276 
00277 // Write out old path
00278 
00279     if ( xa[0] != dev->xold || ya[0] != dev->yold )
00280         pls->bytecnt += fprintf( OF, "PU%d %d;", xa[0], ya[0] );
00281 
00282 // Add new point to path
00283 
00284     for ( i = 1; i < npts; i++ )
00285         pls->bytecnt += fprintf( OF, "PD%d %d\n", xa[i], ya[i] );
00286 
00287     dev->xold = xa[ npts - 1 ];
00288     dev->yold = ya[ npts - 1 ];
00289 }
00290 
00291 //--------------------------------------------------------------------------
00292 // plD_eop_hpgl()
00293 //
00294 // End of page.
00295 //--------------------------------------------------------------------------
00296 
00297 void
00298 plD_eop_hpgl( PLStream *pls )
00299 {
00300 }
00301 
00302 //--------------------------------------------------------------------------
00303 // plD_bop_hpgl()
00304 //
00305 // Set up for the next page.
00306 // Advance to next family file if necessary (file output).
00307 //--------------------------------------------------------------------------
00308 
00309 void
00310 plD_bop_hpgl( PLStream *pls )
00311 {
00312     PLDev *dev = (PLDev *) pls->dev;
00313 
00314     dev->xold = PL_UNDEFINED;
00315     dev->yold = PL_UNDEFINED;
00316 
00317     fputs( "PG;\n", OF );
00318     if ( !pls->termin )
00319         plGetFam( pls );
00320 
00321     pls->page++;
00322 }
00323 
00324 //--------------------------------------------------------------------------
00325 // plD_tidy_hpgl()
00326 //
00327 // Close graphics file or otherwise clean up.
00328 //--------------------------------------------------------------------------
00329 
00330 void
00331 plD_tidy_hpgl( PLStream *pls )
00332 {
00333     fputs( "SP0\n", OF );
00334     plCloseFile( pls );
00335 }
00336 
00337 //--------------------------------------------------------------------------
00338 // plD_state_hpgl()
00339 //
00340 // Handle change in PLStream state (color, pen width, fill attribute, etc).
00341 //--------------------------------------------------------------------------
00342 
00343 void
00344 plD_state_hpgl( PLStream *pls, PLINT op )
00345 {
00346     switch ( op )
00347     {
00348     case PLSTATE_WIDTH:
00349     case PLSTATE_COLOR0: {
00350         int width = (int) (
00351             ( pls->width < MIN_WIDTH ) ? DEF_WIDTH :
00352             ( pls->width > MAX_WIDTH ) ? MAX_WIDTH : pls->width );
00353 
00354         if ( pls->icol0 < 1 || pls->icol0 > 8 )
00355             fputs( "\nInvalid pen selection.", stderr );
00356         else
00357             fprintf( OF, "SP%d %d\n", pls->icol0, width );
00358 
00359         break;
00360     }
00361     case PLSTATE_COLOR1:
00362         break;
00363     }
00364 }
00365 
00366 //--------------------------------------------------------------------------
00367 // plD_esc_hpgl()
00368 //
00369 // Escape function.
00370 //--------------------------------------------------------------------------
00371 
00372 void
00373 plD_esc_hpgl( PLStream *pls, PLINT op, void *ptr )
00374 {
00375 }
00376 
00377 #else
00378 int
00379 pldummy_hpgl( void )
00380 {
00381     return 0;
00382 }
00383 
00384 #endif          // PLD_hp7470 || PLD_hp7580 || PLD_lj_hpgl
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines