🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.postscript
Article #2786

showpage-layering (eg. print-odd-pages-only)

#2786
From: tinkelman
Date: Mon, 13 Aug 1990 18:54
167 lines
7413 bytes
A week or so ago, I responded to a comp.lang.postscript posting, saying
something like:

      ``Printing every other page of a PostScript document?  That
      shouldn't be hard.  I'll just write a showpage-replacement
      that'll eat every other page.  It should work with any (well
      almost any) PostScript file...''

(Me and my big mouth!)

So, I eventually got around to writing it.  It wasn't too hard, and it
worked on my own handwritten PostScript.  [Usual comments apply here about
debugging == `training it to work on the test data'.]  It worked on the
PostScript produced by the program (PSPRINT) we use to convert TeX DVI files
into PostScript.  It even layered on top of DEC's ScriptPrinter software,
eg. using PARAM=NUMBER_UP=2 (though the utility of this is questionable). 
So far so good.  I even mailed it out to a few people who had sent me
mail-requests.  So much for the good news.

Now for the bad news.  It worked with almost no other program-produced
PostScript that I've tried since.  I looked around our system for PostScript
files that had been produced by various packages, some of which we don't run
here.  Without exception, they have all implemented `next page' in a way
that thwarts many types of showpage-layering.  I've appended some excerpts.  

I'll also append my odd.ps file (as it's pretty short).  But beware, from my
testing it very well might not work with your PostScript.

Now my request to the net:  Am I doing something dumb?  Are the programs
that produced the attached PostScript doing something bad?  Do the Adobe
specs/guidelines cover this area explicitly enough to say?  And, if you 
do happen to try the attached every-other-page code, I would appreciate 
mail reporting the results.

Thanks.
--
Bob Tinkelman, Cambridge Computer Associates, Inc., 212-425-5830              
bob@camb.com  or ...!{uupsi,uunet}!camb.com!bob      
--------------------------------------------------------------------------------
%%%%%%%%%% The following lines excerpted from eroff output   %%%%%%%%%%
%%%%%%%%%% The sequence save-...-showpage-restore defeats    %%%%%%%%%%
%%%%%%%%%% any layered showpage which wants to retain state. %%%%%%%%%%

%%Creator: user@host with Eroff/eps release 2.2C
%[lots of stuff deleted]
%[The following is at the page break between pages 1 and 2; others are similar]
showpage
PageState8620 restore
%%PageFonts: Times-Bold Times-Roman Helvetica Symbol
%%Page: label 2
%%PageFonts: (atend)
/PageState8620 save def

%%%%%%%%%% The following lines excerpted from psprint output %%%%%%%%%%
%%%%%%%%%% The sequence showpage-save-...-restore allows a   %%%%%%%%%%
%%%%%%%%%% layering of a showpage with retained state, but   %%%%%%%%%%
%%%%%%%%%% the `initgraphics' seems scary.                   %%%%%%%%%%
/@bop1                                % begin setting DVI page n
{ pop                                 % throw away page number
  initgraphics                        % start with a clean slate
  mtrx setmatrix                      % switch to our TeX coordinate system
  /prepageVM save def                 % save state of VM at start of page
} def
/@eop                                 % end DVI page n
{ pop                                 % throw away page number
  prepageVM restore                   % restore VM to state at start of page
  showpage
} def
%[lots of stuff deleted]
@eop
2 @bop0
2 @bop1

%%%%%%%%%% The following lines excerpted from softquad troff output %%%%%%%%%%
%%%%%%%%%% The gsave-showpage-grestore is less harmful than the     %%%%%%%%%%
%%%%%%%%%% same sequence with save/restore, but it still seems to   %%%%%%%%%%
%%%%%%%%%% disallow showpage-layering to things like 2-up, where    %%%%%%%%%% 
%%%%%%%%%% you need to do things like define a new clip path...     %%%%%%%%%% 
%%Creator: SoftQuad Troff
% @(#)preamble	1.37 88/03/18 Copyright 1986, 1987, 1988 SoftQuad Inc.
%[lots of stuff deleted]
/endofpage	{
	/#copies
	exch def
	gsave showpage grestore
}def
%[lots of stuff deleted]
1791(Cambridge)s
2006(Computer)s
1 endofpage
%%PageFonts: Times-Roman
sqr
%%Page: 2 2
%%PageFonts: (atend)
sqs
2 2 1 startofpage

%%%%%%%%%% The following lines excerpted from wordperfect output. %%%%%%%%%%
%%%%%%%%%% This is a showpage-restore-save-... sequence, which    %%%%%%%%%%
%%%%%%%%%% (again) kills layered showpages which retain state.    %%%%%%%%%%
/_bp	{save 2 setmiterlimit .06 .06 scale 0 0 moveto} bdef

/_ep	{showpage restore 0 0 moveto} bdef

%[lots of stuff deleted]
_u _ep
 _bp /Times-RomanR 507 _ff
 0 13200
10200 _ornt 3954 11712 _m
 (AGREEMENT)_S 62 _rm (FOR)_S 62 _rm (SERVICES)_S 3693 11543 _m

%%%%%%%%%%%%% And finally, the following was my `odd pages' try. %%%%%%%%%%%%%
%%%%%%%%%%%%% (You need to change only one line to make even.ps) %%%%%%%%%%%%%
%---------------------------------- CUT HERE ----------------------------------
%  Odd.ps
%
%  Define a replacement showpage module which prints every other page.
%  It is written so it can be `nested' with other showpage replacements.
%
%  Revision history:
%	12-Aug-1990 Original Version: Bob Tinkelman <bob@camb.com>
%
%  Limitations:
%	Cannot be used `after' (layered on top of) other `showpage
%	replacements' which paint a background for the next page.
%	(eg DRAFT).  For cases like this, it must be used `before'.
%
%  Logic overview: On alternate invocations, it will:
%	(1) Invoke the `real' showpage 
%	(2) Erase everything written since the previous call.

/showpage 

{ 0 begin		% Use local dictionary (inserted for `0' below)

%   page_no 2 mod 0 eq	% See if even; if so, need a real showpage
    page_no 2 mod 1 eq	% See if odd;  if so, need a real showpage
    {
	page_no 0 ne {s} if	  % Do a real showpage (unless page 0)
	gsave			  % Save graphics state for grestore after
     }				  % our `client' has drawn page we'll erase
    { 
	page_no 0 ne {grestore} if% Restore saved graphics state
        c			  % Set current path to clippath
        1 currentgray sub setgray %    Reverse current gray
        fill			  %    Fill (erase) the clippath bounded region
        1 currentgray sub setgray %    Set the gray back to the way it was
     }
    ifelse
    /page_no page_no 1 add def	% Increment the page number
  end
} bind dup 0		% Stack: /showpage {...} {...} 0

% Make new showpages's local dict

4 dict dup begin		% Stack: /showpage {...} {...} 0 showpage-dict
  put				% Stack: /showpage {...}
  /page_no 0 def		% Used for even/odd check and 1st page check
  /c /clippath load def		% Get current definition of clippath
  /s /showpage load def		% Get definition of current showpage
end				% Stack: /showpage {...}

% Define the new showpage and `do page zero'

def				% Define new showpage.
showpage
%---------------------------------- CUT HERE ----------------------------------
Technical Details
Message-ID: <30532.26c6bf13@ccavax.camb.com>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uwm.edu!rpi!uupsi!ccavax!tinkelman

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uwm.edu!rpi!uupsi!ccavax!tinkelman
From: tinkelman@ccavax.camb.com
Newsgroups: comp.lang.postscript
Subject: showpage-layering (eg. print-odd-pages-only)
Summary: Problems with PostScript output by doc prep programs
Keywords: showpage,troff,word-perfect,PSPRINT,problems
Message-ID: <30532.26c6bf13@ccavax.camb.com>
Date: 13 Aug 90 18:54:10 GMT
Organization: Cambridge Computer Associates, Inc.
Lines: 167