home *** CD-ROM | disk | FTP | other *** search
/ World of Shareware - Software Farm 2 / wosw_2.zip / wosw_2 / PRINTING / DVIPS54.ZIP / DVIPS / TEXC.LPR < prev    next >
Text File  |  1990-11-25  |  10KB  |  301 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. % here's the alternate code for unpacking compressed fonts
  160.      /id ch-image N                          % image data
  161.      /rw ch-width 7 add 8 idiv string N      % row, initially zero
  162.      /rc 0 N                                 % repeat count
  163.      /gp 0 N                                 % image data pointer
  164.      /cp 0 N                                 % column pointer
  165.      { rc 0 ne { rc 1 sub /rc X rw } { G } ifelse } imagemask
  166.    restore
  167. } B
  168. /G { { id gp get /gp gp 1 add N
  169.   dup 18 mod S 18 idiv pl S get exec } loop } B
  170. /adv { cp add /cp X } B
  171. /chg { rw cp id gp 4 index getinterval putinterval
  172.         dup gp add /gp X adv } B
  173. /nd { /cp 0 N rw exit } B
  174. /lsh { rw cp 2 copy get dup 0 eq { pop 1 } { dup 255 eq { pop 254 }
  175.     { dup dup add 255 and S 1 and or } ifelse } ifelse put 1 adv } B
  176. /rsh { rw cp 2 copy get dup 0 eq { pop 128 } { dup 255 eq { pop 127 }
  177.     { dup 2 idiv S 128 and or } ifelse } ifelse put 1 adv } B
  178. /clr { rw cp 2 index string putinterval adv } B
  179. /set { rw cp fillstr 0 4 index getinterval putinterval adv } B
  180. /fillstr 18 string 0 1 17 { 2 copy 255 put pop } for N
  181. /pl [
  182.    { adv 1 chg } bind
  183.    { adv 1 chg nd } bind
  184.    { 1 add chg } bind
  185.    { 1 add chg nd } bind
  186.    { adv lsh } bind
  187.    { adv lsh nd } bind
  188.    { adv rsh } bind
  189.    { adv rsh nd } bind
  190.    { 1 add adv } bind
  191.    { /rc X nd } bind
  192.    { 1 add set } bind
  193.    { 1 add clr } bind
  194.    { adv 2 chg } bind
  195.    { adv 2 chg nd } bind
  196.    { pop nd } bind ] N
  197. % end of code for unpacking compressed fonts
  198.  
  199.                % in the following, the font-cacheing mechanism requires that
  200.                 % a name unique in the particular font be generated
  201.  
  202. /D            % char-data ch D -    -- define character bitmap in current font
  203.   { /cc X
  204.     dup type /stringtype ne {]} if
  205.     nn /base get cc ctr put
  206.     nn /BitMaps get S ctr S
  207.     sf 1 ne {
  208.        dup dup length 1 sub dup 2 index S get sf div put
  209.     } if
  210.     put
  211.     /ctr ctr 1 add N
  212.   } B
  213.  
  214. /I            % a faster D for when the next char follows immediately
  215.   { cc 1 add D } B
  216.  
  217. /bop           % bop -              -- begin a brand new page
  218.   {
  219.     userdict /bop-hook known { bop-hook } if
  220.     /SI save N
  221.     @rigin
  222.     0 0 moveto
  223.   } B
  224.  
  225. /eop           % - eop -              -- end a page
  226.   { % eop-aux  % -- to observe VM usage
  227.     clear SI restore
  228.     showpage
  229.     userdict /eop-hook known { eop-hook } if
  230.   } B
  231.  
  232. /@start         % - @start -            -- start everything
  233.   {
  234.     userdict /start-hook known { start-hook } if
  235.     /VResolution X
  236.     /Resolution X
  237.     1000 div /DVImag X
  238.     /IE 256 array N
  239.     0 1 255 {IE S 1 string dup 0 3 index put cvn put} for
  240.   } B
  241.  
  242. /p /show load N        %  the main character setting routine
  243.  
  244. /RMat [ 1 0 0 -1 0 0 ] N % things we need for rules
  245. /BDot 8 string N
  246. /v {                   % can't use ...fill; it makes rules too big
  247.    /ruley X /rulex X
  248.    V
  249. } B
  250. /V {
  251.    gsave
  252.       TR -.1 -.1 TR rulex ruley scale 1 1
  253.       false RMat { BDot } imagemask
  254.    grestore
  255. } B
  256. /a { moveto } B    % absolute positioning
  257. /delta 0 N         % we need a variable to hold space moves
  258. %
  259. %   The next ten macros allow us to make horizontal motions that
  260. %   are within 4 of the previous horizontal motion with a single
  261. %   character.  These are typically used for spaces.
  262. %
  263. /tail { dup /delta X 0 rmoveto } B
  264. /M { S p delta add tail } B
  265. /b { S p tail } B      % show and tail!
  266. /c { -4 M } B
  267. /d { -3 M } B
  268. /e { -2 M } B
  269. /f { -1 M } B
  270. /g { 0 M } B
  271. /h { 1 M } B
  272. /i { 2 M } B
  273. /j { 3 M } B
  274. /k { 4 M } B
  275. %
  276. %   These next allow us to make small motions (-4..4) cheaply.
  277. %   Typically used for kerns.
  278. %
  279. /l { p -4 w } B
  280. /m { p -3 w } B
  281. /n { p -2 w } B
  282. /o { p -1 w } B
  283. /q { p 1 w } B
  284. /r { p 2 w } B
  285. /s { p 3 w } B
  286. /t { p 4 w } B
  287. %
  288. %   w is good for small horizontal positioning.  x is good for small
  289. %   vertical positioning.  And y is good for a print followed by a move.
  290. %
  291. /w { 0 rmoveto } B
  292. /x { 0 S rmoveto } B
  293. /y { 3 2 roll p a } B
  294. %
  295. %   The bos and eos commands bracket sections of downloaded characters.
  296. %
  297. /bos { /SS save N } B
  298. /eos { clear SS restore } B
  299.  
  300. end  % revert to previous dictionary
  301.