1 % Copyright (C) 1996 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_diskf.ps,v 1.4 2002/02/21 21:49:28 giles Exp $
17 % Support for converting Type 1 fonts without eexec encryption to
18 % Type 4 fonts that load individual character outlines on demand.
20 % If DISKFONTS is true, we load individual CharStrings as they are needed.
21 % (This is intended primarily for machines with very small memories.)
22 % Initially, the character definition is the file position of the definition;
23 % this gets replaced with the actual CharString.
24 % Note that if we are loading characters lazily, CharStrings is writable.
26 % _Cstring must be long enough to hold the longest CharString for
27 % a character defined using seac. This is lenIV + 4 * 5 (for the operands
28 % of sbw, assuming div is not used) + 2 (for sbw) + 3 * 5 (for the operands
29 % of seac other than the character codes) + 2 * 2 (for the character codes)
30 % + 2 (for seac), i.e., lenIV + 43.
32 /_Cstring 60 string def
34 % When we initially load the font, we call
35 % <index|charname> <length> <readproc> cskip_C
36 % to skip over each character definition and return the file position instead.
37 % This substitutes for the procedure
38 % <index|charname> <length> string currentfile exch read[hex]string pop
40 % What we actually store in the CharString is fileposition * 1000 + length,
41 % negated if the string is stored in binary form.
44 { exch dup 1000 ge 3 index type /nametype ne or
45 { % This is a Subrs string, or the string is so long we can't represent
46 % its length. Load it now.
49 { % Record the position and length, and skip the string.
50 dup currentfile fileposition 1000 mul add
51 2 index 3 get /readstring cvx eq { neg } if
53 dup _Cstring length idiv
54 { currentfile _Cstring 3 index 3 get exec pop pop
56 _Cstring length mod _Cstring exch 0 exch getinterval
57 currentfile exch 3 -1 roll 3 get exec pop pop
62 % Load a CharString from the file. The font is the top entry
63 % on the dictionary stack.
64 /load_C % <charname> <fileposandlength> load_C -
65 { dup abs 1000 idiv FontFile exch setfileposition
67 .currentglobal CharStrings .gcheck .setglobal exch
69 { neg 1000 mod string FontFile exch readstring }
70 { 1000 mod string FontFile exch readhexstring }
73 % If the CharStrings aren't encrypted on the file, encrypt now.
76 { dup length 5 sub 5 exch getinterval exec }
78 ifelse dup 4 1 roll put
79 % If the character is defined with seac, load its components now.
82 { StandardEncoding exch get dup CharStrings exch get
83 dup type /integertype eq { load_C } { pop pop } ifelse
88 /seac_C % <charstring> seac_C <achar> <bchar> ..or nothing..
89 { dup length _Cstring length le
90 { 4330 exch _Cstring .type1decrypt exch pop
91 dup dup length 2 sub 2 getinterval <0c06> eq % seac
93 Private /lenIV known { Private /lenIV get } { 4 } ifelse
94 exch 1 index sub getinterval
95 % Parse the string just enough to extract the seac information.
96 % We assume that the only possible operators are hsbw, sbw, and seac,
97 % and that there are no 5-byte numbers.
105 { 247 sub 256 mul 108 add 1 1 }
106 { 251 sub -256 mul -108 add -1 1 }
118 counttomark 1 add 2 roll cleartomark % pop all but achar bchar
129 % Define replacement procedures for loading fonts.
130 % If DISKFONTS is true and the body of the font is not encrypted with eexec:
131 % - Prevent the CharStrings from being made read-only.
132 % - Substitute a different CharString-reading procedure.
133 % (eexec disables this because the implicit 'systemdict begin' hides
134 % the redefinitions that make the scheme work.)
136 % - The magic procedures (-|, -!, |-, and |) are defined with
137 % executeonly or readonly;
138 % - The contents of the reading procedures are as defined in bdftops.ps;
139 % - The font includes the code
140 % <font> /CharStrings <CharStrings> readonly put
141 /.loadfontdict 6 dict def mark
142 /begin % push this dict after systemdict
144 //systemdict eq { //.loadfontdict begin } if
148 //.loadfontdict eq currentdict //systemdict eq and { end } if
150 /dict % leave room for FontFile, BuildChar, BuildGlyph
153 /executeonly % for reading procedures
156 /noaccess % for Subrs strings and Private dictionary
159 /readonly % for procedures and CharStrings dictionary
160 { % We want to take the following non-standard actions here:
161 % - If the operand is the CharStrings dictionary, do nothing;
162 % - If the operand is a number (a file position replacing the
163 % actual CharString), do nothing;
164 % - If the operand is either of the reading procedures (-| or -!),
165 % substitute a different one.
166 dup type /dicttype eq % CharStrings or Private
168 { 1 index /CharStrings ne { readonly } if }
169 { dup type /arraytype eq % procedure or data array
170 { dup length 5 ge 1 index xcheck and
171 { dup 0 get /string eq
172 1 index 1 get /currentfile eq and
173 1 index 2 get /exch eq and
174 1 index 3 get dup /readstring eq exch /readhexstring eq or and
175 1 index 4 get /pop eq and
176 { /cskip_C cvx 2 packedarray cvx
186 { dup type /stringtype eq % must be a Subr string
194 /definefont % to insert BuildChar/Glyph and change FontType
195 { dup /FontType get 1 eq
196 { dup /FontType 4 put
197 dup /BuildChar /build_C load put
198 dup /BuildGlyph /build_C load put
202 counttomark 2 idiv { .loadfontdict 3 1 roll put } repeat pop
203 .loadfontdict readonly pop
205 % Define the BuildChar and BuildGlyph procedures for modified fonts.
206 % A single procedure serves for both.
207 /build_C % <font> <code|name> build_C -
209 dup dup type /integertype eq { Encoding exch get } if
210 % Stack: font code|name name
211 dup CharStrings exch .knownget not
212 { 2 copy eq { exch pop /.notdef exch } if
214 { (Substituting .notdef for ) print = flush }
217 /.notdef CharStrings /.notdef get
219 % Stack: font code|name name charstring
220 dup type /integertype eq
221 { load_C end build_C }
222 { end .type1execchar }