13 PLDLLIMPEXP_DRIVER const char* plD_DEVICE_INFO_xfig =
"xfig:Fig file:0:xfig:31:xfig\n";
22 PLFLT xscale_dev, yscale_dev;
24 int *buffptr, bufflen;
29 long cmap0_pos, cmap1_pos;
30 int cmap0_ncol, cmap1_ncol;
31 int offset, offset_inc;
39 void plD_line_xfig(
PLStream *,
short,
short,
short,
short );
40 void plD_polyline_xfig(
PLStream *,
short *,
short *,
PLINT );
47 static void flushbuffer(
PLStream * );
51 #define FIGX 297 // portrait A4 mm
60 #define XFIG_COLBASE 33 // xfig first user color, plplot colormap0[0],
70 static DrvOpt xfig_options[] = { {
"text",
DRV_INT, &
text,
"Use Postscript text (text=1|0)" },
71 { NULL,
DRV_INT, NULL, NULL } };
75 #ifndef ENABLE_DYNDRIVERS
116 if ( pls->
dev != NULL )
117 free( (
void *) pls->
dev );
119 pls->
dev = calloc( 1, (
size_t)
sizeof ( xfig_Dev ) );
121 if ( pls->
dev == NULL )
122 plexit(
"plD_init_xfig: cannot allocate memory\n" );
124 dev = (xfig_Dev *) pls->
dev;
126 dev->curwid = pls->
width < 1 ? 1 : pls->
width;
135 dev->xscale_dev =
DPI / 25.4;
136 dev->yscale_dev =
DPI / 25.4;
137 dev->offset_inc = dev->ymax * (
PLINT) dev->yscale_dev;
138 dev->offset = -dev->offset_inc;
143 plP_setpxl( dev->xscale_dev, dev->xscale_dev );
148 fprintf( pls->
OutFile,
"#FIG 3.2\n" );
149 fprintf( pls->
OutFile,
"Landscape\n" );
150 fprintf( pls->
OutFile,
"Center\n" );
151 fprintf( pls->
OutFile,
"Metric\n" );
152 fprintf( pls->
OutFile,
"A4\n" );
153 fprintf( pls->
OutFile,
"100.0\n" );
154 fprintf( pls->
OutFile,
"Single\n" );
155 fprintf( pls->
OutFile,
"-2\n" );
159 dev->cmap0_ncol = 2 * pls->
ncol0;
160 dev->cmap0_pos = ftell( pls->
OutFile );
164 dev->cmap1_ncol = 2 * pls->
ncol1;
165 dev->cmap1_pos = ftell( pls->
OutFile );
168 dev->bufflen = 2 * BSIZE;
169 dev->buffptr = (
int *) malloc(
sizeof (
int ) * (size_t) ( dev->bufflen ) );
170 if ( dev->buffptr == NULL )
171 plexit(
"plD_init_xfig: Out of memory!" );
181 dev = (xfig_Dev *) pls->
dev;
183 if ( pls->
ncol0 > dev->cmap0_ncol )
184 plwarn(
"Too many colors for cmap0. Preallocate using command line '-ncol0 n.\n'" );
186 cur_pos = ftell( pls->
OutFile );
188 if ( fseek( pls->
OutFile, dev->cmap0_pos, SEEK_SET ) )
189 plexit(
"Sorry, only file based output, no pipes.\n" );
192 for ( i = 0; i < pls->
ncol0; i++ )
193 fprintf( pls->
OutFile,
"0 %d #%.2x%.2x%.2x\n", i + XFIG_COLBASE,
197 for ( i = pls->
ncol0; i < dev->cmap0_ncol; i++ )
198 fprintf( pls->
OutFile,
"0 %d #000000\n", i + XFIG_COLBASE );
200 if ( cur_pos != dev->cmap0_pos )
201 fseek( pls->
OutFile, cur_pos, SEEK_SET );
211 dev = (xfig_Dev *) pls->
dev;
213 if ( pls->
ncol1 > dev->cmap1_ncol )
214 plwarn(
"Too many colors for cmap1. Preallocate using command line '-ncol1 n.\n'" );
216 cur_pos = ftell( pls->
OutFile );
218 if ( fseek( pls->
OutFile, dev->cmap1_pos, SEEK_SET ) )
219 plexit(
"Sorry, only file based output, no pipes.\n" );
222 for ( i = 0; i < pls->
ncol1; i++ )
223 fprintf( pls->
OutFile,
"0 %d #%.2x%.2x%.2x\n", i + XFIG_COLBASE + dev->cmap0_ncol,
227 for ( i = pls->
ncol1; i < dev->cmap1_ncol; i++ )
228 fprintf( pls->
OutFile,
"0 %d #000000\n", i + XFIG_COLBASE + dev->cmap0_ncol );
230 if ( cur_pos != dev->cmap1_pos )
231 fseek( pls->
OutFile, cur_pos, SEEK_SET );
241 plD_line_xfig(
PLStream *pls,
short x1a,
short y1a,
short x2a,
short y2a )
243 xfig_Dev *dev = (xfig_Dev *) pls->
dev;
244 int x1 = x1a, y1 = y1a, x2 = x2a, y2 = y2a;
252 if ( dev->firstline )
255 *( dev->buffptr +
count++ ) = x1;
256 *( dev->buffptr +
count++ ) = y1;
257 *( dev->buffptr +
count++ ) = x2;
258 *( dev->buffptr +
count++ ) = y2;
261 else if ( x1 == dev->xold && y1 == dev->yold )
264 if (
count + 2 >= dev->bufflen )
266 dev->bufflen += 2 * BSIZE;
268 realloc( (
void *) dev->buffptr, (size_t) ( dev->bufflen ) *
sizeof ( int ) );
269 if ( tempptr == NULL )
271 free( (
void *) dev->buffptr );
272 plexit(
"plD_line_xfig: Out of memory!" );
274 dev->buffptr = tempptr;
276 *( dev->buffptr +
count++ ) = x2;
277 *( dev->buffptr +
count++ ) = y2;
283 *( dev->buffptr +
count++ ) = x1;
284 *( dev->buffptr +
count++ ) = y1;
285 *( dev->buffptr +
count++ ) = x2;
286 *( dev->buffptr +
count++ ) = y2;
300 plD_polyline_xfig(
PLStream *pls,
short *xa,
short *ya,
PLINT npts )
304 for ( i = 0; i < npts - 1; i++ )
305 plD_line_xfig( pls, xa[i], ya[i], xa[i + 1], ya[i + 1] );
317 xfig_Dev *dev = (xfig_Dev *) pls->
dev;
319 if ( !dev->firstline )
338 dev = (xfig_Dev *) pls->
dev;
347 dev->offset += dev->offset_inc;
351 dev->curcol = XFIG_COLBASE;
352 fprintf( pls->
OutFile,
"2 1 0 1 %d %d 50 0 20 0.0 0 0 -1 0 0 5\n", dev->curcol, dev->curcol );
353 fprintf( pls->
OutFile,
"%d %d %d %d %d %d %d %d %d %d\n",
355 0, (
int) ( FIGY * dev->yscale_dev ) + dev->offset,
356 (
int) ( FIGX * dev->xscale_dev ), (
int) ( FIGY * dev->yscale_dev ) + dev->offset,
357 (
int) ( FIGX * dev->xscale_dev ), dev->offset,
370 xfig_Dev *dev = (xfig_Dev *) pls->
dev;
373 free( (
void *) dev->buffptr );
386 xfig_Dev *dev = (xfig_Dev *) pls->
dev;
393 dev->curwid = pls->
width < 1 ? 1 : pls->
width;
398 dev->curcol = pls->
icol0 + XFIG_COLBASE;
403 dev->curcol = pls->
icol1 + XFIG_COLBASE + pls->
ncol0;
426 xfig_Dev *dev = pls->
dev;
436 fprintf( pls->
OutFile,
"2 1 0 1 %d %d 50 0 20 0.0 0 0 0 0 0 %d\n",
437 dev->curcol, dev->curcol, npts );
439 for ( i = 0; i < npts; i++ )
441 dev->offset + dev->ymax * (
int) dev->xscale_dev - pls->
dev_y[i] );
459 xfig_Dev *dev = pls->
dev;
462 if ( dev->count == 0 )
465 fprintf( pls->
OutFile,
"2 1 0 %d %d 0 50 0 -1 0.0 0 0 0 0 0 %d\n",
466 dev->curwid, dev->curcol, dev->count / 2 );
467 while ( i < dev->
count )
469 fprintf( pls->
OutFile,
"%d %d ", *( dev->buffptr + i ),
470 dev->offset + dev->ymax * (
int) dev->yscale_dev - *( dev->buffptr + i + 1 ) );
481 PLFLT a1, alpha, ft_ht, angle, ref;
482 xfig_Dev *dev = (xfig_Dev *) pls->
dev;
483 PLINT clxmin, clxmax, clymin, clymax;
487 ft_ht = pls->
chrht * 72.0 / 25.4;
490 angle = pls->
diorot * 90.;
491 a1 = acos( t[0] ) * 180. /
PI;
495 alpha = 360. - a1 - angle;
497 alpha = alpha *
PI / 180.;
503 difilt( &args->
x, &args->
y, 1, &clxmin, &clxmax, &clymin, &clymax );
510 if ( args->
x < clxmin || args->
x > clxmax || args->
y < clymin || args->
y > clymax )
519 if ( args->
just == 0.5 )
521 else if ( args->
just == 1. )
526 args->
x = args->
refx;
527 args->
y = args->
refy;
539 if ( args->
base == 2 )
540 ref = -
DPI / 72. * ft_ht / 2.;
541 else if ( args->
base == 1 )
544 ref =
DPI / 72. * ft_ht / 2.;
547 args->
y = (
PLINT) ( dev->offset + dev->ymax * (
int) dev->xscale_dev - ( args->
y - ref * cos( alpha ) ) );
548 args->
x = (
PLINT) ( args->
x + ref * sin( alpha ) );
560 switch ( pls->
cfont )
562 case ( 1 ): font = 0;
break;
563 case ( 2 ): font = 1;
break;
564 case ( 3 ): font = 3;
break;
565 case ( 4 ): font = 4;
break;
569 fprintf( pls->
OutFile,
"4 %d %d 50 0 %d %f %f 4 1 1 %d %d %s\\001\n",
570 jst, dev->curcol, font, 1.8 * ft_ht, alpha, args->
x, args->
y, args->
string );
int plParseDrvOpts(DrvOpt *acc_opt)
void(* plD_line_fp)(struct PLStream_struct *, short, short, short, short)
void(* plD_eop_fp)(struct PLStream_struct *)
void(* plD_state_fp)(struct PLStream_struct *, PLINT)
void(* plD_tidy_fp)(struct PLStream_struct *)
PLDLLIMPEXP_DRIVER void plD_dispatch_init_xfig(PLDispatchTable *pdt)
void plOpenFile(PLStream *pls)
void plCloseFile(PLStream *pls)
void plGetFam(PLStream *pls)
void plFamInit(PLStream *pls)
void(* plD_polyline_fp)(struct PLStream_struct *, short *, short *, PLINT)
void(* plD_esc_fp)(struct PLStream_struct *, PLINT, void *)
void(* plD_bop_fp)(struct PLStream_struct *)
void difilt(PLINT *xsc, PLINT *ysc, PLINT npts, PLINT *clpxmi, PLINT *clpxma, PLINT *clpymi, PLINT *clpyma)
void plP_setpxl(PLFLT xpmm, PLFLT ypmm)
#define PLDLLIMPEXP_DRIVER
void plP_setphy(PLINT xmin, PLINT xmax, PLINT ymin, PLINT ymax)
static void proc_str(PLStream *, EscText *)
void plwarn(const char *errormsg)
plD_polyline_fp pl_polyline
void(* plD_init_fp)(struct PLStream_struct *)
void plexit(const char *errormsg)