home *** CD-ROM | disk | FTP | other *** search
/ Garbo / Garbo.cdr / mac / tex / oztex.sit / PS-files / DVItoPS.ps < prev    next >
Text File  |  1990-08-17  |  8KB  |  255 lines

  1. %!
  2. % This is the prologue used by OzTeX 1.3 to convert a DVI file into PostScript.
  3.  
  4. % Set dev to "LW" if LaserWriter, "LINO" if Linotronic, or "?" if unknown:
  5.  
  6. /dev (?) def
  7. statusdict /product known
  8. { statusdict /product get dup
  9.   (LaserWriter) anchorsearch { pop pop /dev (LW)   def } { pop } ifelse
  10.   (Linotype)    anchorsearch { pop pop /dev (LINO) def } { pop } ifelse
  11. } if
  12.  
  13. % OzTeX calls @setup soon after defining land (boolean) and res (integer):
  14.  
  15. /@setup {                                    % set up OzTeX's coordinate system
  16.  
  17. dev (?) eq                                    % unknown device?
  18. { land
  19.   {                                            % landscape
  20.      90 rotate                                % rotate axes 90deg anticlockwise
  21.      72 res div dup neg scale            % units now device dots
  22.      res dup translate                    % move to TeX origin
  23.   }
  24.   {                                            % portrait
  25.      72 res div dup neg scale            % units now device dots
  26.      res -10.7 res mul translate        % move to TeX origin; assumes A4 height
  27.   } ifelse
  28. } if
  29.  
  30. dev (LW) eq                                            % LaserWriter?
  31. { land
  32.   {                                                    % landscape
  33.      % rotate/scale/translate can cause scaling problems, so use setmatrix:
  34.      version cvr 38.0 le
  35.      { [ 0 -1 1 0 235 3100 ] setmatrix }    % LaserWriter
  36.      { version cvr 47.0 lt
  37.      { [ 0 -1 1 0 235 3130 ] setmatrix }    % LaserWriter Plus
  38.      { [ 0 -1 1 0 235 3160 ] setmatrix }    % LaserWriter II NTX
  39.                       % add y to move TeX origin down by y pixels
  40.                             % add x to move TeX origin left by x pixels
  41.      ifelse } ifelse
  42.   }
  43.   {                                                    % portrait
  44.      % scale/translate can cause scaling problems, so use setmatrix:
  45.      version cvr 38.0 le
  46.      { [ 1 0 0 1 235 190 ] setmatrix }        % LaserWriter
  47.      { version cvr 47.0 lt
  48.      { [ 1 0 0 1 235 215 ] setmatrix }        % LaserWriter Plus
  49.      { [ 1 0 0 1 235 265 ] setmatrix }        % LaserWriter II NTX
  50.                      % add x to move TeX origin right by x pixels
  51.                           % add y to move TeX origin down by y pixels
  52.      ifelse } ifelse
  53.   } ifelse
  54. } if
  55.  
  56. dev (LINO) eq                                    % Linotronic?
  57. { land
  58.   {                                                % landscape
  59.      90 rotate                                    % rotate axes 90deg anticlockwise
  60.      72 res div dup neg scale                % units now device dots
  61.      res res translate                        % move to TeX origin
  62.  
  63.      % setmatrix won't work properly with a3/a4/a5/b5 page setups
  64.      % [1 0 0 1 1270 margin 72 div 1270 mul add 1270] setmatrix        % res=1270
  65.      % [2 0 0 2 1270 margin 72 div 1270 mul add 1270] setmatrix        % res=635
  66.   }
  67.   {                                                % portrait
  68.      newpath clippath pathbbox                % push LLx LLy URx URy (URy = ht in pts)
  69.      /paperht exch 72 div def                % paper height in inches
  70.      pop pop pop                                % remove URx LLy LLx
  71.      72 res div dup neg scale                % units now device dots
  72.      res paperht res mul neg res add
  73.                                   translate        % move to TeX origin
  74.  
  75.      % setmatrix won't work properly with a3/a4/a5/b5 page setups
  76.      % [0 1 -1 0 paperht 1270 mul 1270 sub                                    % res=1270
  77.      %              margin 72 div 1270 mul add 1270] setmatrix
  78.      % [0 2 -2 0 paperht 1270 mul 1270 sub                                    % res=635
  79.      %              margin 72 div 1270 mul add 1270] setmatrix
  80.   } ifelse
  81. } if
  82.  
  83. /mtrx 6 array def
  84. mtrx currentmatrix pop                        % save our new transformation matrix
  85.  
  86. } def                                                % end of @setup
  87.  
  88. % @saveVM and @restoreVM are only used if we are conserving VM
  89. % by downloading font bitmaps more often:
  90.  
  91. /@saveVM {/prefontVM save def} def
  92.  
  93. /@restoreVM {prefontVM restore} def
  94.  
  95. /@newfont                                        % create new font dict
  96. { /maxchcode exch def
  97.   /fontid exch def
  98.   fontid 7 dict def
  99.   fontid load begin
  100.       /FontType 3 def
  101.       /FontMatrix [1 0 0 -1 0 0] def        % -1 because y scale is negative
  102.       /FontBBox [0 0 1 1] def
  103.       /BitMaps maxchcode 1 add array def
  104.       /BuildChar {CharBuilder} def
  105.       /Encoding maxchcode 1 add array def
  106.       0 1 maxchcode {Encoding exch /.notdef put} for
  107.       end
  108.   fontid fontid load definefont pop
  109. } def
  110.  
  111. % The char data, a bitmap descriptor, is an array with 6 elements:
  112.  
  113. /ch-image    {ch-data 0 get} def        % the hex string image
  114. /ch-width    {ch-data 1 get} def        % the number of pixels across
  115. /ch-height    {ch-data 2 get} def        % the number of pixels tall
  116. /ch-xoff        {ch-data 3 get} def        % number of pixels to left of origin
  117. /ch-yoff        {ch-data 4 get} def        % number of pixels below origin
  118. /ch-advw        {ch-data 5 get} def        % advance width
  119.  
  120. % The following character builder looks up the char data in the BitMaps array
  121. % and paints the character:
  122.  
  123. /CharBuilder                                % image one char
  124. { /ch-code exch def                        % save the char code
  125.   /font-dict exch def                    % and the font dict
  126.   /ch-data font-dict /BitMaps get
  127.   ch-code get def
  128.       ch-advw 0
  129.       ch-xoff neg ch-height ch-yoff sub 1 sub neg    % -xo , -(ht-yo-1)
  130.       ch-width ch-xoff sub 1 sub ch-yoff                % (wd-xo-1) , yo
  131.   setcachedevice
  132.       ch-width ch-height true
  133.       [1 0 0 -1 ch-xoff ch-yoff]        % bitmap sent top to bottom
  134.       {ch-image}
  135.   imagemask
  136. } def
  137.  
  138. /sf {setfont} def                            % set current font
  139.  
  140. /dc                                            % define new character
  141. { /ch-code exch def
  142.   /ch-data exch def
  143.  
  144.   % The following code should be enabled if you have an old LaserWriter.
  145.   % It attempts to overcome a bug that causes the printer to crash
  146.   % and print a test page rather then report a VMerror.
  147.   %
  148.   % vmstatus                                % returns: savelevel vmused vmmax
  149.   % 10000 sub gt                            % is vmused > (vmmax-10000)?
  150.   %    { pop VMERROR }                    % causes error message (avoiding crash)
  151.   %    { pop }                                % pop savelevel
  152.   % ifelse
  153.  
  154.   currentfont /BitMaps get ch-code ch-data put
  155.   currentfont /Encoding get ch-code
  156.   dup (   ) cvs cvn put                    % generate unique name
  157. } bind def
  158.  
  159. /@bop0 {pop} def                            % begin DVI page n
  160.  
  161. /@bop1                                        % begin setting DVI page n
  162. { pop                                            % throw away page number
  163.   initgraphics                                % start with a clean slate
  164.   mtrx setmatrix                            % switch to our TeX coordinate system
  165.   /prepageVM save def                    % save state of VM at start of page
  166. } def
  167.  
  168. /@eop                                            % end DVI page n
  169. { pop                                            % throw away page number
  170.   prepageVM restore                        % restore VM to state at start of page
  171.   showpage
  172. } def
  173.  
  174. /@end { } def                                % end of file
  175.  
  176. % h and s are used to typeset downloaded bitmap fonts:
  177.  
  178. /h {exch 0 rmoveto show} bind def    % move right by dh and show (...)
  179.  
  180. /s {3 1 roll moveto show} bind def    % move to h,v and show (...)
  181.  
  182. % H and S are used to typeset resident PostScript fonts.
  183. % We can't use relative horizontal positioning because the advance widths in
  184. % a PostScript font are not integers and rounding errors would accumulate:
  185.  
  186. /H {exch v moveto show} bind def        % move to h,v and show (...)
  187.  
  188. /S                                                % ditto, and save v position
  189. { 3 1 roll dup /v exch def
  190.   moveto show
  191. } bind def
  192.  
  193. % Some fine-tuning of the code used to draw a rule is necessary:
  194.  
  195. dev (LW) eq                                    % LaserWriter?
  196. version cvr 38.0 le and                    % and version <= 38.0?
  197. {
  198.   /r                                            % set a wd by ht rule at h,v
  199.   { newpath
  200.      1 add moveto                            % move to h,v+1 (don't ask me why)
  201.      /ht exch 1 sub def                    % reduce height by 1
  202.      /wd exch 1 sub def                    % ditto for width
  203.      wd 0 rlineto
  204.      0 ht neg rlineto
  205.      wd neg 0 rlineto
  206.      fill
  207.   } bind def
  208. }
  209. {
  210.   /r                                            % set a wd by ht rule at h,v
  211.   { newpath
  212.      moveto                                    % move to h,v
  213.      /ht exch 1 sub def                    % reduce height by 1
  214.      /wd exch 1 sub def                    % ditto for width
  215.      wd 0 rlineto
  216.      0 ht neg rlineto
  217.      wd neg 0 rlineto
  218.      fill
  219.   } bind def
  220. } ifelse
  221.  
  222. % Following procedures are invoked as the result of a \special command.
  223. % We change all scaling and graphics back to defaults, but shift the origin
  224. % to the current position on the page:
  225.  
  226. /p {moveto} bind def                        % move to h,v
  227.  
  228. /@bsp                                            % begin special mode
  229. { gsave
  230.   /prespecialVM save def                % save showpage, TeX procedures etc.
  231.   currentpoint transform
  232.   initgraphics itransform translate
  233.   land { 90 rotate } if                    % rotate axes if landscape
  234.   /showpage { } def                        % user does not have to remove showpage
  235. } bind def
  236.  
  237. /@esp                                            % end special mode
  238. { prespecialVM restore                    % restore saved showpage value etc.
  239.   grestore
  240. } bind def
  241.  
  242. % Here are the definitions needed to handle resident PostScript fonts:
  243.  
  244. /sp                                            % scaled pts to device dots
  245. { 16#10000 div                                % scaled pts to pts
  246.   res mul 72.27 div                        % pts to device dots
  247. } bind def
  248.  
  249. /PSfont                                        % uses dot size and TFM name
  250. { dup /Times-Slanted eq
  251.   {pop /Times-Roman findfont [1 0 .268 -1 0 0] makefont exch scalefont setfont}
  252.   {findfont [1 0 0 -1 0 0] makefont exch scalefont setfont}
  253.   ifelse
  254. } bind def
  255.