2 |
- |
1 |
% Copyright (C) 2000 artofcode LLC. All rights reserved.
|
|
|
2 |
%
|
|
|
3 |
% This software is provided AS-IS with no warranty, either express or
|
|
|
4 |
% implied.
|
|
|
5 |
%
|
|
|
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.
|
|
|
9 |
%
|
|
|
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.
|
|
|
15 |
|
|
|
16 |
% $Id: gs_fapi.ps,v 1.25 2003/04/12 18:08:18 ray Exp $
|
|
|
17 |
% Redefine Font and CIDFont categories with FAPI-handeled fonts.
|
|
|
18 |
|
|
|
19 |
systemdict /.FAPIavailable known { .FAPIavailable } { false } ifelse not {
|
|
|
20 |
(%END FAPI) .skipeof
|
|
|
21 |
} if
|
|
|
22 |
|
|
|
23 |
languagelevel 2 .setlanguagelevel
|
|
|
24 |
|
|
|
25 |
%====================================================================
|
|
|
26 |
% Redefine Font category with FAPIfontmap and CIDFont with FAPIfontmap :
|
|
|
27 |
15 dict begin % a temporary dictionary for local binding.
|
|
|
28 |
|
|
|
29 |
/EmbedFontObjectsQuery mark
|
|
|
30 |
/.EmbedFontObjects 0
|
|
|
31 |
.dicttomark def
|
|
|
32 |
|
|
|
33 |
/is_device_compatible_to_FAPI % - is_device_compatible_to_FAPI <bool>
|
|
|
34 |
{ currentdevice //EmbedFontObjectsQuery .getdeviceparams % <mark> <name> <value> ...
|
|
|
35 |
dup mark eq {
|
|
|
36 |
pop true
|
|
|
37 |
} {
|
|
|
38 |
exch pop exch pop 0 eq
|
|
|
39 |
} ifelse
|
|
|
40 |
% The code above assumes that only the requested parameter is rendered.
|
|
|
41 |
% The commented-out code below may be useful for general case.
|
|
|
42 |
% Keeping it for a while.
|
|
|
43 |
% counttomark 2 idiv {
|
|
|
44 |
% exch /.EmbedFontObjects eq {
|
|
|
45 |
% counttomark 1 add 1 roll cleartomark
|
|
|
46 |
% 0 eq exit
|
|
|
47 |
% } if
|
|
|
48 |
% } repeat
|
|
|
49 |
% dup mark eq {
|
|
|
50 |
% pop true
|
|
|
51 |
% } if
|
|
|
52 |
} bind def
|
|
|
53 |
|
|
|
54 |
%----------------------------- Process FAPIconfig -----------------------
|
|
|
55 |
|
|
|
56 |
/Config
|
|
|
57 |
<<
|
|
|
58 |
%% Replace 1 (FAPIconfig)
|
|
|
59 |
(FAPIconfig) .runlibfile
|
|
|
60 |
>> def
|
|
|
61 |
|
|
|
62 |
%------------------Copy the FontEmulationProcs here : -------------------
|
|
|
63 |
|
|
|
64 |
/FontEmulationProcs /ProcSet findresource {
|
|
|
65 |
def
|
|
|
66 |
} forall
|
|
|
67 |
|
|
|
68 |
currentdict /super.complete_instance currentdict /complete_instance get put
|
|
|
69 |
|
|
|
70 |
%-----------FAPI-specific methods for category redefinition : -----------
|
|
|
71 |
|
|
|
72 |
/RefinePath % <FontDict> /key RefinePath <FontDict>
|
|
|
73 |
{ exch begin
|
|
|
74 |
//Config exch get
|
|
|
75 |
/Path exch
|
|
|
76 |
Path false .file_name_combine not {
|
|
|
77 |
exch
|
|
|
78 |
(Can't combine paths ) print print ( and ) print =
|
|
|
79 |
/RefinePath /configurationerror signalerror
|
|
|
80 |
} if
|
|
|
81 |
def
|
|
|
82 |
currentdict end
|
|
|
83 |
} bind def
|
|
|
84 |
|
|
|
85 |
/complete_instance % <font_name> <FontDict> <Options> complete_FAPI_Font <font_name> <FontDict>
|
|
|
86 |
{ //super.complete_instance exec
|
|
|
87 |
dup /CIDFontName known { /CIDFontPath } { /FontPath } ifelse //RefinePath exec
|
|
|
88 |
} bind def
|
|
|
89 |
|
|
|
90 |
/IsMyRecord % <raw_record> -> <raw_record> bool
|
|
|
91 |
{ dup type /dicttype eq { dup /FAPI known } { false } ifelse
|
|
|
92 |
} bind def
|
|
|
93 |
|
|
|
94 |
/IsActive % <record> IsActive <bool>
|
|
|
95 |
{ pop //is_device_compatible_to_FAPI exec
|
|
|
96 |
} bind def
|
|
|
97 |
|
|
|
98 |
/FontRecordVirtualMethods //RecordVirtualMethodsStub dup length 2 add dict copy begin
|
|
|
99 |
/IsActive //IsActive def
|
|
|
100 |
/MakeInstance % <Name> <record> MakeInstance <Name> <Instance> <size>
|
|
|
101 |
{ //FontOptions //complete_instance exec
|
|
|
102 |
2 copy //GetSize exec
|
|
|
103 |
} bind def
|
|
|
104 |
currentdict end def
|
|
|
105 |
|
|
|
106 |
/CIDFontRecordVirtualMethods //RecordVirtualMethodsStub dup length 3 add dict copy begin
|
|
|
107 |
/GetCSI //TranslateCSI def
|
|
|
108 |
/IsActive //IsActive def
|
|
|
109 |
/MakeInstance % <Name> <record> MakeInstance <Name> <Instance> <size>
|
|
|
110 |
{ //CIDFontOptions //complete_instance exec
|
|
|
111 |
2 copy //GetSize exec
|
|
|
112 |
} bind def
|
|
|
113 |
currentdict end def
|
|
|
114 |
|
|
|
115 |
%----------------------------------The Redefintion---------------------
|
|
|
116 |
|
|
|
117 |
/MappedCategoryRedefiner /ProcSet findresource /Redefine get /Redefine exch def
|
|
|
118 |
|
|
|
119 |
% Redefine the /Font category :
|
|
|
120 |
4 dict begin
|
|
|
121 |
/CategoryName /Font def
|
|
|
122 |
/MapFileName (FAPIfontmap) def
|
|
|
123 |
/VerifyMap { pop } bind def
|
|
|
124 |
/PreprocessRecord % <map> <Name> <raw_record> PreprocessRecord <map> <Name> <record> <bool>
|
|
|
125 |
{ //IsMyRecord exec dup {
|
|
|
126 |
pop dup /RecordVirtualMethods //FontRecordVirtualMethods put
|
|
|
127 |
true
|
|
|
128 |
} if
|
|
|
129 |
} bind def
|
|
|
130 |
currentdict end Redefine
|
|
|
131 |
|
|
|
132 |
% Redefine the /CIDFont category :
|
|
|
133 |
4 dict begin
|
|
|
134 |
/CategoryName /CIDFont def
|
|
|
135 |
/MapFileName (FAPIcidfmap) def
|
|
|
136 |
/VerifyMap { pop } bind def
|
|
|
137 |
/PreprocessRecord % <map> <Name> <raw_record> PreprocessRecord <map> <Name> <record> <bool>
|
|
|
138 |
{ //IsMyRecord exec dup {
|
|
|
139 |
pop dup /RecordVirtualMethods //CIDFontRecordVirtualMethods put
|
|
|
140 |
true
|
|
|
141 |
} if
|
|
|
142 |
} bind def
|
|
|
143 |
currentdict end Redefine
|
|
|
144 |
|
|
|
145 |
%==================== A hook for buildfont* operators ====================
|
|
|
146 |
|
|
|
147 |
% The procedure .FAPIhook redirects PS fonts to FAPI on necessity.
|
|
|
148 |
% This depends on the following conditions :
|
|
|
149 |
%
|
|
|
150 |
% 1. If font dictionary has /FAPI entry, it is a font listed in FAPIconfig.FontPath,
|
|
|
151 |
% and must be build with .FAPIrebuildfont, or a copy of a font, which was
|
|
|
152 |
% built with .FAPIrebuildfont .
|
|
|
153 |
%
|
|
|
154 |
% 2. If the font dictionary has /PathLoad entry, and has no /FAPI entry,
|
|
|
155 |
% it is an installed PS font, which is described in lib/fontmap or
|
|
|
156 |
% in GS_FONTPATH. .loadfont inserts /PathLoad entry for this case
|
|
|
157 |
% (see gs_fonts.ps).
|
|
|
158 |
%
|
|
|
159 |
% Installed fonts are being loaded with GS font loader,
|
|
|
160 |
% the they are passed to FAPI is same way as embedded fonts are.
|
|
|
161 |
% We do so because UFST cannot read fonts, which don't
|
|
|
162 |
% follow Type 1/42 file format strongly.
|
|
|
163 |
%
|
|
|
164 |
% 3. Executing .loadfont, we place /FAPI_hook_disable in the 0th
|
|
|
165 |
% element of some procedure on the execution stack - see gs_fonts.ps .
|
|
|
166 |
% If FAPI_hook finds /FAPI_hook_disable in there,
|
|
|
167 |
% it knows that it is called for a disk font during
|
|
|
168 |
% its internal definefont.
|
|
|
169 |
%
|
|
|
170 |
% 4. If font dictionary has no /FAPI entry, and has no /Path entry,
|
|
|
171 |
% and if we are not in .loadfont context, it is an embedded font.
|
|
|
172 |
%
|
|
|
173 |
% 5. Two entries to be defined in lib/FAPIconfig to control the hooking of PS fonts :
|
|
|
174 |
% HookDiskFonts and HookEmbeddedFonts .
|
|
|
175 |
% They specify arrays of font types (integers) to be redirected with FAPI.
|
|
|
176 |
% HookDiskFonts controls disk PS fonts (which fall into (2) and (3) ).
|
|
|
177 |
% HookEmbeddedFonts controls fonts being embedded into documents.
|
|
|
178 |
%
|
|
|
179 |
% 7. We apply the operator .passtoFAPI for checking whether FAPI can handle a font.
|
|
|
180 |
% If so, we insert /FAPI entry into the font dictionary and convert it
|
|
|
181 |
% with .FAPIrebuildfont . Otherwise the font is handled with the native GS font renderer.
|
|
|
182 |
|
|
|
183 |
/FAPI_hook_debug % <proc> FAPI_hook_debug -
|
|
|
184 |
FAPIDEBUG { {exec} } { {pop} } ifelse
|
|
|
185 |
bind def
|
|
|
186 |
|
|
|
187 |
/FAPI_hook_warn % <proc> FAPI_hook_debug -
|
|
|
188 |
QUIET { {pop} } { {exec} } ifelse
|
|
|
189 |
bind def
|
|
|
190 |
|
|
|
191 |
/FAPI_is_hook_disabled % - FAPI_is_hook_disabled <bool>
|
|
|
192 |
{ % checks whether execution stack contains packedarray started with /FAPI_hook_disable .
|
|
|
193 |
/FAPI_hook_disable /MappedCategoryRedefiner /ProcSet findresource /execstack_lookup get exec
|
|
|
194 |
null ne
|
|
|
195 |
} bind def
|
|
|
196 |
|
|
|
197 |
/FAPIhook_aux % <string|name> <font_dict> .FAPIhook <string|name> <font>
|
|
|
198 |
{ % name <<font>>
|
|
|
199 |
{ (FAPIhook ) print 1 index = } //FAPI_hook_debug exec
|
|
|
200 |
dup /FAPI known {
|
|
|
201 |
{ //PrintFontRef exec ( is mapped to FAPI=) print dup /FAPI get = } //FAPI_hook_warn exec
|
|
|
202 |
true //.FAPIrebuildfont //ChooseDecoding exec
|
|
|
203 |
} {
|
|
|
204 |
dup /PathLoad known dup {
|
|
|
205 |
{ (PathLoad known for the font ) print //PrintFontRef exec (.) = } //FAPI_hook_debug exec
|
|
|
206 |
} {
|
|
|
207 |
pop //FAPI_is_hook_disabled exec dup
|
|
|
208 |
{ pop
|
|
|
209 |
{ (FAPIhook is in .loadfont context for the font ) print //PrintFontRef exec (.) = } //FAPI_hook_debug exec
|
|
|
210 |
true
|
|
|
211 |
} if
|
|
|
212 |
} ifelse
|
|
|
213 |
{ /HookDiskFonts } { /HookEmbeddedFonts } ifelse
|
|
|
214 |
//Config exch get % name <<font>> [types]
|
|
|
215 |
1 index //GetFontType exec //FindInArray exec % name <<font>> bHook
|
|
|
216 |
{ { (Trying to render the font ) print //PrintFontRef exec ( with FAPI...) = } //FAPI_hook_debug exec
|
|
|
217 |
//.FAPIpassfont {
|
|
|
218 |
{ //PrintFontRef exec ( is being rendered with FAPI=) print dup /FAPI get = } //FAPI_hook_warn exec
|
|
|
219 |
false //.FAPIrebuildfont //ChooseDecoding exec
|
|
|
220 |
} {
|
|
|
221 |
{ (Can't render ) print //PrintFontRef exec ( with FAPI, will do with native GS renderer.) = } //FAPI_hook_warn exec
|
|
|
222 |
} ifelse
|
|
|
223 |
} {
|
|
|
224 |
{ (The font ) print //PrintFontRef exec ( doesn't need to render with FAPI.) = } //FAPI_hook_debug exec
|
|
|
225 |
} ifelse
|
|
|
226 |
} ifelse
|
|
|
227 |
} bind def
|
|
|
228 |
|
|
|
229 |
/FAPIhook % <string|name> <font_dict> .FAPIhook <string|name> <font>
|
|
|
230 |
{ //is_device_compatible_to_FAPI exec
|
|
|
231 |
{ //FAPIhook_aux exec
|
|
|
232 |
} {
|
|
|
233 |
{ (FAPIhook is disabled for the current device.) = } //FAPI_hook_debug exec
|
|
|
234 |
} ifelse
|
|
|
235 |
} bind def
|
|
|
236 |
|
|
|
237 |
% ------------------ Redefine .buildfont* with FAPI : -----------------------
|
|
|
238 |
|
|
|
239 |
/.buildfont1
|
|
|
240 |
{ //.buildfont1 exec //FAPIhook exec
|
|
|
241 |
} bind % 'odef' is below.
|
|
|
242 |
|
|
|
243 |
/.buildfont2
|
|
|
244 |
{ //.buildfont2 exec //FAPIhook exec
|
|
|
245 |
} bind % 'odef' is below.
|
|
|
246 |
|
|
|
247 |
/.buildfont42
|
|
|
248 |
{ //.buildfont42 exec //FAPIhook exec
|
|
|
249 |
} bind % 'odef' is below.
|
|
|
250 |
|
|
|
251 |
/.buildfont9
|
|
|
252 |
{ //.buildfont9 exec //FAPIhook exec
|
|
|
253 |
} bind % 'odef' is below.
|
|
|
254 |
|
|
|
255 |
/.buildfont10
|
|
|
256 |
{ //.buildfont10 exec //FAPIhook exec
|
|
|
257 |
} bind % 'odef' is below.
|
|
|
258 |
|
|
|
259 |
/.buildfont11
|
|
|
260 |
{ //.buildfont11 exec //FAPIhook exec
|
|
|
261 |
} bind % 'odef' is below.
|
|
|
262 |
|
|
|
263 |
end % the temporary dictionary for local binding.
|
|
|
264 |
odef odef odef odef odef odef
|
|
|
265 |
|
|
|
266 |
.setlanguagelevel
|
|
|
267 |
|
|
|
268 |
%END FAPI
|