%! $Header: tex.pro,v 1.11 88/09/26 16:49:11 tli Exp $ % % for use by dvi2ps Version 2.11 or later. % % a start (Ha!) at a TeX mode for PostScript. % The following defines procedures assumed and used by program "dvi2ps" % and must be downloaded or sent as a header file for all TeX jobs. % % Original author: % Neal Holtz, Carleton University, Ottawa, Canada % % % June, 1985 Last Modified: Aug 25/85 % % PostScript illustration support: % Jean-Francois Lamy, AI group, University of Toronto, Canada % lamy@ai.toronto.edu, lamy@ai.toronto.cdn % % $Log: tex.pro,v $ % Revision 1.11 88/09/26 16:49:11 tli % Made things so that they work even if note isn't defined. % % Revision 1.10 88/07/11 14:50:43 tli % Added the Matlab patch again. % % Revision 1.9 88/07/01 14:18:45 tli % Added new psfig.pro from Trevor Darrell. % % Revision 1.8 88/05/03 00:42:06 tli % Add support for larger GF fonts. % % Revision 1.7 88/04/20 11:16:13 tli % MATLAB does wierd things at the end of a page. Specifically, they use % copypage and erasepage. I added some definitions to startTeXFig so % that these commands are acceptable. % % Revision 1.6 88/04/14 19:23:24 tli % In a @beginspecial, after changing the user coordinate space, we execute % a 0 0 moveto to restore the current point. % % Revision 1.5 88/04/07 13:05:22 tli % Start of local USC modifications. % % Revision 1.5 86/11/27 10:30:54 lamy % Mixing Mac and other PostScript illustrations now possible. % vsize positive now means "above current point". % % Revision 1.4 86/10/30 12:43:24 lamy % Now uses the rotate operator for landscape and envelope modes. % Used to be convoluted, non portable code to avoid round-off errors % that do not seem to be present on any of our printers. % % Revision 1.3 86/10/30 12:27:50 lamy % Fixed bug in @bop1 that caused top lines to be clipped when using proc.sty % % 86-07-17 jfl % Added envelope keyword definition. Same as landscape but positioned % so that an envelope inserted upside down is printed correctly % This reduces the occurence of paper jams. % % 86-06-23 JF Lamy, U. of Toronto % Updated to support the Macintosh LaserWriter driver version 3.x % instead of 1.1. Added rotation of illustrations. % % oystr 12-Feb-1986 % Changed @dc macro to check for badly formed bits in character % definitions. Can get a <> bit map if a character is not actually % in the font file. This is absolutely guaranteed to drive the % printer nuts - it will appear that you can no longer define a % new font, although the built-ins will still be there. % % To convert this file into a downloaded file instead of a header % file, uncomment all of the lines beginning with %-% %-%0000000 % Server loop exit password %-%serverdict begin exitserver %-% systemdict /statusdict known %-% {statusdict begin 9 0 3 setsccinteractive /waittimeout 300 def end} %-% if /TeXDict 200 dict def % define a working dictionary TeXDict begin % start using it. % units are in "dots" (300/inch) /Resolution 300 def /Inch {Resolution mul} def % converts inches to internal units /PageCounter statusdict begin pagecount end def % so we can report # pages printed /Mtrx 6 array def %%%%%%%%%%%%%%%%%%%%% Page setup (user) options %%%%%%%%%%%%%%%%%%%%%%%% % dvi2ps will output coordinates in the TeX system ([0,0] 1" down and in % from top left, with y +ive downward). The default PostScript system % is [0,0] at bottom left, y +ive up. The Many Matrix Machinations in % the following code are an attempt to reconcile that. The intent is to % specify the scaling as 1 and have only translations in the matrix to % properly position the text. Caution: the default device matrices are % *not* the same in all PostScript devices; that should not matter in most % of the code below (except for lanscape mode -- in that, rotations of % -90 degrees resulted in the the rotation matrix [ e 1 ] % [ 1 e ] % where the "e"s were almost exactly but not quite zeros. % /@letter { letter initmatrix 72 Resolution div dup neg scale % set scaling to 1. 310 -3005 translate % move origin to top (these are not exactly 1" Mtrx currentmatrix pop % and -10" because margins aren't set exactly right) } def % note mode is like letter, except it uses less VM /@note { note initmatrix 72 Resolution div dup neg scale % set scaling to 1. 310 -3005 translate % move origin to top Mtrx currentmatrix pop } def /@landscape { letter initmatrix 72 Resolution div dup neg scale % set scaling to 1. -90 rotate % it would be nice to be able to do this % Mtrx currentmatrix 0 0.0 put % but instead we have to do things % % like this because what should be zero % Mtrx 1 -1.0 put % terms aren't (and text comes out wobbly) % Mtrx 2 1.0 put % Fie! This likely will not work on QMS printers % Mtrx 3 0.0 put % (nor on others where the device matrix is not like % Mtrx setmatrix % like it is on the LaserWriter). 300 310 translate % move origin to top Mtrx currentmatrix pop } def /@legal { legal initmatrix 72 Resolution div dup neg scale % set scaling to 1. 295 -3880 translate % move origin to top Mtrx currentmatrix pop } def /@manualfeed { statusdict /manualfeed true put } def % n @copies - set number of copies /@envelope { statusdict /manualfeed true put letter initmatrix 72 Resolution div dup neg scale -90 rotate % Mtrx currentmatrix 0 0.0 put % Mtrx 1 -1.0 put % Mtrx 2 1.0 put % Mtrx 3 0.0 put % Mtrx setmatrix 450 1275 translate % upper right corner of regular envelope % when fed manually 300 310 translate Mtrx currentmatrix pop } def /@copies { /#copies exch def } def %%%%%%%%%%%%%%%%%%%% Procedure Defintions %%%%%%%%%%%%%%%%%%%%%%%%%% /@newfont % id @newfont - -- initialize a new font dictionary { /newname exch def pop newname 7 dict def % allocate new font dictionary newname load begin /FontType 3 def /FontMatrix [1 0 0 -1 0 0] def /FontBBox [0 0 1 1] def /BitMaps 256 array def /BuildChar {CharBuilder} def /Encoding 256 array def 0 1 255 {Encoding exch /.undef put} for end newname newname load definefont pop } def % the following is the only character builder we need. it looks up the % char data in the BitMaps array, and paints the character if possible. % char data -- a bitmap descriptor -- is an array of length 6, of % which the various slots are: /ch-image {ch-data 0 get} def % the hex string image /ch-width {ch-data 1 get} def % the number of pixels across /ch-height {ch-data 2 get} def % the number of pixels tall /ch-xoff {ch-data 3 get} def % number of pixels below origin /ch-yoff {ch-data 4 get} def % number of pixels to left of origin /ch-tfmw {ch-data 5 get} def % spacing to next character /CharBuilder % fontdict ch Charbuilder - -- image one character { /ch-code exch def % save the char code /font-dict exch def % and the font dict. /ch-data font-dict /BitMaps get ch-code get def % get the bitmap descriptor for char ch-data null eq not { ch-tfmw 0 ch-xoff neg ch-yoff neg ch-width ch-xoff sub ch-height ch-yoff sub setcachedevice ch-width ch-height true [1 0 0 1 ch-xoff ch-yoff] {ch-image} imagemask } if } def /@sf % fontdict @sf - -- make that the current font { setfont() pop } def % in the following, the font-cacheing mechanism requires that % a name unique in the particular font be generated /@dc % char-data ch @dc - -- define a new character bitmap { /ch-code exch def % ++oystr 12-Feb-86++ dup 0 get length 2 lt { pop [ <00> 1 1 0 0 8.00 ] } % replace <> with null if % --oystr 12-Feb-86-- /ch-data exch def currentfont /BitMaps get ch-code ch-data put currentfont /Encoding get ch-code dup ( ) cvs cvn % generate a unique name simply from the character code put } def /@bop0 % n @bop0 - -- begin the char def section of a new page { } def /@bop1 % n @bop1 - -- begin a brand new page { pop erasepage initgraphics Mtrx setmatrix 0 0 moveto /SaveImage save def } def /@eop % - @eop - -- end a page { showpage SaveImage restore } def /@start % - @start - -- start everything { /note where % check to see if note exists {@note} {@letter} ifelse % if so, do that. Otherwise % use letter % @note % (there is not much to do) } def /@end % - @end - -- done the whole shebang { end } def /p % x y p - -- move to position { moveto } def /r % x r - -- move right { 0 rmoveto } def /s % string s - -- show the string { show } def /c % ch c - -- show the character (code given) { c-string exch 0 exch put c-string show } def /c-string ( ) def /ru % dx dy ru - -- set a rule (rectangle) { /dy exch neg def % because dy is height up from bottom /dx exch def /x currentpoint /y exch def def % remember current point newpath x y moveto dx 0 rlineto 0 dy rlineto dx neg 0 rlineto closepath fill x y moveto } def %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% the \special command junk %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % The structure of the PostScript produced by dvi2ps for \special is: % @beginspecial % - any number of @hsize, @hoffset, @hscale, etc., commands % @setspecial % - the users file of PostScript commands % @endspecial % The @beginspecial command recognizes whether the Macintosh Laserprep % has been loaded or not, and redfines some Mac commands if so. % The @setspecial handles the users shifting, scaling, clipping commands % The following are user settable options from the \special command. /@SpecialDefaults { /hsi 72 8.5 mul def % 8.5 Inch def /vsi 72 11 mul def % 11 Inch def /hof 0 def /vof 0 def /hsc 1 def /vsc 1 def /rotat 0 def /CLIP false def } def % d @hsize - specify a horizontal clipping dimension % these 2 are executed before the MacDraw initializations /@hsize {/hsi exch def /CLIP true def} def /@vsize {/vsi exch def /CLIP true def} def % d @hoffset - specify a shift for the drwgs /@hoffset {/hof exch def} def /@voffset {/vof exch def} def % s @hscale - set scale factor /@hscale {/hsc exch def} def /@vscale {/vsc exch def} def % r @rotation - set rotation angle /@rotation {/rotat exch def} def /@setclipper { CLIP { newpath 0 0 moveto hsi 0 rlineto 0 vsi rlineto hsi neg 0 rlineto closepath clip } if } def % this will be invoked as the result of a \special command (for the % inclusion of PostScript graphics). The basic idea is to change all % scaling and graphics back to defaults, but to shift the origin % to the current position on the page (left margin?) /@beginspecial % - @beginspecial - -- enter special mode { gsave /SpecialSave save def % the following magic incantation establishes the current point as % the users origin, and reverts back to default scalings, rotations % and restore the current point currentpoint transform initgraphics itransform translate 0 0 moveto @SpecialDefaults % setup default offsets, scales, sizes % @MacSetUp % fix up Mac stuff } def /@setspecial % to setup user specified offsets, scales, sizes (for clipping) { hof vof translate @setclipper hsc vsc scale rotat rotate } def /@endspecial % - @endspecial - -- leave special mode { SpecialSave restore grestore } def % - @MacSetUp - turn-off/fix-up all the LaserPrep stuff that might hurt us /@MacSetUp { userdict /md known % if md is defined { userdict /md get type /dicttype eq % and if it is a dictionary { /MacDrwgs true def md begin % then redefine some stuff /txpose{ 1 -1 scale % make y coordinates relative to top of figure } bind def % ignore Mac page breaks /cp {pop pop} bind def end } if } if } def end % revert to previous dictionary %! % All software, documentation, and related files in this distribution of % psfig/tex are Copyright (c) 1987 Trevor J. Darrell % % Permission is granted for use and non-profit distribution of psfig/tex % providing that this notice be clearly maintained, but the right to % distribute any portion of psfig/tex for profit or as part of any commercial % product is specifically reserved for the author. % % % Psfig/TeX Release 1.2 % $Header: tex.pro,v 1.11 88/09/26 16:49:11 tli Exp $ % /TeXscale { 65536 div } def %/DocumentInitState [ matrix currentmatrix currentlinewidth currentlinecap %currentlinejoin currentdash currentgray currentmiterlimit ] cvx def % % Since dvi2ps has an initgraphics at the beginning of texpre.ps, we can % assume: gsave initgraphics /DocumentInitState [ matrix currentmatrix currentlinewidth currentlinecap currentlinejoin currentdash currentgray currentmiterlimit ] cvx def grestore /startTexFig { % usage : x y bb-llx bb-lly bb-urx bb-ury startFig /SavedState save def userdict maxlength dict begin currentpoint transform DocumentInitState setmiterlimit setgray setdash setlinejoin setlinecap setlinewidth setmatrix itransform moveto /ury exch TeXscale def /urx exch TeXscale def /lly exch TeXscale def /llx exch TeXscale def /y exch TeXscale def /x exch TeXscale def currentpoint /cy exch def /cx exch def /sx x urx llx sub div def % scaling for x /sy y ury lly sub div def % scaling for y sx sy scale % scale by (sx,sy) cx sx div llx sub cy sy div ury sub translate /DefFigCTM matrix currentmatrix def /initmatrix { DefFigCTM setmatrix } def /defaultmatrix { DefFigCTM exch copy } def /initgraphics { DocumentInitState setmiterlimit setgray setdash setlinejoin setlinecap setlinewidth setmatrix DefFigCTM setmatrix } def /showpage { initgraphics } def /erasepage { initgraphics } def /copypage {} def } def % Args are llx lly urx ury (in figure coordinates) /clipFig { currentpoint 6 2 roll newpath 4 copy 4 2 roll moveto 6 -1 roll exch lineto exch lineto exch lineto closepath clip newpath moveto } def % doclip, if called, will always be just after a `startfig' /doclip { llx lly urx ury clipFig } def /endTexFig { end SavedState restore } def