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