home *** CD-ROM | disk | FTP | other *** search
/ World of Shareware - Software Farm 2 / wosw_2.zip / wosw_2 / PRINTING / DVIPS386.ZIP / TEX.LPR < prev    next >
Text File  |  1990-11-25  |  10KB  |  306 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 200 dict def   % define a working dictionary
  39. TeXDict begin           % start using it.
  40. /N /def load def
  41. /B { bind def } N
  42. /S /exch load def
  43. /X { S N } B
  44. /TR /translate load 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 10 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.     Resolution VResolution vsize neg mul TR } B
  61.  
  62. % Here we assume the PostScript origin is at the bottom left corner
  63. % and that the paper is 11 inches high;
  64. % the dvips origin is 1 inch from top left corner;
  65. % hence if Resolution=300, we have (xps,yps)=(-300,3000). 
  66. /@letter { /vsize 10 N } B
  67.  
  68. /@landscape { /isls true N /vsize -1 N } B
  69.  
  70. /@a4 { /vsize 10.6929133858 N } B
  71.  
  72. /@a3 { /vsize 15.5531 N } B
  73.  
  74. /@ledger { /vsize 16 N } B
  75.  
  76. /@legal { /vsize 13 N } B
  77.  
  78. /@manualfeed
  79.    { statusdict /manualfeed true put
  80.    } B
  81.  
  82.         % n @copies -   set number of copies
  83. /@copies
  84.    { /#copies X
  85.    } B
  86.  
  87. % Bitmap fonts are called Fa, Fb, ..., Fz, F0, F1 . . . Ga . . .
  88. % The calling sequence for downloading font foo is
  89. %           /foo df chardef1 ... chardefn E 
  90. % where each chardef is
  91. %           <hexstring> wd ht xoff yoff dx charno D 
  92. %  or       <hexstring> wd ht xoff yoff dx I
  93. %  or       <hexstring> charno D
  94. %  or       <hexstring> I
  95.  
  96. /FMat [1 0 0 -1 0 0] N
  97. /FBB [0 0 0 0] N
  98.  
  99. % /dmystr (ZZf@@@) N       % define a place to put the new name
  100. % /nn {dmystr cvn} B  % make it easy to get that name
  101. /df {
  102.    /sf 1 N
  103.    /fntrx FMat N
  104.    df-tail
  105. } B
  106. /dfs { div /sf X
  107.    /fntrx [ sf 0 0 sf neg 0 0 ] N
  108.    df-tail
  109. } B
  110. /df-tail       % id numcc maxcc df-tail -- initialize a new font dictionary
  111.   {
  112. %   dmystr 2 fontname cvx (@@@@) cvs putinterval  % put name in template
  113.     /nn 8 dict N              % allocate new font dictionary
  114.     nn begin
  115.         /FontType 3 N
  116.     /FontMatrix fntrx N
  117.     /FontBBox FBB N
  118.         string /base X
  119.         array /BitMaps X
  120.         /BuildChar {CharBuilder} N
  121.         /Encoding IE N
  122.         end
  123.     dup { /foo setfont }          %  dummy macro to be filled in
  124.        2 array copy cvx N         %  have to allocate a new one
  125.     load                          %  now we change it
  126. %      0 dmystr 6 string copy       %  get a copy of the font name
  127.        0 nn put
  128. %      cvn cvx put                  %  and stick it in the dummy macro
  129.     /ctr 0 N                      %  go, count, and etc.
  130.     [                               %  start next char definition
  131.   } B
  132.  
  133. /E { pop nn dup definefont setfont } B
  134.  
  135. % the following is the only character builder we need.  it looks up the
  136. % char data in the BitMaps array, and paints the character if possible.
  137. % char data  -- a bitmap descriptor -- is an array of length 6, of
  138. %          which the various slots are:
  139.  
  140. /ch-image {ch-data dup type /stringtype ne
  141.       { ctr get /ctr ctr 1 add N } if
  142.    } B                        % the hex string image, or array of same
  143. /ch-width {ch-data dup length 5 sub get} B % the number of pixels across
  144. /ch-height {ch-data dup length 4 sub get} B % the number of pixels tall
  145. /ch-xoff  {128 ch-data dup length 3 sub get sub} B % num pixels right of origin
  146. /ch-yoff  {ch-data dup length 2 sub get 127 sub} B % number of pixels below origin
  147. /ch-dx  {ch-data dup length 1 sub get} B     % number of pixels to next character
  148. /ctr 0 N                      % the current string to read
  149.  
  150. /CharBuilder    % fontdict ch Charbuilder -     -- image one character
  151.      {save 3 1 roll S dup /base get 2 index get S /BitMaps get S get
  152.       /ch-data X pop
  153.       /ctr 0 N
  154.       ch-dx 0 ch-xoff ch-yoff ch-height sub
  155.       ch-xoff ch-width add ch-yoff
  156.       setcachedevice
  157.       ch-width ch-height true
  158.       [1 0 0 -1 -.1 ch-xoff sub ch-yoff .1 add]
  159. % begin code for uncompressed fonts only
  160.       {ch-image} imagemask
  161.       restore
  162.   } B
  163. % end code for uncompressed fonts only
  164. % % here's the alternate code for unpacking compressed fonts
  165. %      /id ch-image N                          % image data
  166. %      /rw ch-width 7 add 8 idiv string N      % row, initially zero
  167. %      /rc 0 N                                 % repeat count
  168. %      /gp 0 N                                 % image data pointer
  169. %      /cp 0 N                                 % column pointer
  170. %      { rc 0 ne { rc 1 sub /rc X rw } { G } ifelse } imagemask
  171. %    restore
  172. % } B
  173. % /G { { id gp get /gp gp 1 add N
  174. %   dup 18 mod S 18 idiv pl S get exec } loop } B
  175. % /adv { cp add /cp X } B
  176. % /chg { rw cp id gp 4 index getinterval putinterval
  177. %         dup gp add /gp X adv } B
  178. % /nd { /cp 0 N rw exit } B
  179. % /lsh { rw cp 2 copy get dup 0 eq { pop 1 } { dup 255 eq { pop 254 }
  180. %     { dup dup add 255 and S 1 and or } ifelse } ifelse put 1 adv } B
  181. % /rsh { rw cp 2 copy get dup 0 eq { pop 128 } { dup 255 eq { pop 127 }
  182. %     { dup 2 idiv S 128 and or } ifelse } ifelse put 1 adv } B
  183. % /clr { rw cp 2 index string putinterval adv } B
  184. % /set { rw cp fillstr 0 4 index getinterval putinterval adv } B
  185. % /fillstr 18 string 0 1 17 { 2 copy 255 put pop } for N
  186. % /pl [
  187. %    { adv 1 chg } bind
  188. %    { adv 1 chg nd } bind
  189. %    { 1 add chg } bind
  190. %    { 1 add chg nd } bind
  191. %    { adv lsh } bind
  192. %    { adv lsh nd } bind
  193. %    { adv rsh } bind
  194. %    { adv rsh nd } bind
  195. %    { 1 add adv } bind
  196. %    { /rc X nd } bind
  197. %    { 1 add set } bind
  198. %    { 1 add clr } bind
  199. %    { adv 2 chg } bind
  200. %    { adv 2 chg nd } bind
  201. %    { pop nd } bind ] N
  202. % % end of code for unpacking compressed fonts
  203.  
  204.                % in the following, the font-cacheing mechanism requires that
  205.                 % a name unique in the particular font be generated
  206.  
  207. /D            % char-data ch D -    -- define character bitmap in current font
  208.   { /cc X
  209.     dup type /stringtype ne {]} if
  210.     nn /base get cc ctr put
  211.     nn /BitMaps get S ctr S
  212.     sf 1 ne {
  213.        dup dup length 1 sub dup 2 index S get sf div put
  214.     } if
  215.     put
  216.     /ctr ctr 1 add N
  217.   } B
  218.  
  219. /I            % a faster D for when the next char follows immediately
  220.   { cc 1 add D } B
  221.  
  222. /bop           % bop -              -- begin a brand new page
  223.   {
  224.     userdict /bop-hook known { bop-hook } if
  225.     /SI save N
  226.     @rigin
  227.     0 0 moveto
  228.   } B
  229.  
  230. /eop           % - eop -              -- end a page
  231.   { % eop-aux  % -- to observe VM usage
  232.     clear SI restore
  233.     showpage
  234.     userdict /eop-hook known { eop-hook } if
  235.   } B
  236.  
  237. /@start         % - @start -            -- start everything
  238.   {
  239.     userdict /start-hook known { start-hook } if
  240.     /VResolution X
  241.     /Resolution X
  242.     1000 div /DVImag X
  243.     /IE 256 array N
  244.     0 1 255 {IE S 1 string dup 0 3 index put cvn put} for
  245.   } B
  246.  
  247. /p /show load N        %  the main character setting routine
  248.  
  249. /RMat [ 1 0 0 -1 0 0 ] N % things we need for rules
  250. /BDot 8 string N
  251. /v {                   % can't use ...fill; it makes rules too big
  252.    /ruley X /rulex X
  253.    V
  254. } B
  255. /V {
  256.    gsave
  257.       TR -.1 -.1 TR rulex ruley scale 1 1
  258.       false RMat { BDot } imagemask
  259.    grestore
  260. } B
  261. /a { moveto } B    % absolute positioning
  262. /delta 0 N         % we need a variable to hold space moves
  263. %
  264. %   The next ten macros allow us to make horizontal motions that
  265. %   are within 4 of the previous horizontal motion with a single
  266. %   character.  These are typically used for spaces.
  267. %
  268. /tail { dup /delta X 0 rmoveto } B
  269. /M { S p delta add tail } B
  270. /b { S p tail } B      % show and tail!
  271. /c { -4 M } B
  272. /d { -3 M } B
  273. /e { -2 M } B
  274. /f { -1 M } B
  275. /g { 0 M } B
  276. /h { 1 M } B
  277. /i { 2 M } B
  278. /j { 3 M } B
  279. /k { 4 M } B
  280. %
  281. %   These next allow us to make small motions (-4..4) cheaply.
  282. %   Typically used for kerns.
  283. %
  284. /l { p -4 w } B
  285. /m { p -3 w } B
  286. /n { p -2 w } B
  287. /o { p -1 w } B
  288. /q { p 1 w } B
  289. /r { p 2 w } B
  290. /s { p 3 w } B
  291. /t { p 4 w } B
  292. %
  293. %   w is good for small horizontal positioning.  x is good for small
  294. %   vertical positioning.  And y is good for a print followed by a move.
  295. %
  296. /w { 0 rmoveto } B
  297. /x { 0 S rmoveto } B
  298. /y { 3 2 roll p a } B
  299. %
  300. %   The bos and eos commands bracket sections of downloaded characters.
  301. %
  302. /bos { /SS save N } B
  303. /eos { clear SS restore } B
  304.  
  305. end  % revert to previous dictionary
  306.