[GRASS-dev] d.out.file now talks to the PostScript driver

Hi,

I added PostScript support to d.out.file, and also did a bit of cleanup
in the script along the way. It seems to work very nicely.
For an example see the d.out.file help page.

Also new in d.out.file is a size=width,height option for setting
GRASS_WIDTH and GRASS_HEIGHT.

One thing that I wanted to add was EPS support. To do that I'd just
apply a little patch to the start of the output file:

-%!PS
+%!PS-Adobe-2.0 EPSF-2.0
+%%Creator: $USER
+%%CreationDate: `date`
+%%Title: $outname
+%%BoundingBox: 0 0 $GRASS_WIDTH $GRASS_HEIGHT

According to this page, EPS doesn't like the "erasepage" and "initclip"
operators, which the PS driver uses.
  http://www.postscript.org/FAQs/language/node82.html

Can this be solved with awk magic or must the file be rejigged?
It would sure be nice if the PS driver could act like the PNG driver
does for ppm files if it detects an .eps extension to GRASS_PSFILE.
I don't mind a little awk in d.out.file, but native eps support would
be much nicer for general use. I'd prefer not to have to rely on a 3rd
party dependancy (ps2epsi) for this simple task-- using GRASS_WIDTH and
GRASS_HEIGHT with GRASS_PAPER undefined gets us 95% of the way to .eps
already.

d.vect.chart updated to use D_polygon(). I notice D_polygon() leads to
round(), which rounds away from zero (ie ceil() for positive pixel
values). Would it help with exact map placement to use floor(0.5+float x),
or round(float x -0.5)? I didn't bother to update other calls to
G_plot_polygon() as they weren't relevant to the PS driver & don't seem
to have much of a future anyway.

Various driver man pages updated to mention the existance of the other
drivers.

Outstanding issues: PS driver is still missing description.html and the
HTML-map's help page + example needs updating for GRASS 6. Preferably
with a working spearfish example.

Also, FYI, d.out.png now displays a warning about impending removal.

Hamish

On Mon, May 14, 2007 at 08:09:58PM +1200, Hamish wrote:

Hi,

I added PostScript support to d.out.file, and also did a bit of cleanup
in the script along the way. It seems to work very nicely.
For an example see the d.out.file help page.

Molto bello!

Small observation: the barscale font color is grey in the resulting
PS file while black in PNG (at least for my eyes).

Markus

Hamish wrote:

I added PostScript support to d.out.file, and also did a bit of cleanup
in the script along the way. It seems to work very nicely.
For an example see the d.out.file help page.

Also new in d.out.file is a size=width,height option for setting
GRASS_WIDTH and GRASS_HEIGHT.

One thing that I wanted to add was EPS support. To do that I'd just
apply a little patch to the start of the output file:

-%!PS
+%!PS-Adobe-2.0 EPSF-2.0
+%%Creator: $USER
+%%CreationDate: `date`
+%%Title: $outname
+%%BoundingBox: 0 0 $GRASS_WIDTH $GRASS_HEIGHT

According to this page, EPS doesn't like the "erasepage" and "initclip"
operators, which the PS driver uses.
  http://www.postscript.org/FAQs/language/node82.html

Can this be solved with awk magic or must the file be rejigged?

Ultimately, the display architecture must be re-jigged; the existing
API wasn't designed for encapsulation.

Both of these issues correspond to features in the graphics API which
are fundamentally incompatible with encapsulation.

To eliminate the specific features in question, it would be necessary
to make a couple of changes.

1. R_erase() would need to erase the current frame, rather than the
entire screen.

XDRIVER already behaves this way (the default erase implementation
fills a screen-sized rectangle with the current colour, which will
honour the current clip rectangle), but the PNG driver doesn't (it
provides its own implementation which erases the entire screen to
either transparent or the background colour).

[The XDRIVER behaviour is an artifact of having made the clip
rectangle apply to all rendering operations; I've only just noticed
that it also affects the erase operation. This doesn't actually matter
at present, as the only code which uses R_erase() also removes any
frames first, so the clip rectangle will always be the entire screen.]

But, the existing erase implementation is intentional. It is meant to
be a "reset" operation. The main reason why I implemented a specific
erase operation in the PS driver (rather than using the default "fill
a screen-sized rectangle) is so that it could be replaced with e.g.
"showpage" for generating multi-page PostScript output.

If you want EPS, you probably shouldn't be using the erase operation
anyhow.

R_erase() is currently used by "d.frame -e", d.profile, and
D_full_screen(). D_full_screen() is used by "d.erase -f", "d.frame -e"
and the "usual suspects" of i.class, i.ortho.photo, i.points and
i.vpoints.

If you think about it, these are all cases which violate the principle
of encapsulation. Rather than their output being encapsulated within
the existing context (i.e. the current frame), they override it and
assert global control.

That only leaves the PS_Erase() at initialisation, which is
unnecessary (essentially, that part of the PNG driver was carried over
without noticing that it's unnecessary; PostScript always starts with
a clean page).

2. R_set_window() would need a matching "unset window" operation.

In practice, this means that calls to the display functions which
select specific frames would need matching calls to unset those
frames.

The reason is that, once you set a clip path in PostScript, any
subsequent clip path is cumulative, i.e. the new clip path is itself
clipped to the current clip path, so the resulting clip path is the
intersection of the two.

The only way to remove an existing clip path is either initclip (which
is incompatible with encapsulation, because it will also remove any
clip path set outside the encapsulated object) or to use grestore to
revert the graphics state to the point prior to the clip path having
been set.

But gsave/grestore have to be matched. This means that you need an API
which, rather than setting global state "from now on", sets it until a
matching "end" operation occurs. And the begin/end operations have to
nest correctly.

IOW, you can't just call D_set_cur_wind() etc and forget about it; you
would have to explicitly revert to the previous window when you're
done with it.

For now, the only practical solution is to provide a way to avoid the
initclip in the WINDOW operation. That will have the side-effect that
programs which create their own frames will be largely incompatible
with EPS output. Once a frame has been created, it will cease to be
possible to draw anything outside of that frame.

It would sure be nice if the PS driver could act like the PNG driver
does for ppm files if it detects an .eps extension to GRASS_PSFILE.
I don't mind a little awk in d.out.file, but native eps support would
be much nicer for general use. I'd prefer not to have to rely on a 3rd
party dependancy (ps2epsi) for this simple task-- using GRASS_WIDTH and
GRASS_HEIGHT with GRASS_PAPER undefined gets us 95% of the way to .eps
already.

Changing details of the output format depending upon the $GRASS_PSFILE
extension is simple enough. What I can't do in the PS driver is to
change the way that d.* commands use the R_* API. That can only be
done by changing the d.* commands themselves.

d.vect.chart updated to use D_polygon(). I notice D_polygon() leads to
round(), which rounds away from zero (ie ceil() for positive pixel
values). Would it help with exact map placement to use floor(0.5+float x),
or round(float x -0.5)? I didn't bother to update other calls to
G_plot_polygon() as they weren't relevant to the PS driver & don't seem
to have much of a future anyway.

round() rounds to the nearest integer:

  #define round(x) ((int) floor(0.5 + (x)))

Once 7.x is started, the first change to the R_* API will be to
replace integer coordinates with floats, so this will no longer be an
issue.

--
Glynn Clements <glynn@gclements.plus.com>

Markus Neteler wrote:

> I added PostScript support to d.out.file, and also did a bit of cleanup
> in the script along the way. It seems to work very nicely.
> For an example see the d.out.file help page.

Small observation: the barscale font color is grey in the resulting
PS file while black in PNG (at least for my eyes).

If you're using GV, try turning of anti-aliasing.

--
Glynn Clements <glynn@gclements.plus.com>

Hamish wrote:

I added PostScript support to d.out.file, and also did a bit of cleanup
in the script along the way. It seems to work very nicely.
For an example see the d.out.file help page.

Also new in d.out.file is a size=width,height option for setting
GRASS_WIDTH and GRASS_HEIGHT.

One thing that I wanted to add was EPS support. To do that I'd just
apply a little patch to the start of the output file:

-%!PS
+%!PS-Adobe-2.0 EPSF-2.0
+%%Creator: $USER
+%%CreationDate: `date`
+%%Title: $outname
+%%BoundingBox: 0 0 $GRASS_WIDTH $GRASS_HEIGHT

According to this page, EPS doesn't like the "erasepage" and "initclip"
operators, which the PS driver uses.
  http://www.postscript.org/FAQs/language/node82.html

FWIW, I've added some enhancements to the PS driver:

1. DSC comments are added.

2. If the output file ends in ".eps", the problematic operators will
not be used, and "EPSF-3.0" will be added to the %!PS- line.

One problem with the DSC comments is that the driver cannot determine
the language level at the point that the header is written, so it
always reports level 3.

Printers don't read DSC comments, so this shouldn't have any effect
upon printers which don't support level 3.

--
Glynn Clements <glynn@gclements.plus.com>

Hamish:

> > I added PostScript support to d.out.file, and also did a bit of
> > cleanup in the script along the way. It seems to work very nicely.
> > For an example see the d.out.file help page.

[I've now added support for .eps too, thanks Glynn!]

Markus:

> Small observation: the barscale font color is grey in the resulting
> PS file while black in PNG (at least for my eyes).

Glynn:

If you're using GV, try turning of anti-aliasing.

See attached. Turning off anti-aliasing doesn't help. I guess it happens
as the default line width is 0 not 1? Adding D_line_width(1) to the
start of d.barscale/draw_scale.c makes everything a bit thicker
(probably too thick, although the "N" and stroke text is nicer), but it
doesn't solve the jagged bits where the lines meet the black rectangles.

From memory d.barscale has a bad mix of float->int rounding throughout.

Glynn:

For now, the only practical solution is to provide a way to avoid the
initclip in the WINDOW operation. That will have the side-effect that
programs which create their own frames will be largely incompatible
with EPS output. Once a frame has been created, it will cease to be
possible to draw anything outside of that frame.

We can note this in the PS driver help page, and suggest .ps + ps2epsi
for those cases.

Changing details of the output format depending upon the $GRASS_PSFILE
extension is simple enough. What I can't do in the PS driver is to
change the way that d.* commands use the R_* API. That can only be
done by changing the d.* commands themselves.

Suggested "best practice" text for the Programmer's Manual wrt the R_*
API?

"IOW, you can't just call D_set_cur_wind() etc and forget about it; you
would have to explicitly revert to the previous window when you're
done with it."

FWIW, I count 22 d.* relevant modules that do original drawing:

d.barscale
d.correlate
d.frame
d.geodesic
d.graph
d.grid
d.his
d.histogram
d.labels
d.legend
d.linegraph
d.path
d.polar
d.rast
d.rast.arrow
d.rast.num
d.rgb
d.rhumbline
d.text
d.title
d.vect
d.vect.chart

round() rounds to the nearest integer:

sorry, I misread the man page, focusing on what happened in a tie.

Glynn:

FWIW, I've added some enhancements to the PS driver:

1. DSC comments are added.

.ps format now includes "%%BoundingBox: 36 72 559 769" (GRASS_PAPER=A4)
which crops off the margins. Usually I'd expect the BBox to be the full
A4 range. Is this intentional?

.eps format needs the last two BBox numbers swapped to render correctly
in gv if GRASS_LANDSCAPE=TRUE. (if landscape is even meaningful for .eps)
%%BoundingBox: 0 0 469 675
Landscape .ps is fine already.

2. If the output file ends in ".eps", the problematic operators will
not be used, and "EPSF-3.0" will be added to the %!PS- line.

One problem with the DSC comments is that the driver cannot determine
the language level at the point that the header is written, so it
always reports level 3.

Printers don't read DSC comments, so this shouldn't have any effect
upon printers which don't support level 3.

I added a ps_level= option to d.out.file to set/unset GRASS_TRUECOLOR.
We could use sed to force that into the output file header, but I think
it would be badly misleading.

Hamish

(attachments)

barscale_eps.jpg

Hi Hamish

d.out.file is a very very useful script because it prints at high resolution…
but I have a problem: now I can only work via terminal. Example:

g.region rast=slope -p
d.mon gism
d.rast slope
d.vect streams type=area,line
d.barscale at=0,94.5
d.out.file spearfish_pic format=png size=800,600
d.out.file spearfish_pic format=ps -r paper=a4

I have my ps file or png.
I have not use x0 terminal. I use new GIS Manager (in GRASS OS X - no X11) and if I enter:

% d.mon -L

I have:

HTMLMAP Create HTML Image Map not running

PS Create PS Map not running

ps1 Create PS Map not running

ps2 Create PS Map not running

ps3 Create PS Map not running

ps4 Create PS Map not running

ps5 Create PS Map not running

ps6 Create PS Map not running

ps7 Create PS Map not running

PNG Create PNG Map not running

png1 Create PNG Map not running

png2 Create PNG Map not running

png3 Create PNG Map not running

png4 Create PNG Map not running

png5 Create PNG Map not running

png6 Create PNG Map not running

png7 Create PNG Map not running

gism Create PNG Map for gis.m not running

My GIS Manager works very well but it has not a selected monitor.

d.out.file has a GUI but how it can view all layers inside GIS Manager?

Thanks in advance


|| Lorenzo Moretti e-mail: lorenzo.moretti@bologna.enea.it
||/|/| ENEA ACS PROTIDR Web: http://wwwamb.bologna.enea.it/
|| | via Don Fiammelli, 2 FTP: ftp://ftpamb.bologna.enea.it/ (ris.)

ENEA - Ente Nazionale per le Nuove Tecnologie, l'Energia e l'Ambiente
ENEA - The Italian Agency for New Technologies, Energy and the Environment
__________________________________________________________________________

Lorenzo,

Probably a longer answer than you need, but it might be helpful to address the larger issue of the appearance of GRASS screen output.

I originally wrote d.out.file, the successor to d.out.png (my first GRASS script written to solve the complete lack of screen->to graphic file output in version 5). It will only work with the xmon screen displays because it uses d.save to capture all xdriver commands used to create the screen, and then plays them back with the output set to PNG (or PS with Hamish’s update). The display in the TclTk and wxPython GUI is generated by sending all d.* commands directly to the PNG driver. So d.save never captures these display commands. For this reason, d.out.file will not work with the GUI.

The GUI does save the screen to various formats, including EPS.

The high resolution in d.out.file is a bit of a problem. It achieves this by setting the size of the output graphic to some multiple of its current width and height in pixels before rendering to the PNG driver. This can put more pixels into the output graphic file. However, it also causes problems with vectors (lines get increasingly thin with increased resolution), scales (the scales get shorter vertically and type gets smaller), and possible some other features.

Explore mode in the TclTk GUI and normal mode in the wxgrass GUI no longer tie the number of pixels in the display to the resolution of the raster. So you get a nicer output image from the screen without the distortions introduced by the method used in d.out.file. Text is rendering a lot nicer too because native GUI text can be used for manually placed text objects and there is much better rendering of TrueType fonts in any text output from the PNG driver now. Vectors can still look pixelated, however, until we have a different method of rendering them.

There is ongoing discussion of making a better interface to ps.map to produce nicer output too.

Michael

On 5/15/07 8:23 AM, “Lorenzo Moretti” lorenzo.moretti@bologna.enea.it wrote:

Hi Hamish

d.out.file is a very very useful script because it prints at high resolution…
but I have a problem: now I can only work via terminal. Example:

g.region rast=slope -p
d.mon gism
d.rast slope
d.vect streams type=area,line
d.barscale at=0,94.5
d.out.file spearfish_pic format=png size=800,600
d.out.file spearfish_pic format=ps -r paper=a4

I have my ps file or png.
I have not use x0 terminal. I use new GIS Manager (in GRASS OS X - no X11) and if I enter:

% d.mon -L

I have:

HTMLMAP Create HTML Image Map not running
PS Create PS Map not running
ps1 Create PS Map not running
ps2 Create PS Map not running
ps3 Create PS Map not running
ps4 Create PS Map not running
ps5 Create PS Map not running
ps6 Create PS Map not running
ps7 Create PS Map not running
PNG Create PNG Map not running
png1 Create PNG Map not running
png2 Create PNG Map not running
png3 Create PNG Map not running
png4 Create PNG Map not running
png5 Create PNG Map not running
png6 Create PNG Map not running
png7 Create PNG Map not running
gism Create PNG Map for gis.m not running

My GIS Manager works very well but it has not a selected monitor.

d.out.file has a GUI but how it can view all layers inside GIS Manager?

Thanks in advance


Michael Barton, Professor of Anthropology
School of Human Evolution & Social Change
Center for Social Dynamics & Complexity
Arizona State University

phone: 480-965-6213
fax: 480-965-7671
www: http://www.public.asu.edu/~cmbarton

Hamish wrote:

> > Small observation: the barscale font color is grey in the resulting
> > PS file while black in PNG (at least for my eyes).
Glynn:
> If you're using GV, try turning of anti-aliasing.

See attached. Turning off anti-aliasing doesn't help.

What am I supposed to be looking at? I don't see any grey text in that
image.

> Changing details of the output format depending upon the $GRASS_PSFILE
> extension is simple enough. What I can't do in the PS driver is to
> change the way that d.* commands use the R_* API. That can only be
> done by changing the d.* commands themselves.

Suggested "best practice" text for the Programmer's Manual wrt the R_*
API?

Avoid using frames or erasing the screen unless you are writing
d.frame or d.erase :wink:

Anything beyond that needs API changes, which I'd rather deal with as
a whole than through piecemeal fixes.

The API should have a generalised encapsulation (save/restore)
mechanism. Not just for frames, but for all state, e.g. line width,
font, text size, text rotation, etc.

"IOW, you can't just call D_set_cur_wind() etc and forget about it; you
would have to explicitly revert to the previous window when you're
done with it."

FWIW, I count 22 d.* relevant modules that do original drawing:

"original drawing"?

> FWIW, I've added some enhancements to the PS driver:
>
> 1. DSC comments are added.

.ps format now includes "%%BoundingBox: 36 72 559 769" (GRASS_PAPER=A4)
which crops off the margins. Usually I'd expect the BBox to be the full
A4 range. Is this intentional?

BoundingBox refers to the actual graphics:

  This comment specifies the bounding box that encloses all
  marks painted on all pages of a document. That is, it must be
  a "high water mark" in all directions for marks made on any
  page.

.eps format needs the last two BBox numbers swapped to render correctly
in gv if GRASS_LANDSCAPE=TRUE. (if landscape is even meaningful for .eps)
%%BoundingBox: 0 0 469 675
Landscape .ps is fine already.

So GV interprets it differently depending upon whether the file is PS
or EPS? (is it using the extension or the EPSF-3.0 in the header?)

Does the %%Orientation setting affect it? How about the relative sizes
of the width and height?

The DSC manual is unclear as to how %%BoundingBox and %%Orientation
interact. I think that the existing behaviour was necessary to get .ps
to work correctly; getting this to work correctly with .ps files took
several attempts.

I'll look into it some more as I get time.

> 2. If the output file ends in ".eps", the problematic operators will
> not be used, and "EPSF-3.0" will be added to the %!PS- line.
>
> One problem with the DSC comments is that the driver cannot determine
> the language level at the point that the header is written, so it
> always reports level 3.
>
> Printers don't read DSC comments, so this shouldn't have any effect
> upon printers which don't support level 3.

I added a ps_level= option to d.out.file to set/unset GRASS_TRUECOLOR.
We could use sed to force that into the output file header, but I think
it would be badly misleading.

GRASS_TRUECOLOR requires either level 2 or level 1 plus the colorimage
and setrgbcolor operators (this is the case for colour printers which
pre-date level 2 PostScript).

Only masked images (d.rast -o, d.rgb -o, d.his -n) require level 3.

--
Glynn Clements <glynn@gclements.plus.com>

Michael Barton wrote:

The display in the TclTk and wxPython GUI is generated by sending
all d.* commands directly to the PNG driver. So d.save never captures
these display commands. For this reason, d.out.file will not work with
the GUI.

I have now added a test in d.out.file to make sure that the current
monitor is an xmon. (and a warning if attempting EPS + d.frame)

Theoretically it may be possible to do PNG->HTMLmap driver with d.save,
but I have no idea so leave that for someone to try by hand if they want
it.

The high resolution in d.out.file is a bit of a problem. It achieves
this by setting the size of the output graphic to some multiple of its
current width and height in pixels before rendering to the PNG driver.
This can put more pixels into the output graphic file. However, it
also causes problems with vectors (lines get increasingly thin with
increased resolution), scales (the scales get shorter vertically and
type gets smaller), and possible some other features.

notes:
* but the horizontal scale length information should remain correct.
* things like "d.text size=" and d.legend will scale font size as a
percentage of the frame size, so they'll be ok. Things that force a
font size of "10" won't be.
* you can partially work around the thin-line problem with 'd.vect
width='
that won't help d.grid though where both fonts and lines will be shrunk.
* The PS driver doesn't suffer from this, only the PNG driver.

I figured out my d.out.file d.font problem. I was calling it before
d.frame.quarter, which erases the display including the font setting.

d.font Vera
d.erase -f
echo "A" | d.text color=black size=40 at=50,50
# draws in TTF
d.out.file A
# draws using default scale font

d.erase -f
d.font Vera
echo "A" | d.text color=black size=40 at=50,50
# draws using TTF
d.out.file A --overwrite
# draws using TTF

So d.erase removes the explicit "d.font" call, and the XDRIVER has
sticky memory about what the font setting is. But the other drivers
don't. And that's understandable once you think about it- the other
drivers you refresh by stop= and start=, while the xmon driver remains
open and in whatever state you left it in.
aka "d.erase" != "d.mon stop="

TTF output from the PNG driver is Very Nice (same as in GUI) -- much
better than in the xmon display window. TTF output in the PS driver is
very unnice -- it comes out horribly pixelated. Stroke fonts with the PS
driver generally look ok, especially if you use "d.text -b".

In other news I just added a new brighten= option to d.his.
(for the new d.out.file 4-pane example)

Hamish

Lorenzo:

> My GIS Manager works very well but it has not a selected monitor.
>
> d.out.file has a GUI but how it can view all layers inside GIS
> Manager?

I got off on a tangent and never answered your question-

For GUI export use the 3.5" floppy disk button in the "Map Display 1"
window toolbar.

Hamish

Glynn Clements wrote:

Hamish wrote:

> > > Small observation: the barscale font color is grey in the
> > > resulting PS file while black in PNG (at least for my eyes).
> Glynn:
> > If you're using GV, try turning of anti-aliasing.
>
> See attached. Turning off anti-aliasing doesn't help.

What am I supposed to be looking at? I don't see any grey text in that
image.

I moved on.. not grey text but jagged lower edge of the barscale box.

Avoid using frames or erasing the screen unless you are writing
d.frame or d.erase :wink:

Anything beyond that needs API changes, which I'd rather deal with as
a whole than through piecemeal fixes.

The API should have a generalised encapsulation (save/restore)
mechanism. Not just for frames, but for all state, e.g. line width,
font, text size, text rotation, etc.

for now I have added a warning in d.out.file that PS driver + d.frame
will not work as the user might expect, and to use ps2epsi for that.

> FWIW, I count 22 d.* relevant modules that do original drawing:

"original drawing"?

I meant not modules like d.rast.leg and d.vect.thematic that just call
other d.* modules.

> .eps format needs the last two BBox numbers swapped to render
> correctly in gv if GRASS_LANDSCAPE=TRUE. (if landscape is even
> meaningful for .eps) %%BoundingBox: 0 0 469 675
> Landscape .ps is fine already.

So GV interprets it differently depending upon whether the file is PS
or EPS? (is it using the extension or the EPSF-3.0 in the header?)

Does the %%Orientation setting affect it?

I am working d.out.file example 1 here. Inserting as a figure in LyX for
a more real-world test. (I can live with GV not being 100% if it prints ok)

.ps displays as expected in GV, both G_LANDS= Portr & Landsc.

.eps G_LANDS=FALSE (Portrait) displays as expected in GV

.eps G_LANDS=TRUE is the funny one.

> (if landscape is even meaningful for .eps)

- GV orientation box says Landscape
- GV canvas is 640 Tall by 480 wide
- GV map is 480 tall and falls off the right edge
* Same brokeness in LyX display, seen in full in PS output but the top
   figure caption falls off of top of output PS page (rot 90 CCW)
- if I change orientaion in the GV top menu to Portrait,
    canvas is 480 Tall by 640 wide but map is rot 90 CCW and falls
    off top

- if I edit the .eps file to switch the last 2 nums in %%BBox, GV
    displays as expected (640x480, orientation menu says Landscape)
* edited version is rot 90 CCW in LyX but all there. Top figure
    caption obeys expected page margins.
    (rot 90 ccw is ok as LyX allows figure rotation)

- if I edit the .eps file keeping BBox as created but changing %%Ori,
   GV canvas is 480 Tall by 640 wide but map is rot 90 CCW and falls
   off top
* Same brokeness in LyX display, seen in full in PS output but the top
   figure caption falls off of top of output PS page (rot 90 CCW)

So AFAICT, %%Ori is used independently of {%%BBox and the following}:
%%BeginSetup
0 0 translate
-0 480 translate 1 -1 scale
+90 rotate 0 1 -1 scale
640 480 BEGIN
%%EndSetup

ie %%BBox and the above exist in the same plane, %%Ori rotates that plane.
??

How about the relative sizes of the width and height?

not tested.

The DSC manual is unclear as to how %%BoundingBox and %%Orientation
interact. I think that the existing behaviour was necessary to get .ps
to work correctly; getting this to work correctly with .ps files took
several attempts.

For sure .eps in landscape mode is the lowest priority and everything
else seems to work properly.

I'll look into it some more as I get time.

thanks.

> > 2. If the output file ends in ".eps", the problematic operators
> > will not be used, and "EPSF-3.0" will be added to the %!PS- line.
> >
> > One problem with the DSC comments is that the driver cannot
> > determine the language level at the point that the header is
> > written, so it always reports level 3.
> >
> > Printers don't read DSC comments, so this shouldn't have any
> > effect upon printers which don't support level 3.
>
> I added a ps_level= option to d.out.file to set/unset
> GRASS_TRUECOLOR. We could use sed to force that into the output file
> header, but I think it would be badly misleading.

GRASS_TRUECOLOR requires either level 2 or level 1 plus the colorimage
and setrgbcolor operators (this is the case for colour printers which
pre-date level 2 PostScript).

Only masked images (d.rast -o, d.rgb -o, d.his -n) require level 3.

I have left ps_level= setting GRASS_TRUECOLOR (and nothing else), not sure
what else to do with it. (could grep for those three MASK calls and print
a warning or something if level<3)

Hamish

Glynn Clements wrote:

> .eps format needs the last two BBox numbers swapped to render correctly
> in gv if GRASS_LANDSCAPE=TRUE. (if landscape is even meaningful for .eps)
> %%BoundingBox: 0 0 469 675
> Landscape .ps is fine already.

So GV interprets it differently depending upon whether the file is PS
or EPS? (is it using the extension or the EPSF-3.0 in the header?)

Does the %%Orientation setting affect it? How about the relative sizes
of the width and height?

I'll look into it some more as I get time.

Done that; conclusions:

1. Neither the extension nor the header have any effect. EPS is
treated identically to PS.

2. GV interprets "%%Orientation: Landscape" as "rotate the plot" and
"%%Orientation: Portrait" as "don't rotate". The shape of the bounding
box doesn't have any effect.

3. The bounding box was computed incorrectly if GRASS_{WIDTH,HEIGHT}
were used instead of a paper size.

AFAICT, all combinations now work correctly. Things to bear in mind:

1. The bounding box corresponds to the "screen" area. This may be
larger than the area where rendering occurs, e.g. if you have a region
with width>height but a screen with height>width, you will get blank
regions above and below.

2. GRASS_{WIDTH,HEIGHT} refer to the screen dimensions seen by d.*
commands. If you use GRASS_LANDSCAPE=TRUE, the default 640x480 screen
results in a plot 480pt wide and 640pt high on the page.

3. GRASS_LANDSCAPE=TRUE causes the plot to be rotated so that a
"landscape" plot (width>height) fills more of a page (the known paper
sizes all have portrait orientation, i.e. height>width).

If you want a single plot to fill a sheet of paper, you will want
typically want GRASS_LANDSCAPE=TRUE for "landscape" regions
(width>height). If you're creating output for rendering to an image or
embedding within a document, you should probably leave
GRASS_LANDSCAPE=FALSE (or unset) and just set GRASS_{WIDTH,HEIGHT}
appropriately.

--
Glynn Clements <glynn@gclements.plus.com>

Glynn Clements wrote:

> .ps format now includes "%%BoundingBox: 36 72 559 769"
> (GRASS_PAPER=A4) which crops off the margins. Usually I'd expect the
> BBox to be the full A4 range. Is this intentional?

BoundingBox refers to the actual graphics:

  This comment specifies the bounding box that encloses all
  marks painted on all pages of a document. That is, it must be
  a "high water mark" in all directions for marks made on any
  page.

FWIW ps2epsi interprets this differently.
Given a .ps file made with the GRASS PS driver it will produce an
EPS file which has a bounding box of the full A4, "0 0 595 842".

Something else, not a big deal for printed material, but is for on-
screen reading:

ps2pdf13 of the .ps output doesn't respect PS driver DSC Landscape
hinting, the page is rot90ccw in Acroread (but intact).

In the past Acroread has correctly rotated ps.map -r landscape pages
to on-screen landscape mode using the same ps2pdf (regular "paper a4")
But then the orig ps.map output looks sideways in GV (reports Portrait
(no Ori DSC)). BBox is "0 0 595 841" for both rotated and non-rotated,
but somehow Acroread knows. Maybe Acroread rotates based on the best
text-up orientation?? (and the PS driver doesn't create text objects)

shrug. I guess the best we can do is go by the book and hope that other
softwares will do the same.

*** hey- #$%#!#@!! ps.map -r rotate flag is broken if you specify a
paper size! Without the "paper" instruction it works ok.

No wonder I couldn't understand why Markus needed to add a4-landscape
as a paper size.

If you don't use the "paper" instruction it defaults to a4 dimensions
and correctly rotates the map 90deg! If you specify the paper size it
does the rotation again, leaving you with the original page, but
sideways (still portrait but "up" is now to the left). argh.

"ps.map -r" to just rotate the page intact would be a pretty lame
option!

Fixed in 6.3cvs and backported to the 6.2 branch. I've removed the new
a4-landscape & a3-l paper sizes as they were only needed to work around
this bug. Added a note to the man page to lessen confusion in future.

Annoyed that I didn't notice this with ps.map/r_paper.c rev 1.3.

Hamish

Hamish wrote:

> > .ps format now includes "%%BoundingBox: 36 72 559 769"
> > (GRASS_PAPER=A4) which crops off the margins. Usually I'd expect the
> > BBox to be the full A4 range. Is this intentional?
>
> BoundingBox refers to the actual graphics:
>
> This comment specifies the bounding box that encloses all
> marks painted on all pages of a document. That is, it must be
> a "high water mark" in all directions for marks made on any
> page.

FWIW ps2epsi interprets this differently.
Given a .ps file made with the GRASS PS driver it will produce an
EPS file which has a bounding box of the full A4, "0 0 595 842".

If you use GRASS_PAPER=A4, that's correct.

Note that all frames (even the full_screen frame) always have a border
drawn, so the bounding box will always encompass the entire "screen",
even if you only use a portion of it.

--
Glynn Clements <glynn@gclements.plus.com>