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_fntem.ps,v 1.8 2004/10/25 15:11:37 igor Exp $
17 % A procset for Postscript font emulation
19 % The procedures must not depend on the presence of the
20 % procset dictionary on the dictionary stack.
22 languagelevel 2 .setlanguagelevel
24 %========================= Process xlatmap ====================
26 %% Replace 1 (xlatmap)
28 .dicttomark dup systemdict exch /.xlatmap_dict exch put
30 % Convert it into a plain text to simplify the processing in C :
31 % *(fontkind\0\0\ *(charmap\0decoding\0) ) \0
34 3 1 roll =string cvs concatstrings (\0\0) concatstrings
36 { =string cvs concatstrings (\0) concatstrings
40 systemdict exch /.xlatmap exch put
42 /FontEmulationProcs 10 dict begin
44 %-------------------------------Font--------------------------------
47 /FontCommon % - font_common -
48 { currentdict /PaintType known not {
51 currentdict /Encoding .knownget not {
54 dup type /nametype eq {
55 /Encoding findresource
60 /FontOptions 5 dict begin
61 /make_procs currentdict def
62 /NameKey /FontName def
63 /TypeKey /FontType def
66 { /FontMatrix [0.001 0 0 0.001 0 0] def
67 /FontBBox [-128 -128 1024 1024] def % zfapi.ps refines it.
69 /CharStrings << /.notdef () >> def
74 { /FontMatrix [1 0 0 1 0 0] def
75 /FontBBox [0 0 1 1] def % zfapi.ps refines it.
77 /sfnts [<00010000 0000 0000 0000 0000 0000>] def
78 /GlyphDirectory [] def
82 %fixme : more font types.
86 %---------------------------CIDFont---------------------------
88 /TranslateCSI % <record> TranslateCSI <CSI>
89 { RESMPDEBUG { (fntem TranslateCSI beg ) = } if
92 /Ordering CSI aload pop
96 RESMPDEBUG { (fntem TranslateCSI end ) = } if
100 { /CIDSystemInfo currentdict //TranslateCSI exec def
101 currentdict /CSI undef
102 /FontBBox [-128 -128 1024 1024] def % zfapi.ps refines it.
103 /CIDCount 1 def % ChooseDecoding will set a reasonable value.
106 % GFlyph substitution table for narrow, wide, proportional glyphs -
107 % used with TrueTypes.
109 currentpacking false setpacking
112 % Array format : orig_type, beg_CID, end_CID, subst_beg_CID, subst_type
113 % type = (n==narrow, w==wide, p==proportional).
121 w 842 842 7918 w % fixme: These substitutions require to shift the glyph origin.
176 /CIDFontOptions 5 dict begin
177 /make_procs currentdict def
178 /NameKey /CIDFontName def
179 /TypeKey /CIDFontType def
182 { //CIDFontCommon exec
185 /FontName CIDFontName =string cvs (%) concatstrings cvn def
187 /FontMatrix [0.001 0 0 0.001 0 0 ] def
193 /GlyphDirectory [] def
199 { //CIDFontCommon exec
200 /FontMatrix [1 0 0 1 0 0] def
205 { //CIDFontCommon exec
206 /FontMatrix [1 0 0 1 0 0] def
209 /sfnts [<00010000 0000 0000 0000 0000 0000>] def
211 /CharStrings << /.notdef 0 >> def
216 /complete_instance % <font_name> <FontDict> <Options> complete_FAPI_Font <font_name> <FontDict>
220 1 index NameKey exch def
221 currentglobal true setglobal
222 make_procs TypeKey load .knownget {
225 /complete_instance cvx /invalidfont signalerror
232 /GetFilePath % <scratch> <Name> <record> GetFilePath <filepath>
233 { exch pop % (scratch) <record>
234 /Path get % (scratch) (path)
236 % What we make here it is not a complete PS resource.
237 % Unable to provide full conformity :
238 % the attempt to run this file may fail.
241 /GetSize % <Name> <record> GetSize <size>
242 { pop pop -1 % Unknown size.
243 % fixme: probably we could provide an estimation size for some fonts.
246 /RecordVirtualMethodsStub 3 dict begin
247 /GetFilePath //GetFilePath def
248 /GetSize //GetSize def
251 % ---------------------- Decoding helpers ----------------------------
254 StandardEncoding /StandardEncoding
255 ISOLatin1Encoding /ISOLatin1Encoding
256 SymbolEncoding /SymbolEncoding
257 DingbatsEncoding /DingbatsEncoding
258 /resourceforall where
259 { pop (*) { cvn dup findencoding exch } 1024 string /Encoding resourceforall }
263 /ChooseDecoding % <font> ChooseDecoding <font>
264 { { % A loop for 'exit' context.
265 dup /Decoding .knownget {
266 dup type /nametype eq {
267 1 index /CIDFontType known { /CIDDecoding } { /Decoding } ifelse
268 findresource 1 index exch /Decoding exch put
272 dup /CIDFontType known {
273 dup dup /Decoding get /CIDCount get /CIDCount exch put
277 dup /CIDFontType known {
278 % This is a hooked CID font, no need for Decoding.
281 % This works when the renderer can't choose character by name,
282 % and we cannot determine the charset.
283 % Probably this branch is to be removed after UFST problem is fixed.
284 dup /Encoding get % <<font>> encoding
285 dup type /nametype eq {
286 /Decoding findresource 1 index exch /Decoding exch put
291 /Decoding findresource 1 index exch /Decoding exch put
293 % unknown encoding, convert it to decoding :
294 dup length dict begin
296 0 1 currentdict length 1 sub
297 { dup 2 index exch get
306 1 index exch /Decoding exch put
311 dup /CIDFontType known {
312 dup /SubstNWP .knownget not {
313 dup /CIDSystemInfo get /Ordering get cvn
315 dup type /nametype eq {
316 //SubstNWP exch get % <<font>> [SubstNWP]
318 1 index exch /SubstNWP exch put
322 /PrintFontRef % <string|name> <font> PrintFontRef <string|name> <font>
323 { dup /FontName known { (Font ) } { (CIDFont ) } ifelse print
324 1 index =string cvs print
325 dup /FontName .knownget not {
327 } if % <string|name> <font> <fontname>
329 ( \( aliased from ) print
330 =string cvs print ( \)) print
336 /GetFontType % <font> GetFontType int
337 { dup /CIDFontType .knownget {
344 /FindInArray % <array> <elem> .array_find <bool>
346 exch { % false elem elem_i
347 1 index eq { % false elem
354 /ProvideUnicodeDecoding % <font> ProvideUnicodeDecoding <font>
356 % If the font is maintained by FAPI, or if it is TT-emulated CID font,
357 % it already has /Decoding. But its value isn't guaranteeed to
358 % be an Unicode decoding. Since we can't determine whether
359 % it is an Unicode decoding, we unconditionally load an appropriate Unicode decoding
360 % and attach it with /GlyphNames2Unicode entry.
362 % Another interesting case is when the font already has /GlyphNames2Unicode.
363 % The latter to be used instead. Note that /GlyphNames2Unicode
364 % appears only when type 32 fonts are disable (see .pdf_hook_DSC_Creator),
365 % but an automatic disabling is not implemented yet.
367 currentglobal true setglobal exch
368 dup /FontInfo known not {
369 dup /FontInfo 1 dict put
371 { % A loop just for 'exit' context.
372 dup /FontInfo get /GlyphNames2Unicode known {
375 dup /CIDFontType known {
376 dup mark exch % bool <font> [ <font>
377 dup /CIDSystemInfo get /Ordering get (.Unicode) % bool <font> [ <font> () ()
378 concatstrings cvn % bool <font> [ <font> /Name
379 /CIDDecoding { findresource } stopped {
380 % Can't provide a decoding, giving up without creating /GlyphNames2Unicode.
382 } if % bool <font> [ <font> <D>
383 exch /FontInfo get exch % bool <font> [ <FI> <D>
384 /GlyphNames2Unicode exch
385 .forceput % FontInfo can be read-only.
389 dup /FontInfo get % bool <font> <FI>
390 /GlyphNames2Unicode /Unicode /Decoding findresource
391 .forceput % FontInfo can be read-only.
397 currentdict end /ProcSet defineresource pop