| 1 |
% Copyright (C) 2001-2023 Artifex Software, Inc. |
| 2 |
% All Rights Reserved. |
| 3 |
% |
| 4 |
% This software is provided AS-IS with no warranty, either express or |
| 5 |
% implied. |
| 6 |
% |
| 7 |
% This software is distributed under license and may not be copied, |
| 8 |
% modified or distributed except as expressly authorized under the terms |
| 9 |
% of the license contained in the file LICENSE in this distribution. |
| 10 |
% |
| 11 |
% Refer to licensing information at http://www.artifex.com or contact |
| 12 |
% Artifex Software, Inc., 39 Mesa Street, Suite 108A, San Francisco, |
| 13 |
% CA 94129, USA, for further information. |
| 14 |
% |
| 15 |
|
| 16 |
% Type 1 font support code. |
| 17 |
|
| 18 |
% The standard representation for PostScript compatible fonts is described |
| 19 |
% in the book "Adobe Type 1 Font Format", published by Adobe Systems Inc. |
| 20 |
|
| 21 |
/t1_glyph_equivalence mark % Exported for pf2afm.ps |
| 22 |
/Odblacute /Ohungarumlaut |
| 23 |
/Udblacute /Uhungarumlaut |
| 24 |
/odblacute /ohungarumlaut |
| 25 |
/udblacute /uhungarumlaut |
| 26 |
.dicttomark def |
| 27 |
|
| 28 |
% Define an augmented version of .buildfont1 that inserts UnderlinePosition |
| 29 |
% and UnderlineThickness entries in FontInfo if they aren't there already, |
| 30 |
% and FontBBox isn't degenerate. |
| 31 |
% (This works around the incorrect assumption, made by many word processors, |
| 32 |
% that these entries are present in the built-in fonts.) |
| 33 |
% Also add alternative names to some glyphs. |
| 34 |
/.buildfont1 |
| 35 |
{ |
| 36 |
.currentglobal 3 1 roll |
| 37 |
dup .gcheck .setglobal |
| 38 |
dup .fontbbox { |
| 39 |
pop pop pop pop |
| 40 |
dup /FontInfo known not |
| 41 |
{ //.growfontdict exec dup /FontInfo 2 dict put } |
| 42 |
if |
| 43 |
dup dup /FontInfo get dup dup |
| 44 |
/UnderlinePosition known exch /UnderlineThickness known and |
| 45 |
{ pop pop % entries already present |
| 46 |
} |
| 47 |
{ dup length 2 add dict .copydict |
| 48 |
dup /UnderlinePosition known not |
| 49 |
{ dup /UnderlinePosition 3 index /FontBBox get |
| 50 |
1 get 2 div put % 1/2 the font descent |
| 51 |
} |
| 52 |
if |
| 53 |
dup /UnderlineThickness known not |
| 54 |
{ dup /UnderlineThickness 3 index /FontBBox get |
| 55 |
dup 3 get exch 1 get sub 20 div put % 1/20 the font height |
| 56 |
} |
| 57 |
if |
| 58 |
1 index /FontInfo get wcheck not { readonly } if |
| 59 |
/FontInfo exch put |
| 60 |
} |
| 61 |
ifelse |
| 62 |
} if |
| 63 |
|
| 64 |
% We want to skip this process if we've already done it, and |
| 65 |
% not do it for embedded fonts. |
| 66 |
dup /.AGLprocessed~GS known not 1 index /PathLoad known and |
| 67 |
{ |
| 68 |
dup /CharStrings get |
| 69 |
% Provide all known aliases for each glyph if |
| 70 |
% substitution is allowed (pf2afm.ps has code |
| 71 |
% to disables it by modifying t1_glyph_equivalence). |
| 72 |
t1_glyph_equivalence length 0 ne |
| 73 |
{ |
| 74 |
% 16 byte scratch string |
| 75 |
% 16 bytes is arbitrary, but should be large enough to hold any "uniXXXX" style name |
| 76 |
//ReverseAdobeGlyphList //AdobeGlyphList 3 -1 roll |
| 77 |
% scratch(string) RAGL(dict) AGL(dict) CharStrings(dict) |
| 78 |
[ 1 index {pop} forall ] % scratch(string) RAGL(dict) AGL(dict) CharStrings(dict) [ glyph names ] |
| 79 |
{ % scratch(string) RAGL(dict) AGL(dict) CharStrings(dict) gname |
| 80 |
1 index 1 index get % scratch(string) RAGL(dict) AGL(dict) CharStrings(dict) cstring gname |
| 81 |
exch dup |
| 82 |
4 index exch .knownget |
| 83 |
{ //true} |
| 84 |
{ % scratch(string) RAGL(dict) AGL(dict) CharStrings(dict) cstring gname |
| 85 |
dup length 16 gt |
| 86 |
{ //false } |
| 87 |
{ |
| 88 |
% if we couldn't derive the code point from the AGL, we might derive it |
| 89 |
% from a formatted "uniXXXX" name. |
| 90 |
dup (0000000000000000) cvs dup (uni) anchorsearch |
| 91 |
{ |
| 92 |
% as luck would have it, we can just replace the "uni" with "16#" |
| 93 |
% to get something we can convert to a number |
| 94 |
pop pop dup 0 (16#) putinterval {cvi} //.internalstopped exec |
| 95 |
{ pop //false} |
| 96 |
{ % scratch(string) RAGL(dict) AGL(dict) CharStrings(dict) cstring gname cpoint |
| 97 |
dup 5 index exch known |
| 98 |
{ //true } |
| 99 |
{ pop //false } |
| 100 |
ifelse |
| 101 |
} ifelse |
| 102 |
} |
| 103 |
{ pop pop //false} |
| 104 |
ifelse |
| 105 |
} ifelse |
| 106 |
} ifelse |
| 107 |
|
| 108 |
{ |
| 109 |
% scratch(string) RAGL(dict) AGL(dict) CharStrings(dict) cstring gname cpoint |
| 110 |
% loop through the array of names for this codepoint |
| 111 |
% if the CharStrings dict doesn't contain an entry for the name |
| 112 |
% create one. |
| 113 |
5 index exch .knownget |
| 114 |
{ % scratch(string) RAGL(dict) AGL(dict) CharStrings(dict) cstring gname aglnames(array) |
| 115 |
{ % scratch(string) RAGL(dict) AGL(dict) CharStrings(dict) cstring gname aglname |
| 116 |
dup 4 index exch known not |
| 117 |
{ % scratch(string) RAGL(dict) AGL(dict) CharStrings(dict) cstring gname aglname |
| 118 |
CFFDEBUG { (\nsetting alias: ) print dup ==only |
| 119 |
( to be the same as glyph: ) print 1 index //== exec } if |
| 120 |
3 index exch 3 index .forceput |
| 121 |
% scratch(string) RAGL(dict) AGL(dict) CharStrings(dict) cstring gname |
| 122 |
}executeonly |
| 123 |
{pop} ifelse |
| 124 |
} executeonly forall |
| 125 |
pop pop |
| 126 |
} executeonly |
| 127 |
{ |
| 128 |
pop pop pop |
| 129 |
} ifelse |
| 130 |
} executeonly |
| 131 |
{ |
| 132 |
% scratch(string) RAGL(dict) AGL(dict) CharStrings(dict) cstring gname |
| 133 |
pop pop |
| 134 |
} ifelse |
| 135 |
} executeonly forall |
| 136 |
3 1 roll pop pop |
| 137 |
} executeonly if |
| 138 |
pop |
| 139 |
dup /.AGLprocessed~GS //true .forceput |
| 140 |
} executeonly if |
| 141 |
|
| 142 |
%% We need to excute the C .buildfont1 in a stopped context so that, if there |
| 143 |
%% are errors we can put the stack back sanely and exit. Otherwise callers won't |
| 144 |
%% be able to execute this redefinied .buildfont1 in a stopped context and still |
| 145 |
%% usefully continue (because the stack will be altered, which it shold not be). |
| 146 |
%% |
| 147 |
%% Uncovered working on bug #696306 and fixed as part of that bug. |
| 148 |
%% |
| 149 |
{//.buildfont1} stopped |
| 150 |
4 3 roll .setglobal |
| 151 |
{//.buildfont1 $error /errorname get signalerror} if |
| 152 |
} .forcebind def % hide .forceput |
| 153 |
|
| 154 |
% container for CloseSource flag (default //true to prevent buildup of file handles) |
| 155 |
/closesourcedict mark |
| 156 |
/CloseSource //true |
| 157 |
.dicttomark readonly def |
| 158 |
/.loadfont1 { % <file> .loadfont1 <errorflag> |
| 159 |
{ % We would like to use `false /PFBDecode filter', |
| 160 |
% but this occasionally produces a whitespace character as |
| 161 |
% the first of an eexec section, so we can't do it. |
| 162 |
% Also, since the real input file never reaches EOF if we are using |
| 163 |
% a PFBDecode filter (the filter stops just after reading the last |
| 164 |
% character), we must explicitly close the real file in this case. |
| 165 |
% Since the file might leave garbage on the operand stack, |
| 166 |
% we have to create a procedure to close the file reliably. |
| 167 |
dup read not { -1 } if |
| 168 |
2 copy .unread 16#80 eq { |
| 169 |
dup //closesourcedict //true /PFBDecode filter cvx |
| 170 |
exch .currentresourcefile eq { |
| 171 |
dup /.execasresource .systemvar |
| 172 |
} { |
| 173 |
{exec} |
| 174 |
} ifelse |
| 175 |
2 index cvlit |
| 176 |
/closefile .systemvar 3 .execn |
| 177 |
} { |
| 178 |
cvx exec |
| 179 |
} ifelse |
| 180 |
} stopped |
| 181 |
} .internalbind def |
| 182 |
|
| 183 |
% If the diskfont feature isn't included, define a dummy .loadfontdict. |
| 184 |
/.loadfontdict where |
| 185 |
{ pop } |
| 186 |
{ /.loadfontdict 0 dict readonly def } |
| 187 |
ifelse |
| 188 |
/.loadfontfile % <file> .loadfontfile - |
| 189 |
{ mark exch |
| 190 |
|
| 191 |
% In order to load fonts reliably, we should push systemdict |
| 192 |
% here. However, Ed Taft says that Adobe implementations |
| 193 |
% push userdict and nothing else! |
| 194 |
% We really would just like systemdict on the stack, |
| 195 |
% but fonts produced by Fontographer require a writable dictionary. |
| 196 |
% However, we can't use any of the other well-known dictionaries |
| 197 |
% (such as userdict), since the whole point of pushing systemdict |
| 198 |
% is to make sure that nothing important has been redefined. |
| 199 |
32 dict begin |
| 200 |
% We can't just use `run', because we want to check for .PFB files. |
| 201 |
currentpacking |
| 202 |
{ //false setpacking //.loadfont1 exec //true setpacking } |
| 203 |
{ //.loadfont1 exec } |
| 204 |
ifelse |
| 205 |
end |
| 206 |
{ stop } if |
| 207 |
cleartomark |
| 208 |
} .internalbind def |
| 209 |
% undefine stuff that is only used internally, and is immediately bound |
| 210 |
currentdict /closesourcedict .undef |
| 211 |
currentdict /.loadfont1 .undef |
| 212 |
|
| 213 |
% Note: this procedure is used for both Type 1 and Type 2 fonts. |
| 214 |
/.type1build { % <font> <code|name> <name> .type1build |
| 215 |
% <font> <code|name> <name> <charstring> |
| 216 |
2 index begin |
| 217 |
dup CharStrings exch .knownget not { |
| 218 |
2 copy eq { exch pop /.notdef exch } if |
| 219 |
QUIET not |
| 220 |
{ (Substituting .notdef for ) print |
| 221 |
=string cvs print ( in the font ) print |
| 222 |
1 index /FontName get = flush |
| 223 |
} |
| 224 |
{ pop } |
| 225 |
ifelse |
| 226 |
/.notdef CharStrings /.notdef get |
| 227 |
} if |
| 228 |
dup type /integertype eq |
| 229 |
currentdict /CFFCharStrings known and |
| 230 |
{ |
| 231 |
CFFCharStrings exch .knownget not |
| 232 |
{ CFFCharStrings 0 get} if |
| 233 |
} if |
| 234 |
end |
| 235 |
} .internalbind def |
| 236 |
|
| 237 |
% Here are the BuildChar and BuildGlyph implementation for Type 1 fonts. |
| 238 |
% The names %Type1BuildChar and %Type1BuildGlyph are known to the interpreter. |
| 239 |
% The real work is done in an operator: |
| 240 |
% <font> <code|name> <name> <charstring> .type1execchar - |
| 241 |
|
| 242 |
(%Type1BuildChar) cvn { % <font> <code> %Type1BuildChar - |
| 243 |
1 index /Encoding get 1 index get //.type1build exec .type1execchar |
| 244 |
} .internalbind def |
| 245 |
(%Type1BuildGlyph) cvn { % <font> <name> %Type1BuildGlyph - |
| 246 |
dup //.type1build exec .type1execchar |
| 247 |
} .internalbind def |
| 248 |
|
| 249 |
1183615869 internaldict begin |
| 250 |
% CCRun is an undocumented procedure provided for Type 4 and Type 0 fonts. |
| 251 |
% Apparently there are two different argument lists for CCRun. |
| 252 |
% Handling the one with the extra Private dictionary requires fabricating |
| 253 |
% a Type 1 font on the fly, since we aren't currently prepared to parse the |
| 254 |
% dictionary any other way. |
| 255 |
/CCRun { % <font> <code|name> <charstring> CCRun - |
| 256 |
% <font> <code|name> <charstring> <Private> CCRun - |
| 257 |
dup type /dicttype eq { |
| 258 |
dup 4 index /Private .knownget { ne } { pop //true } ifelse { |
| 259 |
% The Private dictionary was supplied, and is different |
| 260 |
% from the Private dictionary of the font. Fabricate a |
| 261 |
% Type 1 font with this Private dictionary. Most of the |
| 262 |
% font entries are arbitrary or not needed. |
| 263 |
.currentglobal //false .setglobal 10 dict exch .setglobal begin |
| 264 |
/Private exch def |
| 265 |
/FontType 1 def |
| 266 |
/FontMatrix 3 index /FontMatrix get def |
| 267 |
/Encoding 3 index /Encoding .knownget not { StandardEncoding } if def |
| 268 |
/FontBBox 3 index /FontBBox .knownget not { {0 0 0 0} } if def |
| 269 |
/PaintType 0 def |
| 270 |
/CharStrings 1 dict dup /.notdef () put def |
| 271 |
3 -1 roll pop () currentdict end .buildfont1 exch pop 3 1 roll |
| 272 |
} { |
| 273 |
pop |
| 274 |
} ifelse |
| 275 |
} if |
| 276 |
1 index dup type /integertype eq { |
| 277 |
3 index /Encoding get exch get |
| 278 |
} if exch .type1execchar |
| 279 |
} .internalbind def |
| 280 |
|
| 281 |
% setweightvector is an undocumented procedure that force writes |
| 282 |
% weight vector to the font. Do extra checks for safety. |
| 283 |
/setweightvector { % <font> <vector> setweightvector - |
| 284 |
dup type dup /arraytype ne exch /packedarraytype ne and |
| 285 |
2 index type /dicttype ne or { |
| 286 |
/setweightvector cvx /typecheck signalerror |
| 287 |
} if |
| 288 |
1 index /FontType known not { |
| 289 |
/setweightvector cvx /invalidfont signalerror |
| 290 |
} if |
| 291 |
dup gcheck 2 index gcheck not and { |
| 292 |
/setweightvector cvx /invalidaccess signalerror |
| 293 |
} if |
| 294 |
2 copy /WeightVector exch .forceput |
| 295 |
.setweightvector |
| 296 |
} .forcebind odef |
| 297 |
end |
| 298 |
|
| 299 |
% Register the font types for definefont. |
| 300 |
buildfontdict 1 /.buildfont1 cvx put |
| 301 |
buildfontdict 4 /.buildfont4 cvx put |
| 302 |
|
| 303 |
% Add Type 2 support if applicable. |
| 304 |
/.buildfont2 where not { (%END2) .skipeof } if |
| 305 |
pop |
| 306 |
(%Type2BuildChar) cvn { % <font> <code> %Type2BuildChar - |
| 307 |
1 index /Encoding get 1 index get //.type1build exec .type2execchar |
| 308 |
} .internalbind def |
| 309 |
(%Type2BuildGlyph) cvn { % <font> <name> %Type2BuildGlyph - |
| 310 |
dup //.type1build exec .type2execchar |
| 311 |
} .internalbind def |
| 312 |
buildfontdict 2 /.buildfont2 cvx put |
| 313 |
%END2 |