Subversion Repositories planix.SVN

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
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_fntem.ps,v 1.8 2004/10/25 15:11:37 igor Exp $
17
% A procset for Postscript font emulation
18
 
19
% The procedures must not depend on the presence of the
20
% procset dictionary on the dictionary stack.
21
 
22
languagelevel 2 .setlanguagelevel
23
 
24
%========================= Process xlatmap ====================
25
mark
26
%% Replace 1 (xlatmap)
27
(xlatmap) .runlibfile
28
.dicttomark dup systemdict exch /.xlatmap_dict exch put
29
 
30
% Convert it into a plain text to simplify the processing in C :
31
% *(fontkind\0\0\ *(charmap\0decoding\0) ) \0
32
 
33
() exch {
34
  3 1 roll =string cvs concatstrings (\0\0) concatstrings
35
  exch
36
  { =string cvs concatstrings (\0) concatstrings
37
  } forall
38
} forall
39
(\0) concatstrings
40
systemdict exch /.xlatmap exch put
41
 
42
/FontEmulationProcs 10 dict begin
43
 
44
%-------------------------------Font--------------------------------
45
 
46
 
47
/FontCommon  % - font_common -
48
{ currentdict /PaintType known not {
49
    /PaintType 0 def
50
  } if
51
  currentdict /Encoding .knownget not {
52
    //StandardEncoding
53
  } if
54
  dup type /nametype eq {
55
    /Encoding findresource
56
  } if
57
  /Encoding exch def
58
} bind def
59
 
60
/FontOptions 5 dict begin
61
  /make_procs currentdict def
62
  /NameKey /FontName def
63
  /TypeKey /FontType def
64
 
65
  1
66
  { /FontMatrix [0.001 0 0 0.001 0 0] def
67
    /FontBBox [-128 -128 1024 1024] def % zfapi.ps refines it.
68
    /Private 0 dict def
69
    /CharStrings << /.notdef () >> def
70
    //FontCommon exec
71
  } bind def
72
 
73
  42
74
  { /FontMatrix [1 0 0 1 0 0] def
75
    /FontBBox [0 0 1 1] def % zfapi.ps refines it.
76
    /CharStrings <<>> def
77
    /sfnts [<00010000 0000 0000 0000 0000 0000>] def
78
    /GlyphDirectory [] def
79
    //FontCommon exec
80
  } bind def
81
 
82
  %fixme : more font types.
83
 
84
currentdict end def
85
 
86
%---------------------------CIDFont---------------------------
87
 
88
/TranslateCSI   % <record> TranslateCSI <CSI>
89
{ RESMPDEBUG { (fntem TranslateCSI beg ) = } if
90
  begin
91
  << /Registry (Adobe) 
92
     /Ordering CSI aload pop 
93
     /Supplement exch 
94
  >>
95
  end
96
  RESMPDEBUG { (fntem TranslateCSI end ) = } if
97
} bind def
98
 
99
/CIDFontCommon
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.
104
} bind def
105
 
106
% GFlyph substitution table for narrow, wide, proportional glyphs - 
107
% used with TrueTypes.
108
 
109
currentpacking false setpacking
110
/SubstNWP << 
111
 
112
  % Array format : orig_type, beg_CID, end_CID, subst_beg_CID, subst_type
113
  % type = (n==narrow, w==wide, p==proportional).
114
 
115
  /Japan1
116
  { p 1 94 231 n    
117
 
118
    p 17 26 780 w
119
    p 34 59 790 w
120
    p 66 91 816 w
121
    w 842 842 7918 w  % fixme: These substitutions require to shift the glyph origin.
122
    w 844 844 7919 w
123
    w 846 846 7920 w
124
    w 848 848 7921 w
125
    w 850 850 7922 w
126
    w 876 876 7923 w
127
    w 908 908 7924 w
128
    w 910 910 7925 w
129
    w 912 912 7926 w
130
    w 914 914 7927 w
131
    w 925 925 7928 w
132
    w 927 927 7929 w
133
    w 929 929 7930 w
134
    w 931 931 7931 w
135
    w 933 933 7932 w
136
    w 959 959 7933 w
137
    w 991 991 7934 w
138
    w 993 993 7935 w
139
    w 995 995 7936 w
140
    w 1002 1002 7937 w
141
    w 1009 1009 7938 w
142
    w 1010 1010 7939 w
143
  } cvlit
144
 
145
  /Japan2 1 index
146
 
147
  /CNS1
148
  { p 1 94 13648 n
149
 
150
    p 17 26 333 w
151
    p 34 59 365 w
152
    p 66 91 391 w
153
  } cvlit
154
 
155
  /GB1
156
  { p 2 94 814 n
157
 
158
    p 2 94 262 w
159
 
160
    p 1 1 7716 n
161
  } cvlit
162
 
163
  /Korea1
164
  { p  1 60 8094 n
165
    p 62 94 8155 n
166
 
167
    p  2 59 264 w
168
    p 63 94 325 w
169
  } cvlit
170
 
171
  /Identity []
172
 
173
>> def
174
setpacking
175
 
176
/CIDFontOptions 5 dict begin
177
  /make_procs currentdict def
178
  /NameKey /CIDFontName def
179
  /TypeKey /CIDFontType def
180
 
181
 
182
  { //CIDFontCommon exec
183
    /FDArray [
184
      14 dict begin
185
        /FontName CIDFontName =string cvs (%) concatstrings cvn def
186
        /FontType 1 def
187
        /FontMatrix [0.001 0 0 0.001 0 0 ] def
188
        /PaintType 0 def
189
        /Private 0 dict def
190
        currentdict
191
      end
192
    ] def
193
    /GlyphDirectory [] def
194
    /GDBytes 1 def
195
    /FDBytes 0 def
196
  } bind def
197
 
198
  1
199
  { //CIDFontCommon exec
200
    /FontMatrix [1 0 0 1 0 0] def
201
    /BuildGlyph {} def
202
  } bind def
203
 
204
  2
205
  { //CIDFontCommon exec
206
    /FontMatrix [1 0 0 1 0 0] def
207
    /GDBytes 2 def
208
    /CIDMap <0000> def
209
    /sfnts [<00010000 0000 0000 0000 0000 0000>] def
210
    /Encoding [] def
211
    /CharStrings << /.notdef 0 >> def
212
  } bind def
213
 
214
currentdict end def
215
 
216
/complete_instance  % <font_name> <FontDict> <Options> complete_FAPI_Font <font_name> <FontDict>
217
{ begin
218
  dup length dict copy
219
  begin
220
  1 index NameKey exch def
221
  currentglobal true setglobal
222
  make_procs TypeKey load .knownget {
223
    exec
224
  } { setglobal
225
      /complete_instance cvx /invalidfont signalerror
226
  } ifelse
227
  setglobal
228
  currentdict end
229
  end
230
} bind def
231
 
232
/GetFilePath    % <scratch> <Name> <record> GetFilePath <filepath>
233
{ exch pop                       % (scratch) <record>
234
  /Path get                      % (scratch) (path)
235
  exch copy
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.
239
} bind def
240
 
241
/GetSize        % <Name> <record> GetSize <size>
242
{ pop pop -1 % Unknown size.
243
  % fixme: probably we could provide an estimation size for some fonts.
244
} bind def
245
 
246
/RecordVirtualMethodsStub 3 dict begin
247
  /GetFilePath //GetFilePath def
248
  /GetSize //GetSize def
249
currentdict end def
250
 
251
% ---------------------- Decoding helpers ----------------------------
252
 
253
/encodingnames mark
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 }
260
 if
261
.dicttomark def
262
 
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
269
      } {
270
        pop
271
      } ifelse
272
      dup /CIDFontType known {
273
        dup dup /Decoding get /CIDCount get /CIDCount exch put
274
      } if
275
      exit
276
    } if
277
    dup /CIDFontType known {
278
      % This is a hooked CID font, no need for Decoding.
279
      exit
280
    } if
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
287
    } {
288
      dup //encodingnames
289
      exch .knownget {
290
        exch pop
291
        /Decoding findresource 1 index exch /Decoding exch put
292
      } {
293
        % unknown encoding, convert it to decoding :
294
        dup length dict begin
295
        /.notdef 0 def
296
 
297
        { dup 2 index exch get 
298
          dup /.notdef ne {
299
            exch def
300
          } {
301
            pop pop
302
          } ifelse
303
        } for
304
        pop
305
        currentdict end
306
        1 index exch /Decoding exch put
307
      } ifelse
308
    } ifelse
309
    exit
310
  } loop
311
  dup /CIDFontType known {
312
    dup /SubstNWP .knownget not {
313
      dup /CIDSystemInfo get /Ordering get cvn
314
    } if
315
    dup type /nametype eq {
316
      //SubstNWP exch get                              % <<font>> [SubstNWP]
317
    } if
318
    1 index exch /SubstNWP exch put
319
  } if
320
} bind def
321
 
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 {
326
    dup /CIDFontName get
327
  } if                               % <string|name> <font> <fontname>
328
  dup 3 index ne {
329
    ( \( aliased from ) print
330
    =string cvs print ( \)) print
331
  } {
332
    pop
333
  } ifelse
334
} bind def
335
 
336
/GetFontType       % <font> GetFontType int
337
{ dup /CIDFontType .knownget {
338
    exch pop 9 add
339
  } {
340
    /FontType get
341
  } ifelse
342
} bind def
343
 
344
/FindInArray    % <array> <elem> .array_find <bool>
345
{ false 3 1 roll
346
  exch {                      % false elem elem_i
347
    1 index eq {              % false elem
348
       pop true exch
349
    } if
350
  } forall
351
  pop
352
} bind def
353
 
354
/ProvideUnicodeDecoding % <font> ProvideUnicodeDecoding <font>
355
{
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.
361
  %
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.
366
 
367
  currentglobal true setglobal exch
368
  dup /FontInfo known not {
369
    dup /FontInfo 1 dict put
370
  } if
371
  { % A loop just for 'exit' context.
372
    dup /FontInfo get /GlyphNames2Unicode known {
373
      exit
374
    } if
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.
381
        cleartomark exit
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.
386
      pop                                                        % bool <font>
387
      exit
388
    } if
389
    dup /FontInfo get                                            % bool <font> <FI>
390
    /GlyphNames2Unicode /Unicode /Decoding findresource
391
    .forceput % FontInfo can be read-only.
392
    exit
393
  } loop
394
  exch setglobal
395
} bind def
396
 
397
currentdict end /ProcSet defineresource pop
398
 
399
.setlanguagelevel