70 #define SWAP_BALCK_WHEN_WHITE
100 #define use_experimental_hidden_line_hack
102 static int force_edges = 0;
103 static int disable_background = 0;
105 static DrvOpt cgm_options[] = { {
"force_edges",
DRV_INT, &force_edges,
"Force edges to be drawn on filled polygongs (0|1)" },
106 {
"no_paper",
DRV_INT, &disable_background,
"Disable background (0|1)" },
107 { NULL,
DRV_INT, NULL, NULL } };
124 int colour_index[256];
135 int last_line_colour;
137 int last_fill_colour;
144 int disable_background;
148 void plD_line_cgm(
PLStream *,
short,
short,
short,
short );
149 void plD_polyline_cgm(
PLStream *,
short *,
short *,
PLINT );
159 #ifndef ENABLE_DYNDRIVERS
160 pdt->
pl_MenuStr =
"CGM (Computer Graphics metafile) file";
188 if ( pls->
dev != NULL )
189 free( (
void *) pls->
dev );
191 pls->
dev = calloc( 1, (
size_t)
sizeof ( cgm_Dev ) );
192 if ( pls->
dev == NULL )
193 plexit(
"plD_init_cgm_Dev: Out of memory." );
195 dev = (cgm_Dev *) pls->
dev;
200 dev->force_edges = force_edges;
201 dev->disable_background = disable_background;
204 dev->fill_colour = dev->colour;
205 dev->last_fill_colour = -1;
206 dev->last_line_colour = -1;
228 if ( pls->
width < 1 )
238 plD_init_cgm_Dev( pls );
239 dev = (cgm_Dev *) pls->
dev;
245 if ( pls->
xdpi <= 0. || pls->
ydpi <= 0. )
262 #ifdef use_experimental_hidden_line_hack
264 if ( dev->cgmx > dev->cgmy )
281 plP_setphy( 0, dev->scale * dev->cgmx, 0, dev->scale * dev->cgmy );
291 plD_line_cgm(
PLStream *pls,
short x1a,
short y1a,
short x2a,
short y2a )
293 cgm_Dev *dev = (cgm_Dev *) pls->
dev;
294 int x1 = x1a / dev->scale, y1 = y1a / dev->scale, x2 = x2a / dev->scale, y2 = y2a / dev->scale;
304 if ( dev->last_line_colour != dev->colour )
307 dev->last_line_colour = dev->colour;
310 cdLine( dev->im_out, x1, y1, x2, y2 );
320 plD_polyline_cgm(
PLStream *pls,
short *xa,
short *ya,
PLINT npts )
322 cgm_Dev *dev = (cgm_Dev *) pls->
dev;
326 if ( ( points = calloc( npts, (
size_t)
sizeof (
cdPoint ) ) ) == NULL )
328 plexit(
"Memory allocation error in \"plD_polyline_cgm\"" );
331 for ( i = 0; i < npts; i++ )
333 points[i].x = xa[i] / dev->scale;
334 points[i].y = ( ya[i] / dev->scale );
343 if ( dev->last_line_colour != dev->colour )
346 dev->last_line_colour = dev->colour;
363 cgm_Dev *dev = (cgm_Dev *) pls->
dev;
371 if ( ( points = calloc( pls->
dev_npts, (
size_t) sizeof (
cdPoint ) ) ) == NULL )
373 plexit(
"Memory allocation error in \"plD_fill_polygon_cgm\"" );
376 for ( i = 0; i < pls->
dev_npts; i++ )
378 points[i].x = pls->
dev_x[i] / dev->scale;
379 points[i].y = ( pls->
dev_y[i] / dev->scale );
390 if ( ( dev->fill_colour != dev->last_fill_colour ) || ( dev->force_edges == 1 ) )
400 if ( dev->force_edges == 1 )
406 dev->last_fill_colour = dev->fill_colour;
411 if ( dev->force_edges == 1 )
426 int i, ncol1 = pls->
ncol1;
427 int ncol0 = pls->
ncol0, total_colours;
429 cgm_Dev *dev = (cgm_Dev *) pls->
dev;
430 PLFLT tmp_colour_pos;
439 plwarn(
"Too many colours in cmap0." );
446 total_colours = ncol0 + ncol1;
451 ncol1 = total_colours - ncol0;
455 plexit(
"Problem setting colourmap in CGM driver." );
468 #ifdef SWAP_BALCK_WHEN_WHITE
482 if ( ( pls->
ncol0 > 15 ) && ( pls->
cmap0[0].
r > 227 ) && ( pls->
cmap0[0].
g > 227 ) && ( pls->
cmap0[0].
b > 227 ) )
484 if ( pls->
hack != 1 )
504 for ( i = 0; i < ncol0; i++ )
511 plwarn(
"Problem setting cmap0 in CGM driver." );
523 for ( i = 0; i < ncol1; i++ )
525 if ( ncol1 < pls->ncol1 )
535 tmp_colour_pos = i > 0 ? pls->
ncol1 * ( (
PLFLT) i / ncol1 ) : 0;
546 cmap1col.
r, cmap1col.
g, cmap1col.
b )
549 plwarn(
"Problem setting cmap1 in CGM driver." );
567 cgm_Dev *dev = (cgm_Dev *) pls->
dev;
568 PLFLT tmp_colour_pos;
577 dev->colour = pls->
icol0;
588 plwarn(
"Problem changing colour in \"PLSTATE_COLOR0\"" );
590 dev->colour = dev->totcol;
593 dev->fill_colour = dev->colour;
601 if ( dev->ncol1 < pls->
ncol1 )
604 dev->colour = pls->
ncol0 + (int) tmp_colour_pos;
609 dev->fill_colour = dev->colour;
666 dev = (cgm_Dev *) pls->
dev;
668 if ( pls->
page == 1 )
672 else if ( pls->
family != 1 )
699 if ( dev->disable_background != 1 )
722 cgm_Dev *dev = (cgm_Dev *) pls->
dev;
742 cgm_Dev *dev = (cgm_Dev *) pls->
dev;
750 dev->colour_index[i] = -1;
752 dev->fill_colour = dev->colour;
753 dev->last_fill_colour = -1;
754 dev->last_line_colour = -1;
int plParseDrvOpts(DrvOpt *acc_opt)
int cdSetEdgeWidth(cdImagePtr im, int edwidth)
void(* plD_line_fp)(struct PLStream_struct *, short, short, short, short)
void plexit(PLCHAR_VECTOR errormsg)
void(* plD_eop_fp)(struct PLStream_struct *)
void(* plD_state_fp)(struct PLStream_struct *, PLINT)
void(* plD_tidy_fp)(struct PLStream_struct *)
int cdSetLineType(cdImagePtr im, int lntype)
void plOpenFile(PLStream *pls)
void plCloseFile(PLStream *pls)
int cdImageCgm(cdImagePtr im, FILE *out)
void plGetFam(PLStream *pls)
#define PLPLOT_MM_PER_INCH
void plcol_interp(PLStream *pls, PLColor *newcolor, int i, int ncol)
int cdSetLineColor(cdImagePtr im, int lncolor)
int cdRectangle(cdImagePtr im, int x1, int y1, int x2, int y2)
int cdSetEdgeColor(cdImagePtr im, int edcolor)
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 *)
int cdSetEdgeVis(cdImagePtr im, int edvis)
int cdImageDestroy(cdImagePtr im)
int cdPolyLine(cdImagePtr im, cdPointPtr p, int n)
int cdSetLineWidth(cdImagePtr im, int lnwidth)
int cdCgmNewPic(cdImagePtr im, int sticky)
#define PLPLOT_DEFAULT_WIDTH_PIXELS
int cdLine(cdImagePtr im, int x1, int y1, int x2, int y2)
#define PLPLOT_DEFAULT_PIXELS_PER_INCH
void plP_setpxl(PLFLT xpmm, PLFLT ypmm)
int cdSetFillStyle(cdImagePtr im, int instyle)
#define PLDLLIMPEXP_DRIVER
static PLStream * pls[PL_NSTREAMS]
void plP_setphy(PLINT xmin, PLINT xmax, PLINT ymin, PLINT ymax)
int cdImageColorAllocate(cdImagePtr im, int r, int g, int b)
int cdPolygon(cdImagePtr im, cdPointPtr p, int n)
PLDLLIMPEXP_DRIVER void plD_dispatch_init_cgm(PLDispatchTable *pdt)
void plwarn(PLCHAR_VECTOR errormsg)
int cdImageColorClear(cdImagePtr im)
int cdSetFillColor(cdImagePtr im, int incolor)
cdImagePtr cdImageCreate(int sx, int sy)
#define PLPLOT_DEFAULT_HEIGHT_PIXELS
plD_polyline_fp pl_polyline
void(* plD_init_fp)(struct PLStream_struct *)