Previewing PostScript files, or dvi files.

Chris Torek chris at mimsy.UUCP
Thu Sep 28 03:44:48 AEST 1989


In article <2748 at decuac.DEC.COM> avolio at decuac.dec.com (Frederick M. Avolio)
writes:
>1. I believe that there is a bug in the dxpsview program, but I encourage 
>you to submit an SPR even though I have.  The more the merrier :-).  I see
>the same problem though.  If you edit the ps file and remove the letter
>command it ends up working fine.  I believe that anything that a PS
>printer can support, the previewer should.

This is not really a bug (although dxpsview would be perfectly justified
to accept and ignore `letter', `note', and `legal' commands---incidentally,
you can do this yourself on other printers, if necessary, by using

	<password-here> serverdict begin exitserver
	systemdict begin /letter {} def /note {} def /legal {} def end

which defines letter, note, and legal as empty (no-op) functions in
the system dictionary).  As it turns out, it is instead (or in addition,
if you want to argue that dxpsview should make letter a no-op) a bug
that the PostScript generator is emitting the `letter' call.  This
is an Apple LaserWriter specific function, as you can see by its
place in the PostScript `Red Book'% (Appendix D, I think).

I faced a similar problem with backwards compatibility for the MC-TeX
postscript program, and ended up using the following (warning, this is
only partially tested as yet):

% `Canclobber' controls whether the page selection operators are used.
% On many printers, these clear the frame buffer and set up the graphics
% state.  On others, they may do something different.  In any case, it
% is fairly likely you will not want them here.  The previous system used
% them, though, and you may want them to work as before.
%/canclobber true def % allow paper-mode commands
/canclobber false def % disallow paper-mode commands

% Set default resolution.  We always reset it later, but just in case....
/Resolution 300 def % pixels per inch

% There are three transform matrices carried about:
%
% - DefaultMatrix holds the usual device matrix.
% - SpecialMatrix holds an `extra' transform to be applied to specials.
% - Mtrx holds a matrix used to obtain TeX coordinate space.
%
% The normal (non-landscape) TeX coordinate system has (0,0) at the
% top left corner of the page, and x and y values become more positive
% as one moves rightwards and down respectively.  The landscaped system
% has (0,0) at the lower left corner of the page, and positive x and y
% are upwards and rightwards respectively.  All values are in pixels
% (from the device resolution in Resolution).
%
% Thus, the TeX transform would normally be either [1 0 0 1 0 0]
% (standard pages) or [0 -1 1 0 0 paperheight] (landscaped), but alas,
% things are not quite so simple.  For instance, the LaserWriter that
% Torek had in his office while editing this sentence had an initial
% matrix of [300/72 0 0 300/72 300(-1/4) 300(11-.04)], corresponding
% to a normal 8.5 inch by 11 inch page, except that the translations, which
% one would expect to be 0 and paperheight, are offset.  This is because
% that particular LaserWriter printed about 1/4 inch to the right, and .04
% inches down, from where it should.  We have to make sure that this
% offset is included in our TeX transform.
%
% The device default is assumed to be set up at the beginning of each page,
% and so DefaultMatrix is simply salted away at each BOP.
%
% Although the width does not figure into the calculation above, the
% code below takes it, in case someone has to do something different
% on some other printer.

/DefaultMatrix matrix def % create it now, to be set later, per page

% Little functions to set paper size (in inches) and the landscape flag.
/set at width { /paperwidth exch def } def
/set at height { /paperheight exch def } def
/set at wh { set at height set at width } def
/set at landscape { /landscape exch def } def


% @setmode		modename @setmode -
%
% Sets the mode, if canclobber allows this.  Otherwise it does nothing.
% It does nothing anyway, if the name is not known in any dictionary.
/@setmode {
	dup where { pop canclobber { load exec } if } { pop } ifelse
} bind def

% @setup		- @setup -
%
% This routine creates the TeX matrices.  The paper size and landscape
% flag are used to define the matrices.
/@setup {
	landscape {
		/SpecialMatrix [0 1 -1 0 0 0] def % rotate 90 degrees
		/Mtrx [0 72 Resolution div dup 0 0 0] def
		% [(r/72) 0 0 -(r/72) a b] [Mtrx] = [0 -1 1 0 a b]
	} {
		/SpecialMatrix matrix def % identity
		/Mtrx [72 Resolution div 0 0 2 index neg
			0 paperheight 72 mul] def
		% [(r/72) 0 0 -(r/72) a b] [Mtrx] = [1 0 0 1 a b-(h*r)]
	} ifelse
} bind def

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Document options (must be in opt[] table in postscript.c).
% All are argumentless.  A few appear later in this file.
% Here is a full list:
%	letter note legal a4size legalsize lettersize manualfeed draft

% these do nothing different from their counterparts below if canclobber
% is false
/@a4 { /letter @setmode @a4size } def
/@letter { /letter @setmode @lettersize } def
/@note { /note @setup @lettersize } def
/@legal { /legal @setmode @legalsize } def

/@a4size { 8.5 11.5 set at wh @setup } def
/@legalsize { 8.5 14 set at wh @setup } def
/@lettersize { 8.5 11 set at wh @setup } def
/@notesize { @lettersize } def % for completeness

/@landscape { true set at landscape @setup } def

/@manualfeed {statusdict /manualfeed true put} def

% n @copies - set number of copies
/@copies {/#copies exch def} def

% [much deleted here]

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Begin page, version for pass 0 and pass 1, and end page.
% The pass 0 and 1 versions are called with an array containing the
% ten count values and the absolute page number (in that order).

% called from bop1 to set everything up
/@@bop {
	DefaultMatrix currentmatrix pop % save it away
	/@bop at save save def	% ready to reclaim VM
	@save at state		% save graphics state for \specials
	Mtrx concat		% enter TeX coordinates
	0 0 moveto		% start us off
} bind def

/@BOP0 {pop} bind def

/@BOP1 {pop @@bop} bind def

/@EOP {
	showpage
	@bop at save restore	% put everything back
} bind def

% @DRAFTF and @DRAFTM put the word `draft' in stippled grey
% angled across the front of a page (@DRAFTF) or at the top
% (@DRAFTM) of each page.  These are used by the @draft document
% option.
/@DRAFTF {
	gsave newpath
	/Helvetica-Bold findfont setfont
	(Draft) dup stringwidth pop 8.875 exch div dup 72 mul dup scale
	52.3 rotate 2.5 exch div -.35 translate
	0.95 setgray
	0 0 moveto show
	grestore
} bind def

/@DRAFTM {
	gsave newpath
	/Helvetica-Bold findfont 72 scalefont setfont
	0.95 setgray
	576 702 moveto
	(Draft) dup stringwidth exch neg exch neg rmoveto show
	grestore
} bind def

% @draft document option redefines BOP1:
/@draft {
	/@BOP1 {	% page-vector @BOP1
		0 get 1 le {@DRAFTF} {@DRAFTM} ifelse
		@@bop
	} def
} def

% [much more deleted]

Much of the preceding (including avoiding initmatrix) is due to code
and commentary recieved from Joe Pallas since the beta release of MC-TeX.
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163)
Domain:	chris at mimsy.umd.edu	Path:	uunet!mimsy!chris



More information about the Comp.unix.ultrix mailing list