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

impress.c

Go to the documentation of this file.
00001 // $Id: impress.c 11282 2010-10-28 16:26:09Z airwin $
00002 //
00003 //      PLplot ImPress device driver.
00004 //
00005 #include "plDevs.h"
00006 
00007 #ifdef PLD_imp
00008 
00009 #include "plplotP.h"
00010 #include "drivers.h"
00011 
00012 // Device info
00013 PLDLLIMPEXP_DRIVER const char* plD_DEVICE_INFO_impress = "imp:Impress File:0:impress:37:imp\n";
00014 
00015 // Function prototypes
00016 
00017 void plD_dispatch_init_imp( PLDispatchTable *pdt );
00018 
00019 void plD_init_imp( PLStream * );
00020 void plD_line_imp( PLStream *, short, short, short, short );
00021 void plD_polyline_imp( PLStream *, short *, short *, PLINT );
00022 void plD_eop_imp( PLStream * );
00023 void plD_bop_imp( PLStream * );
00024 void plD_tidy_imp( PLStream * );
00025 void plD_state_imp( PLStream *, PLINT );
00026 void plD_esc_imp( PLStream *, PLINT, void * );
00027 
00028 static void flushline( PLStream * );
00029 
00030 // top level declarations
00031 
00032 #define IMPX        2999
00033 #define IMPY        2249
00034 
00035 #define BUFFPTS     50
00036 #define BUFFLENG    2 * BUFFPTS
00037 
00038 // Graphics control characters.
00039 
00040 #define SET_HV_SYSTEM    0315
00041 #define OPBYTE1          031
00042 #define OPBYTE2          0140
00043 #define SET_ABS_H        0207
00044 #define SET_ABS_V        0211
00045 #define OPWORDH1         0
00046 #define OPWORDH2         150
00047 #define OPWORDV1         0
00048 #define OPWORDV2         150
00049 #define ENDPAGE          0333
00050 
00051 #define SET_PEN          0350
00052 #define CREATE_PATH      0346
00053 #define DRAW_PATH        0352
00054 #define OPTYPE           017
00055 
00056 static int *LineBuff;
00057 static int FirstLine;
00058 static int penchange = 0, penwidth = 1;
00059 static int count;
00060 
00061 void plD_dispatch_init_imp( PLDispatchTable *pdt )
00062 {
00063 #ifndef ENABLE_DYNDRIVERS
00064     pdt->pl_MenuStr = "Impress File";
00065     pdt->pl_DevName = "imp";
00066 #endif
00067     pdt->pl_type     = plDevType_FileOriented;
00068     pdt->pl_seq      = 37;
00069     pdt->pl_init     = (plD_init_fp) plD_init_imp;
00070     pdt->pl_line     = (plD_line_fp) plD_line_imp;
00071     pdt->pl_polyline = (plD_polyline_fp) plD_polyline_imp;
00072     pdt->pl_eop      = (plD_eop_fp) plD_eop_imp;
00073     pdt->pl_bop      = (plD_bop_fp) plD_bop_imp;
00074     pdt->pl_tidy     = (plD_tidy_fp) plD_tidy_imp;
00075     pdt->pl_state    = (plD_state_fp) plD_state_imp;
00076     pdt->pl_esc      = (plD_esc_fp) plD_esc_imp;
00077 }
00078 
00079 //--------------------------------------------------------------------------
00080 // plD_init_imp()
00081 //
00082 // Initialize device (terminal).
00083 //--------------------------------------------------------------------------
00084 
00085 void
00086 plD_init_imp( PLStream *pls )
00087 {
00088     PLDev *dev;
00089 
00090 // Initialize family file info
00091 
00092     plFamInit( pls );
00093 
00094 // Prompt for a file name if not already set
00095 
00096     plOpenFile( pls );
00097 
00098 // Allocate and initialize device-specific data
00099 
00100     dev = plAllocDev( pls );
00101 
00102     dev->xold = PL_UNDEFINED;
00103     dev->yold = PL_UNDEFINED;
00104     dev->xmin = 0;
00105     dev->ymin = 0;
00106     dev->xmax = IMPX;
00107     dev->ymax = IMPY;
00108     dev->xlen = dev->xmax - dev->xmin;
00109     dev->ylen = dev->ymax - dev->ymin;
00110 
00111     plP_setpxl( (PLFLT) 11.81, (PLFLT) 11.81 );
00112     plP_setphy( dev->xmin, dev->xmax, dev->ymin, dev->ymax );
00113 
00114     LineBuff = (int *) malloc( BUFFLENG * sizeof ( int ) );
00115     if ( LineBuff == NULL )
00116     {
00117         plexit( "Error in memory alloc in plD_init_imp()." );
00118     }
00119     fprintf( pls->OutFile, "@Document(Language ImPress, jobheader off)" );
00120     fprintf( pls->OutFile, "%c%c", SET_HV_SYSTEM, OPBYTE1 );
00121     fprintf( pls->OutFile, "%c%c%c", SET_ABS_H, OPWORDH1, OPWORDH2 );
00122     fprintf( pls->OutFile, "%c%c%c", SET_ABS_V, OPWORDV1, OPWORDV2 );
00123     fprintf( pls->OutFile, "%c%c", SET_HV_SYSTEM, OPBYTE2 );
00124 }
00125 
00126 //--------------------------------------------------------------------------
00127 // plD_line_imp()
00128 //
00129 // Draw a line in the current color from (x1,y1) to (x2,y2).
00130 //--------------------------------------------------------------------------
00131 
00132 void
00133 plD_line_imp( PLStream *pls, short x1a, short y1a, short x2a, short y2a )
00134 {
00135     PLDev *dev = (PLDev *) pls->dev;
00136     int   x1   = x1a, y1 = y1a, x2 = x2a, y2 = y2a;
00137 
00138     if ( FirstLine )
00139     {
00140         if ( penchange )
00141         {
00142             fprintf( pls->OutFile, "%c%c", SET_PEN, (char) penwidth );
00143             penchange = 0;
00144         }
00145 
00146         // Add both points to path
00147 
00148         count     = 0;
00149         FirstLine = 0;
00150         *( LineBuff + count++ ) = x1;
00151         *( LineBuff + count++ ) = y1;
00152         *( LineBuff + count++ ) = x2;
00153         *( LineBuff + count++ ) = y2;
00154     }
00155     else if ( ( count + 2 ) < BUFFLENG && x1 == dev->xold && y1 == dev->yold )
00156     {
00157         // Add new point to path
00158 
00159         *( LineBuff + count++ ) = x2;
00160         *( LineBuff + count++ ) = y2;
00161     }
00162     else
00163     {
00164         // Write out old path
00165 
00166         count /= 2;
00167         fprintf( pls->OutFile, "%c%c%c", CREATE_PATH, (char) count / 256, (char) count % 256 );
00168         fwrite( (char *) LineBuff, sizeof ( int ), 2 * count, pls->OutFile );
00169         fprintf( pls->OutFile, "%c%c", DRAW_PATH, OPTYPE );
00170 
00171         // And start a new path
00172 
00173         if ( penchange )
00174         {
00175             fprintf( pls->OutFile, "%c%c", SET_PEN, (char) penwidth );
00176             penchange = 0;
00177         }
00178         count = 0;
00179         *( LineBuff + count++ ) = x1;
00180         *( LineBuff + count++ ) = y1;
00181         *( LineBuff + count++ ) = x2;
00182         *( LineBuff + count++ ) = y2;
00183     }
00184     dev->xold = x2;
00185     dev->yold = y2;
00186 }
00187 
00188 //--------------------------------------------------------------------------
00189 // plD_polyline_imp()
00190 //
00191 // Draw a polyline in the current color.
00192 //--------------------------------------------------------------------------
00193 
00194 void
00195 plD_polyline_imp( PLStream *pls, short *xa, short *ya, PLINT npts )
00196 {
00197     PLINT i;
00198 
00199     for ( i = 0; i < npts - 1; i++ )
00200         plD_line_imp( pls, xa[i], ya[i], xa[i + 1], ya[i + 1] );
00201 }
00202 
00203 //--------------------------------------------------------------------------
00204 // plD_eop_imp()
00205 //
00206 // End of page.
00207 //--------------------------------------------------------------------------
00208 
00209 void
00210 plD_eop_imp( PLStream *pls )
00211 {
00212     flushline( pls );
00213     fprintf( pls->OutFile, "%c", ENDPAGE );
00214 }
00215 
00216 //--------------------------------------------------------------------------
00217 // plD_bop_imp()
00218 //
00219 // Set up for the next page.
00220 //--------------------------------------------------------------------------
00221 
00222 void
00223 plD_bop_imp( PLStream *pls )
00224 {
00225     PLDev *dev = (PLDev *) pls->dev;
00226 
00227     FirstLine = 1;
00228     dev->xold = PL_UNDEFINED;
00229     dev->yold = PL_UNDEFINED;
00230 
00231     if ( !pls->termin )
00232         plGetFam( pls );
00233 
00234     pls->page++;
00235 }
00236 
00237 //--------------------------------------------------------------------------
00238 // plD_tidy_imp()
00239 //
00240 // Close graphics file or otherwise clean up.
00241 //--------------------------------------------------------------------------
00242 
00243 void
00244 plD_tidy_imp( PLStream *pls )
00245 {
00246     free( (void *) LineBuff );
00247     plCloseFile( pls );
00248 }
00249 
00250 //--------------------------------------------------------------------------
00251 // plD_state_imp()
00252 //
00253 // Handle change in PLStream state (color, pen width, fill attribute, etc).
00254 //--------------------------------------------------------------------------
00255 
00256 void
00257 plD_state_imp( PLStream *pls, PLINT op )
00258 {
00259     switch ( op )
00260     {
00261     case PLSTATE_WIDTH:
00262         if ( pls->width > 0 && pls->width <= 20 )
00263         {
00264             penwidth  = pls->width;
00265             penchange = 1;
00266         }
00267         break;
00268 
00269     case PLSTATE_COLOR0:
00270         break;
00271 
00272     case PLSTATE_COLOR1:
00273         break;
00274     }
00275 }
00276 
00277 //--------------------------------------------------------------------------
00278 // plD_esc_imp()
00279 //
00280 // Escape function.
00281 //--------------------------------------------------------------------------
00282 
00283 void
00284 plD_esc_imp( PLStream *pls, PLINT op, void *ptr )
00285 {
00286 }
00287 
00288 //--------------------------------------------------------------------------
00289 // flushline()
00290 //
00291 // Spits out the line buffer.
00292 //--------------------------------------------------------------------------
00293 
00294 static void
00295 flushline( PLStream *pls )
00296 {
00297     count /= 2;
00298     fprintf( pls->OutFile, "%c%c%c", CREATE_PATH, (char) count / 256, (char) count % 256 );
00299     fwrite( (char *) LineBuff, sizeof ( int ), 2 * count, pls->OutFile );
00300     fprintf( pls->OutFile, "%c%c", DRAW_PATH, OPTYPE );
00301     FirstLine = 1;
00302 }
00303 
00304 #else
00305 int
00306 pldummy_impress()
00307 {
00308     return 0;
00309 }
00310 
00311 #endif                          // PLD_imp

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