1 % Copyright (C) 2000 artofcode LLC. 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_fapi.ps,v 1.25 2003/04/12 18:08:18 ray Exp $
17 % Redefine Font and CIDFont categories with FAPI-handeled fonts.
19 systemdict /.FAPIavailable known { .FAPIavailable } { false } ifelse not {
23 languagelevel 2 .setlanguagelevel
25 %====================================================================
26 % Redefine Font category with FAPIfontmap and CIDFont with FAPIfontmap :
27 15 dict begin % a temporary dictionary for local binding.
29 /EmbedFontObjectsQuery mark
33 /is_device_compatible_to_FAPI % - is_device_compatible_to_FAPI <bool>
34 { currentdevice //EmbedFontObjectsQuery .getdeviceparams % <mark> <name> <value> ...
38 exch pop exch pop 0 eq
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
54 %----------------------------- Process FAPIconfig -----------------------
58 %% Replace 1 (FAPIconfig)
59 (FAPIconfig) .runlibfile
62 %------------------Copy the FontEmulationProcs here : -------------------
64 /FontEmulationProcs /ProcSet findresource {
68 currentdict /super.complete_instance currentdict /complete_instance get put
70 %-----------FAPI-specific methods for category redefinition : -----------
72 /RefinePath % <FontDict> /key RefinePath <FontDict>
76 Path false .file_name_combine not {
78 (Can't combine paths ) print print ( and ) print =
79 /RefinePath /configurationerror signalerror
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
90 /IsMyRecord % <raw_record> -> <raw_record> bool
91 { dup type /dicttype eq { dup /FAPI known } { false } ifelse
94 /IsActive % <record> IsActive <bool>
95 { pop //is_device_compatible_to_FAPI exec
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
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
115 %----------------------------------The Redefintion---------------------
117 /MappedCategoryRedefiner /ProcSet findresource /Redefine get /Redefine exch def
119 % Redefine the /Font category :
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
130 currentdict end Redefine
132 % Redefine the /CIDFont category :
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
143 currentdict end Redefine
145 %==================== A hook for buildfont* operators ====================
147 % The procedure .FAPIhook redirects PS fonts to FAPI on necessity.
148 % This depends on the following conditions :
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 .
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
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.
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.
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.
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.
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.
183 /FAPI_hook_debug % <proc> FAPI_hook_debug -
184 FAPIDEBUG { {exec} } { {pop} } ifelse
187 /FAPI_hook_warn % <proc> FAPI_hook_debug -
188 QUIET { {pop} } { {exec} } ifelse
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
197 /FAPIhook_aux % <string|name> <font_dict> .FAPIhook <string|name> <font>
199 { (FAPIhook ) print 1 index = } //FAPI_hook_debug exec
201 { //PrintFontRef exec ( is mapped to FAPI=) print dup /FAPI get = } //FAPI_hook_warn exec
202 true //.FAPIrebuildfont //ChooseDecoding exec
204 dup /PathLoad known dup {
205 { (PathLoad known for the font ) print //PrintFontRef exec (.) = } //FAPI_hook_debug exec
207 pop //FAPI_is_hook_disabled exec dup
209 { (FAPIhook is in .loadfont context for the font ) print //PrintFontRef exec (.) = } //FAPI_hook_debug exec
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
218 { //PrintFontRef exec ( is being rendered with FAPI=) print dup /FAPI get = } //FAPI_hook_warn exec
219 false //.FAPIrebuildfont //ChooseDecoding exec
221 { (Can't render ) print //PrintFontRef exec ( with FAPI, will do with native GS renderer.) = } //FAPI_hook_warn exec
224 { (The font ) print //PrintFontRef exec ( doesn't need to render with FAPI.) = } //FAPI_hook_debug exec
229 /FAPIhook % <string|name> <font_dict> .FAPIhook <string|name> <font>
230 { //is_device_compatible_to_FAPI exec
231 { //FAPIhook_aux exec
233 { (FAPIhook is disabled for the current device.) = } //FAPI_hook_debug exec
237 % ------------------ Redefine .buildfont* with FAPI : -----------------------
240 { //.buildfont1 exec //FAPIhook exec
241 } bind % 'odef' is below.
244 { //.buildfont2 exec //FAPIhook exec
245 } bind % 'odef' is below.
248 { //.buildfont42 exec //FAPIhook exec
249 } bind % 'odef' is below.
252 { //.buildfont9 exec //FAPIhook exec
253 } bind % 'odef' is below.
256 { //.buildfont10 exec //FAPIhook exec
257 } bind % 'odef' is below.
260 { //.buildfont11 exec //FAPIhook exec
261 } bind % 'odef' is below.
263 end % the temporary dictionary for local binding.
264 odef odef odef odef odef odef