summaryrefslogtreecommitdiff
path: root/Master/tlpkg/tlgs/Resource/Init/gs_fntem.ps
blob: 8904352deb268077c1acccbbb5ca22769ea41ae6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
% Copyright (C) 2001-2021 Artifex Software, Inc.
% All Rights Reserved.
%
% This software is provided AS-IS with no warranty, either express or
% implied.
%
% This software is distributed under license and may not be copied,
% modified or distributed except as expressly authorized under the terms
% of the license contained in the file LICENSE in this distribution.
%
% Refer to licensing information at http://www.artifex.com or contact
% Artifex Software, Inc.,  1305 Grant Avenue - Suite 200, Novato,
% CA 94945, U.S.A., +1(415)492-9861, for further information.
%

% A procset for Postscript font emulation

% The procedures must not depend on the presence of the
% procset dictionary on the dictionary stack.

languagelevel 2 .setlanguagelevel

%========================= Process xlatmap ====================
mark
%% Replace 1 (xlatmap)
(xlatmap) .runlibfile
.dicttomark dup systemdict exch /.xlatmap_dict exch put

% Convert it into a plain text to simplify the processing in C :
% *(fontkind\0\0\ *(charmap\0decoding\0) ) \0

() exch {
  3 1 roll =string cvs concatstrings (\0\0) concatstrings
  exch
  { =string cvs concatstrings (\0) concatstrings
  } forall
} forall
(\0) concatstrings
systemdict exch /.xlatmap exch put

/FontEmulationProcs 10 dict begin

%-------------------------------Font--------------------------------

/FontCommon  % - font_common -
{ currentdict /PaintType known not {
    /PaintType 0 def
  } if
  currentdict /Encoding .knownget not {
    //StandardEncoding
  } if
  dup type /nametype eq {
    /Encoding findresource
  } if
  /Encoding exch def
} bind def

/FontOptions 5 dict begin
  /make_procs currentdict def
  /NameKey /FontName def
  /TypeKey /FontType def

  1
  {
    currentdict /FontMatrix known not { /FontMatrix [0.001 0 0 0.001 0 0] def } if
    currentdict /FontBBox known not { /FontBBox [-128 -128 1024 1024] cvx def } if % zfapi.ps refines it.
    /Private 0 dict def
    % if we're using the FAPI/UFST code for Microtype fonts,
    % then we've already created a "fake" CharStrings, so don't replace it.
    % See gs_fapi.ps
    currentdict /CharStrings known not {/CharStrings << /.notdef () >> def} if
    //FontCommon exec
  } bind def

  42
  { /FontMatrix [1 0 0 1 0 0] def
    /FontBBox [0 0 1 1] def % zfapi.ps refines it.
    /CharStrings <<>> def
    /sfnts [<00010000 0000 0000 0000 0000 0000>] def
    /GlyphDirectory [] def
    //FontCommon exec
  } bind def

  %fixme : more font types.

currentdict end def

%---------------------------CIDFont---------------------------

/TranslateCSI   % <record> TranslateCSI <CSI>
{ RESMPDEBUG { (fntem TranslateCSI beg ) = } if
  begin
  CSI length 2 eq {
    << /Registry (Adobe)
       /Ordering CSI aload pop
       /Supplement exch
    >>
  } {
    << /Registry CSI 0 get
       /Ordering CSI 1 get
       /Supplement CSI 2 get
    >>
  } ifelse
  end
  RESMPDEBUG { (fntem TranslateCSI end ) = } if
} bind def

/CIDFontCommon
{ /CIDSystemInfo currentdict //TranslateCSI exec def
  currentdict /CSI undef
  /FontBBox [-128 -128 1024 1024] def % zfapi.ps refines it.
  /CIDCount 1 def % ChooseDecoding will set a reasonable value.
} bind def

% GFlyph substitution table for narrow, wide, proportional glyphs -
% used with TrueTypes.

currentpacking //false setpacking
/SubstNWP <<

  % Array format : orig_type, beg_CID, end_CID, subst_beg_CID, subst_type
  % type = (n==narrow, w==wide, p==proportional).

  /Japan1
  { p 1 94 231 n

    p 17 26 780 w
    p 34 59 790 w
    p 66 91 816 w
    w 842 842 7918 w  % fixme: These substitutions require to shift the glyph origin.
    w 844 844 7919 w
    w 846 846 7920 w
    w 848 848 7921 w
    w 850 850 7922 w
    w 876 876 7923 w
    w 908 908 7924 w
    w 910 910 7925 w
    w 912 912 7926 w
    w 914 914 7927 w
    w 925 925 7928 w
    w 927 927 7929 w
    w 929 929 7930 w
    w 931 931 7931 w
    w 933 933 7932 w
    w 959 959 7933 w
    w 991 991 7934 w
    w 993 993 7935 w
    w 995 995 7936 w
    w 1002 1002 7937 w
    w 1009 1009 7938 w
    w 1010 1010 7939 w
  } cvlit

  /Japan2 1 index

  /CNS1
  { p 1 94 13648 n

    p 17 26 333 w
    p 34 59 365 w
    p 66 91 391 w
  } cvlit

  /GB1
  { p 2 94 814 n

    p 2 94 262 w

    p 1 1 7716 n
  } cvlit

  /Korea1
  { p  1 60 8094 n
    p 62 94 8155 n

    p  2 59 264 w
    p 63 94 325 w
  } cvlit

  /Identity []

  /Unicode []

>> def
setpacking

/CIDFontOptions 5 dict begin
  /make_procs currentdict def
  /NameKey /CIDFontName def
  /TypeKey /CIDFontType def

  0
  { //CIDFontCommon exec
    /FDArray [
      14 dict begin
        /FontName CIDFontName =string cvs (%) concatstrings cvn def
        /FontType 1 def
        /FontMatrix [0.001 0 0 0.001 0 0 ] def
        /PaintType 0 def
        /Private 0 dict def
        currentdict
      end
    ] def
    /GlyphDirectory [] def
    /GDBytes 1 def
    /FDBytes 0 def
  } bind def

  1
  { //CIDFontCommon exec
    /FontMatrix [1 0 0 1 0 0] def
    /BuildGlyph {} def
  } bind def

  2
  { //CIDFontCommon exec
    /FontMatrix [1 0 0 1 0 0] def
    /GDBytes 2 def
    /CIDMap <0000> def
    /sfnts [<00010000 0000 0000 0000 0000 0000>] def
    /Encoding [] def
    /CharStrings << /.notdef 0 >> def
  } bind def

currentdict end def

/complete_instance  % <font_name> <FontDict> <Options> complete_FAPI_Font <font_name> <FontDict>
{ begin
  dup length dict copy
  begin
  dup type /nametype ne { cvn } if
  dup NameKey exch def
  currentglobal //true setglobal
  make_procs TypeKey load .knownget {
    exec
  } { setglobal
      /complete_instance cvx /invalidfont signalerror
  } ifelse
  setglobal
  currentdict end
  end
} bind def

/GetFilePath    % <scratch> <Name> <record> GetFilePath <filepath>
{ exch pop                       % (scratch) <record>
  /Path get                      % (scratch) (path)
  exch copy
  % What we make here it is not a complete PS resource.
  % Unable to provide full conformity :
  % the attempt to run this file may fail.
} bind def

/GetSize        % <Name> <record> GetSize <size>
{ pop pop -1 % Unknown size.
  % fixme: probably we could provide an estimation size for some fonts.
} bind def

/RecordVirtualMethodsStub 3 dict begin
  /GetFilePath //GetFilePath def
  /GetSize //GetSize def
currentdict end def

% ---------------------- Decoding helpers ----------------------------

/encodingnames mark
 StandardEncoding /StandardEncoding
 ISOLatin1Encoding /ISOLatin1Encoding
 SymbolEncoding /SymbolEncoding
 DingbatsEncoding /DingbatsEncoding
.dicttomark def

/ChooseDecoding  % <font> ChooseDecoding <font>
{
  { % A loop for 'exit' context.
    dup /Decoding .knownget {
      dup type /nametype eq {
        1 index /CIDFontType known { /CIDDecoding } { /Decoding } ifelse
        findresource 1 index exch /Decoding exch put
      } {
        pop
      } ifelse
      dup /CIDFontType known {
        dup dup /Decoding get /CIDCount get /CIDCount exch put
      } if
      exit
    } if
    dup /CIDFontType known {
      % This is a hooked CID font, no need for Decoding.
      exit
    } if
    % This works when the renderer can't choose character by name,
    % and we cannot determine the charset.
    % Probably this branch is to be removed after UFST problem is fixed.
    dup /Encoding get                                    % <<font>> encoding
    dup type /nametype eq {
      /Decoding findresource 1 index exch /Decoding exch put
    } {
      dup //encodingnames
      exch .knownget {
        { /Decoding findresource } stopped {pop pop //true}{ exch pop 1 index exch /Decoding exch put //false } ifelse
      }
      {
          //true
      } ifelse

      {
        % unknown encoding, or an encoding for which we don't have a
        % predefined decoding, convert it to decoding :
        currentglobal 3 1 roll 2 index gcheck setglobal
        dup length dict begin
        /.notdef 0 def
        0 1 currentdict length 1 sub
        { dup 2 index exch get
          dup dup /.notdef ne exch type /nulltype ne and {
            exch def
          } {
            pop pop
          } ifelse
        } for
        pop
        currentdict end
        3 -1 roll setglobal
        1 index exch /Decoding exch put
      } if
    } ifelse
    exit
  } loop
  dup /CIDFontType known {
    dup /SubstNWP .knownget not {
      dup /CIDSystemInfo get /Ordering get cvn
    } if
    dup type /nametype eq {
      //SubstNWP exch .knownget not {
        []
      } if                                   % <<font>> [SubstNWP]
    } if
    1 index exch /SubstNWP exch put
  } if
} bind def

/PrintFontRef      % <string|name> <font> PrintFontRef <string|name> <font>
{ dup /FontName known { (Font ) } { (CIDFont ) } ifelse print
  1 index =string cvs print
  dup /FontName .knownget not {
    dup /CIDFontName get
  } if                               % <string|name> <font> <fontname>
  dup 3 index ne {
    ( \( aliased from ) print
    =string cvs print ( \)) print
  } {
    pop
  } ifelse
} bind def

/GetFontType       % <font> GetFontType int
{ dup /CIDFontType .knownget {
    exch pop 9 add
  } {
    /FontType get
  } ifelse
} bind def

/FindInArray    % <array> <elem> .array_find <bool>
{ //false 3 1 roll
  exch {                      % false elem elem_i
    1 index eq {              % false elem
       pop //true exch
    } if
  } forall
  pop
} bind def

/ProvideUnicodeDecoding % <font> ProvideUnicodeDecoding <font>
{
  % If the font is maintained by FAPI, or if it is TT-emulated CID font,
  % it already has /Decoding. But its value isn't guaranteeed to
  % be an Unicode decoding. Since we can't determine whether
  % it is an Unicode decoding, we unconditionally load an appropriate Unicode decoding
  % and attach it with /GlyphNames2Unicode entry.
  %
  % Another interesting case is when the font already has /GlyphNames2Unicode.
  % The latter to be used instead. Note that /GlyphNames2Unicode
  % appears only when type 32 fonts are disable (see .pdf_hook_DSC_Creator),
  % but an automatic disabling is not implemented yet.

  currentglobal //true setglobal exch
  dup /FontInfo known not {
    dup /FontInfo 1 dict put
  } if
  { % A loop just for 'exit' context.
    dup /FontInfo get /GlyphNames2Unicode known {
      exit
    } if
    dup /CIDFontType known {
      dup mark exch                                              % bool <font> [ <font>
      dup /CIDSystemInfo get /Ordering get (.Unicode)            % bool <font> [ <font> () ()
      concatstrings cvn                                          % bool <font> [ <font> /Name
      /CIDDecoding { findresource } stopped {
        % Can't provide a decoding, giving up without creating /GlyphNames2Unicode.
        cleartomark exit
      } if                                                       % bool <font> [ <font> <D>
      exch /FontInfo get exch                                    % bool <font> [ <FI> <D>
      /GlyphNames2Unicode exch
      .forceput % FontInfo can be read-only.
      pop                                                        % bool <font>
      exit
    } executeonly if
    dup /FontInfo get                                            % bool <font> <FI>
    /GlyphNames2Unicode /Unicode /Decoding findresource
    .forceput % FontInfo can be read-only.
    exit
  } executeonly loop
  exch setglobal
} .bind executeonly odef % must be bound and hidden for .forceput

currentdict end /ProcSet defineresource pop

.setlanguagelevel