| 1 |
% Thanks for some changes to: |
| 2 |
%+ This is TEXPS.LPRO as modified by Rob Hutchings 1992Apr02. Public domain. |
| 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 |
FontType 0 ne { |
| 55 |
/Metrics exch def |
| 56 |
% Now we start the dictionary of length n that will eventually be Metrics: |
| 57 |
dict begin |
| 58 |
% When the font is used the width in the Metrics dictionary will be |
| 59 |
% multiplied by FontMatrix[0] to give the actual character width. |
| 60 |
% We therefore divide each width by FontMatrix[0] before storing. |
| 61 |
% (We assume that FontMatrix has the form [ x 0 0 x 0 0 ].) |
| 62 |
% Note that using FontMatrix[0] is safer than assuming milli-em units, |
| 63 |
% and that loading the widths on to the stack rather than using an array |
| 64 |
% allows the following simple coding. |
| 65 |
% We also allow marks on the stack ([) to mean that we don't use |
| 66 |
% that character and thus don't need any Metrics entry for it. |
| 67 |
% This saves lots of VM. |
| 68 |
% A sequence of m marks is represented by `m ['. |
| 69 |
Encoding { exch dup type /integertype ne |
| 70 |
{pop pop 1 sub dup 0 le {pop} {[} ifelse} |
| 71 |
{FontMatrix 0 get div Metrics 0 get div def} ifelse } forall |
| 72 |
% Now we put the widths dictionary into the font, after grabbing |
| 73 |
% the current definition of Metrics back. |
| 74 |
Metrics /Metrics currentdict end def |
| 75 |
} { |
| 76 |
{ 1 index type /nametype eq {exit } if exch pop } loop |
| 77 |
} ifelse |
| 78 |
% and duplicate /foo so that it can be used both in definefont |
| 79 |
% and as the name of the macro, which is created first as a |
| 80 |
% non-executable array so that we can put the new font dictionary |
| 81 |
% itself inside the macro; |
| 82 |
[ 2 index currentdict end definefont 3 -1 roll makefont |
| 83 |
% this involves a circumlocution to insert the setfont command. |
| 84 |
/setfont cvx ] |
| 85 |
% Finally the macro is made executable and given the name /foo. |
| 86 |
cvx def } def |
| 87 |
% |
| 88 |
% Now here's some oblique hackery... an example of making |
| 89 |
% variants of a resident font look like it is resident. |
| 90 |
%+ Since dvips has to repeat the special instructions for each |
| 91 |
%+ incarnation of such a hacked font, there appears to be little virtue in |
| 92 |
%+ the halfway-house of naming the hacked font. I have therefore omitted |
| 93 |
%+ the PostScript names of the modified fonts; |
| 94 |
%+ the defining lines in psfonts could be |
| 95 |
%+ rptmro Times-Roman ".167 SlantFont" |
| 96 |
%+ My versions of SlantFont and ExtendFont are obeyed in the core of the |
| 97 |
%+ main macro, at a point where the stack contains |
| 98 |
%+ atsize [ x y |
| 99 |
%+ where x and y will become entries 0 and 2 of the transformation matrix. |
| 100 |
% Optionally replace the `slant' by `angle ObliqueSlant'; |
| 101 |
% note that the ObliqueSlant of Times-Italic is -15.5 (negative). |
| 102 |
% |
| 103 |
/ObliqueSlant { % angle ObliqueSlant slant |
| 104 |
dup sin S cos div neg |
| 105 |
} B |
| 106 |
|
| 107 |
% A slant is multiplied by atsize and added to entry 2 (initially 0) |
| 108 |
/SlantFont {4 index mul add} def |
| 109 |
|
| 110 |
% An extend is simply a multiplier for entry 0 (initially atsize) |
| 111 |
/ExtendFont {3 -1 roll mul exch} def |
| 112 |
|
| 113 |
% Since at the point at which the hook is obeyed, the current dictionary |
| 114 |
% is that of the new font and writeable, it is trivial to include the |
| 115 |
% option of reencoding the font. |
| 116 |
/ReEncodeFont { |
| 117 |
CharStrings rcheck { |
| 118 |
/Encoding false def dup |
| 119 |
[ exch { |
| 120 |
dup CharStrings exch known not { |
| 121 |
pop /.notdef |
| 122 |
/Encoding true def |
| 123 |
} if |
| 124 |
} forall |
| 125 |
Encoding {] exch pop} {cleartomark} ifelse |
| 126 |
} if |
| 127 |
/Encoding exch def |
| 128 |
} def |
| 129 |
end |