예제 #1
0
파일: ps.c 프로젝트: distanceModling/DAKOTA
void
plD_init_psc(PLStream *pls)
{
  color = 1;
  pls->color = 1;		/* Is a color device */
  plParseDrvOpts(ps_options);

  if (!color)
    pls->color = 0;		/* But user does not want color */
  ps_init(pls);
}
예제 #2
0
파일: ps.c 프로젝트: distanceModling/DAKOTA
void
plD_init_psm(PLStream *pls)
{
  color = 0;
  pls->color = 0;		/* Not a color device */

  plParseDrvOpts(ps_options);
  if (color)
    pls->color = 1;		/* But user wants color */
  ps_init(pls);
}
예제 #3
0
파일: xfig.c 프로젝트: WenchaoLin/JAMg
void
plD_init_xfig(PLStream *pls)
{
    PLDev *dev;

    plParseDrvOpts(xfig_options);
    if (text)
      pls->dev_text = 1; /* want to draw text */

/* Initialize family file info */

    plFamInit(pls);

/* Prompt for a file name if not already set */

    plOpenFile(pls);

/* Allocate and initialize device-specific data */

    dev = plAllocDev(pls);

    dev->xold = PL_UNDEFINED;
    dev->yold = PL_UNDEFINED;
    dev->xmin = 0;
    dev->xmax = FIGX;
    dev->ymin = 0;
    dev->ymax = FIGY;
    dev->xscale_dev = DPI/25.4;
    dev->yscale_dev = DPI/25.4;
    offset_inc = dev->ymax * (PLINT)dev->yscale_dev;
    offset = - offset_inc;
    pls->dev_fill0 = 1;	    /* Handle solid fills */
    if (!pls->colorset)
      pls->color = 1;         /* Is a color device */

    plP_setpxl(dev->xscale_dev, dev->xscale_dev); /* dpmm -- dots per mm */
    plP_setphy(0, FIGX * dev->xscale_dev, 0, FIGY * dev->yscale_dev); /* physical dimension in mm */ 

/* Write out header */

    fprintf(pls->OutFile, "#FIG 3.2\n");
    fprintf(pls->OutFile, "Landscape\n");
    fprintf(pls->OutFile, "Center\n");
    fprintf(pls->OutFile, "Metric\n");
    fprintf(pls->OutFile, "A4\n");
    fprintf(pls->OutFile, "100.0\n");
    fprintf(pls->OutFile, "Single\n");
    fprintf(pls->OutFile, "-2\n");
    fprintf(pls->OutFile, "%d 2\n", DPI);

    /* user defined colors, for colormap0 */
    cmap0_ncol = 2 * pls->ncol0; /* allow for a maximum of 2x the default cmap0 entries */
    cmap0_pos = ftell(pls->OutFile);
    stcmap0(pls);

    /* user defined colors, for colormap1 */
    cmap1_ncol = 2 * pls->ncol1; /* allow for a maximum of  2x the default cmap1 entries */
    cmap1_pos = ftell(pls->OutFile); 
    stcmap1(pls);

    bufflen = 2 * BSIZE;
    buffptr = (short *) malloc(sizeof(short) * bufflen);
    if (buffptr == NULL)
	plexit("Out of memory!");
}
예제 #4
0
void plD_init_win3(PLStream *pls)
{
	HWND      hwndMain;
	WNDCLASS  wndclass;
	HINSTANCE hInstance;
	WinDev    *dev;
	int       greyvalue;
	char      *ptitle;
	//long      backGroundColor;
	
	/* Initial window position */
	int xPos    = 100;
	int yPos    = 100;
	
	/* Initial window size */
	int nWidth  = 720;
	int nHeight = 540;
	
	int xmin = 0;
	int xmax = PIXELS_X-1;
	int ymin = 0;
	int ymax = PIXELS_Y-1;
	
	color = 1;
	hwnd = 0;
	pls->color = 1;		/* Is a color device */
	plParseDrvOpts(win3_options);
	if (!color) pls->color = 0; /* But user does not want color */
	
	/* Set up device parameters */
	pls->termin      = 1; /* is an interactive terminal */
	pls->icol0       = 1; /* current color */
	pls->width       = 1; /* current pen width */
	pls->bytecnt     = 0;
	pls->page        = 0;
	if (buffered)
		pls->plbuf_write = 1; /* buffer the output */
	else
		pls->plbuf_write = 0;
	pls->dev_flush   = 1; /* flush as we like */
	pls->dev_fill0   = 1;	
	pls->dev_fastimg = 1; /* is a fast image device */
	pls->dev_xor     = 1; /* device support xor mode */
	if (pls->dev != NULL) delete pls->dev;
	pls->dev = new WinDev;
	assert(pls->dev != NULL);
	
	dev = (WinDev *) pls->dev;
	dev->nextPlot = 0;
	dev->write_to_window = 1;
	dev->write_to_pixmap = 0;
	dev->PenColor=RGB(pls->cmap0[0].r,pls->cmap0[0].g,pls->cmap0[0].b);
	dev->PenWidth=0;
	
	dev->hPen     = CreatePen(PS_SOLID,dev->PenWidth,dev->PenColor);
	dev->hPenOld = (HPEN)SelectObject(dev->hdc,dev->hPen);
	dev->hbr      = CreateSolidBrush(RGB(pls->cmap0[0].r,pls->cmap0[0].g,pls->cmap0[0].b));
	dev->hbrOld   = (HBRUSH)SelectObject(dev->hdc,dev->hbr);
	dev->hMenu    = NULL;

        dev->isDead   = FALSE;
	
	if (pls->color) {
		dev->backGroundColor = RGB(pls->cmap0[0].r,pls->cmap0[0].g,pls->cmap0[0].b);
	} else {
		greyvalue = (pls->cmap0[0].r+pls->cmap0[0].g+pls->cmap0[0].b)/3;
		dev->backGroundColor = RGB(greyvalue,greyvalue,greyvalue);
	}

	if (!hwnd) {
		/* Window created by the driver */
		dev->externalWindow = 0;
		hInstance = GetModuleHandle(NULL);
		
		wndclass.style = CS_HREDRAW | CS_VREDRAW | CS_SAVEBITS;
		wndclass.lpfnWndProc = ::PlPlotWndProc;
		wndclass.cbClsExtra = 0;
		wndclass.cbWndExtra = sizeof(pls);
		wndclass.hInstance = hInstance;
		wndclass.hIcon = LoadIcon(hInstance,"PLICON");
		wndclass.hCursor = LoadCursor(NULL,IDC_ARROW);
        wndclass.hbrBackground = (struct HBRUSH__ *)CreateSolidBrush(dev->backGroundColor);
		wndclass.lpszMenuName = NULL;
		wndclass.lpszClassName = szPlPlotClass;
		RegisterClass (&wndclass);
		ptitle = (char *) &szPlPlotWName[0] ;
		if ( pls->plwindow ) ptitle = pls->plwindow ;
		
		dev->hwnd = CreateWindow(szPlPlotClass,ptitle,
			WS_OVERLAPPEDWINDOW,
			xPos,yPos,nWidth,nHeight,
			NULL,dev->hMenu,
			hInstance,NULL);
		
		SetWindowLong(dev->hwnd,GWL_USERDATA,(long)pls);
		
		ShowWindow(dev->hwnd,SW_SHOWDEFAULT);
		
		SetForegroundWindow(dev->hwnd);
		
	} else {
		/* Window provided externally */		
		dev->hwnd = (HWND)hwnd;
		dev->externalWindow = 1;
	}


	dev->hdc = GetDC(dev->hwnd);

	SetPolyFillMode(dev->hdc,WINDING);
	
	plP_setpxl(xmax/150.0/nWidth*nHeight,ymax/150.0);
	plP_setphy(xmin,xmax,ymin,ymax);


	if (pls->db)
	{
     	// create a compatible device context
     	dev->db_hdc = CreateCompatibleDC(dev->hdc);
     	dev->db_bmp = CreateCompatibleBitmap(dev->hdc, nWidth,nHeight);
		SelectObject(dev->db_hdc, dev->db_bmp);
		dev->hdc=dev->db_hdc;
	}
}
예제 #5
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;
}
예제 #6
0
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
}
예제 #7
0
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
}