home *** CD-ROM | disk | FTP | other *** search
/ NeXTSTEP 3.3.4.17 [SPARC, PA-RISC] / nextstep33_risc.iso / NextLibrary / TeX / tex / src / dvips / texps.lpro < prev    next >
Text File  |  1992-08-21  |  5KB  |  114 lines

  1. % Thanks for some changes to:
  2. %+ This is TEXPS.LPRO as modified by Rob Hutchings 1992Apr02
  3. %+ My comments are marked as %+ 
  4. % PostScript prolog for using resident fonts.
  5. %+ Provision is made to change the encoding scheme in special instructions. 
  6. %+ This is the only way to access the 20 characters which are present in  
  7. %+ a standard PostScript font, but not included in the standard encoding. 
  8. % All we do is change the widths so that PostScript positioning 
  9. % matches the assumptions of dvips.
  10.  
  11. % The calling sequence defining font foo to be resident font Bar is
  12. %+       /foo wd(n-1) ... wd1 wd0 {specials} n atsize /Bar rf
  13. % where each character width wdi is in pixels,
  14. %+ and atsize is the desired font size, after magnification, in pixels.
  15. % The locations of unused characters are specified by codes of the form
  16. % `m [', denoted m consecutive unused characters, interspersed among the
  17. % widths of the n characters that are actually used.
  18. % The total n + (sum of m's) must equal 256.
  19.  
  20. %
  21. TeXDict begin
  22. %
  23. /rf 
  24. % We copy everything but the FID entry of the resident font
  25. % (just as in section 5.6 of the Red Book second edition).
  26. % We also don't copy UniqueID, even though we want to, because
  27. % this messes up systems that cache the fonts, for some
  28. % PostScript fonts.
  29. { findfont dup length 1 add dict begin 
  30.         { 1 index /FID ne 2 index /UniqueID ne and
  31.           {def} {pop pop} ifelse } forall
  32. % Now the top entry on the stack is the desired size, which
  33. % we use to construct the matrix to transform the font.
  34. % The way we do this is constrained by our desire to leave
  35. % a hook for extending and/or slanting; the hook also allows
  36. % the font to be reencoded extremely cheaply.
  37. % Extend and slant are coded in positions 0 and 2 of the matrix,
  38. % whose default values are atsize and 0
  39.         [ 1 index 0
  40. % at this point we pick up and obey the special instructions
  41.         6 -1 roll exec  
  42. % which changes `{s} n at [ at 0' to `n at [ AT S' (see SlantFont below)
  43. % and then we will insert the rest of the matrix.  It is imperative that
  44. %   VResolution Resolution div mul
  45. % be used instead of
  46. %   VResolution mul Resolution div
  47. % because the latter gives us floating point roundoff error that
  48. % causes the interpreter to think the font isn't square, and this
  49. % leads to substantially deteriorated character glyphs.
  50.         0 exch 5 -1 roll VResolution Resolution div mul neg 0 0 ]
  51. % The top of stack is now `n [ AT 0 S at*aspect 0 0]';
  52. % we use this matrix to scale the font later.  We store it in Metrics,
  53. % which we'll give a different definition to anyway later.
  54.        /Metrics exch def
  55. % Now we start the dictionary of length n that will eventually be Metrics:
  56.         dict begin
  57. % When the font is used the width in the Metrics dictionary will be 
  58. % multiplied by FontMatrix[0] to give the actual character width. 
  59. % We therefore divide each width by FontMatrix[0] before storing.
  60. % (We assume that FontMatrix has the form [ x 0 0 x 0 0 ].)
  61. % Note that using FontMatrix[0] is safer than assuming milli-em units, 
  62. % and that loading the widths on to the stack rather than using an array 
  63. % allows the following simple coding.
  64. %   We also allow marks on the stack ([) to mean that we don't use
  65. %   that character and thus don't need any Metrics entry for it.
  66. %   This saves lots of VM.
  67. %   A sequence of m marks is represented by `m ['.
  68.         Encoding { exch dup type /integertype ne
  69.           {pop pop 1 sub dup 0 le {pop} {[} ifelse}
  70.              {FontMatrix 0 get div Metrics 0 get div def} ifelse } forall
  71. % Now we put the widths dictionary into the font, after grabbing
  72. % the current definition of Metrics back.
  73.         Metrics /Metrics currentdict end def
  74. % and duplicate /foo so that it can be used both in definefont
  75. % and as the name of the macro, which is created first as a 
  76. % non-executable array so that we can put the new font dictionary 
  77. % itself inside the macro;
  78.         [ 2 index currentdict end definefont 3 -1 roll makefont
  79. % this involves a circumlocution to insert the setfont command.
  80.           /setfont load ] 
  81. % Finally the macro is made executable and given the name /foo.
  82.         cvx def } def
  83. %
  84. %   Now here's some oblique hackery... an example of making
  85. %   variants of a resident font look like it is resident.
  86. %+ Since dvips has to repeat the special instructions for each 
  87. %+ incarnation of such a hacked font, there appears to be little virtue in 
  88. %+ the halfway-house of naming the hacked font. I have therefore omitted 
  89. %+ the PostScript names of the modified fonts; 
  90. %+ the defining lines in psfonts could be
  91. %+            rptmro Times-Roman ".167 SlantFont"
  92. %+ My versions of SlantFont and ExtendFont are obeyed in the core of the
  93. %+ main macro, at a point where the stack contains
  94. %+           atsize [ x y
  95. %+ where x and y will become entries 0 and 2 of the transformation matrix.
  96. %   Optionally replace the `slant' by `angle ObliqueSlant';
  97. %   note that the ObliqueSlant of Times-Italic is -15.5 (negative).
  98. %
  99. /ObliqueSlant {   % angle ObliqueSlant slant
  100.     dup sin S cos div neg
  101.     } B
  102.  
  103. % A slant is multiplied by atsize and added to entry 2 (initially 0)
  104. /SlantFont {4 index mul add} def 
  105.  
  106. % An extend is simply a multiplier for entry 0 (initially atsize)
  107. /ExtendFont {3 -1 roll mul exch} def
  108.  
  109. % Since at the point at which the hook is obeyed, the current dictionary
  110. % is that of the new font and writeable, it is trivial to include the
  111. % option of reencoding the font.
  112. /ReEncodeFont {/Encoding exch def} def
  113. end
  114.