static void plD_init_gif_Dev(PLStream *pls) { png_Dev *dev; /* Stuff for the driver options, these vars are copied into the driver * structure so that everything is thread safe and reenterant. */ static int black15=0; static int red15=0; #ifdef HAVE_FREETYPE static int freetype=1; static int smooth_text=1; FT_Data *FT; #endif DrvOpt gd_options[] = {{"def_black15", DRV_INT, 0, &black15, "Define idx 15 as black. If the background is \"whiteish\" (from \"-bg\" option), force index 15 (traditionally white) to be \"black\""}, {"swp_red15", DRV_INT, 0, &red15, "Swap index 1 (usually red) and 1 (usually white); always done after \"black15\"; quite useful for quick changes to web pages"}, #ifdef HAVE_FREETYPE {"text", DRV_INT, 0, &freetype, "Use driver text (FreeType)"}, {"smooth", DRV_INT, 0, &smooth_text, "Turn text smoothing on (1) or off (0)"}, #endif {NULL, DRV_INT, 0, NULL, NULL}}; /* Allocate and initialize device-specific data */ if (pls->dev != NULL) free((void *) pls->dev); pls->dev = calloc(1, (size_t) sizeof(png_Dev)); if (pls->dev == NULL) plexit("plD_init_gif_Dev: Out of memory."); dev = (png_Dev *) pls->dev; dev->colour=1; /* Set a fall back pen colour in case user doesn't */ /* Check for and set up driver options */ plParseDrvOpts(gd_options); dev->black15=black15; dev->red15=red15; dev->optimise=0; /* Optimise does not work for GIFs... should, but it doesn't */ #if GD2_VERS >= 2 dev->palette=1; /* Always use palette mode for GIF files */ dev->truecolour=0; /* Never have truecolour in GIFS */ #endif #ifdef HAVE_FREETYPE if (freetype) { pls->dev_text = 1; /* want to draw text */ pls->dev_unicode = 1; /* want unicode */ init_freetype_lv1(pls); FT=(FT_Data *)pls->FT; FT->want_smooth_text=smooth_text > 0 ? 1 : 0; } #endif }
/*-------------------------------------------------------------------------- * void common_init( PLStream *pls ) * * Basic initialization for all devices. *--------------------------------------------------------------------------*/ wxPLDevBase* common_init( PLStream *pls ) { // Log_Verbose( "common_init()" ); wxPLDevBase* dev; /* default options */ static PLINT freetype=-1; static PLINT smooth_text=1; static PLINT text=-1; static PLINT hrshsym = 0; /* default backend uses wxGraphicsContext, if not available the agg library will be used, if not available the basic backend will be used. */ static PLINT backend=wxBACKEND_DC; #if wxUSE_GRAPHICS_CONTEXT backend=wxBACKEND_GC; #else #ifdef HAVE_AGG backend=wxBACKEND_AGG; #endif #endif DrvOpt wx_options[] = { #ifdef HAVE_FREETYPE {"freetype", DRV_INT, &freetype, "Use FreeType library"}, {"smooth", DRV_INT, &smooth_text, "Turn text smoothing on (1) or off (0)"}, #endif {"hrshsym", DRV_INT, &hrshsym, "Use Hershey symbol set (hrshsym=0|1)"}, {"backend", DRV_INT, &backend, "Choose backend: (0) standard, (1) using AGG library, (2) using wxGraphicsContext"}, {"text", DRV_INT, &text, "Use own text routines (text=0|1)"}, {NULL, DRV_INT, NULL, NULL} }; /* Check for and set up driver options */ plParseDrvOpts( wx_options ); /* allocate memory for the device storage */ switch( backend ) { case wxBACKEND_GC: /* in case wxGraphicsContext isn't available, the next backend (agg if available) in this list will be used */ #if wxUSE_GRAPHICS_CONTEXT dev = new wxPLDevGC; /* by default the own text routines are used for wxGC */ if(text==-1) text=1; freetype = 0; /* this backend is vector oriented and doesn't know pixels */ break; #endif case wxBACKEND_AGG: /* in case the agg library isn't available, the standard backend will be used */ #ifdef HAVE_AGG dev = new wxPLDevAGG; /* by default the freetype text routines are used for wxAGG */ text = 0; /* text processing doesn't work yet for the AGG backend */ if(freetype==-1) freetype=1; break; #endif default: dev = new wxPLDevDC; /* by default the own text routines are used for wxDC */ if(text==-1) if(freetype!=1) text=1; else text=0; if(freetype==-1) freetype=0; break; } if( dev == NULL) { plexit( "Insufficient memory" ); } pls->dev = (void*)dev; /* be verbose and write out debug messages */ #ifdef _DEBUG pls->verbose = 1; pls->debug = 1; #else pls->verbose = 0; pls->debug = 0; #endif pls->color = 1; /* Is a color device */ pls->dev_fill0 = 1; /* Can handle solid fills */ pls->dev_fill1 = 0; /* Can't handle pattern fills */ pls->dev_dash = 0; pls->dev_clear = 1; /* driver supports clear */ if( text ) { pls->dev_text = 1; /* want to draw text */ pls->dev_unicode = 1; /* want unicode */ if( hrshsym ) pls->dev_hrshsym = 1; } #ifdef HAVE_FREETYPE /* own text routines have higher priority over freetype if text and freetype option are set to 1 */ if( !text) { dev->smooth_text=smooth_text; dev->freetype=freetype; } if( dev->freetype ) { pls->dev_text = 1; /* want to draw text */ pls->dev_unicode = 1; /* want unicode */ if( hrshsym ) pls->dev_hrshsym = 1; init_freetype_lv1( pls ); FT_Data* FT=(FT_Data *)pls->FT; FT->want_smooth_text=smooth_text; } #endif /* initialize frame size and position */ if( pls->xlength <= 0 || pls->ylength <=0 ) plspage( 0.0, 0.0, (PLINT)(CANVAS_WIDTH*DEVICE_PIXELS_PER_IN), (PLINT)(CANVAS_HEIGHT*DEVICE_PIXELS_PER_IN), 0, 0 ); dev->width=pls->xlength; dev->height=pls->ylength; dev->clipminx=pls->xlength; dev->clipminy=pls->ylength; if( pls->xoffset!=0 || pls->yoffset!=0) { dev->xpos = (int)(pls->xoffset); dev->ypos = (int)(pls->yoffset); } /* If portrait mode, apply a rotation and set freeaspect */ if( pls->portrait ) { plsdiori( (PLFLT)(4 - ORIENTATION) ); pls->freeaspect = 1; } /* Set the number of pixels per mm */ plP_setpxl( (PLFLT)VIRTUAL_PIXELS_PER_MM, (PLFLT)VIRTUAL_PIXELS_PER_MM ); /* Set up physical limits of plotting device (in drawing units) */ plP_setphy( (PLINT)0, (PLINT)(CANVAS_WIDTH*VIRTUAL_PIXELS_PER_IN), (PLINT)0, (PLINT)(CANVAS_HEIGHT*VIRTUAL_PIXELS_PER_IN) ); /* get physical device limits coordinates */ plP_gphy( &dev->xmin, &dev->xmax, &dev->ymin, &dev->ymax ); /* setting scale factors */ dev->scalex=(PLFLT)(dev->xmax-dev->xmin)/(dev->width); dev->scaley=(PLFLT)(dev->ymax-dev->ymin)/(dev->height); /* set dpi */ plspage(VIRTUAL_PIXELS_PER_IN/dev->scalex, VIRTUAL_PIXELS_PER_IN/dev->scaley, 0, 0, 0, 0); #ifdef HAVE_FREETYPE if( dev->freetype ) init_freetype_lv2( pls ); #endif /* find out what file drivers are available */ plgFileDevs( &dev->devDesc, &dev->devName, &dev->ndev ); return dev; }
static void plD_init_png_Dev(PLStream *pls) { png_Dev *dev; /* Stuff for the driver options, these vars are copied into the driver * structure so that everything is thread safe and reenterant. */ static int optimise=0; static int black15=0; static int red15=0; #if GD2_VERS >= 2 static int truecolour=0; static int palette=0; #endif #ifdef HAVE_FREETYPE static int freetype=1; static int smooth_text=1; FT_Data *FT; #endif DrvOpt gd_options[] = {{"optimise", DRV_INT, 0, &optimise, "Optimise PNG palette when possible"}, {"def_black15", DRV_INT, 0, &black15, "Define idx 15 as black. If the background is \"whiteish\" (from \"-bg\" option), force index 15 (traditionally white) to be \"black\""}, {"swp_red15", DRV_INT, 0, &red15, "Swap index 1 (usually red) and 1 (usually white); always done after \"black15\"; quite useful for quick changes to web pages"}, #if GD2_VERS >= 2 {"8bit", DRV_INT, 0, &palette, "Palette (8 bit) mode"}, {"24bit", DRV_INT, 0, &truecolour, "Truecolor (24 bit) mode"}, #endif #ifdef HAVE_FREETYPE {"text", DRV_INT, 0, &freetype, "Use driver text (FreeType)"}, {"smooth", DRV_INT, 0, &smooth_text, "Turn text smoothing on (1) or off (0)"}, #endif {NULL, DRV_INT, 0, NULL, NULL}}; /* Allocate and initialize device-specific data */ if (pls->dev != NULL) free((void *) pls->dev); pls->dev = calloc(1, (size_t) sizeof(png_Dev)); if (pls->dev == NULL) plexit("plD_init_png_Dev: Out of memory."); dev = (png_Dev *) pls->dev; dev->colour=1; /* Set a fall back pen colour in case user doesn't */ /* * Set the compression/quality level for JPEG files * The higher the value, the bigger/better the image is */ if ( (pls->dev_compression<=0)||(pls->dev_compression>99) ) pls->dev_compression=90; /* Check for and set up driver options */ plParseDrvOpts(gd_options); dev->black15=black15; dev->red15=red15; dev->optimise=optimise; #if GD2_VERS >= 2 dev->palette=palette; dev->truecolour=truecolour; if ((dev->truecolour>0) && (dev->palette>0)) plwarn("Selecting both \"truecolor\" AND \"palette\" driver options is contradictory, so\nI will just use my best judgment.\n"); else if (dev->truecolour>0) NCOLOURS=16777216; else if ((dev->truecolour==0)&&(dev->palette==0)&&((pls->ncol1+pls->ncol0)>NCOLOURS)) { NCOLOURS=16777216; } #ifdef HAVE_FREETYPE if ((dev->palette==0)&&(dev->optimise==0)&&(smooth_text>1)) dev->smooth=1; /* Allow smoothing of lines if we have a truecolour device */ #endif #endif #ifdef HAVE_FREETYPE if (freetype) { pls->dev_text = 1; /* want to draw text */ pls->dev_unicode = 1; /* want unicode */ /* As long as we aren't optimising, we'll try to use better antialaising * We can also only do this if the user wants smoothing, and hasn't * selected a palette mode. */ init_freetype_lv1(pls); FT=(FT_Data *)pls->FT; FT->want_smooth_text=smooth_text>0 ? 1 : 0; if ((dev->optimise==0)&&(dev->palette==0)&&(smooth_text!=0)) { FT->BLENDED_ANTIALIASING=1; dev->truecolour=1; } } #endif }