[comp.lang.postscript] mirror image

hbg6@citek.mcdphx.mot.com (04/10/91)

Please excuse me if this is a FAQ but I'm a real novice at postscript.

Is there some way to make the image on the page come out backwards, like
a mirror image? I want to print on the 'wrong' side of the transperancy
film.

I would think there is something I could insert right before the showpage
that would transform the image, or would you reverse the whole coordinate
system for the page?

I'm lost.

John

.....................................................................
Have fun, Play nice, Don't fight.                             OK Dad.
.....................................................................
John Schuch - Motorola Inc., Computer Systems Division (602)438-3008
All opinions expressed are mine and not Motorolas,        their loss.
.....................................................................

rodney@sun.ipl.rpi.edu (Rodney Peck II) (04/10/91)

In article <14828@mcdphx.phx.mcd.mot.com> hbg6@citek.mcdphx.mot.com writes:
>Please excuse me if this is a FAQ but I'm a real novice at postscript.
>
>Is there some way to make the image on the page come out backwards, like
>a mirror image? I want to print on the 'wrong' side of the transperancy
>film.
>
>I would think there is something I could insert right before the showpage
>that would transform the image, or would you reverse the whole coordinate
>system for the page?

before you start drawing, do this:

8.5 72 mul 0 translate
-1 1 scale

you should be able to edit your ps file and stick it in after the header
comments.

The effect is to multiply all the X coords by negative 1, and leave the
y coords alone, and the translate moves the origin over to the other
side of the page.  If you use some strange page size, you should use it's
width in points instead of 8.5 72 mul.

I just tested this out on the output from dvips, and it works fine.


-- 
Rodney

rberlin@birdlandEng.Sun.COM (Rich Berlin) (04/11/91)

The first thing you should try for mirror imaging is probably to see
if the printer has a "mirror" button.  It's a common option on color
printers and typesetters (on the latter, the orientations are called
Right-Reading Emulsion-Down, or RRED, and Right-Reading Emulsion-Up,
RREU).

In article <b#dg8qa@rpi.edu>, rodney@sun.ipl.rpi.edu (Rodney Peck II) writes:
|> 8.5 72 mul 0 translate
|> -1 1 scale
|> 
|>  . . .
|> 
|> If you use some strange page size, you should use it's
|> width in points instead of 8.5 72 mul.

Alert of Rodney to mention that it's size specific.  It seems that
lots of people are taught to code the page size into their documents,
but it's not necessary, and often can lead to problems when you print
on more than one type of printer.  The PostScript interpreter can
ALWAYS tell your program the size of the page.  Add the following
procedure to your bag of tricks:

/printable-area { % - => llx lly urx ury
   gsave clippath pathbbox grestore
} bind def

leaves the dimensions of the current clip area, in current user
coordinates, on the top of the stack.  (This probably qualifies for
the FAQ list.)  If it's done before anyone has done any clipping, the
current clip area = the imageable area.  (If your document has been
included in another one, the including document should have set your
clip area for you, so it's probably better that you *not* do an
initclip, though an alert program designer will overshadow initclip
when including documents, for just this reason.)

To mirror image the document, try

printable-area   % stack: llx lly urx ury
0 exch                  % llx lly urx 0 ury
translate               % llx lly urx 
pop pop pop             % -
-1 1 scale

-- Rich

rcd@ico.isc.com (Dick Dunn) (04/12/91)

rberlin@birdlandEng.Sun.COM (Rich Berlin) suggests the following, in the
course of trying to get rid of page width hard-wired into a piece of
PostScript from an earlier article:

> ...The PostScript interpreter can
> ALWAYS tell your program the size of the page.  Add the following
> procedure to your bag of tricks:
> 
> /printable-area { % - => llx lly urx ury
>    gsave clippath pathbbox grestore
> } bind def

The procedure gives just what it says--the printable area.  This is seldom
the same as the page size, because most printers have to provide a "margin"
so they won't try to dump toner off the edges of the paper.  (It also
reduces the memory for the page bitmap a little.)

A reasonable guess is that the margins on the printable area will be
symmetric, so adding llx to urx should give the page width.  (No guarantee
there, of course; it's just a good guess.  x symmetry is more likely than
y.)

Also...Rich suggests mirror-imaging as follows:
> printable-area   % stack: llx lly urx ury
> 0 exch                  % llx lly urx 0 ury
> translate               % llx lly urx 
> pop pop pop             % -
> -1 1 scale

Aside from the margin problem, this looks to me as if it translates up to
the top of the page (using 0 ury) as if to prepare for a vertical reflec-
tion, then does -1 1 scale, which is a horizontal reflection and will throw
the image off the page above and to the left.
-- 
Dick Dunn     rcd@ico.isc.com -or- ico!rcd       Boulder, CO   (303)449-2870
   ...Lately it occurs to me what a long, strange trip it's been.

rberlin@birdlandEng.Sun.COM (Rich Berlin) (04/12/91)

Errata to my previous message:

1) There's an exch that shouldn't be there.

2) I use this so habitually that I forgot you have to compensate
for the margins: (0,0) is the lower left hand corner of the PAPER,
not the printable area.

Here's the corrected code:

printable-area pop 0 translate pop neg 0 translate
-1 1 scale

The second translate moves the origin to be in the same place
relative to the printable area, so any clipping that would have
occurred will be identical.  However, if the physical page margins
aren't the same on the left and the right, the image won't show up
in quite the same place.   In the printers I've seen, this is more
likely to cause a problem if you're working in the paper-feed
direction (typically Y) than in the transverse direction.

Sorry about any inconvenience my earlier errors may have caused.
Thanks to Sean Malloy for pointing them out.

-- Rich

rberlin@birdlandEng.Sun.COM (Rich Berlin) (04/12/91)

Erratum to the errata:

|> printable-area pop 0 translate pop neg 0 translate
|> -1 1 scale

The neg shouldn't be there.  Sigh.  I shouldn't have tested it in
PageView (which has a 0 offset).   So for hopefully the last time:

printable-area pop 0 translate pop 0 translate
-1 1 scale

-- Rich

"The groom's name is Rick, not Bick."

brown@vidiot.UUCP (Vidiot) (04/12/91)

In article <14828@mcdphx.phx.mcd.mot.com> hbg6@citek.mcdphx.mot.com writes:
<Please excuse me if this is a FAQ but I'm a real novice at postscript.
<
<Is there some way to make the image on the page come out backwards, like
<a mirror image? I want to print on the 'wrong' side of the transperancy
<film.
<
<I would think there is something I could insert right before the showpage
<that would transform the image, or would you reverse the whole coordinate
<system for the page?
<
<I'm lost.

You have to look at the code very carefully.  But, if there is a spot where
there is a scale function already done, change the x or y value by putting
a `neg' after that number.  You will also have translate the coordinates
of the x or y, whichever you negated.  I suggest doing the translate before
the scale, otherwise you have to remember to use a negative of the direction
you really want to go.

Good luck.
-- 
      harvard\     att!nicmad\          spool.cs.wisc.edu!astroatc!vidiot!brown
Vidiot  ucbvax!uwvax..........!astroatc!vidiot!brown
      rutgers/  decvax!nicmad/ INTERNET:vidiot!brown%astroatc@spool.cs.wisc.edu