1 % Copyright (C) 1994, 2000 Aladdin Enterprises. All rights reserved.
3 % This software is provided AS-IS with no warranty, either express or
6 % This software is distributed under license and may not be copied,
7 % modified or distributed except as expressly authorized under the terms
8 % of the license contained in the file LICENSE in this distribution.
10 % For more information about licensing, please refer to
11 % http://www.ghostscript.com/licensing/. For information on
12 % commercial licensing, go to http://www.artifex.com/licensing/ or
13 % contact Artifex Software, Inc., 101 Lucas Valley Road #110,
14 % San Rafael, CA 94903, U.S.A., +1(415)492-9861.
16 % $Id: gs_type1.ps,v 1.16 2004/12/15 23:21:33 igor Exp $
17 % Type 1 font support code.
19 % The standard representation for PostScript compatible fonts is described
20 % in the book "Adobe Type 1 Font Format", published by Adobe Systems Inc.
22 % Define an augmented version of .buildfont1 that inserts UnderlinePosition
23 % and UnderlineThickness entries in FontInfo if they aren't there already,
24 % and FontBBox isn't degenerate.
25 % (This works around the incorrect assumption, made by many word processors,
26 % that these entries are present in the built-in fonts.)
31 dup /FontInfo known not
32 { .growfontdict dup /FontInfo 2 dict put }
34 dup dup /FontInfo get dup dup
35 /UnderlinePosition known exch /UnderlineThickness known and
36 { pop pop % entries already present
38 { dup length 2 add dict .copydict
39 dup /UnderlinePosition known not
40 { dup /UnderlinePosition 3 index /FontBBox get
41 1 get 2 div put % 1/2 the font descent
44 dup /UnderlineThickness known not
45 { dup /UnderlineThickness 3 index /FontBBox get
46 dup 3 get exch 1 get sub 20 div put % 1/20 the font height
49 1 index /FontInfo get wcheck not { readonly } if
56 % If the diskfont feature isn't included, define a dummy .loadfontdict.
59 { /.loadfontdict 0 dict readonly def }
61 /.loadfontfile % <file> .loadfontfile -
63 DISKFONTS { .loadfontdict begin } if
64 % In order to load fonts reliably, we should push systemdict
65 % here. However, Ed Taft says that Adobe implementations
66 % push userdict and nothing else!
67 % We really would just like systemdict on the stack,
68 % but fonts produced by Fontographer require a writable dictionary.
69 % However, we can't use any of the other well-known dictionaries
70 % (such as userdict), since the whole point of pushing systemdict
71 % is to make sure that nothing important has been redefined.
73 % We can't just use `run', because we want to check for .PFB files.
75 { false setpacking .loadfont1 true setpacking }
82 % container for CloseSource flag (default true to prevent buildup of file handles)
85 .dicttomark readonly def
86 /.loadfont1 { % <file> .loadfont1 <errorflag>
87 { % We would like to use `false /PFBDecode filter',
88 % but this occasionally produces a whitespace character as
89 % the first of an eexec section, so we can't do it.
90 % Also, since the real input file never reaches EOF if we are using
91 % a PFBDecode filter (the filter stops just after reading the last
92 % character), we must explicitly close the real file in this case.
93 % Since the file might leave garbage on the operand stack,
94 % we have to create a procedure to close the file reliably.
95 dup read not { -1 } if
96 2 copy unread 16#80 eq {
97 dup //closesourcedict //true /PFBDecode filter cvx
98 exch .currentresourcefile eq {
99 dup /.execasresource .systemvar
104 /closefile .systemvar 3 .execn
110 % undefine a dict that is only used internally, and is immediately bound
111 currentdict /closesourcedict .undef
113 % Here are the BuildChar and BuildGlyph implementation for Type 1 fonts.
114 % The names %Type1BuildChar and %Type1BuildGlyph are known to the interpreter.
115 % The real work is done in an operator:
116 % <font> <code|name> <name> <charstring> .type1execchar -
118 (%Type1BuildChar) cvn { % <font> <code> %Type1BuildChar -
119 1 index /Encoding get 1 index get .type1build .type1execchar
121 (%Type1BuildGlyph) cvn { % <font> <name> %Type1BuildGlyph -
122 dup .type1build .type1execchar
124 % Note: this procedure is used for both Type 1 and Type 2 fonts.
125 /.type1build { % <font> <code|name> <name> .type1build
126 % <font> <code|name> <name> <charstring>
128 dup CharStrings exch .knownget not {
129 2 copy eq { exch pop /.notdef exch } if
131 { (Substituting .notdef for ) print
132 =string cvs print ( in the font ) print
133 1 index /FontName get = flush
137 /.notdef CharStrings /.notdef get
142 1183615869 internaldict begin
143 % CCRun is an undocumented procedure provided for Type 4 and Type 0 fonts.
144 % Apparently there are two different argument lists for CCRun.
145 % Handling the one with the extra Private dictionary requires fabricating
146 % a Type 1 font on the fly, since we aren't currently prepared to parse the
147 % dictionary any other way.
148 /CCRun { % <font> <code|name> <charstring> CCRun -
149 % <font> <code|name> <charstring> <Private> CCRun -
150 dup type /dicttype eq {
151 dup 4 index /Private .knownget { ne } { pop true } ifelse {
152 % The Private dictionary was supplied, and is different
153 % from the Private dictionary of the font. Fabricate a
154 % Type 1 font with this Private dictionary. Most of the
155 % font entries are arbitrary or not needed.
156 .currentglobal false .setglobal 10 dict exch .setglobal begin
159 /FontMatrix 3 index /FontMatrix get def
160 /Encoding 3 index /Encoding .knownget not { StandardEncoding } if def
161 /FontBBox 3 index /FontBBox .knownget not { {0 0 0 0} } if def
163 /CharStrings 1 dict dup /.notdef () put def
164 3 -1 roll pop () currentdict end .buildfont1 exch pop 3 1 roll
169 1 index dup type /integertype eq {
170 3 index /Encoding get exch get
171 } if exch .type1execchar
174 % setweightvector is an undocumented procedure that force writes
175 % weight vector to the font. Do extra checks for safety.
176 /setweightvector { % <font> <vector> setweightvector -
177 dup type dup /arraytype ne exch /packedarraytype ne and
178 2 index type /dicttype ne or {
179 /setweightvector cvx /typecheck signalerror
181 1 index /FontType known not {
182 /setweightvector cvx /invalidfont signalerror
184 dup gcheck 2 index gcheck not and {
185 /setweightvector cvx /invalidaccess signalerror
187 2 copy /WeightVector exch .forceput
189 } .bind executeonly def
192 % Register the font types for definefont.
193 buildfontdict 1 /.buildfont1 cvx put
194 buildfontdict 4 /.buildfont4 cvx put
196 % Add Type 2 support if applicable.
197 /.buildfont2 where not { (%END2) .skipeof } if
199 (%Type2BuildChar) cvn { % <font> <code> %Type2BuildChar -
200 1 index /Encoding get 1 index get .type1build .type2execchar
202 (%Type2BuildGlyph) cvn { % <font> <name> %Type2BuildGlyph -
203 dup .type1build .type2execchar
205 buildfontdict 2 /.buildfont2 cvx put