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