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, char *argv[] ) { PLFLT xmin0, xmax0, ymin0, ymax0, zxmin0, zxmax0, zymin0, zymax0; PLFLT xmin, xmax, ymin, ymax, zxmin, zxmax, zymin, zymax; PLFLT xmid, ymid, wx, wy; PLFLT mar0, aspect0, jx0, jy0, ori0; PLFLT mar, aspect, jx, jy, ori; PLINT win, level2, digmax, digits, compression1, compression2; PLFLT xp0, yp0; PLINT xleng0, yleng0, xoff0, yoff0; PLFLT xp1, yp1; PLINT xleng1, yleng1, xoff1, yoff1; PLFLT xp2, yp2; PLINT xleng2, yleng2, xoff2, yoff2; PLINT fam0, num0, bmax0; PLINT fam1, num1, bmax1; PLINT fam2, num2, bmax2; PLINT r0, g0, b0; PLFLT a0; PLINT r, g, b; PLFLT a; PLINT r1[] = { 0, 255 }; PLINT g1[] = { 255, 0 }; PLINT b1[] = { 0, 0 }; PLFLT a1[] = { 1.0, 1.0 }; int status; char fnam[256]; // Parse and process command line arguments status = 0; (void) plparseopts( &argc, argv, PL_PARSE_FULL ); // Test setting / getting familying parameters before plinit // Save values set by plparseopts to be restored later. plgfam( &fam0, &num0, &bmax0 ); fam1 = 0; num1 = 10; bmax1 = 1000; plsfam( fam1, num1, bmax1 ); // Retrieve the same values? plgfam( &fam2, &num2, &bmax2 ); printf( "family parameters: fam, num, bmax = %d %d %d\n", fam2, num2, bmax2 ); if ( fam2 != fam1 || num2 != num1 || bmax2 != bmax1 ) { fputs( "plgfam test failed\n", stderr ); status = 1; } // Restore values set initially by plparseopts. plsfam( fam0, num0, bmax0 ); // Test setting / getting page parameters before plinit // Save values set by plparseopts to be restored later. plgpage( &xp0, &yp0, &xleng0, &yleng0, &xoff0, &yoff0 ); xp1 = 200.; yp1 = 200.; xleng1 = 400; yleng1 = 200; xoff1 = 10; yoff1 = 20; plspage( xp1, yp1, xleng1, yleng1, xoff1, yoff1 ); // Retrieve the same values? plgpage( &xp2, &yp2, &xleng2, &yleng2, &xoff2, &yoff2 ); printf( "page parameters: xp, yp, xleng, yleng, xoff, yoff = %f %f %d %d %d %d\n", xp2, yp2, xleng2, yleng2, xoff2, yoff2 ); if ( xp2 != xp1 || yp2 != yp1 || xleng2 != xleng1 || yleng2 != yleng1 || xoff2 != xoff1 || yoff2 != yoff1 ) { fputs( "plgpage test failed\n", stderr ); status = 1; } // Restore values set initially by plparseopts. plspage( xp0, yp0, xleng0, yleng0, xoff0, yoff0 ); // Test setting / getting compression parameter across plinit. compression1 = 95; plscompression( compression1 ); // Initialize plplot plinit(); // Test if device initialization screwed around with the preset // compression parameter. plgcompression( &compression2 ); printf( "Output various PLplot parameters\n" ); printf( "compression parameter = %d\n", compression2 ); if ( compression2 != compression1 ) { fputs( "plgcompression test failed\n", stderr ); status = 1; } // Exercise plscolor, plscol0, plscmap1, and plscmap1a to make sure // they work without any obvious error messages. plscolor( 1 ); plscol0( 1, 255, 0, 0 ); plscmap1( r1, g1, b1, 2 ); plscmap1a( r1, g1, b1, a1, 2 ); plglevel( &level2 ); printf( "level parameter = %d\n", level2 ); if ( level2 != 1 ) { fputs( "plglevel test failed.\n", stderr ); status = 1; } pladv( 0 ); xmin0 = 0.01; xmax0 = 0.99; ymin0 = 0.02; ymax0 = 0.49; plvpor( xmin0, xmax0, ymin0, ymax0 ); plgvpd( &xmin, &xmax, &ymin, &ymax ); printf( "plvpor: xmin, xmax, ymin, ymax = %f %f %f %f\n", xmin, xmax, ymin, ymax ); if ( xmin != xmin0 || xmax != xmax0 || ymin != ymin0 || ymax != ymax0 ) { fputs( "plgvpd test failed\n", stderr ); status = 1; } xmid = 0.5 * ( xmin + xmax ); ymid = 0.5 * ( ymin + ymax ); xmin0 = 0.2; xmax0 = 0.3; ymin0 = 0.4; ymax0 = 0.5; plwind( xmin0, xmax0, ymin0, ymax0 ); plgvpw( &xmin, &xmax, &ymin, &ymax ); printf( "plwind: xmin, xmax, ymin, ymax = %f %f %f %f\n", xmin, xmax, ymin, ymax ); if ( xmin != xmin0 || xmax != xmax0 || ymin != ymin0 || ymax != ymax0 ) { fputs( "plgvpw test failed\n", stderr ); status = 1; } // Get world coordinates for middle of viewport plcalc_world( xmid, ymid, &wx, &wy, &win ); printf( "world parameters: wx, wy, win = %f %f %d\n", wx, wy, win ); if ( fabs( wx - 0.5 * ( xmin + xmax ) ) > 1.0E-5 || fabs( wy - 0.5 * ( ymin + ymax ) ) > 1.0E-5 ) { fputs( "plcalc_world test failed\n", stderr ); status = 1; } // Retrieve and print the name of the output file (if any). // This goes to stderr not stdout since it will vary between tests and // we want stdout to be identical for compare test. plgfnam( fnam ); if ( fnam[0] == '\0' ) { printf( "No output file name is set\n" ); } else { printf( "Output file name read\n" ); } fprintf( stderr, "Output file name is %s\n", fnam ); // Set and get the number of digits used to display axis labels // Note digits is currently ignored in pls[xyz]ax and // therefore it does not make sense to test the returned // value plsxax( 3, 0 ); plgxax( &digmax, &digits ); printf( "x axis parameters: digmax, digits = %d %d\n", digmax, digits ); if ( digmax != 3 ) { fputs( "plgxax test failed\n", stderr ); status = 1; } plsyax( 4, 0 ); plgyax( &digmax, &digits ); printf( "y axis parameters: digmax, digits = %d %d\n", digmax, digits ); if ( digmax != 4 ) { fputs( "plgyax test failed\n", stderr ); status = 1; } plszax( 5, 0 ); plgzax( &digmax, &digits ); printf( "z axis parameters: digmax, digits = %d %d\n", digmax, digits ); if ( digmax != 5 ) { fputs( "plgzax test failed\n", stderr ); status = 1; } mar0 = 0.05; aspect0 = PL_NOTSET; jx0 = 0.1; jy0 = 0.2; plsdidev( mar0, aspect0, jx0, jy0 ); plgdidev( &mar, &aspect, &jx, &jy ); printf( "device-space window parameters: mar, aspect, jx, jy = %f %f %f %f\n", mar, aspect, jx, jy ); if ( mar != mar0 || jx != jx0 || jy != jy0 ) { fputs( "plgdidev test failed\n", stderr ); status = 1; } ori0 = 1.0; plsdiori( ori0 ); plgdiori( &ori ); printf( "ori parameter = %f\n", ori ); if ( ori != ori0 ) { fputs( "plgdiori test failed\n", stderr ); status = 1; } xmin0 = 0.1; ymin0 = 0.2; xmax0 = 0.9; ymax0 = 0.8; plsdiplt( xmin0, ymin0, xmax0, ymax0 ); plgdiplt( &xmin, &ymin, &xmax, &ymax ); printf( "plot-space window parameters: xmin, ymin, xmax, ymax = %f %f %f %f\n", xmin, ymin, xmax, ymax ); if ( xmin != xmin0 || ymin != ymin0 || xmax != xmax0 || ymax != ymax0 ) { fputs( "plgdiplt test failed\n", stderr ); status = 1; } zxmin0 = 0.1; zymin0 = 0.1; zxmax0 = 0.9; zymax0 = 0.9; plsdiplz( zxmin0, zymin0, zxmax0, zymax0 ); plgdiplt( &zxmin, &zymin, &zxmax, &zymax ); printf( "zoomed plot-space window parameters: xmin, ymin, xmax, ymax = %f %f %f %f\n", zxmin, zymin, zxmax, zymax ); if ( fabs( zxmin - ( xmin + ( xmax - xmin ) * zxmin0 ) ) > 1.0E-5 || fabs( zymin - ( ymin + ( ymax - ymin ) * zymin0 ) ) > 1.0E-5 || fabs( zxmax - ( xmin + ( xmax - xmin ) * zxmax0 ) ) > 1.0E-5 || fabs( zymax - ( ymin + ( ymax - ymin ) * zymax0 ) ) > 1.0E-5 ) { fputs( "plsdiplz test failed\n", stderr ); status = 1; } r0 = 10; g0 = 20; b0 = 30; plscolbg( r0, g0, b0 ); plgcolbg( &r, &g, &b ); printf( "background colour parameters: r, g, b = %d %d %d\n", r, g, b ); if ( r != r0 || g != g0 || b != b0 ) { fputs( "plgcolbg test failed\n", stderr ); status = 1; } r0 = 20; g0 = 30; b0 = 40; a0 = 0.5; plscolbga( r0, g0, b0, a0 ); plgcolbga( &r, &g, &b, &a ); printf( "background/transparency colour parameters: r, g, b, a = %d %d %d %f\n", r, g, b, a ); if ( r != r0 || g != g0 || b != b0 || a != a0 ) { fputs( "plgcolbga test failed\n", stderr ); status = 1; } plend(); exit( status ); }
/* * Plot specified x/y coordinates, x as int32_t and y as float, with an arbitrary number * of separate lines, as lines and/or points. * Output is PDF file, location specified by 'fileName'. */ int plplotLines( PlplotSetup *setup, uint32_t numSamples, /* size of ix[] and fy[] arrays */ uint32_t numLines, /* size of lineDef[] array */ int32_t *ix, /* numSamples */ LineDef *lineDef, /* numLines */ const char *graphName, const char *fileName, bool plotPoints, /* true: plot points */ bool plotLine, /* true: plot line */ bool skipTrailZeroes) /* don't plot zero Y values at end of graph */ { if(setup == NULL) { printf("***plplotLine: setup required\n"); return -1; } char tmpFile[TEMP_FN_LEN]; makeTempFile(tmpFile, TEMP_FN_LEN); PLFLT fx[numSamples]; PLFLT minX = setup->minX; PLFLT maxX = setup->maxX; PLFLT minY = setup->minY; PLFLT maxY = setup->maxY; for(uint32_t dex=0; dex<numSamples; dex++) { fx[dex] = ix[dex]; } const char *yName = ""; if(setup->yAxisName) { yName = setup->yAxisName; } const char *xName = ""; if(setup->xAxisName) { xName = setup->xAxisName; } plsdev ("psc"); /* standard: background white, foreground (axes, labels, etc.) black */ plscolbg(PLOT_WHITE); plscol0(1, PLOT_BLACK); plsfnam(tmpFile); plsdiori(1.0); // portrait plinit(); plenv(minX, maxX, minY, maxY, 0, 0); pllab(xName, yName, graphName); for(uint32_t dex=0; dex<numLines; dex++) { uint32_t thisSamples = numSamples; if(skipTrailZeroes) { while((lineDef[dex].fy[thisSamples-1] == 0.0) && (thisSamples > 0)) { thisSamples--; } if(thisSamples == 0) { printf("***plplotLines: Warning: line with all zeroes skipped\n"); continue; } } plotOneLine(thisSamples, fx, &lineDef[dex], plotPoints, plotLine); } plend(); int ourRtn = psToPdf(tmpFile, fileName); unlink(tmpFile); return ourRtn; }
/* * Plot a histogram of prebinned data. X values are int32_t's, and the corresponding * Y values - the counts for each X - are uint32_t's. */ int plplotBins( uint32_t numBins, const int32_t *x, /* numBins of X values, monotonically increasing */ const uint32_t *y, /* numBins of Y values for each associated X */ const char *graphName, const char *fileName, const char *xAxisName, /* optional */ const char *yAxisName) /* optional */ { char tmpFile[TEMP_FN_LEN]; makeTempFile(tmpFile, TEMP_FN_LEN); PLINT totalBins = numBins + 2; /* PLFLT array of sample values */ PLFLT *xf = (PLFLT *)malloc(totalBins * sizeof(PLFLT)); /* these two will have Y values of zero */ xf[0] = x[0] - 1; xf[totalBins - 1] = x[numBins-1] + 1; const int32_t *ip = x; PLFLT *op = xf + 1; for(uint32_t dex=0; dex<numBins; dex++) { *op++ = *ip++; } /* PLFLT array of bins */ PLFLT *yf = (PLFLT *)malloc(totalBins * sizeof(PLFLT)); yf[0] = 0.0; yf[totalBins - 1] = 0.0; const uint32_t *uip = y; op = yf + 1; for(uint32_t dex=0; dex<numBins; dex++) { *op++ = *uip++; } /* get max Y value */ uint32_t maxY = 0; uip = y; for(uint32_t dex=0; dex<numBins; dex++) { uint32_t currY = *uip++; if(currY > maxY) { maxY = currY; } } const char *yName = yAxisName ? yAxisName : ""; const char *xName = xAxisName ? xAxisName : ""; #if HIST_COLOR plsdev ("psc"); plscolbg(255, 255, 255); /* white background */ #else plsdev ("ps"); #endif plsfnam(tmpFile); plsdiori(1.0); // portrait plinit(); plenv(xf[0], xf[totalBins - 1], 0, maxY, 0, 0); #if HIST_COLOR /* can we alter colors of lines and the spaces inside the histograms? */ plscolbg(255, 0, 0); /* red background */ plscol0(1, 255, 0, 0); /* red foreground - no effect */ #endif pllab(xName, yName, graphName); plbin(totalBins, xf, yf, PL_BIN_CENTRED); plend(); free(xf); free(yf); int ourRtn = psToPdf(tmpFile, fileName); unlink(tmpFile); return ourRtn; }
/* * Plot a histogram showing the number of occurences of each possible * value of 'samples'. */ int plplotHist( const int32_t *samples, uint32_t numSamples, const char *graphName, const char *fileName, const char *xAxisName, /* optional */ const char *yAxisName) /* optional */ { char tmpFile[TEMP_FN_LEN]; makeTempFile(tmpFile, TEMP_FN_LEN); /* First determine the range, i.e. the number of bins */ int32_t minSamp = samples[0]; int32_t maxSamp = samples[0]; for(uint32_t dex=0; dex<numSamples; dex++) { int32_t s = samples[dex]; if(s < minSamp) { minSamp = s; } if(s > maxSamp) { maxSamp = s; } } /* When we specify PL_BIN_CENTRED, the min and max values are half the normal width */ minSamp--; maxSamp++; PLINT numBins = maxSamp - minSamp + 1; /* One array containing the sample values, x */ PLFLT *x = (PLFLT *)malloc(numBins * sizeof(PLFLT)); int32_t binNum = minSamp; for(uint32_t dex=0; dex<(uint32_t)numBins; dex++) { x[dex] = binNum++; } /* Now make and fill the bins proper */ PLFLT *y = (PLFLT *)malloc(numBins * sizeof(PLFLT)); for(uint32_t dex=0; dex<(uint32_t)numBins; dex++) { y[dex] = 0; } PLFLT maxY = 0.0; for(uint32_t dex=0; dex<numSamples; dex++) { int32_t s = samples[dex]; PLFLT *yp = y + s - minSamp; *yp += 1.0; if(*yp > maxY) { maxY = *yp; } } const char *yName = yAxisName ? yAxisName : ""; const char *xName = xAxisName ? xAxisName : ""; #if HIST_COLOR plsdev ("psc"); plscolor(1); plscolbg(255, 255, 255); /* white background */ #else plsdev ("ps"); #endif plsfnam(tmpFile); plsdiori(1.0); // portrait plinit(); plenv(minSamp, maxSamp, 0, maxY, 0, 0); #if HIST_COLOR /* can we alter colors of lines and the spaces inside the histograms? */ plscolbg(255, 0, 0); /* red background */ plscol0(1, 255, 0, 0); /* red foreground - no effect */ #endif pllab(xName, yName, graphName); plbin(numBins, x, y, PL_BIN_CENTRED); plend(); free(x); free(y); int ourRtn = psToPdf(tmpFile, fileName); unlink(tmpFile); return ourRtn; }
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"); }
/*-------------------------------------------------------------------------- * 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; }