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 / TEXC.LPR < prev    next >
Text File  |  1992-10-14  |  11KB  |  335 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. % here's the alternate code for unpacking compressed fonts
  152.      /id ch-image N                          % image data
  153.      /rw ch-width 7 add 8 idiv string N      % row, initially zero
  154.      /rc 0 N                                 % repeat count
  155.      /gp 0 N                                 % image data pointer
  156.      /cp 0 N                                 % column pointer
  157.      { rc 0 ne { rc 1 sub /rc X rw } { G } ifelse } imagemask
  158.    restore
  159. } B
  160. /G { { id gp get /gp gp 1 add N
  161.   dup 18 mod S 18 idiv pl S get exec } loop } B
  162. /adv { cp add /cp X } B
  163. /chg { rw cp id gp 4 index getinterval putinterval
  164.         dup gp add /gp X adv } B
  165. /nd { /cp 0 N rw exit } B
  166. /lsh { rw cp 2 copy get dup 0 eq { pop 1 } { dup 255 eq { pop 254 }
  167.     { dup dup add 255 and S 1 and or } ifelse } ifelse put 1 adv } B
  168. /rsh { rw cp 2 copy get dup 0 eq { pop 128 } { dup 255 eq { pop 127 }
  169.     { dup 2 idiv S 128 and or } ifelse } ifelse put 1 adv } B
  170. /clr { rw cp 2 index string putinterval adv } B
  171. /set { rw cp fillstr 0 4 index getinterval putinterval adv } B
  172. /fillstr 18 string 0 1 17 { 2 copy 255 put pop } for N
  173. /pl [
  174.    { adv 1 chg }
  175.    { adv 1 chg nd }
  176.    { 1 add chg }
  177.    { 1 add chg nd }
  178.    { adv lsh }
  179.    { adv lsh nd }
  180.    { adv rsh }
  181.    { adv rsh nd }
  182.    { 1 add adv }
  183.    { /rc X nd }
  184.    { 1 add set }
  185.    { 1 add clr }
  186.    { adv 2 chg }
  187.    { adv 2 chg nd }
  188.    { pop nd } ] dup { bind pop } forall N
  189. % end of code for unpacking compressed fonts
  190.  
  191.                % in the following, the font-cacheing mechanism requires that
  192.                 % a name unique in the particular font be generated
  193.  
  194. /D            % char-data ch D -    -- define character bitmap in current font
  195.   { /cc X
  196.     dup type /stringtype ne {]} if
  197.     nn /base get cc ctr put
  198.     nn /BitMaps get S ctr S
  199.     sf 1 ne {
  200.        dup dup length 1 sub dup 2 index S get sf div put
  201.     } if
  202.     put
  203.     /ctr ctr 1 add N
  204.   } B
  205.  
  206. /I            % a faster D for when the next char follows immediately
  207.   { cc 1 add D } B
  208.  
  209. /bop           % %t %d bop -  -- begin a brand new page, %t=pageno %d=seqno
  210.   {
  211.     userdict /bop-hook known { bop-hook } if
  212.     /SI save N
  213.     @rigin
  214. %
  215. %   Now we check the resolution.  If it's correct, we use RV as V,
  216. %   otherwise we use QV.
  217. %
  218.     0 0 moveto
  219.     /V matrix currentmatrix
  220.     dup 1 get dup mul exch 0 get dup mul add .99 lt
  221.     {/QV} {/RV} ifelse load def
  222.     pop pop
  223.   } N
  224.  
  225. /eop           % - eop -              -- end a page
  226.   { % eop-aux  % -- to observe VM usage
  227.     SI restore
  228.     showpage
  229.     userdict /eop-hook known { eop-hook } if
  230.   } N
  231.  
  232. /@start         % hsz vsz mag dpi vdpi name @start -   -- start everything
  233.   {
  234.     userdict /start-hook known { start-hook } if
  235.     pop % the job name string is used only by start-hook
  236.     /VResolution X
  237.     /Resolution X
  238.     1000 div /DVImag X
  239.     /IE 256 array N
  240.     0 1 255 {IE S 1 string dup 0 3 index put cvn put} for
  241.     65781.76 div /vsize X
  242.     65781.76 div /hsize X
  243.   } N
  244.  
  245. /p {show} N        %  the main character setting routine
  246.  
  247. /RMat [ 1 0 0 -1 0 0 ] N % things we need for rules
  248. /BDot 260 string N
  249. /rulex 0 N /ruley 0 N
  250. /v {                   % can't use ...fill; it makes rules too big
  251.    /ruley X /rulex X
  252.    V
  253. } B
  254. %
  255. %   What we need to do to get things to work here is tragic.
  256. %
  257. /V {} B /RV
  258. %
  259. %   Which do we use?  The first if we are talking to Display
  260. %   PostScript, the latter otherwise.
  261. %
  262. statusdict begin /product where
  263.    { pop product dup length 7 ge
  264.       { 0 7 getinterval dup (Display) eq exch 0 4 getinterval (NeXT) eq or }
  265.       { pop false } ifelse }
  266.    { false } ifelse end
  267. { {
  268.    gsave
  269.       TR -.1 -.1 TR 1 1 scale rulex ruley
  270.       false RMat { BDot } imagemask
  271.    grestore
  272. } }
  273. { {
  274.    gsave
  275.       TR -.1 -.1 TR rulex ruley scale 1 1
  276.       false RMat { BDot } imagemask
  277.    grestore
  278. } } ifelse B
  279. %
  280. %   We use this if the resolution doesn't match.
  281. %
  282. /QV {
  283.    gsave
  284.       transform round exch round exch itransform moveto
  285.       rulex 0 rlineto 0 ruley neg rlineto
  286.       rulex neg 0 rlineto fill
  287.    grestore
  288. } B
  289. %
  290. /a { moveto } B    % absolute positioning
  291. /delta 0 N         % we need a variable to hold space moves
  292. %
  293. %   The next ten macros allow us to make horizontal motions that
  294. %   are within 4 of the previous horizontal motion with a single
  295. %   character.  These are typically used for spaces.
  296. %
  297. /tail { dup /delta X 0 rmoveto } B
  298. /M { S p delta add tail } B
  299. /b { S p tail } B      % show and tail!
  300. /c { -4 M } B
  301. /d { -3 M } B
  302. /e { -2 M } B
  303. /f { -1 M } B
  304. /g { 0 M } B
  305. /h { 1 M } B
  306. /i { 2 M } B
  307. /j { 3 M } B
  308. /k { 4 M } B
  309. %
  310. %   These next allow us to make small motions (-4..4) cheaply.
  311. %   Typically used for kerns.
  312. %
  313. /w { 0 rmoveto } B
  314. /l { p -4 w } B
  315. /m { p -3 w } B
  316. /n { p -2 w } B
  317. /o { p -1 w } B
  318. /q { p 1 w } B
  319. /r { p 2 w } B
  320. /s { p 3 w } B
  321. /t { p 4 w } B
  322. %
  323. %  x is good for small vertical positioning.
  324. %  And y is good for a print followed by a move.
  325. %
  326. /x { 0 S rmoveto } B
  327. /y { 3 2 roll p a } B
  328. %
  329. %   The bos and eos commands bracket sections of downloaded characters.
  330. %
  331. /bos { /SS save N } B
  332. /eos { SS restore } B
  333.  
  334. end  % revert to previous dictionary
  335.