Debian Codegraph @

Resource/Init/gs_fapi.ps

raw
1 % Copyright (C) 2001-2026 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 % Redefine Font and CIDFont categories with FAPI-handeled fonts.
17
18 systemdict /.FAPIavailable known { //null .FAPIavailable } { //false } ifelse not {
19 (%END FAPI) .skipeof
20 } if
21
22 languagelevel 2 .setlanguagelevel
23
24 %====================================================================
25 % Redefine Font category with FAPIfontmap and CIDFont with FAPIfontmap :
26 15 dict begin % a temporary dictionary for local binding.
27
28 /EmbedFontObjectsQuery mark
29 /.EmbedFontObjects 0
30 .dicttomark def
31
32 %----------------------------- Process FAPIconfig -----------------------
33
34 % The HookDiskFonts and HookEmbeddedFonts take a simple array setting normally.
35 % but if two or more FAPI plugins are built in, they can take a dictionary,
36 % whose contents are the FAPI subtype string of a given plugin as the key,
37 % and an array containing the (sub)set of font types the plugin should handle.
38 % Any repetition of font types is ill advised since the resulting bevhaviour
39 % will depend on the order entries are stored in the dictionary, which is
40 % indeterminate. An attempt to use request a font scaler/renderer which cannot
41 % deal with a given font type will result in the FAPI resorting to it's default
42 % search for a viable plugin.
43 %
44 % As an example, you might want UFST to handle Truetype/Type 42 fonts, and
45 % Freetype to handle others, thus:
46 % /HookDiskFonts << /UFST [11 42] /FreeType [1 2 9] >>
47 % /HookEmbeddedFonts << /UFST [11 42] /FreeType [1 2 9] >>
48
49 /Config
50 <<
51 % If we've got a FAPIConfig, run it now.
52 systemdict /FAPIconfig known
53 {
54 /FAPIconfig .systemvar .runlibfile
55 } if
56
57 % Now setup defaults for any entries not set above - these defaults are correct
58 % for FAPI/Freeetype
59 currentdict /FontPath known not { /FontPath (/Fonts)} if % A default directory for FAPI-handled font files
60 % path in FAPIfontmap.
61 currentdict /CIDFontPath known not { /CIDFontPath (/CIDFonts)} if % A default directory for FAPI-handled CIDfont % files path in FAPIcidfmap.
62 currentdict /HookDiskFonts known not { /HookDiskFonts [1 2 9 11 42] } if % FontType values for disk PS fonts to be
63 % redirected to FAPI.
64 currentdict /HookEmbeddedFonts known not { /HookEmbeddedFonts [1 2 9 11 42] } if % FontType values for embedded PS fonts to be
65 % redirected to FAPI.
66 /ServerOptions 2 dict
67 >> def
68 systemdict /.FAPIconfig //Config put
69
70 /UFST .FAPIavailable
71 {
72 systemdict /UFST_SSdir known
73 {
74 /UFSTFONTDIR UFST_SSdir def
75 systemdict /UFST_SSdir undef
76 }
77 {
78 /UFSTROMFONTDIR (%rom%fontdata/) def
79
80 UFSTROMFONTDIR (mtfonts/pcl45/mt3/plug__xi.fco)
81 concatstrings status
82 {
83 pop pop pop pop
84 /UFSTFONTDIR UFSTROMFONTDIR def
85 }
86 {
87 /UFSTFONTDIR () def
88 } ifelse
89 } ifelse
90
91 systemdict /UFST_PlugIn known not
92 {
93 systemdict /UFST_PlugIn UFSTFONTDIR (mtfonts/pcl45/mt3/plug__xi.fco) concatstrings put
94 } if
95
96 systemdict /FCOfontfile known not
97 {
98 systemdict /FCOfontfile UFSTFONTDIR (mtfonts/pclps2/mt3/pclp2_xj.fco) concatstrings put
99 } if
100
101 systemdict /FCOfontfile2 known not
102 {
103 systemdict /FCOfontfile2 UFSTFONTDIR (mtfonts/pcl45/mt3/wd____xh.fco) concatstrings put
104 } if
105
106 systemdict /FAPIfontmap known not
107 {
108 systemdict /FAPIfontmap (FCOfontmap-PCLPS2) put
109 } if
110 } if
111
112 ()
113 systemdict /UFST_SSdir .knownget {
114 (UFST_SSdir=) exch concatstrings concatstrings
115 } if
116 systemdict /UFST_PlugIn .knownget {
117 1 index length 0 ne {
118 exch .filenamelistseparator concatstrings exch
119 } if
120 (UFST_PlugIn=) exch concatstrings concatstrings
121 } if
122 dup length 0 ne {
123 //Config /ServerOptions get exch /UFST exch put
124 } {
125 pop
126 } ifelse
127
128 %------------------Copy the FontEmulationProcs here : -------------------
129
130 /FontEmulationProcs /ProcSet findresource {
131 def
132 } forall
133
134 currentdict /super.complete_instance currentdict /complete_instance get put
135
136 %-----------FAPI-specific methods for category redefinition : -----------
137
138 /RefinePath % <FontDict> /key RefinePath <FontDict>
139 { exch begin
140 //Config exch get
141 /Path exch
142 Path //false .file_name_combine not {
143 exch
144 (Can't combine paths ) print print ( and ) print =
145 /RefinePath cvx /configurationerror signalerror
146 } if
147 def
148 currentdict end
149 } .internalbind def
150
151 /complete_instance % <font_name> <FontDict> <Options> complete_FAPI_Font <font_name> <FontDict>
152 { //super.complete_instance exec
153 dup /CIDFontName known { /CIDFontPath } { /FontPath } ifelse //RefinePath exec
154 } .internalbind def
155
156 /IsMyRecord % <raw_record> -> <raw_record> bool
157 { dup type /dicttype eq { dup /FAPI known } { //false } ifelse
158 } .internalbind def
159
160 /FontRecordVirtualMethods //RecordVirtualMethodsStub dup length 2 add dict copy begin
161 /IsActive //true def
162 /MakeInstance % <Name> <record> MakeInstance <Name> <Instance> <size>
163 { currentglobal 3 1 roll //true setglobal
164 //FontOptions //complete_instance exec
165 2 copy //GetSize exec
166 4 3 roll setglobal
167 } .internalbind def
168 currentdict end def
169
170 /CIDFontRecordVirtualMethods //RecordVirtualMethodsStub dup length 3 add dict copy begin
171 /GetCSI //TranslateCSI def
172 /IsActive //true def
173 /MakeInstance % <Name> <record> MakeInstance <Name> <Instance> <size>
174 { currentglobal 3 1 roll //true setglobal
175 //CIDFontOptions //complete_instance exec
176 2 copy //GetSize exec
177 4 3 roll setglobal
178 } .internalbind def
179 currentdict end def
180
181 /ReadFCOfontmap: % <path> ReadFCOfontmap: name dict ...
182 {
183 /fontfile exch def
184 {
185 currentfile =string readline not {
186 pop exit
187 } if
188 dup length 0 ne {
189 0 () /SubFileDecode filter
190 dup token not {
191 % A comment line
192 closefile
193 } {
194 dup /EndFCOfontmap cvx eq {
195 pop closefile exit
196 } if
197 exch dup token not {
198 /ReadFCOfontmap: cvx /rangecheck signalerror
199 } if
200 exch dup token not {
201 /StandardEncoding
202 } {
203 dup type /nametype ne {
204 /ReadFCOfontmap: cvx /rangecheck signalerror
205 } if
206 } ifelse
207 findencoding
208 exch dup token not {
209 //null
210 } {
211 dup type /nametype ne {
212 /ReadFCOfontmap: cvx /rangecheck signalerror
213 } if
214 /Decoding findresource
215 } ifelse
216 exch closefile % index name enc dec|null
217 4 3 roll % name enc dec|null index
218 << /Path fontfile
219 /FontType 1
220 /FAPI /UFST
221 /SubfontId counttomark 2 add -1 roll
222 /Decoding counttomark 2 add -1 roll
223 dup //null eq {
224 pop pop
225 } if
226 /Encoding counttomark 2 add -1 roll
227
228 /FontInfo
229 <<
230 /UnderlineThickness 50
231 /Weight (Regular)
232 /version (0.00)
233 /ItalicAngle 0
234 /UnderlinePosition -100
235 /FamilyName ()
236 /Notice ()
237 /FullName ()
238 >>
239 % although we pretend this is a Type 1, the FAPI interface currently
240 % needs an identity FontMatrix
241 /FontMatrix [0.001 0.0 0.0 0.001 0.0 0.0]
242 % we need a fake CharStrings dictionary to placate certain jobs
243 % which try to look inside it
244 /CharStrings
245 <<
246 /.notdef ( )
247 StandardEncoding { ( ) } forall
248 >>
249 % FontBBox will get replaced with valid numbers pulled from the rendering engine
250 /FontBBox [-128 -128 1024 1024] cvx
251 >> % dup { exch == = } forall
252 } ifelse
253 } {
254 pop
255 } ifelse
256 } loop
257 currentdict /fontfile undef
258 } .internalbind def
259
260 %----------------------------------The Redefintion---------------------
261
262 /MappedCategoryRedefiner /ProcSet findresource /Redefine get /Redefine exch def
263
264 % Redefine the /Font category :
265 4 dict begin
266 /CategoryName /Font def
267 /MapFileName systemdict /FAPIfontmap known {/FAPIfontmap .systemvar} {(FAPIfontmap)} ifelse def
268 /VerifyMap { pop } .internalbind def
269 /PreprocessRecord % <map> <Name> <raw_record> PreprocessRecord <map> <Name> <record> <bool>
270 { //IsMyRecord exec dup {
271 pop dup /RecordVirtualMethods //FontRecordVirtualMethods put
272 //true
273 } if
274 } .internalbind def
275 currentdict end Redefine
276
277 % Redefine the /CIDFont category :
278 4 dict begin
279 /CategoryName /CIDFont def
280 /MapFileName systemdict /FAPIcidfmap known {/FAPIcidfmap .systemvar} {(FAPIcidfmap)} ifelse def
281 /VerifyMap { pop } .internalbind def
282 /PreprocessRecord % <map> <Name> <raw_record> PreprocessRecord <map> <Name> <record> <bool>
283 { //IsMyRecord exec dup {
284 pop dup /RecordVirtualMethods //CIDFontRecordVirtualMethods put
285 //true
286 } if
287 } .internalbind def
288 currentdict end Redefine
289
290 %==================== A hook for buildfont* operators ====================
291
292 % The procedure .FAPIhook redirects PS fonts to FAPI on necessity.
293 % This depends on the following conditions :
294 %
295 % 1. If font dictionary has /FAPI entry, it is a font listed in FAPIconfig.FontPath,
296 % and must be build with .FAPIrebuildfont, or a copy of a font, which was
297 % built with .FAPIrebuildfont .
298 %
299 % 2. If the font dictionary has /PathLoad entry, and has no /FAPI entry,
300 % it is an installed PS font, which is described in lib/fontmap or
301 % in GS_FONTPATH. .loadfont inserts /PathLoad entry for this case
302 % (see gs_fonts.ps).
303 %
304 % Installed fonts are being loaded with GS font loader,
305 % the they are passed to FAPI is same way as embedded fonts are.
306 % We do so because UFST cannot read fonts, which don't
307 % follow Type 1/42 file format strongly.
308 %
309 % 3. Executing .loadfont, we place /FAPI_hook_disable in the 0th
310 % element of some procedure on the execution stack - see gs_fonts.ps .
311 % If FAPI_hook finds /FAPI_hook_disable in there,
312 % it knows that it is called for a disk font during
313 % its internal definefont.
314 %
315 % 4. If font dictionary has no /FAPI entry, and has no /Path entry,
316 % and if we are not in .loadfont context, it is an embedded font.
317 %
318 % 5. Two entries to be defined in lib/FAPIconfig to control the hooking of PS fonts :
319 % HookDiskFonts and HookEmbeddedFonts .
320 % They specify arrays of font types (integers) to be redirected with FAPI.
321 % HookDiskFonts controls disk PS fonts (which fall into (2) and (3) ).
322 % HookEmbeddedFonts controls fonts being embedded into documents.
323 %
324 % 7. We apply the operator .passtoFAPI for checking whether FAPI can handle a font.
325 % If so, we insert /FAPI entry into the font dictionary and convert it
326 % with .FAPIrebuildfont . Otherwise the font is handled with the native GS font renderer.
327
328 /FAPI_hook_debug % <proc> FAPI_hook_debug -
329 FAPIDEBUG { {exec} } { {pop} } ifelse
330 bind def
331
332 /FAPI_hook_warn % <proc> FAPI_hook_debug -
333 QUIET { {pop} } { {exec} } ifelse
334 bind def
335
336 /FAPI_is_hook_disabled % - FAPI_is_hook_disabled <bool>
337 { % checks whether execution stack contains packedarray started with /FAPI_hook_disable .
338 /FAPI_hook_disable /MappedCategoryRedefiner /ProcSet findresource /execstack_lookup get exec
339 //null ne
340 } .internalbind def
341
342 /FAPIhook_aux % <string|name> <font_dict> .FAPIhook <string|name> <font>
343 { % name <<font>>
344 { (\nFAPIhook ) print 1 index = flush } //FAPI_hook_debug exec
345 dup /FAPI known {
346 { //PrintFontRef exec ( is mapped to FAPI=) print dup /FAPI get = flush } //FAPI_hook_debug exec
347 //true .FAPIrebuildfont //ChooseDecoding exec
348 } {
349 dup /PathLoad known dup {
350 { (PathLoad known for the font ) print //PrintFontRef exec (.\n) print flush} //FAPI_hook_debug exec
351 } {
352 pop //FAPI_is_hook_disabled exec dup
353 { pop
354 { (FAPIhook is in .loadfont context for the font ) print //PrintFontRef exec (.\n) print flush } //FAPI_hook_debug exec
355 //true
356 } if
357 } ifelse
358 { /HookDiskFonts } { /HookEmbeddedFonts } ifelse
359 //Config exch get % name <<font>> [types]
360
361 dup type /dicttype eq
362 {
363 //false exch
364 {
365 3 index //GetFontType exec //FindInArray exec
366 {
367 2 index exch /FAPIPlugInReq exch put
368 pop //true exit
369 }
370 { pop } ifelse
371 } forall
372 }
373 {
374 1 index //GetFontType exec //FindInArray exec % name <<font>> bHook
375 } ifelse
376
377 { { (Trying to render the font ) print //PrintFontRef exec ( with FAPI...\n) print flush } //FAPI_hook_debug exec
378 .FAPIpassfont {
379 { //PrintFontRef exec ( is being rendered with FAPI=) print dup /FAPI get = flush } //FAPI_hook_debug exec
380 //false .FAPIrebuildfont //ChooseDecoding exec
381 } {
382 { (Can't render ) print //PrintFontRef exec ( with FAPI, will do with native GS renderer.\n) print flush } //FAPI_hook_warn exec
383 } ifelse
384 } {
385 { (The font ) print //PrintFontRef exec ( doesn't need to render with FAPI.\n) print flush } //FAPI_hook_debug exec
386 } ifelse
387
388 % Remove the plugin request from the font dictionary
389 dup /FAPIPlugInReq undef
390 } ifelse
391 } .internalbind def
392
393 /FAPIhook % <string|name> <font_dict> .FAPIhook <string|name> <font>
394 {
395 //FAPIhook_aux exec
396 } .internalbind def
397
398 % ------------------ Redefine .buildfont* with FAPI : -----------------------
399
400 /.buildfont1
401 { //.buildfont1 exec //FAPIhook exec
402 } .internalbind % 'odef' is below.
403
404 /.buildfont2
405 { //.buildfont2 exec //FAPIhook exec
406 } .internalbind % 'odef' is below.
407
408 /.buildfont42
409 { //.buildfont42 exec //FAPIhook exec
410 } .internalbind % 'odef' is below.
411
412 /.buildfont9
413 { //.buildfont9 exec //FAPIhook exec
414 } .internalbind % 'odef' is below.
415
416 /.buildfont10
417 { //.buildfont10 exec //FAPIhook exec
418 } .internalbind % 'odef' is below.
419
420 /.buildfont11
421 { //.buildfont11 exec //FAPIhook exec
422 } .internalbind % 'odef' is below.
423
424 end % the temporary dictionary for local binding.
425 odef odef odef odef odef odef
426
427 % Undef these, not needed outside this file
428 [ /.FAPIavailable /.FAPIpassfont /.FAPIrebuildfont ] systemdict .undefinternalnames
429
430 .setlanguagelevel
431
432 %END FAPI