home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / d / dvips549.zip / DVIPS / TEX.LPR < prev    next >
Text File  |  1992-10-14  |  11KB  |  340 lines

  1. % The following defines procedures assumed and used by program "dvips"
  2. % and must be downloaded or sent as a header file for all TeX jobs.
  3. % Originated by Neal Holtz, Carleton University, Ottawa, Canada
  4. %      <holtz@cascade.carleton.cdn>
  5. %      June, 1985
  6. %
  7. %   Hacked by tgr, July 1987, stripped down to bare essentials,
  8. %   plus a few new commands for speed.
  9. %
  10. %   Hacked by don, December 1989, to give characters top down and to
  11. %   remove other small nuisances; merged with tgr's compression scheme
  12. %
  13. % To convert this file into a downloaded file instead of a header
  14. % file, uncomment all of the lines beginning with %-%
  15. %
  16. %   To observe available VM, uncomment the following.
  17. %   (The first ten lines define a general 'printnumber' routine.)
  18. %
  19. % /VirginMtrx 6 array currentmatrix def
  20. % /dummystring 20 string def
  21. % /numberpos 36 def
  22. % /printnumber { gsave VirginMtrx setmatrix
  23. %   /Helvetica findfont 10 scalefont setfont
  24. %   36 numberpos moveto
  25. %   /numberpos numberpos 12 add def
  26. %   dummystring cvs show
  27. %   grestore
  28. %   } bind def
  29. % /showVM { vmstatus exch sub exch pop printnumber } def
  30. % /eop-aux { showVM } def
  31. %
  32. %-%0000000             % Server loop exit password
  33. %-%serverdict begin exitserver
  34. %-%  systemdict /statusdict known
  35. %-%  {statusdict begin 9 0 3 setsccinteractive /waittimeout 300 def end}
  36. %-% if
  37.  
  38. /TeXDict 250 dict def   % define a working dictionary ( IBM: color - 200->250 )
  39. TeXDict begin           % start using it.
  40. /N {def} def
  41. /B {bind def} N
  42. /S {exch} N
  43. /X { S N } B
  44. /TR {translate} N
  45.  
  46. % The output of dvips assumes pixel units, Resolution/inch, with
  47. % increasing y coordinates corresponding to moving DOWNWARD.
  48. % The PostScript default is big point units (bp), 72/inch, with
  49. % increasing y coordinates corresponding to moving UP; the
  50. % following routines handle conversion to dvips conventions. 
  51.  
  52. % Let the PostScript origin be (xps,yps) in dvips coordinates.
  53.  
  54. /isls false N
  55. /vsize 11 72 mul N
  56.  
  57. /@rigin                 % -xps -yps @rigin -   establishes dvips conventions
  58.   { isls { [ 0 -1 1 0 0 0 ] concat } if
  59.     72 Resolution div 72 VResolution div neg scale
  60.     isls { Resolution hsize -72 div mul 0 TR } if
  61.     Resolution VResolution vsize -72 div 1 add mul TR
  62. % As bad as setmatrix is, it is better than misalignment.
  63.     matrix currentmatrix
  64.     dup dup 4 get round 4 exch put
  65.     dup dup 5 get round 5 exch put
  66.     setmatrix } N
  67.  
  68. /@landscape { /isls true N } B
  69.  
  70. /@manualfeed
  71.    { statusdict /manualfeed true put
  72.    } B
  73.  
  74.         % n @copies -   set number of copies
  75. /@copies
  76.    { /#copies X
  77.    } B
  78.  
  79. % Bitmap fonts are called Fa, Fb, ..., Fz, F0, F1 . . . Ga . . .
  80. % The calling sequence for downloading font foo is
  81. %           /foo df chardef1 ... chardefn E 
  82. % where each chardef is
  83. %           <hexstring> wd ht xoff yoff dx charno D 
  84. %  or       <hexstring> wd ht xoff yoff dx I
  85. %  or       <hexstring> charno D
  86. %  or       <hexstring> I
  87.  
  88. /FMat [1 0 0 -1 0 0] N
  89. /FBB [0 0 0 0] N
  90.  
  91. /nn 0 N /IE 0 N /ctr 0 N
  92. /df-tail       % id numcc maxcc df-tail -- initialize a new font dictionary
  93.   {
  94. %   dmystr 2 fontname cvx (@@@@) cvs putinterval  % put name in template
  95.     /nn 8 dict N              % allocate new font dictionary
  96.     nn begin
  97.         /FontType 3 N
  98.     /FontMatrix fntrx N
  99.     /FontBBox FBB N
  100.         string /base X
  101.         array /BitMaps X
  102.         /BuildChar {CharBuilder} N
  103.         /Encoding IE N
  104.         end
  105.     dup { /foo setfont }          %  dummy macro to be filled in
  106.        2 array copy cvx N         %  have to allocate a new one
  107.     load                          %  now we change it
  108. %      0 dmystr 6 string copy       %  get a copy of the font name
  109.        0 nn put
  110. %      cvn cvx put                  %  and stick it in the dummy macro
  111.     /ctr 0 N                      %  go, count, and etc.
  112.     [                               %  start next char definition
  113.   } B
  114. /df {
  115.    /sf 1 N
  116.    /fntrx FMat N
  117.    df-tail
  118. } B
  119. /dfs { div /sf X
  120.    /fntrx [ sf 0 0 sf neg 0 0 ] N
  121.    df-tail
  122. } B
  123.  
  124. /E { pop nn dup definefont setfont } B
  125.  
  126. % the following is the only character builder we need.  it looks up the
  127. % char data in the BitMaps array, and paints the character if possible.
  128. % char data  -- a bitmap descriptor -- is an array of length 6, of
  129. %          which the various slots are:
  130.  
  131. /ch-width {ch-data dup length 5 sub get} B % the number of pixels across
  132. /ch-height {ch-data dup length 4 sub get} B % the number of pixels tall
  133. /ch-xoff  {128 ch-data dup length 3 sub get sub} B % num pixels right of origin
  134. /ch-yoff  {ch-data dup length 2 sub get 127 sub} B % number of pixels below origin
  135. /ch-dx  {ch-data dup length 1 sub get} B     % number of pixels to next character
  136. /ch-image {ch-data dup type /stringtype ne
  137.       { ctr get /ctr ctr 1 add N } if
  138.    } B                        % the hex string image, or array of same
  139. %      /id ch-image N                          % image data
  140. /id 0 N /rw 0 N /rc 0 N /gp 0 N /cp 0 N /G 0 N /sf 0 N
  141.  
  142. /CharBuilder    % fontdict ch Charbuilder -     -- image one character
  143.      {save 3 1 roll S dup /base get 2 index get S /BitMaps get S get
  144.       /ch-data X pop
  145.       /ctr 0 N
  146.       ch-dx 0 ch-xoff ch-yoff ch-height sub
  147.       ch-xoff ch-width add ch-yoff
  148.       setcachedevice
  149.       ch-width ch-height true
  150.       [1 0 0 -1 -.1 ch-xoff sub ch-yoff .1 add]
  151. % begin code for uncompressed fonts only
  152.       {ch-image} imagemask
  153.       restore
  154.   } B
  155. % end code for uncompressed fonts only
  156. % % here's the alternate code for unpacking compressed fonts
  157. %      /id ch-image N                          % image data
  158. %      /rw ch-width 7 add 8 idiv string N      % row, initially zero
  159. %      /rc 0 N                                 % repeat count
  160. %      /gp 0 N                                 % image data pointer
  161. %      /cp 0 N                                 % column pointer
  162. %      { rc 0 ne { rc 1 sub /rc X rw } { G } ifelse } imagemask
  163. %    restore
  164. % } B
  165. % /G { { id gp get /gp gp 1 add N
  166. %   dup 18 mod S 18 idiv pl S get exec } loop } B
  167. % /adv { cp add /cp X } B
  168. % /chg { rw cp id gp 4 index getinterval putinterval
  169. %         dup gp add /gp X adv } B
  170. % /nd { /cp 0 N rw exit } B
  171. % /lsh { rw cp 2 copy get dup 0 eq { pop 1 } { dup 255 eq { pop 254 }
  172. %     { dup dup add 255 and S 1 and or } ifelse } ifelse put 1 adv } B
  173. % /rsh { rw cp 2 copy get dup 0 eq { pop 128 } { dup 255 eq { pop 127 }
  174. %     { dup 2 idiv S 128 and or } ifelse } ifelse put 1 adv } B
  175. % /clr { rw cp 2 index string putinterval adv } B
  176. % /set { rw cp fillstr 0 4 index getinterval putinterval adv } B
  177. % /fillstr 18 string 0 1 17 { 2 copy 255 put pop } for N
  178. % /pl [
  179. %    { adv 1 chg }
  180. %    { adv 1 chg nd }
  181. %    { 1 add chg }
  182. %    { 1 add chg nd }
  183. %    { adv lsh }
  184. %    { adv lsh nd }
  185. %    { adv rsh }
  186. %    { adv rsh nd }
  187. %    { 1 add adv }
  188. %    { /rc X nd }
  189. %    { 1 add set }
  190. %    { 1 add clr }
  191. %    { adv 2 chg }
  192. %    { adv 2 chg nd }
  193. %    { pop nd } ] dup { bind pop } forall N
  194. % % end of code for unpacking compressed fonts
  195.  
  196.                % in the following, the font-cacheing mechanism requires that
  197.                 % a name unique in the particular font be generated
  198.  
  199. /D            % char-data ch D -    -- define character bitmap in current font
  200.   { /cc X
  201.     dup type /stringtype ne {]} if
  202.     nn /base get cc ctr put
  203.     nn /BitMaps get S ctr S
  204.     sf 1 ne {
  205.        dup dup length 1 sub dup 2 index S get sf div put
  206.     } if
  207.     put
  208.     /ctr ctr 1 add N
  209.   } B
  210.  
  211. /I            % a faster D for when the next char follows immediately
  212.   { cc 1 add D } B
  213.  
  214. /bop           % %t %d bop -  -- begin a brand new page, %t=pageno %d=seqno
  215.   {
  216.     userdict /bop-hook known { bop-hook } if
  217.     /SI save N
  218.     @rigin
  219. %
  220. %   Now we check the resolution.  If it's correct, we use RV as V,
  221. %   otherwise we use QV.
  222. %
  223.     0 0 moveto
  224.     /V matrix currentmatrix
  225.     dup 1 get dup mul exch 0 get dup mul add .99 lt
  226.     {/QV} {/RV} ifelse load def
  227.     pop pop
  228.   } N
  229.  
  230. /eop           % - eop -              -- end a page
  231.   { % eop-aux  % -- to observe VM usage
  232.     SI restore
  233.     showpage
  234.     userdict /eop-hook known { eop-hook } if
  235.   } N
  236.  
  237. /@start         % hsz vsz mag dpi vdpi name @start -   -- start everything
  238.   {
  239.     userdict /start-hook known { start-hook } if
  240.     pop % the job name string is used only by start-hook
  241.     /VResolution X
  242.     /Resolution X
  243.     1000 div /DVImag X
  244.     /IE 256 array N
  245.     0 1 255 {IE S 1 string dup 0 3 index put cvn put} for
  246.     65781.76 div /vsize X
  247.     65781.76 div /hsize X
  248.   } N
  249.  
  250. /p {show} N        %  the main character setting routine
  251.  
  252. /RMat [ 1 0 0 -1 0 0 ] N % things we need for rules
  253. /BDot 260 string N
  254. /rulex 0 N /ruley 0 N
  255. /v {                   % can't use ...fill; it makes rules too big
  256.    /ruley X /rulex X
  257.    V
  258. } B
  259. %
  260. %   What we need to do to get things to work here is tragic.
  261. %
  262. /V {} B /RV
  263. %
  264. %   Which do we use?  The first if we are talking to Display
  265. %   PostScript, the latter otherwise.
  266. %
  267. statusdict begin /product where
  268.    { pop product dup length 7 ge
  269.       { 0 7 getinterval dup (Display) eq exch 0 4 getinterval (NeXT) eq or }
  270.       { pop false } ifelse }
  271.    { false } ifelse end
  272. { {
  273.    gsave
  274.       TR -.1 -.1 TR 1 1 scale rulex ruley
  275.       false RMat { BDot } imagemask
  276.    grestore
  277. } }
  278. { {
  279.    gsave
  280.       TR -.1 -.1 TR rulex ruley scale 1 1
  281.       false RMat { BDot } imagemask
  282.    grestore
  283. } } ifelse B
  284. %
  285. %   We use this if the resolution doesn't match.
  286. %
  287. /QV {
  288.    gsave
  289.       transform round exch round exch itransform moveto
  290.       rulex 0 rlineto 0 ruley neg rlineto
  291.       rulex neg 0 rlineto fill
  292.    grestore
  293. } B
  294. %
  295. /a { moveto } B    % absolute positioning
  296. /delta 0 N         % we need a variable to hold space moves
  297. %
  298. %   The next ten macros allow us to make horizontal motions that
  299. %   are within 4 of the previous horizontal motion with a single
  300. %   character.  These are typically used for spaces.
  301. %
  302. /tail { dup /delta X 0 rmoveto } B
  303. /M { S p delta add tail } B
  304. /b { S p tail } B      % show and tail!
  305. /c { -4 M } B
  306. /d { -3 M } B
  307. /e { -2 M } B
  308. /f { -1 M } B
  309. /g { 0 M } B
  310. /h { 1 M } B
  311. /i { 2 M } B
  312. /j { 3 M } B
  313. /k { 4 M } B
  314. %
  315. %   These next allow us to make small motions (-4..4) cheaply.
  316. %   Typically used for kerns.
  317. %
  318. /w { 0 rmoveto } B
  319. /l { p -4 w } B
  320. /m { p -3 w } B
  321. /n { p -2 w } B
  322. /o { p -1 w } B
  323. /q { p 1 w } B
  324. /r { p 2 w } B
  325. /s { p 3 w } B
  326. /t { p 4 w } B
  327. %
  328. %  x is good for small vertical positioning.
  329. %  And y is good for a print followed by a move.
  330. %
  331. /x { 0 S rmoveto } B
  332. /y { 3 2 roll p a } B
  333. %
  334. %   The bos and eos commands bracket sections of downloaded characters.
  335. %
  336. /bos { /SS save N } B
  337. /eos { SS restore } B
  338.  
  339. end  % revert to previous dictionary
  340.