From b1a507a844cd6b679f9c53db49bb5817e99f1548 Mon Sep 17 00:00:00 2001 From: GillesDuvert Date: Wed, 13 Sep 2023 17:28:47 +0200 Subject: [PATCH] this commitconcerns exclusively the PostScript driver and PostScript Device It should - insure exact position and dimension of paper (plots,[0,0,1,1,0],[0,1,1,0,0],/norm) on a postscript file whatever the size ratio and landscape/portrait - a better THICKness of lines for PostScript output - no more 'stretching' of Hershey fonts and Symbols as described in commit https://github.com/gnudatalanguage/gdl/commit/d6a8e4e55fdfe5111081e715050743378b3605cf - a better default size for landscape PostScript outputs. However: the Hershey fonts and Symbols, while maintaining their shape, may differ from size depending on the paper size (should be harmless for most uses) --- src/deviceps.hpp | 60 ++++++++++++++++++++++++++----------------- src/plplotdriver/ps.c | 5 ++-- src/plplotdriver/ps.h | 2 +- 3 files changed, 40 insertions(+), 27 deletions(-) diff --git a/src/deviceps.hpp b/src/deviceps.hpp index 0ec1b5ca6..b43e4ea18 100644 --- a/src/deviceps.hpp +++ b/src/deviceps.hpp @@ -84,21 +84,6 @@ class DevicePS: public GraphicsDevice PLINT XOFF=encapsulated?0:ceil(XOffset*DPICM); PLINT YOFF=encapsulated?0:ceil(YOffset*DPICM); - // as setting the offsets and sizes with plPlot is (extremely) tricky, and some of these setting - // are hardcoded into plplot (like EPS header, and offsets in older versions of plplot) - // here we play only with the aspect ratio - - // plot orientation - //std::cout << "orientation : " << orient_portrait<< '\n'; - if (orient_portrait) { //X size will be OK, Y size must be scaled - actStream->setopt( "portrait",NULL); - actStream->sdidev( PL_NOTSET, PlplotInternalPageRatioXoverY, PL_NOTSET, PL_NOTSET ); //only OK if page ratio is 540x720 - actStream->spage(PS_DPI, PS_DPI, XSIZE, YSIZE, YOFF, XOFF); - } else { - actStream->spage(PS_DPI, PS_DPI, YSIZE, XSIZE, YOFF-XSIZE, XOFF); //invert axes, displace as does IDL.. - actStream->sdiori(2); - } - // no pause on destruction actStream->spause( false); @@ -116,6 +101,33 @@ class DevicePS: public GraphicsDevice actStream->setopt( "drvopt",what.c_str()); actStream->scolbg(255,255,255); // start with a white background + // as setting the offsets and sizes with plPlot is (extremely) tricky, and some of these setting + // are hardcoded into plplot (like EPS header, and offsets in older versions of plplot) + // here we play only with the aspect ratio, and, I must confess, this has been largely based on trial and error. + + // plot orientation + PLFLT xovery = float(XSIZE) / float(YSIZE); + //Only by using the -a option can we really fix the aspect ratio. use plsdidev (revious version) did absolutely nothing + //to keep characters etc aspect ok we need to make the 'good' size larger or smaller by truc*PlplotInternalPageRatioXoverY and displace by half this value + actStream->setopt("a", i2s(xovery).c_str()); //this will compress the X or Y axis by xovery, but does not change the position of the axis center. So some difficulty to find the good offsets as + //they depend on the axis compression, the half axis size . the following should do. + if (orient_portrait) { //X size will be OK, Y size must be scaled + actStream->setopt("portrait", NULL); + if (xovery <= PlplotInternalPageRatioXoverY) { //expand Y (will be compressed by the -a setopt) + actStream->spage(PS_DPI, PS_DPI, XSIZE, YSIZE/xovery*PlplotInternalPageRatioXoverY, YOFF -YSIZE/2/xovery*PlplotInternalPageRatioXoverY + YSIZE/2, XOFF); + } else { //expand X + actStream->spage(PS_DPI, PS_DPI, XSIZE*xovery/PlplotInternalPageRatioXoverY, YSIZE, YOFF, -XSIZE/2*xovery/PlplotInternalPageRatioXoverY + XSIZE/2 + XOFF); + } + } else { //landscape: XOFF and YOFF are X and Y but XSIZE and YSIZE are exchanged wrt previous case, and YOFF is replaced by YOFF-XSIZE. + if (xovery <= PlplotInternalPageRatioXoverY) { + actStream->spage(PS_DPI, PS_DPI, YSIZE, XSIZE/xovery*PlplotInternalPageRatioXoverY, YOFF-XSIZE -XSIZE/2/xovery*PlplotInternalPageRatioXoverY + XSIZE/2 , XOFF); + } else { + actStream->spage(PS_DPI, PS_DPI, YSIZE*xovery/PlplotInternalPageRatioXoverY, XSIZE, YOFF-XSIZE, -YSIZE/2*xovery/PlplotInternalPageRatioXoverY + YSIZE/2 + XOFF); + } + actStream->sdiori(2); + + } + actStream->Init(); // need to be called initially. permit to fix things @@ -135,7 +147,7 @@ class DevicePS: public GraphicsDevice public: DevicePS(): GraphicsDevice(), fileName( "gdl.ps"), actStream( NULL), - XPageSize(17.78), YPageSize(12.7), XOffset(1.905),YOffset(12.7), //IDL default for offests: 54 pts /X and 360 pts/Y + XPageSize(17.78), YPageSize(12.7), XOffset(1.905),YOffset(12.7), //IDL default for offsets: 54 pts /X and 360 pts/Y color(0), decomposed( 0), encapsulated(false), scale(1.), orient_portrait(true), bitsPerPix(8) { name = "PS"; @@ -263,10 +275,10 @@ class DevicePS: public GraphicsDevice // no need to update !D orient_portrait = true; // nb: IDL defaults to: -// SetXPageSize(7 * in2cm); -// SetYPageSize(5 * in2cm); -// SetXOffset(.75 * in2cm); -// SetYOffset(5 * in2cm); + SetXPageSize(7 * in2cm); + SetYPageSize(5 * in2cm); + SetXOffset(.75 * in2cm); + SetYOffset(5 * in2cm); return true; } @@ -274,10 +286,10 @@ class DevicePS: public GraphicsDevice { // no need to update !D orient_portrait = false; -// SetXPageSize(9.5 * in2cm); -// SetYPageSize(7.0 * in2cm); -// SetXOffset(.75 * in2cm); -// SetYOffset(10.25 * in2cm); + SetXPageSize(9.5 * in2cm); + SetYPageSize(7.0 * in2cm); + SetXOffset(.75 * in2cm); + SetYOffset(10.25 * in2cm); return true; } diff --git a/src/plplotdriver/ps.c b/src/plplotdriver/ps.c index cbdf0934f..cb16f1891 100644 --- a/src/plplotdriver/ps.c +++ b/src/plplotdriver/ps.c @@ -369,7 +369,7 @@ ps_init( PLStream *pls ) fprintf( OF, "/@SetPlot\n" ); fprintf( OF, " {\n" ); fprintf( OF, " ho vo translate\n" ); - fprintf( OF, " XScale YScale scale\n" ); + fprintf( OF, " XScale YScale scale \n" ); fprintf( OF, " } def\n" ); // Setup x & y scales @@ -396,7 +396,8 @@ ps_init( PLStream *pls ) fprintf( OF, "/N {newpath} def\n" ); fprintf( OF, "/C {setrgbcolor} def\n" ); fprintf( OF, "/G {setgray} def\n" ); - fprintf( OF, "/W {setlinewidth} def\n" ); +// try to make linewidth more like IDL + fprintf( OF, "/W { XScale YScale add 2 div div 2 div setlinewidth} def %% note: IDL scale is fixed to 0.028346 \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" ); diff --git a/src/plplotdriver/ps.h b/src/plplotdriver/ps.h index 6ef274b0e..2ec4bf076 100644 --- a/src/plplotdriver/ps.h +++ b/src/plplotdriver/ps.h @@ -24,7 +24,7 @@ #define OF pls->OutFile #define MIN_WIDTH 0. // Minimum pen width in default pen width (dots) #define MAX_WIDTH 50 // Maximum pen width -#define DEF_WIDTH 10. // Default pen width +#define DEF_WIDTH 1. // Default pen width // These are for covering the page with the background color