Skip to content

Commit

Permalink
this commitconcerns exclusively the PostScript driver and PostScript …
Browse files Browse the repository at this point in the history
…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 d6a8e4e
 - 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)
  • Loading branch information
GillesDuvert committed Sep 13, 2023
1 parent 4957c61 commit b1a507a
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 27 deletions.
60 changes: 36 additions & 24 deletions src/deviceps.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);

Check warning on line 125 in src/deviceps.hpp

View check run for this annotation

Codecov / codecov/patch

src/deviceps.hpp#L125

Added line #L125 was not covered by tests
}
actStream->sdiori(2);

}

actStream->Init();

// need to be called initially. permit to fix things
Expand All @@ -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";
Expand Down Expand Up @@ -263,21 +275,21 @@ 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;
}

bool SetLandscape()
{
// 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;
}

Expand Down
5 changes: 3 additions & 2 deletions src/plplotdriver/ps.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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" );
Expand Down
2 changes: 1 addition & 1 deletion src/plplotdriver/ps.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit b1a507a

Please sign in to comment.