• Main Page
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

hpgl.c

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

Generated on Wed Oct 12 2011 20:42:21 for PLplot by  doxygen 1.7.1