Ejemplo n.º 1
0
/*--------------------------------------------------------------------------
 *  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;
}
Ejemplo n.º 2
0
void plD_init_gif(PLStream *pls)
{
    png_Dev *dev=NULL;

    pls->termin = 0;            /* Not an interactive device */
    pls->icol0 = 1;
    pls->bytecnt = 0;
    pls->page = 0;
    pls->dev_fill0 = 1;         /* Can do solid fills */
    pls->family = 1;            /* pmr:  allow multiple pages. */

    if (!pls->colorset)
	pls->color = 1;         /* Is a color device */

/* Initialize family file info */
    plFamInit(pls);

/* Prompt for a file name if not already set */
    plOpenFile(pls);

/* Allocate and initialize device-specific data */
    plD_init_gif_Dev(pls);
    dev=(png_Dev *)pls->dev;

      if (pls->xlength <= 0 || pls->ylength <=0)
      {
/* use default width, height of 800x600 if not specifed by -geometry option
 * or plspage */
	 plspage(0., 0., 800, 600, 0, 0);
      }

     pls->graphx = GRAPHICS_MODE;

     dev->pngx = pls->xlength - 1;	/* should I use -1 or not??? */
     dev->pngy = pls->ylength - 1;

#ifdef use_experimental_hidden_line_hack

     if (dev->pngx>dev->pngy)    /* Work out the scaling factor for the  */
        {                        /* "virtual" (oversized) page           */
        dev->scale=PIXELS_X/dev->pngx;
        }
     else
        {
        dev->scale=PIXELS_Y/dev->pngy;
        }
#else

     dev->scale=1;

#endif


     if (pls->xdpi<=0)
     {
/* This corresponds to a typical monitor resolution of 4 pixels/mm. */
        plspage(4.*25.4, 4.*25.4, 0, 0, 0, 0);
     }
     else
     {
        pls->ydpi=pls->xdpi;        /* Set X and Y dpi's to the same value */
     }
/* Convert DPI to pixels/mm */
     plP_setpxl(dev->scale*pls->xdpi/25.4,dev->scale*pls->ydpi/25.4);

     plP_setphy(0, dev->scale*dev->pngx, 0, dev->scale*dev->pngy);

#ifdef HAVE_FREETYPE
if (pls->dev_text)
   {
    init_freetype_lv2(pls);
   }
#endif

}