70#define SWAP_BALCK_WHEN_WHITE
100#define use_experimental_hidden_line_hack
102static int force_edges = 0;
103static int disable_background = 0;
105static 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;
148void plD_line_cgm(
PLStream *,
short,
short,
short,
short );
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;
225 if ( !
pls->colorset )
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. )
251 if (
pls->xlength == 0 ||
pls->ylength == 0 )
259 dev->cgmx =
pls->xlength - 1;
260 dev->cgmy =
pls->ylength - 1;
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 );
291plD_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 );
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;
368 if (
pls->dev_npts < 1 )
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 )
486 pls->cmap0[15].r = 0;
487 pls->cmap0[15].g = 0;
488 pls->cmap0[15].b = 0;
492 pls->cmap0[15].r =
pls->cmap0[1].r;
493 pls->cmap0[15].g =
pls->cmap0[1].g;
494 pls->cmap0[15].b =
pls->cmap0[1].b;
504 for ( i = 0; i < ncol0; i++ )
508 pls->cmap0[i].r,
pls->cmap0[i].g,
pls->cmap0[i].b )
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;
580 int r =
pls->curcolor.r;
581 int g =
pls->curcolor.g;
582 int b =
pls->curcolor.b;
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 )
603 tmp_colour_pos = dev->ncol1 * ( (
PLFLT)
pls->icol1 / (
pls->ncol1 > 0 ?
pls->ncol1 : 1 ) );
604 dev->colour =
pls->ncol0 + (int) tmp_colour_pos;
607 dev->colour =
pls->ncol0 +
pls->icol1;
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;
724 if (
pls->family != 1 )
742 cgm_Dev *dev = (cgm_Dev *)
pls->dev;
745 if (
pls->family == 1 )
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 cdSetEdgeWidth(cdImagePtr im, int edwidth)
int cdSetLineType(cdImagePtr im, int lntype)
int cdSetEdgeColor(cdImagePtr im, int edcolor)
int cdSetEdgeVis(cdImagePtr im, int edvis)
int cdImageCgm(cdImagePtr im, FILE *out)
int cdCgmNewPic(cdImagePtr im, int sticky)
int cdPolyLine(cdImagePtr im, cdPointPtr p, int n)
int cdLine(cdImagePtr im, int x1, int y1, int x2, int y2)
int cdImageColorClear(cdImagePtr im)
int cdPolygon(cdImagePtr im, cdPointPtr p, int n)
int cdImageColorAllocate(cdImagePtr im, int r, int g, int b)
int cdSetLineWidth(cdImagePtr im, int lnwidth)
int cdSetFillColor(cdImagePtr im, int incolor)
int cdSetFillStyle(cdImagePtr im, int instyle)
int cdRectangle(cdImagePtr im, int x1, int y1, int x2, int y2)
int cdSetLineColor(cdImagePtr im, int lncolor)
int cdImageDestroy(cdImagePtr im)
cdImagePtr cdImageCreate(int sx, int sy)
struct cdPointStruct cdPoint
void(* plD_line_fp)(struct PLStream_struct *, short, short, short, short)
void(* plD_tidy_fp)(struct PLStream_struct *)
void(* plD_bop_fp)(struct PLStream_struct *)
void(* plD_state_fp)(struct PLStream_struct *, PLINT)
void(* plD_eop_fp)(struct PLStream_struct *)
void(* plD_init_fp)(struct PLStream_struct *)
void(* plD_esc_fp)(struct PLStream_struct *, PLINT, void *)
void(* plD_polyline_fp)(struct PLStream_struct *, short *, short *, PLINT)
PLDLLIMPEXP_DRIVER void plD_dispatch_init_cgm(PLDispatchTable *pdt)
int plParseDrvOpts(DrvOpt *acc_opt)
void plP_setpxl(PLFLT xpmm, PLFLT ypmm)
void plP_setphy(PLINT xmin, PLINT xmax, PLINT ymin, PLINT ymax)
static PLStream * pls[PL_NSTREAMS]
void plFamInit(PLStream *pls)
void plwarn(PLCHAR_VECTOR errormsg)
void plcol_interp(PLStream *pls, PLColor *newcolor, int i, int ncol)
void plCloseFile(PLStream *pls)
void plOpenFile(PLStream *pls)
void plexit(PLCHAR_VECTOR errormsg)
void plGetFam(PLStream *pls)
#define PLDLLIMPEXP_DRIVER
#define PLPLOT_MM_PER_INCH
#define PLPLOT_DEFAULT_WIDTH_PIXELS
#define PLPLOT_DEFAULT_HEIGHT_PIXELS
#define PLPLOT_DEFAULT_PIXELS_PER_INCH
static void fill_polygon(PLStream *pls)
plD_polyline_fp pl_polyline