static void UpdateIndex(PLStream *pls, FPOS_T cp_offset) { PLmDev *dev = (PLmDev *) pls->dev; FILE *file = pls->OutFile; /* Update file index. Right now only number of pages. */ /* The ordering here is critical */ if (dev->index_offset > 0) { pldebug("UpdateIndex (plmeta.c)", "Location: %d, seeking to: %d\n", (int) cp_offset, (int) dev->lp_offset); if (pl_fsetpos(file, &dev->index_offset)) { sprintf(buffer, "UpdateIndex (plmeta.c): fsetpos to index_offset (%d) failed", (int) dev->index_offset); plexit(buffer); } plm_wr( pdf_wr_header(pls->pdfs, "pages") ); plm_wr( pdf_wr_2bytes(pls->pdfs, (U_SHORT) pls->page) ); pldebug("UpdateIndex (plmeta.c)", "Location: %d, seeking to: %d\n", (int) dev->lp_offset, (int) cp_offset); if (pl_fsetpos(file, &cp_offset)) { sprintf(buffer, "UpdateIndex (plmeta.c): fsetpos to cp_offset (%d) failed", (int) cp_offset); plexit(buffer); } } }
/*---------------------------------------------------------------------- * void install_buffer( PLStream *pls ) * * If this driver is called from a command line executable (and not * from within a wxWidgets program), this function prepares a DC and a * bitmap to plot into. *----------------------------------------------------------------------*/ static void install_buffer( PLStream *pls ) { // Log_Verbose( "install_buffer" ); wxPLDevBase* dev = (wxPLDevBase*)pls->dev; static bool initApp=false; if( !initApp ) { /* this hack enables to have a GUI on Mac OSX even if the program was called from the command line (and isn't a bundle) */ #ifdef __WXMAC__ ProcessSerialNumber psn; GetCurrentProcess( &psn ); CPSEnableForegroundOperation( &psn ); SetFrontProcess( &psn ); #endif /* initialize wxWidgets */ wxInitialize(); wxLog::GetActiveTarget(); wxTRY { wxPLGetApp().CallOnInit(); } wxCATCH_ALL( wxPLGetApp().OnUnhandledException(); plexit( "Can't init wxWidgets!"); )
PLFLT plGetFlt(char *s) { PLFLT m; double m1; int i = 0; char line[256]; while (i++ < 10) { fprintf(stdout, "%s", s); plio_fgets(line, sizeof(line), stdin); #ifdef MSDOS m = atof(line); return (m); #else if (sscanf(line, "%lf", &m1) == 1) { m = (PLFLT) m1; return (m); } fprintf(stdout, "No value or value out of range; please try again\n"); #endif } plexit("Too many tries."); return (0.); }
void stcmap1(PLStream *pls) { long cur_pos; int i; if (pls->ncol1 > cmap1_ncol) plwarn("Too much colors for cmap1. Preallocate using command line '-ncol1 n.\n'"); cur_pos = ftell(pls->OutFile); if (fseek(pls->OutFile, cmap1_pos, SEEK_SET)) plexit("Sorry, only file based output, no pipes.\n"); /* fill the colormap */ for (i=0; i<pls->ncol1; i++) fprintf(pls->OutFile,"0 %d #%.2x%.2x%.2x\n", i+XFIG_COLBASE+cmap0_ncol, pls->cmap1[i].r, pls->cmap1[i].g, pls->cmap1[i].b); /* fill the nonspecified entries colormap */ for (i=pls->ncol1; i<cmap1_ncol; i++) fprintf(pls->OutFile,"0 %d #000000\n", i+XFIG_COLBASE+cmap0_ncol); if (cur_pos != cmap1_pos) fseek(pls->OutFile, cur_pos, SEEK_SET); }
void plD_esc_xfig(PLStream *pls, PLINT op, void *ptr) { PLDev *dev = pls->dev; int i, npts; switch (op) { case PLESC_FILL: npts = pls->dev_npts; if (npts > PL_MAXPOLY) plexit("FillPolygonCmd: Too many points in polygon\n"); flushbuffer(pls); fprintf(pls->OutFile, "2 1 0 1 %d %d 50 0 20 0.0 0 0 0 0 0 %d\n", curcol, curcol, npts); for (i = 0; i < npts; i++) fprintf(pls->OutFile,"%d %d ", pls->dev_x[i], offset + dev->ymax * (int)dev->xscale_dev - pls->dev_y[i]); fprintf(pls->OutFile, "\n"); break; case PLESC_HAS_TEXT: proc_str(pls, ptr); break; } }
void plD_init_plm(PLStream *pls) { PLmDev *dev; U_CHAR c = (U_CHAR) INITIALIZE; dbug_enter("plD_init_plm"); pls->color = 1; /* Is a color device */ pls->dev_fill0 = 1; /* Handle solid fills */ pls->dev_fill1 = 1; /* Handle pattern fills */ /* Initialize family file info */ plFamInit(pls); /* Prompt for a file name if not already set */ plOpenFile(pls); pls->pdfs = pdf_finit(pls->OutFile); /* Allocate and initialize device-specific data */ pls->dev = calloc(1, (size_t) sizeof(PLmDev)); if (pls->dev == NULL) plexit("plD_init_plm: Out of memory."); dev = (PLmDev *) pls->dev; dev->xold = PL_UNDEFINED; dev->yold = PL_UNDEFINED; dev->xmin = 0; dev->xmax = PIXELS_X - 1; dev->ymin = 0; dev->ymax = PIXELS_Y - 1; dev->pxlx = (double) PIXELS_X / (double) LPAGE_X; dev->pxly = (double) PIXELS_Y / (double) LPAGE_Y; plP_setpxl(dev->pxlx, dev->pxly); plP_setphy(dev->xmin, dev->xmax, dev->ymin, dev->ymax); /* Write Metafile header. */ WriteFileHeader(pls); /* Write color map state info */ plD_state_plm(pls, PLSTATE_CMAP0); plD_state_plm(pls, PLSTATE_CMAP1); /* Write initialization command. */ DEBUG_PRINT_LOCATION("before init"); plm_wr( pdf_wr_1byte(pls->pdfs, c) ); }
void plOpenFile(PLStream *pls) { int i = 0, count = 0; size_t len; char line[256]; while (pls->OutFile == NULL) { /* Setting pls->FileName = NULL forces creation of a new family member */ /* You should also free the memory associated with it if you do this */ if (pls->family && pls->BaseName != NULL) plP_getmember(pls); /* Prompt if filename still not known */ if (pls->FileName == NULL) { do { fprintf(stdout, "Enter graphics output file name: "); plio_fgets(line, sizeof(line), stdin); len = strlen(line); if (len) len--; line[len] = '\0'; /* strip new-line */ count++; /* count zero entries */ } while (!len && count < MAX_NUM_TRIES); plP_sfnam(pls, line); } /* If name is "-", send to stdout */ if ( ! strcmp(pls->FileName, "-")) { pls->OutFile = stdout; pls->output_type = 1; break; } /* Need this here again, for prompted family initialization */ if (pls->family && pls->BaseName != NULL) plP_getmember(pls); if (i++ > 10) plexit("Too many tries."); if ((pls->OutFile = fopen(pls->FileName, "wb+")) == NULL) fprintf(stderr, "Can't open %s.\n", pls->FileName); /* silence this message - Peter Rice, 5-Apr-2002 */ /* // else // pldebug("plOpenFile", "Opened %s\n", pls->FileName); */ } }
PLDev * plAllocDev(PLStream *pls) { if (pls->dev != NULL) free((void *) pls->dev); pls->dev = calloc(1, (size_t) sizeof(PLDev)); if (pls->dev == NULL) plexit("plAllocDev: cannot allocate memory\n"); return (PLDev *) pls->dev; }
/*-------------------------------------------------------------*\ * FillPolygonCmd() \*-------------------------------------------------------------*/ static void FillPolygonCmd(PLStream *pls) { POINT pt[PL_MAXPOLY]; int i; WinDev *dev = (WinDev *)pls->dev; if (pls->dev_npts > PL_MAXPOLY) plexit("FillPolygonCmd : Too many points in polygon\n"); for (i=0; i < pls->dev_npts;i++) { pt[i].x = pls->dev_x[i] * dev->xScale; pt[i].y = (PIXELS_Y - pls->dev_y[i]) * dev->yScale; } Polygon(dev->hdc,pt,pls->dev_npts); }
MZ_DLLEXPORT void pltr1(PLFLT x, PLFLT y, PLFLT *tx, PLFLT *ty, PLPointer pltr_data) { PLINT ul, ur, vl, vr; PLFLT du, dv; PLFLT xl, xr, yl, yr; PLcGrid *grid = (PLcGrid *) pltr_data; PLFLT *xg = grid->xg; PLFLT *yg = grid->yg; PLINT nx = grid->nx; PLINT ny = grid->ny; ul = (PLINT) x; ur = ul + 1; du = x - ul; vl = (PLINT) y; vr = vl + 1; dv = y - vl; if (x < 0 || x > nx - 1 || y < 0 || y > ny - 1) { /* fprintf(stderr, "nx : %d, ny : %d",nx,ny); */ plexit("pltr1: Invalid coordinates"); } /* Look up coordinates in row-dominant array. * Have to handle right boundary specially -- if at the edge, we'd better * not reference the out of bounds point. */ xl = xg[ul]; yl = yg[vl]; if (ur == nx) { *tx = xl; } else { xr = xg[ur]; *tx = xl * (1 - du) + xr * du; } if (vr == ny) { *ty = yl; } else { yr = yg[vr]; *ty = yl * (1 - dv) + yr * dv; } }
void pldtik(PLFLT vmin, PLFLT vmax, PLFLT *tick, PLINT *nsubt) { PLFLT t1, t2, tick_reasonable; PLINT np, ns; /* Magnitude of min/max difference to get tick spacing */ t1 = (PLFLT) log10(ABS(vmax - vmin)); np = (PLINT) floor(t1); t1 = t1 - np; /* Get tick spacing. */ if (t1 > 0.7781512503) { t2 = 2.0; ns = 4; } else if (t1 > 0.4771212549) { t2 = 1.0; ns = 5; } else if (t1 > 0.1760912591) { t2 = 5.0; ns = 5; np = np - 1; } else { t2 = 2.0; ns = 4; np = np - 1; } /* Now compute reasonable tick spacing */ tick_reasonable = t2 * pow(10.0, (double) np); if (*tick == 0) { *tick = t2 * pow(10.0, (double) np); } else { *tick = ABS(*tick); if(*tick < 1.e-4*tick_reasonable) { plexit("pldtik: magnitude of specified tick spacing is much too small"); return; } } if (*nsubt == 0) *nsubt = ns; *nsubt = ABS(*nsubt); }
/*--------------------------------------------------------------------------*\ * plD_polyline_win3() * * Draw a polyline in the current color. \*--------------------------------------------------------------------------*/ void plD_polyline_win3(PLStream *pls, short *xa, short *ya, PLINT npts) { WinDev *dev = (WinDev *)pls->dev; POINT pt[PL_MAXPOLY]; int i; if (npts > PL_MAXPOLY) plexit("FillPolygonCmd : Too many points in polygon\n"); for (i=0; i < npts;i++) { pt[i].x = xa[i] * dev->xScale; pt[i].y = (PIXELS_Y - ya[i]) * dev->yScale; } Polyline(dev->hdc,pt,npts); }
static void PrintLocation(PLStream *pls, char *tag) { int isfile = (pls->output_type == 0); if (isfile) { FILE *file = pls->OutFile; FPOS_T current_offset; if (pl_fgetpos(file, ¤t_offset)) plexit("PrintLocation (plmeta.c): fgetpos call failed"); pldebug(tag, "at offset %d in file %s\n", (int) current_offset, pls->FileName); } }
void plbuf_bop(PLStream *pls) { dbug_enter("plbuf_bop"); plbuf_tidy(pls); pls->plbufFile = tmpfile(); if (pls->plbufFile == NULL) plexit("plbuf_init: Error opening plot data storage file."); wr_command(pls, (U_CHAR) BOP); plbuf_state(pls, PLSTATE_COLOR0); plbuf_state(pls, PLSTATE_WIDTH); }
/* * Plot an individual vector */ static void plP_plotvect(PLFLT x, PLFLT y, PLFLT u, PLFLT v, PLFLT scale) { PLFLT uu, vv, px0, py0, dpx, dpy; PLINT *a_x, *a_y; int j; uu = scale*u; vv = scale*v; if(uu == 0.0 && vv == 0.0) return; if (((a_x = (PLINT *)malloc(sizeof(PLINT)*(plsc->arrow_npts)))==NULL)|| ((a_y = (PLINT *)malloc(sizeof(PLINT)*(plsc->arrow_npts)))==NULL)) { plexit("plP_plotvect: Insufficient memory"); } px0 = plP_wcpcx(x); py0 = plP_wcpcy(y); pldebug("plP_plotvect", "%f %f %d %d\n",x,y,px0,py0); dpx = plP_wcpcx(x + 0.5*uu) - px0; dpy = plP_wcpcy(y + 0.5*vv) - py0; /* transform arrow -> a */ for (j = 0; j < plsc->arrow_npts; j++) { a_x[j] = (PLINT)(plsc->arrow_x[j] * dpx - plsc->arrow_y[j] * dpy + px0); a_y[j] = (PLINT)(plsc->arrow_x[j] * dpy + plsc->arrow_y[j] * dpx + py0); } /* draw the arrow */ plP_draphy_poly(a_x,a_y,plsc->arrow_npts); if (plsc->arrow_fill) { plP_plfclp(a_x, a_y, plsc->arrow_npts, plsc->clpxmi, plsc->clpxma, plsc->clpymi, plsc->clpyma, plP_fill); } free((void *)a_x); free((void *)a_y); }
static void addcoord(PLINT xp1, PLINT yp1) { PLINT *temp; if (bufferleng + 2 > buffersize) { buffersize += 2 * BINC; temp = (PLINT *) realloc((void *) buffer, (size_t) buffersize * sizeof(PLINT)); if (!temp) { free((void *) buffer); plexit("plfill: Out of memory!"); } buffer = temp; } buffer[bufferleng++] = xp1; buffer[bufferleng++] = yp1; }
void plD_line_xfig(PLStream *pls, short x1a, short y1a, short x2a, short y2a) { PLDev *dev = (PLDev *) pls->dev; int xx1 = x1a, yy1 = y1a, xx2 = x2a, yy2 = y2a; short *tempptr; /* If starting point of this line is the same as the ending point of */ /* the previous line then don't raise the pen. (This really speeds up */ /* plotting and reduces the size of the file. */ if (firstline) { count = 0; *(buffptr + count++) = xx1; *(buffptr + count++) = yy1; *(buffptr + count++) = xx2; *(buffptr + count++) = yy2; firstline = 0; } else if (xx1 == dev->xold && yy1 == dev->yold) { if (count + 2 >= bufflen) { bufflen += 2 * BSIZE; tempptr = (short *) realloc((void *) buffptr, bufflen * sizeof(short)); if (tempptr == NULL) { free((void *) buffptr); plexit("Out of memory!"); } buffptr = tempptr; } *(buffptr + count++) = xx2; *(buffptr + count++) = yy2; } else { flushbuffer(pls); *(buffptr + count++) = xx1; *(buffptr + count++) = yy1; *(buffptr + count++) = xx2; *(buffptr + count++) = yy2; } dev->xold = xx2; dev->yold = yy2; }
void c_plsvect(PLFLT *arrowx, PLFLT *arrowy, PLINT npts, PLINT fill) { int i; if (plsc->arrow_x) free_mem(plsc->arrow_x); if (plsc->arrow_y) free_mem(plsc->arrow_y); if (((plsc->arrow_x = (PLFLT *)malloc(npts*sizeof(PLFLT)))==NULL)|| ((plsc->arrow_y = (PLFLT *)malloc(npts*sizeof(PLFLT)))==NULL)) { plexit("c_plsvect: Insufficient memory"); } plsc->arrow_npts = npts; plsc->arrow_fill = fill; for (i=0; i<npts; i++) { plsc->arrow_x[i] = arrowx[i]; plsc->arrow_y[i] = arrowy[i]; } }
static void WritePageInfo(PLStream *pls, FPOS_T pp_offset) { PLmDev *dev = (PLmDev *) pls->dev; FILE *file = pls->OutFile; int isfile = (pls->output_type == 0); U_CHAR c; FPOS_T cp_offset=0; /* Update table of contents. */ if (isfile) { if (pl_fgetpos(file, &cp_offset)) plexit("WritePageInfo (plmeta.c): fgetpos call failed"); UpdateIndex(pls, cp_offset); } /* Write new page header */ if (dev->notfirst) c = BOP; else { c = BOP0; dev->notfirst = 1; } plm_wr( pdf_wr_1byte(pls->pdfs, c) ); plm_wr( pdf_wr_2bytes(pls->pdfs, (U_SHORT) pls->page) ); plm_wr( pdf_wr_4bytes(pls->pdfs, (U_LONG) pp_offset) ); plm_wr( pdf_wr_4bytes(pls->pdfs, (U_LONG) 0) ); /* Update last page offset with current page value */ dev->lp_offset = cp_offset; /* Write some page state information just to make things nice later on */ /* Eventually there will be more */ plD_state_plm(pls, PLSTATE_COLOR0); }
void plD_init_imp(PLStream *pls) { PLDev *dev; /* 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->ymin = 0; dev->xmax = IMPX; dev->ymax = IMPY; dev->xlen = dev->xmax - dev->xmin; dev->ylen = dev->ymax - dev->ymin; plP_setpxl((PLFLT) 11.81, (PLFLT) 11.81); plP_setphy(dev->xmin, dev->xmax, dev->ymin, dev->ymax); LineBuff = (short *) malloc(BUFFLENG * sizeof(short)); if (LineBuff == NULL) { plexit("Error in memory alloc in plD_init_imp()."); } fprintf(pls->OutFile, "@Document(Language ImPress, jobheader off)"); fprintf(pls->OutFile, "%c%c", SET_HV_SYSTEM, OPBYTE1); fprintf(pls->OutFile, "%c%c%c", SET_ABS_H, OPWORDH1, OPWORDH2); fprintf(pls->OutFile, "%c%c%c", SET_ABS_V, OPWORDV1, OPWORDV2); fprintf(pls->OutFile, "%c%c", SET_HV_SYSTEM, OPBYTE2); }
PLINT plGetInt(char *s) { int m; int i = 0; char line[256]; while (i++ < 10) { fprintf(stdout, s); fgets(line, sizeof(line), stdin); #ifdef MSDOS m = atoi(line); return (m); #else if (sscanf(line, "%d", &m) == 1) return (m); fprintf(stdout, "No value or value out of range; please try again\n"); #endif } plexit("Too many tries."); return (0); }
void plD_gd_optimise(PLStream *pls) { png_Dev *dev=(png_Dev *)pls->dev; int i,j; char *bbuf; bbuf=calloc(256,(size_t) 1); /* Allocate a buffer to "check off" colours as they are used */ if (bbuf==NULL) plexit("plD_gd_optimise: Out of memory."); for(i=0;i<(pls->xlength-1);i++) /* Walk through the image pixel by pixel */ { /* checking to see what colour it is */ for(j=0;j<(pls->ylength-1);j++) /* and adding it to the list of used colours */ { bbuf[gdImagePalettePixel(dev->im_out, i, j)]=1; } } for (i=0;i<256;i++) /* next walk over the colours and deallocate */ { /* unused ones */ if (bbuf[i]==0) gdImageColorDeallocate(dev->im_out,i); } free(bbuf); }
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!"); }
void plD_init_ljii(PLStream *pls) { PLDev *dev; /* 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->ymin = 0; plP_setpxl((PLFLT) 5.905, (PLFLT) 5.905); /* Rotate by 90 degrees since portrait mode addressing is used */ dev->xmin = 0; dev->ymin = 0; dev->xmax = JETY; dev->ymax = JETX; dev->xlen = dev->xmax - dev->xmin; dev->ylen = dev->ymax - dev->ymin; plP_setphy(dev->xmin, dev->xmax, dev->ymin, dev->ymax); /* If portrait mode is specified, then set up an additional rotation * transformation with aspect ratio allowed to adjust via freeaspect. * Default orientation is landscape (ORIENTATION == 3 or 90 deg rotation * counter-clockwise from portrait). (Legacy PLplot used seascape * which was equivalent to ORIENTATION == 1 or 90 deg clockwise rotation * from portrait.) */ if (pls->portrait) { plsdiori((PLFLT)(4 - ORIENTATION)); pls->freeaspect = 1; } /* Allocate storage for bit map matrix */ #ifdef MSDOS if ((bitmap = (char _HUGE *) halloc((long) NBYTES, sizeof(char))) == NULL) plexit("Out of memory in call to calloc"); #else if ((bitmap = (void *) calloc(NBYTES, sizeof(char))) == NULL) plexit("Out of memory in call to calloc"); #endif /* Reset Printer */ fprintf(OF, "%cE", ESC); }
int main( int argc, const char *argv[] ) { int i, j, k; PLFLT *x, *y, **z, *z_row_major, *z_col_major; PLFLT dx = 2. / (PLFLT) ( XPTS - 1 ); PLFLT dy = 2. / (PLFLT) ( YPTS - 1 ); PLfGrid2 grid_c, grid_row_major, grid_col_major; PLFLT xx, yy, r; PLINT ifshade; PLFLT zmin, zmax, step; PLFLT clevel[LEVELS]; PLINT nlevel = LEVELS; PLINT indexxmin = 0; PLINT indexxmax = XPTS; PLINT *indexymin; PLINT *indexymax; PLFLT **zlimited; // parameters of ellipse (in x, y index coordinates) that limits the data. // x0, y0 correspond to the exact floating point centre of the index // range. PLFLT x0 = 0.5 * (PLFLT) ( XPTS - 1 ); PLFLT a = 0.9 * x0; PLFLT y0 = 0.5 * (PLFLT) ( YPTS - 1 ); PLFLT b = 0.7 * y0; PLFLT square_root; // Parse and process command line arguments plMergeOpts( options, "x08c options", NULL ); (void) plparseopts( &argc, argv, PL_PARSE_FULL ); // Initialize plplot plinit(); // Allocate data structures x = (PLFLT *) calloc( XPTS, sizeof ( PLFLT ) ); y = (PLFLT *) calloc( YPTS, sizeof ( PLFLT ) ); plAlloc2dGrid( &z, XPTS, YPTS ); z_row_major = (PLFLT *) malloc( XPTS * YPTS * sizeof ( PLFLT ) ); z_col_major = (PLFLT *) malloc( XPTS * YPTS * sizeof ( PLFLT ) ); if ( !z_row_major || !z_col_major ) plexit( "Memory allocation error" ); grid_c.f = z; grid_row_major.f = (PLFLT **) z_row_major; grid_col_major.f = (PLFLT **) z_col_major; grid_c.nx = grid_row_major.nx = grid_col_major.nx = XPTS; grid_c.ny = grid_row_major.ny = grid_col_major.ny = YPTS; for ( i = 0; i < XPTS; i++ ) { x[i] = -1. + (PLFLT) i * dx; if ( rosen ) x[i] *= 1.5; } for ( j = 0; j < YPTS; j++ ) { y[j] = -1. + (PLFLT) j * dy; if ( rosen ) y[j] += 0.5; } for ( i = 0; i < XPTS; i++ ) { xx = x[i]; for ( j = 0; j < YPTS; j++ ) { yy = y[j]; if ( rosen ) { z[i][j] = pow( 1. - xx, 2. ) + 100. * pow( yy - pow( xx, 2. ), 2. ); // The log argument might be zero for just the right grid. if ( z[i][j] > 0. ) z[i][j] = log( z[i][j] ); else z[i][j] = -5.; // -MAXFLOAT would mess-up up the scale } else { r = sqrt( xx * xx + yy * yy ); z[i][j] = exp( -r * r ) * cos( 2.0 * M_PI * r ); } z_row_major[i * YPTS + j] = z[i][j]; z_col_major[i + XPTS * j] = z[i][j]; } } // Allocate and calculate y index ranges and corresponding zlimited. plAlloc2dGrid( &zlimited, XPTS, YPTS ); indexymin = (PLINT *) malloc( XPTS * sizeof ( PLINT ) ); indexymax = (PLINT *) malloc( XPTS * sizeof ( PLINT ) ); if ( !indexymin || !indexymax ) plexit( "Memory allocation error" ); //printf("XPTS = %d\n", XPTS); //printf("x0 = %f\n", x0); //printf("a = %f\n", a); //printf("YPTS = %d\n", YPTS); //printf("y0 = %f\n", y0); //printf("b = %f\n", b); // These values should all be ignored because of the i index range. #if 0 for ( i = 0; i < indexxmin; i++ ) { indexymin[i] = 0; indexymax[i] = YPTS; for ( j = indexymin[i]; j < indexymax[i]; j++ ) // Mark with large value to check this is ignored. zlimited[i][j] = 1.e300; } #endif for ( i = indexxmin; i < indexxmax; i++ ) { square_root = sqrt( 1. - MIN( 1., pow( ( (PLFLT) i - x0 ) / a, 2. ) ) ); // Add 0.5 to find nearest integer and therefore preserve symmetry // with regard to lower and upper bound of y range. indexymin[i] = MAX( 0, (PLINT) ( 0.5 + y0 - b * square_root ) ); // indexymax calculated with the convention that it is 1 // greater than highest valid index. indexymax[i] = MIN( YPTS, 1 + (PLINT) ( 0.5 + y0 + b * square_root ) ); //printf("i, b*square_root, indexymin[i], YPTS - indexymax[i] = %d, %e, %d, %d\n", i, b*square_root, indexymin[i], YPTS - indexymax[i]); #if 0 // These values should all be ignored because of the j index range. for ( j = 0; j < indexymin[i]; j++ ) // Mark with large value to check this is ignored. zlimited[i][j] = 1.e300; #endif for ( j = indexymin[i]; j < indexymax[i]; j++ ) zlimited[i][j] = z[i][j]; #if 0 // These values should all be ignored because of the j index range. for ( j = indexymax[i]; j < YPTS; j++ ) // Mark with large value to check this is ignored. zlimited[i][j] = 1.e300; #endif } #if 0 // These values should all be ignored because of the i index range. for ( i = indexxmax; i < XPTS; i++ ) { indexymin[i] = 0; indexymax[i] = YPTS; for ( j = indexymin[i]; j < indexymax[i]; j++ ) // Mark with large value to check this is ignored. zlimited[i][j] = 1.e300; } #endif plMinMax2dGrid( (const PLFLT * const *) z, XPTS, YPTS, &zmax, &zmin ); step = ( zmax - zmin ) / ( nlevel + 1 ); for ( i = 0; i < nlevel; i++ ) clevel[i] = zmin + step + step * i; pllightsource( 1., 1., 1. ); for ( k = 0; k < 2; k++ ) { for ( ifshade = 0; ifshade < 5; ifshade++ ) { pladv( 0 ); plvpor( 0.0, 1.0, 0.0, 0.9 ); plwind( -1.0, 1.0, -0.9, 1.1 ); plcol0( 3 ); plmtex( "t", 1.0, 0.5, 0.5, title[k] ); plcol0( 1 ); if ( rosen ) plw3d( 1.0, 1.0, 1.0, -1.5, 1.5, -0.5, 1.5, zmin, zmax, alt[k], az[k] ); else plw3d( 1.0, 1.0, 1.0, -1.0, 1.0, -1.0, 1.0, zmin, zmax, alt[k], az[k] ); plbox3( "bnstu", "x axis", 0.0, 0, "bnstu", "y axis", 0.0, 0, "bcdmnstuv", "z axis", 0.0, 0 ); plcol0( 2 ); if ( ifshade == 0 ) // diffuse light surface plot { cmap1_init( 1 ); plfsurf3d( x, y, plf2ops_c(), (PLPointer) z, XPTS, YPTS, 0, NULL, 0 ); } else if ( ifshade == 1 ) // magnitude colored plot { cmap1_init( 0 ); plfsurf3d( x, y, plf2ops_grid_c(), ( PLPointer ) & grid_c, XPTS, YPTS, MAG_COLOR, NULL, 0 ); } else if ( ifshade == 2 ) // magnitude colored plot with faceted squares { cmap1_init( 0 ); plfsurf3d( x, y, plf2ops_grid_row_major(), ( PLPointer ) & grid_row_major, XPTS, YPTS, MAG_COLOR | FACETED, NULL, 0 ); } else if ( ifshade == 3 ) // magnitude colored plot with contours { cmap1_init( 0 ); plfsurf3d( x, y, plf2ops_grid_col_major(), ( PLPointer ) & grid_col_major, XPTS, YPTS, MAG_COLOR | SURF_CONT | BASE_CONT, clevel, nlevel ); } else // magnitude colored plot with contours and index limits. { cmap1_init( 0 ); plsurf3dl( x, y, (const PLFLT * const *) zlimited, XPTS, YPTS, MAG_COLOR | SURF_CONT | BASE_CONT, clevel, nlevel, indexxmin, indexxmax, indexymin, indexymax ); } } } // Clean up free( (void *) x ); free( (void *) y ); plFree2dGrid( z, XPTS, YPTS ); free( (void *) z_row_major ); free( (void *) z_col_major ); plFree2dGrid( zlimited, XPTS, YPTS ); free( (void *) indexymin ); free( (void *) indexymax ); plend(); exit( 0 ); }
static void ps_init(PLStream *pls) { PSDev *dev; PLFLT pxlx = YPSSIZE/LPAGE_X; PLFLT pxly = XPSSIZE/LPAGE_Y; if (text) { pls->dev_text = 1; /* want to draw text */ pls->dev_unicode = 1; /* want unicode */ if(hrshsym) pls->dev_hrshsym = 1; /* want Hershey symbols */ } pls->dev_fill0 = 1; /* Can do solid fills */ /* Initialize family file info */ plFamInit(pls); /* Prompt for a file name if not already set */ plOpenFile(pls); /* Allocate and initialize device-specific data */ if (pls->dev != NULL) free((void *) pls->dev); pls->dev = calloc(1, (size_t) sizeof(PSDev)); if (pls->dev == NULL) plexit("ps_init: Out of memory."); dev = (PSDev *) pls->dev; dev->xold = PL_UNDEFINED; dev->yold = PL_UNDEFINED; plP_setpxl(pxlx, pxly); dev->llx = XPSSIZE; dev->lly = YPSSIZE; dev->urx = 0; dev->ury = 0; dev->ptcnt = 0; /* Rotate by 90 degrees since portrait mode addressing is used */ dev->xmin = 0; dev->ymin = 0; dev->xmax = PSY; dev->ymax = PSX; dev->xlen = dev->xmax - dev->xmin; dev->ylen = dev->ymax - dev->ymin; plP_setphy(dev->xmin, dev->xmax, dev->ymin, dev->ymax); /* If portrait mode is specified, then set up an additional rotation * transformation with aspect ratio allowed to adjust via freeaspect. * Default orientation is landscape (ORIENTATION == 3 or 90 deg rotation * counter-clockwise from portrait). (Legacy PLplot used seascape * which was equivalent to ORIENTATION == 1 or 90 deg clockwise rotation * from portrait.) */ if (pls->portrait) { plsdiori((PLFLT)(4 - ORIENTATION)); pls->freeaspect = 1; } /* Header comments into PostScript file */ fprintf(OF, "%%!PS-Adobe-2.0 EPSF-2.0\n"); fprintf(OF, "%%%%BoundingBox: \n"); fprintf(OF, "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n"); fprintf(OF, "%%%%Title: PLplot Graph\n"); fprintf(OF, "%%%%Creator: PLplot Version %s\n", VERSION); fprintf(OF, "%%%%CreationDate: %s\n", ps_getdate()); fprintf(OF, "%%%%Pages: (atend)\n"); fprintf(OF, "%%%%EndComments\n\n"); /* Definitions */ /* Save VM state */ fprintf(OF, "/PSSave save def\n"); /* Define a dictionary and start using it */ fprintf(OF, "/PSDict 200 dict def\n"); fprintf(OF, "PSDict begin\n"); fprintf(OF, "/@restore /restore load def\n"); fprintf(OF, "/restore\n"); fprintf(OF, " {vmstatus pop\n"); fprintf(OF, " dup @VMused lt {pop @VMused} if\n"); fprintf(OF, " exch pop exch @restore /@VMused exch def\n"); fprintf(OF, " } def\n"); fprintf(OF, "/@pri\n"); fprintf(OF, " {\n"); fprintf(OF, " ( ) print\n"); fprintf(OF, " ( ) cvs print\n"); fprintf(OF, " } def\n"); /* n @copies - */ fprintf(OF, "/@copies\n"); fprintf(OF, " {\n"); fprintf(OF, " /#copies exch def\n"); fprintf(OF, " } def\n"); /* - @start - -- start everything */ fprintf(OF, "/@start\n"); fprintf(OF, " {\n"); fprintf(OF, " vmstatus pop /@VMused exch def pop\n"); fprintf(OF, " } def\n"); /* - @end - -- finished */ fprintf(OF, "/@end\n"); fprintf(OF, " {flush\n"); fprintf(OF, " end\n"); fprintf(OF, " PSSave restore\n"); fprintf(OF, " } def\n"); /* bop - -- begin a new page */ /* Only fill background if we are using color and if the bg isn't white */ fprintf(OF, "/bop\n"); fprintf(OF, " {\n"); fprintf(OF, " /SaveImage save def\n"); fprintf(OF, " } def\n"); /* - eop - -- end a page */ fprintf(OF, "/eop\n"); fprintf(OF, " {\n"); fprintf(OF, " showpage\n"); fprintf(OF, " SaveImage restore\n"); fprintf(OF, " } def\n"); /* Set line parameters */ fprintf(OF, "/@line\n"); fprintf(OF, " {0 setlinecap\n"); fprintf(OF, " 0 setlinejoin\n"); fprintf(OF, " 1 setmiterlimit\n"); fprintf(OF, " } def\n"); /* d @hsize - horizontal clipping dimension */ fprintf(OF, "/@hsize {/hs exch def} def\n"); fprintf(OF, "/@vsize {/vs exch def} def\n"); /* d @hoffset - shift for the plots */ fprintf(OF, "/@hoffset {/ho exch def} def\n"); fprintf(OF, "/@voffset {/vo exch def} def\n"); /* Set line width */ fprintf(OF, "/lw %d def\n", (int) ( (pls->width < MIN_WIDTH) ? DEF_WIDTH : (pls->width > MAX_WIDTH) ? MAX_WIDTH : pls->width)); /* Setup user specified offsets, scales, sizes for clipping */ fprintf(OF, "/@SetPlot\n"); fprintf(OF, " {\n"); fprintf(OF, " ho vo translate\n"); fprintf(OF, " XScale YScale scale\n"); fprintf(OF, " lw setlinewidth\n"); fprintf(OF, " } def\n"); /* Setup x & y scales */ fprintf(OF, "/XScale\n"); fprintf(OF, " {hs %d div} def\n", YPSSIZE); fprintf(OF, "/YScale\n"); fprintf(OF, " {vs %d div} def\n", XPSSIZE); /* Macro definitions of common instructions, to keep output small */ fprintf(OF, "/M {moveto} def\n"); fprintf(OF, "/D {lineto} def\n"); fprintf(OF, "/A {0.5 0 360 arc} def\n"); fprintf(OF, "/S {stroke} def\n"); fprintf(OF, "/Z {stroke newpath} def\n"); fprintf(OF, "/F {fill} def\n"); fprintf(OF, "/C {setrgbcolor} def\n"); fprintf(OF, "/G {setgray} def\n"); fprintf(OF, "/W {setlinewidth} def\n"); fprintf(OF, "/SF {selectfont} def\n"); fprintf(OF, "/R {rotate} def\n"); fprintf(OF, "/SW {stringwidth 2 index mul exch 2 index mul exch rmoveto pop} bind def\n"); fprintf(OF, "/B {Z %d %d M %d %d D %d %d D %d %d D %d %d closepath} def\n", XMIN, YMIN, XMIN, YMAX, XMAX, YMAX, XMAX, YMIN, XMIN, YMIN); fprintf(OF, "/CL {newpath M D D D closepath clip} def\n"); /* End of dictionary definition */ fprintf(OF, "end\n\n"); /* Set up the plots */ fprintf(OF, "PSDict begin\n"); fprintf(OF, "@start\n"); fprintf(OF, "%d @copies\n", COPIES); fprintf(OF, "@line\n"); fprintf(OF, "%d @hsize\n", YSIZE); fprintf(OF, "%d @vsize\n", XSIZE); fprintf(OF, "%d @hoffset\n", YOFFSET); fprintf(OF, "%d @voffset\n", XOFFSET); fprintf(OF, "@SetPlot\n\n"); }
static void exfill( void ( *fill )( PLINT, const PLFLT *, const PLFLT * ), PLINT ( *defined )( PLFLT, PLFLT ), int n, const PLFLT *x, const PLFLT *y ) { if ( n < 3 ) { plabort( "exfill: Not enough points in object" ); return; } if ( defined == NULL ) ( *fill )( n, x, y ); else { PLFLT *xx; PLFLT *yy; PLFLT xb, yb; PLINT count = 0; PLINT im1 = n - 1; PLINT is_defined = defined( x[im1], y[im1] ); PLINT i; // Slightly less than 2 n points are required for xx, yy, but // allocate room for 2 n to be safe. if ( ( xx = (PLFLT *) malloc( 2 * (size_t) n * sizeof ( PLFLT ) ) ) == NULL ) plexit( "exfill: out of memory for xx" ); if ( ( yy = (PLFLT *) malloc( 2 * (size_t) n * sizeof ( PLFLT ) ) ) == NULL ) plexit( "exfill: out of memory for yy." ); for ( i = 0; i < n; i++ ) { // is_defined tells whether im1 point was in defined region. if ( defined( x[i], y[i] ) ) { if ( !is_defined ) { // Cross from undefined (at im1) to defined region. // Bisect for the first point inside the defined region // and add it to xx, yy. bisect( defined, NUMBER_BISECTIONS, x[i], y[i], x[im1], y[im1], &xb, &yb ); xx[count] = xb; yy[count++] = yb; } // x[i], y[i] known to be in defined region so add this // point to xx, yy. xx[count] = x[i]; yy[count++] = y[i]; is_defined = 1; } else { if ( is_defined ) { // Cross from defined (at im1) to undefined region. // Bisect for the last point in the defined region and // add it to xx, yy. bisect( defined, NUMBER_BISECTIONS, x[im1], y[im1], x[i], y[i], &xb, &yb ); xx[count] = xb; yy[count++] = yb; is_defined = 0; } } im1 = i; } if ( count >= 3 ) ( *fill )( count, (const PLFLT *) xx, (const PLFLT *) yy ); free( xx ); free( yy ); } }
void plfshades( PLF2OPS zops, PLPointer zp, PLINT nx, PLINT ny, PLINT ( *defined )( PLFLT, PLFLT ), PLFLT xmin, PLFLT xmax, PLFLT ymin, PLFLT ymax, const PLFLT *clevel, PLINT nlevel, PLFLT fill_width, PLINT cont_color, PLFLT cont_width, void ( *fill )( PLINT, const PLFLT *, const PLFLT * ), PLINT rectangular, void ( *pltr )( PLFLT, PLFLT, PLFLT *, PLFLT *, PLPointer ), PLPointer pltr_data ) { PLFLT shade_min, shade_max, shade_color; PLINT i, init_color; PLFLT init_width, color_min, color_max, color_range; // Color range to use color_min = plsc->cmap1_min; color_max = plsc->cmap1_max; color_range = color_max - color_min; for ( i = 0; i < nlevel - 1; i++ ) { shade_min = clevel[i]; shade_max = clevel[i + 1]; shade_color = color_min + i / (PLFLT) ( nlevel - 2 ) * color_range; // The constants in order mean // (1) color map1, // (0, 0, 0, 0) all edge effects will be done with plcont rather // than the normal plshade drawing which gets partially blocked // when sequential shading is done as in the present case plfshade1( zops, zp, nx, ny, defined, xmin, xmax, ymin, ymax, shade_min, shade_max, 1, shade_color, fill_width, 0, 0, 0, 0, fill, rectangular, pltr, pltr_data ); } if ( cont_color > 0 && cont_width > 0 ) { init_color = plsc->icol0; init_width = plsc->width; plcol0( cont_color ); plwidth( cont_width ); if ( pltr ) { plfcont( zops->f2eval, zp, nx, ny, 1, nx, 1, ny, clevel, nlevel, pltr, pltr_data ); } else { // For this case use the same interpretation that occurs internally // for plshade. That is set up x and y grids that map from the // index ranges to xmin, xmax, ymin, ymax, and use those grids // for the plcont call. // PLcGrid cgrid1; PLFLT *x, *y; cgrid1.nx = nx; cgrid1.ny = ny; x = (PLFLT *) malloc( (size_t) nx * sizeof ( PLFLT ) ); if ( x == NULL ) plexit( "plfshades: Out of memory for x" ); cgrid1.xg = x; for ( i = 0; i < nx; i++ ) cgrid1.xg[i] = xmin + ( xmax - xmin ) * (float) i / (float) ( nx - 1 ); y = (PLFLT *) malloc( (size_t) ny * sizeof ( PLFLT ) ); if ( y == NULL ) plexit( "plfshades: Out of memory for y" ); cgrid1.yg = y; for ( i = 0; i < ny; i++ ) cgrid1.yg[i] = ymin + ( ymax - ymin ) * (float) i / (float) ( ny - 1 ); plfcont( zops->f2eval, zp, nx, ny, 1, nx, 1, ny, clevel, nlevel, pltr1, (void *) &cgrid1 ); free( x ); free( y ); } plcol0( init_color ); plwidth( init_width ); } }
static void setcmap(PLStream *pls) { int i, ncol1=pls->ncol1; int ncol0=pls->ncol0, total_colours; PLColor cmap1col; png_Dev *dev=(png_Dev *)pls->dev; PLFLT tmp_colour_pos; /* * Yuckky fix to get rid of the previosuly allocated palette from the * GD image */ if (dev->im_out != NULL) { for (i=0;i<256;i++) { gdImageColorDeallocate(dev->im_out,i); } } if (ncol0>NCOLOURS/2) /* Check for ridiculous number of colours */ { /* in ncol0, and appropriately adjust the */ plwarn("Too many colours in cmap0."); /* number, issuing a */ ncol0=NCOLOURS/2; /* warning if it does */ pls->ncol0=ncol0; } dev->totcol=0; /* Reset the number of colours counter to zero */ total_colours=ncol0+ncol1; /* Work out how many colours are wanted */ if (total_colours>NCOLOURS) /* Do some rather modest error */ { /* checking to make sure that */ total_colours=NCOLOURS; /* we are not defining more colours */ ncol1=total_colours-ncol0; /* than we have room for. */ if (ncol1<=0) { plexit("Problem setting colourmap in PNG or JPEG driver."); } } dev->ncol1=ncol1; /* The actual size of ncol1, regardless of what was asked. * This is dependent on colour slots available. * It might well be the same as ncol1. */ /* Initialize cmap 0 colors */ if ((ncol0>0)&&(dev->im_out != NULL)) /* make sure the program actually asked for cmap0 first */ { for (i = 0; i < ncol0; i++) { gdImageColorAllocate(dev->im_out, pls->cmap0[i].r, pls->cmap0[i].g, pls->cmap0[i].b); ++dev->totcol; /* count the number of colours we use as we use them */ } } /* Initialize any remaining slots for cmap1 */ if ((ncol1>0)&&(dev->im_out != NULL)) /* make sure that we want to define cmap1 first */ { for (i = 0; i < ncol1; i++) { if (ncol1<pls->ncol1) /* Check the dynamic range of colours */ { /* * Ok, now if we have less colour slots available than are being * defined by pls->ncol1, then we still want to use the full * dynamic range of cmap1 as best we can, so what we do is work * out an approximation to the index in the full dynamic range * in cases when pls->ncol1 exceeds the number of free colours. */ tmp_colour_pos= i>0 ? pls->ncol1*((PLFLT)i/ncol1) : 0; plcol_interp(pls, &cmap1col, (int) tmp_colour_pos, pls->ncol1); } else { plcol_interp(pls, &cmap1col, i, ncol1); } gdImageColorAllocate(dev->im_out, cmap1col.r, cmap1col.g, cmap1col.b); ++dev->totcol; /* count the number of colours we use as we go */ } } }
/*-------------------------------------------------------------------------- * 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; }