~ubuntu-branches/ubuntu/hardy/ghostscript/hardy

« back to all changes in this revision

Viewing changes to lib/cjkv/tt11util.ps

  • Committer: Bazaar Package Importer
  • Author(s): Till Kamppeter
  • Date: 2007-11-22 12:17:43 UTC
  • mfrom: (1.1.7 upstream)
  • Revision ID: james.westby@ubuntu.com-20071122121743-cd70s3ypq0r243mp
Tags: 8.61.dfsg.1-0ubtuntu1
* New upstream release
  o Final 8.61 release
* debian/patches/09_ijs_krgb_support.dpatch: Adapted to upstream changes.
* debian/rules: Updated CUPS-related variables for "make install" calls.
* debian/rules: Remove /usr/include/ghostscript from the ghostscript
  package, they go into lings-dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
%!
2
 
%
3
 
% Developed by AXE,Inc., BBR Inc. and Turbolinux Inc.
4
 
%   under the technical advice by suzuki toshiya (Hiroshima University)
5
 
% For questions, please send mail to espgs8-cjk@printing-japan.org
6
 
%
7
 
% (C) Copyright 2006 Center of the International Cooperation for
8
 
%     Computerization
9
 
%
10
 
%
11
 
% Based on gs-cjk patches
12
 
% Copyright (C) 2001-2003 gs-cjk project:
13
 
%   Taiji Yamada, Hideyuki Suzuki, Masatake Yamato and suzuki toshiya.
14
 
%   Enhancements by Akira Tagoh and Taiji Yamada, 2005.
15
 
%   All rights reserved.
16
 
%
17
 
%
18
 
% Based on GNU Ghostscript 7.07 and 8.15
19
 
% Copyright (C) 1996-2003 artofcode LLC.  All rights reserved.
20
 
%
21
 
% This software is provided AS-IS with no warranty, either express or
22
 
% implied.
23
 
%
24
 
%
25
 
% This program is free software;  you can redistribute it and/or
26
 
% modify it under the terms of the GNU General Public License as
27
 
% published by the Free Software Foundation; either version 2 of
28
 
% the License, or (at your option) any later version.
29
 
%
30
 
% This program is distributed in the hope that it will be useful,
31
 
% but WITHOUT ANY WARRANTY; without even the implied warranty of
32
 
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
33
 
% See the GNU General Public License for more details.
34
 
%
35
 
% You should have received a copy of the GNU General Public License
36
 
% along with this program; if not, write to the Free Software Foundation,
37
 
% Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
38
 
%
39
 
 
40
 
 
41
 
[
42
 
   /CJKV_DEBUG_TT11
43
 
   /CJKV_DEBUG_OS2
44
 
   /CJKV_DEBUG_GSUB
45
 
] {dup where {pop pop} { currentdict exch false def pop } ifelse} forall
46
 
 
47
 
% ---------------- CIDFontType 2 font loading ---------------- %
48
 
 
49
 
/_cjkv_type11_tmp 15 dict def
50
 
 
51
 
/_cjkv_type11_util 30 dict dup begin
52
 
  
53
 
  % Create a string with array of CIDs
54
 
  % [ <cid1> ... <cidN> ] .cjkv_makecidmapstring <string>
55
 
  /.cjkv_makecidmapstring {
56
 
    CJKV_DEBUG_TT11 { (.cjkv_makecidmapstring\n) print flush } if
57
 
    mark exch cvx exec counttomark                % mark 1..N len
58
 
    dup 2 mul string                              % mark 1..N len s
59
 
    dup 3 -1 roll 1 sub 2 mul -2 0 {              % mark 1..N s s
60
 
      2 copy 5 index -8 bitshift put              % mark 1..N s s j2
61
 
      1 add 4 -1 roll 16#ff and put dup           % mark 1..N-1 s s
62
 
    } for pop                                     % mark s
63
 
    exch pop                                      % s
64
 
  } bind def
65
 
  
66
 
  % Create a string or an array of strings with array of CIDs
67
 
  % [ <cid1> ... <cidN> ] .makecidmap <string>|[<string> ...]
68
 
  %   written by Taiji Yamada <taiji@aihara.co.jp>
69
 
  /.cjkv_makecidmap {
70
 
    CJKV_DEBUG_TT11 { (.cjkv_makecidmap\n) print flush } if
71
 
    dup length maxstring le {
72
 
      _cjkv_type11_util /.cjkv_makecidmapstring get exec
73
 
    } {
74
 
      dup length dup maxstring idiv exch
75
 
      maxstring mod 0 ne { 1 add } if array exch
76
 
      0 1 3 index length 1 sub {
77
 
        dup maxstring mul 1 index 1 add maxstring mul
78
 
        3 index length .min 1 index sub
79
 
        3 index 3 1 roll getinterval
80
 
        _cjkv_type11_util /.cjkv_makecidmapstring get exec
81
 
        3 index 3 1 roll put
82
 
      } for pop
83
 
    } ifelse
84
 
  } bind def
85
 
  
86
 
  % <file> .cjkv_loadttcidfont <cidtype2font>
87
 
  /.cjkv_loadttcidfont {
88
 
    CJKV_DEBUG_TT11 { (+++ .cjkv_loadttcidfont\n) print flush } if
89
 
    _cjkv_type42_util /.cjkv_loadttfonttables get exec
90
 
    .cjkv_makesfnts
91
 
          % CIDFontType2 fonts don't have a cmap: they are indexed by CID.
92
 
    /.cjkv_ttencmapproc false def
93
 
    mark
94
 
    CJKV_DEBUG_TT11 { (+++ mark ok\n) print flush } if
95
 
    .cjkv_ttkeys
96
 
    CJKV_DEBUG_TT11 { (+++ .cjkv_ttkeys finished\n) print flush } if
97
 
    .cjkv_definettcidfont
98
 
    CJKV_DEBUG_TT11 { (+++ .cjkv_definettcidfont finished\n) print flush } if
99
 
  } bind def
100
 
  
101
 
  % - .getgsub -
102
 
  % Defines gsubh, gsubv, gsubh2v and also defines gsubver, gsubfmt
103
 
  %   in the case that GSUB table has 'Single Substitution Format 2'
104
 
  %   which is formally used for vertically oriented glyphs such as CJK fonts.
105
 
  % Written by Hideyuki Suzuki <hideyuki@sat.t.u-tokyo.ac.jp>
106
 
  % Modified by Taiji Yamada <taiji@aihara.co.jp>
107
 
  %
108
 
  % [GSUB - The Glyph Substitution Table]
109
 
  % Index        Size        Type        Name of Entry
110
 
  % -----------------------------------
111
 
  % 0        4        Fixed        Version
112
 
  % 4        2        Offset        ScriptList
113
 
  % 6        2        Offset        FeatureList
114
 
  % 8        2        Offset        LookupList
115
 
  %
116
 
  % [Single Substitution Format 2, Subtable at LookupList]
117
 
  % Index        Size        Type        Name of Entry
118
 
  % -----------------------------------
119
 
  % 0        2        uint16        SubstFormat
120
 
  % 4        2        Offset        Coverage(--)
121
 
  % 6        2        uint16        GlyphCount
122
 
  % 8        2        GlyphID        Substitute(vertically oriented glyphs)
123
 
  % --        2        uint16        SubstFormat
124
 
  % +2        2        uint16        GlyphCount(same as above GlyphCount)
125
 
  % +4        2        GlyphID        GlyphArray(horizontally oriented glyphs)
126
 
  % -----------------------------------
127
 
  % References
128
 
  % 1. http://www.microsoft.com/typography/OTSPEC/gsub.htm
129
 
  %
130
 
  /.cjkv_getgsub {
131
 
    CJKV_DEBUG_TT11 { (***   getgsub start\n) print } if
132
 
    _cjkv_type11_tmp /gsubhog null put
133
 
    _cjkv_type11_tmp /gsubvog null put
134
 
    _cjkv_type11_tmp /gsubh2v null put
135
 
    tabdict /GSUB .knownget { % if
136
 
      CJKV_DEBUG_TT11 { (***      GSUB is known\n) print } if
137
 
      dup /gsubver exch 0 .cjkv_getu32 _cjkv_type11_tmp 3 1 roll put
138
 
      % dup /gsubosl exch 4 .cjkv_getu16 _cjkv_type11_tmp 3 1 roll put
139
 
      % dup /gsubofl exch 6 .cjkv_getu16 _cjkv_type11_tmp 3 1 roll put
140
 
      dup /gsuboll exch 8 .cjkv_getu16 _cjkv_type11_tmp 3 1 roll put
141
 
      CJKV_DEBUG_GSUB {
142
 
        (gsubver: ) print _cjkv_type11_tmp /gsubver get =
143
 
        % (gsubosl: ) print _cjkv_type11_tmp /gsubosl get =
144
 
        % (gsubofl: ) print _cjkv_type11_tmp /gsubofl get =
145
 
        (gsuboll: ) print _cjkv_type11_tmp /gsuboll get =
146
 
      } if
147
 
      % dup /gsubfmt exch _cjkv_type11_tmp /gsuboll get 0 add .cjkv_getu16 _cjkv_type11_tmp 3 1 roll put
148
 
      dup /gsublc exch _cjkv_type11_tmp /gsuboll get 0 add .cjkv_getu16 _cjkv_type11_tmp 3 1 roll put
149
 
      CJKV_DEBUG_GSUB {
150
 
        (gsublc: ) print _cjkv_type11_tmp /gsublc get =
151
 
        % (gsubfmt: ) print _cjkv_type11_tmp /gsubfmt get =
152
 
      } if
153
 
      _cjkv_type11_tmp /gsublc get 0 ne {
154
 
        0 1 _cjkv_type11_tmp /gsublc get 1 sub {
155
 
          2 mul /gsubolt exch 2 index exch _cjkv_type11_tmp /gsuboll get 2 add add .cjkv_getu16 _cjkv_type11_tmp /gsuboll get add _cjkv_type11_tmp 3 1 roll put
156
 
          dup /gsubltype exch _cjkv_type11_tmp /gsubolt get 0 add .cjkv_getu16 _cjkv_type11_tmp 3 1 roll put
157
 
          dup /gsublflag exch _cjkv_type11_tmp /gsubolt get 2 add .cjkv_getu16 _cjkv_type11_tmp 3 1 roll put
158
 
          dup /gsubsubc exch _cjkv_type11_tmp /gsubolt get 4 add .cjkv_getu16 _cjkv_type11_tmp 3 1 roll put
159
 
          CJKV_DEBUG_GSUB {
160
 
            (gsubolt: ) print _cjkv_type11_tmp /gsubolt get =
161
 
            (gsubltype: ) print _cjkv_type11_tmp /gsubltype get =
162
 
            (gsublflag: ) print _cjkv_type11_tmp /gsublflag get =
163
 
            (gsubsubc: ) print _cjkv_type11_tmp /gsubsubc get =
164
 
          } if
165
 
          _cjkv_type11_tmp /gsubsubc get 0 ne {
166
 
            0 1 _cjkv_type11_tmp /gsubsubc get 1 sub {
167
 
              2 mul /gsubost exch 2 index exch _cjkv_type11_tmp /gsubolt get 6 add add .cjkv_getu16 _cjkv_type11_tmp /gsubolt get add _cjkv_type11_tmp 3 1 roll put
168
 
              dup /substfmt exch _cjkv_type11_tmp /gsubost get 0 add .cjkv_getu16 _cjkv_type11_tmp 3 1 roll put
169
 
              CJKV_DEBUG_GSUB {
170
 
                (gsubost: ) print _cjkv_type11_tmp /gsubost get =
171
 
                (substfmt: ) print _cjkv_type11_tmp /substfmt get =
172
 
              } if
173
 
  %           _cjkv_type11_tmp /gsubver get 16#00010000 eq { % ifelse
174
 
              _cjkv_type11_tmp /gsubltype get 1 eq _cjkv_type11_tmp /substfmt get 2 eq and { % ifelse
175
 
                dup /gsubocv exch _cjkv_type11_tmp /gsubost get 2 add .cjkv_getu16 _cjkv_type11_tmp 3 1 roll put
176
 
                dup /gsubglc exch _cjkv_type11_tmp /gsubost get 4 add .cjkv_getu16 _cjkv_type11_tmp 3 1 roll put
177
 
                % hacked by suzuki toshiya at 2001/3/6
178
 
                %dup /gsubvog exch _cjkv_type11_tmp /gsubost get 6 add _cjkv_type11_tmp /gsubglc get getinterval _cjkv_type11_tmp 3 1 roll put
179
 
                %dup /gsubhog exch _cjkv_type11_tmp /gsubost get _cjkv_type11_tmp /gsubocv get add 4 add _cjkv_type11_tmp /gsubglc get getinterval _cjkv_type11_tmp 3 1 roll put
180
 
                dup /gsubvog exch _cjkv_type11_tmp /gsubost get 6 add _cjkv_type11_tmp /gsubglc get 2 mul getinterval _cjkv_type11_tmp 3 1 roll put
181
 
                dup /cvfmt exch _cjkv_type11_tmp /gsubost get _cjkv_type11_tmp /gsubocv get add 0 add .cjkv_getu16 _cjkv_type11_tmp 3 1 roll put
182
 
                _cjkv_type11_tmp /cvfmt get 1 eq {
183
 
                dup /cvglc exch _cjkv_type11_tmp /gsubost get _cjkv_type11_tmp /gsubocv get add 2 add .cjkv_getu16 _cjkv_type11_tmp 3 1 roll put
184
 
                dup /gsubhog exch _cjkv_type11_tmp /gsubost get _cjkv_type11_tmp /gsubocv get add 4 add _cjkv_type11_tmp /cvglc get 2 mul getinterval _cjkv_type11_tmp 3 1 roll put
185
 
                CJKV_DEBUG_GSUB {
186
 
                  (gsubocv: ) print _cjkv_type11_tmp /gsubocv get =
187
 
                  (gsubglc: ) print _cjkv_type11_tmp /gsubglc get =
188
 
                  (cvfmt: ) print _cjkv_type11_tmp /cvfmt get =
189
 
  
190
 
                  (gsubhog->gsubvog ) =
191
 
                  0 2 _cjkv_type11_tmp /gsubhog get length 2 sub { % for
192
 
                    dup
193
 
                    _cjkv_type11_tmp /gsubhog get exch .cjkv_getu16 =only
194
 
                    (->) =only
195
 
                    _cjkv_type11_tmp /gsubvog get exch .cjkv_getu16 =
196
 
                  } for
197
 
                } if
198
 
                  /gsubh2v << 0 2 _cjkv_type11_tmp /gsubhog get length 2 sub {
199
 
                    dup _cjkv_type11_tmp /gsubhog get exch .cjkv_getu16
200
 
                    exch _cjkv_type11_tmp /gsubvog get exch .cjkv_getu16
201
 
                  } for >> _cjkv_type11_tmp 3 1 roll put
202
 
                } {
203
 
                  _cjkv_type11_tmp /cvfmt get 2 eq {
204
 
                    dup /cvrngc exch _cjkv_type11_tmp /gsubost get _cjkv_type11_tmp /gsubocv get add 2 add .cjkv_getu16 _cjkv_type11_tmp 3 1 roll put
205
 
                    dup /cvrngs exch _cjkv_type11_tmp /gsubost get _cjkv_type11_tmp /gsubocv get add 4 add _cjkv_type11_tmp /cvrngc get 6 mul getinterval _cjkv_type11_tmp 3 1 roll put
206
 
                    /gsubh2v << 0 6 _cjkv_type11_tmp /cvrngs get length 6 sub {
207
 
                      dup 0 add /fgid exch _cjkv_type11_tmp /cvrngs get exch .cjkv_getu16 _cjkv_type11_tmp 3 1 roll put
208
 
                      dup 2 add /lgid exch _cjkv_type11_tmp /cvrngs get exch .cjkv_getu16 _cjkv_type11_tmp 3 1 roll put
209
 
                      4 add /cvidx exch _cjkv_type11_tmp /cvrngs get exch .cjkv_getu16 _cjkv_type11_tmp 3 1 roll put
210
 
                      CJKV_DEBUG_GSUB {
211
 
                        (fgid: ) print _cjkv_type11_tmp /fgid get =
212
 
                        (lgid: ) print _cjkv_type11_tmp /lgid get =
213
 
                        (cvidx: ) print _cjkv_type11_tmp /cvidx get =
214
 
                      } if
215
 
                      _cjkv_type11_tmp /fgid get 1 _cjkv_type11_tmp /lgid get {
216
 
                        dup _cjkv_type11_tmp /cvidx get add _cjkv_type11_tmp /fgid get sub 2 mul
217
 
                        _cjkv_type11_tmp /gsubvog get exch .cjkv_getu16
218
 
                      } for
219
 
                    } for >> _cjkv_type11_tmp 3 1 roll put
220
 
                  } {
221
 
                    %(UNKNWON COVERAGE FORMAT.) = flush
222
 
                  } ifelse
223
 
                } ifelse
224
 
              } {
225
 
                %(UNKNOWN GSUB FORMAT.) = flush
226
 
              } ifelse
227
 
  %           } {
228
 
  %             (ILLEGAL GSUB VERSION.) = flush
229
 
  %           } ifelse
230
 
            } for
231
 
          } if
232
 
        } for
233
 
      } if
234
 
      pop
235
 
    } if
236
 
  } bind def
237
 
  
238
 
  % glyphid .gsublookup glyphid
239
 
  % Lookup substitute table. return the origin if not found.
240
 
  %   modified by Taiji Yamada <taiji@aihara.co.jp> and Hideyuki Suzuki
241
 
  /.gsublookup {
242
 
    CJKV_DEBUG_TT11 { (.gsublookup\n) print flush } if
243
 
    dup _cjkv_type11_tmp /gsubh2v get exch .knownget { exch pop } if
244
 
  } bind def
245
 
  
246
 
  % - .cjkv_getos2 -
247
 
  % Defines os2ver, os2cp1, os2cp2
248
 
  %   to detect the kind of CID with the OS/2 table of a TrueType font.
249
 
  % Written by Taiji Yamada <taiji@aihara.co.jp>
250
 
  %
251
 
  % [OS/2 - OS/2 and Windows Metrics]
252
 
  % Index        Size        Type        Name of Entry
253
 
  % -----------------------------------
254
 
  % 0        2        USHORT        version
255
 
  % 2        2        SHORT        xAvgCharWidth
256
 
  % 4        2        USHORT        usWeightClass
257
 
  % 6        2        USHORT        usWidthClass
258
 
  % 8        2        SHORT        fsType
259
 
  % 10        2        SHORT        ySubscriptXSize
260
 
  % 12        2        SHORT        ySubscriptYSize
261
 
  % 14        2        SHORT        ySubscriptXOffset
262
 
  % 16        2        SHORT        ySubscriptYOffset
263
 
  % 18        2        SHORT        ySuperscriptXSize
264
 
  % 20        2        SHORT        ySuperscriptYSize
265
 
  % 22        2        SHORT   ySuperscriptXOffset
266
 
  % 24        2        SHORT        ySuperscriptYOffset
267
 
  % 26        2        SHORT        yStrikeoutSize
268
 
  % 28        2        SHORT        yStrikeoutPosition
269
 
  % 30        2        SHORT        sFamilyClass
270
 
  % 32        10        BYTE        panose[10]
271
 
  % 42        4        ULONG        ulUnicodeRange1
272
 
  % 46        4        ULONG        ulUnicodeRange2
273
 
  % 50        4        ULONG        ulUnicodeRange3
274
 
  % 54        4        ULONG        ulUnicodeRange4
275
 
  % 58        4        CHAR        achVendID[4]
276
 
  % 62        2        USHORT        fsSelection
277
 
  % 64        2        USHORT        usFirstCharIndex
278
 
  % 66        2        USHORT        usLastCharIndex
279
 
  % 68        2        SHORT        sTypoAscender
280
 
  % 70        2        SHORT        sTypoDescender
281
 
  % 72        2        SHORT        sTypoLineGap
282
 
  % 74        2        USHORT        usWinAscent
283
 
  % 76        2        USHORT        usWinDescent
284
 
  % 78        4        ULONG        ulCodePageRange1
285
 
  % 82        4        ULONG        ulCodePageRange2
286
 
  % 86        2        SHORT        sxHeight
287
 
  % 88        2        SHORT        sCapHeight
288
 
  % 90        2        USHORT        usDefaultChar
289
 
  % 92        2        USHORT        usBreakChar
290
 
  % 94        2        USHORT        usMaxContext
291
 
  % -----------------------------------
292
 
  % References
293
 
  % 1. http://www.microsoft.com/typography/OTSPEC/os2.htm
294
 
  %
295
 
  /.cjkv_getos2 {
296
 
    CJKV_DEBUG_TT11 { (.cjkv_getos2\n) print flush } if
297
 
    /os2ver 0 def
298
 
    tabdict (OS/2) cvn .knownget { % if
299
 
      dup /os2ver exch 0 .cjkv_getu16 def
300
 
      os2ver 0 gt { % if
301
 
        %dup /os2typ exch 8 .cjkv_gets16 def
302
 
        %dup /os2fam exch 30 .cjkv_gets16 def
303
 
        dup /os2ur1 exch 42 .cjkv_getu32 def
304
 
        dup /os2ur2 exch 46 .cjkv_getu32 def
305
 
        dup /os2ur3 exch 50 .cjkv_getu32 def
306
 
        dup /os2ur4 exch 54 .cjkv_getu32 def
307
 
        %dup /os2sel exch 62 .cjkv_getu16 def
308
 
        %dup /os2fci exch 64 .cjkv_getu16 def
309
 
        %dup /os2lci exch 64 .cjkv_getu16 def
310
 
        dup /os2cp1 exch 78 .cjkv_getu32 def 
311
 
        dup /os2cp2 exch 82 .cjkv_getu32 def
312
 
        CJKV_DEBUG_OS2 {
313
 
          /tmp 64 string def
314
 
          (os2ver: ) print os2ver 2 tmp cvrs =
315
 
          %(os2typ: ) print os2typ 2 tmp cvrs =
316
 
          %(os2fam: ) print os2fam 2 tmp cvrs =
317
 
          (os2ur1: ) print os2ur1 2 tmp cvrs =
318
 
          (os2ur2: ) print os2ur2 2 tmp cvrs =
319
 
          (os2ur3: ) print os2ur3 2 tmp cvrs =
320
 
          (os2ur4: ) print os2ur4 2 tmp cvrs =
321
 
          %(os2sel: ) print os2sel 2 tmp cvrs =
322
 
          %(os2fci: ) print os2fci 2 tmp cvrs =
323
 
          %(os2lci: ) print os2lci 2 tmp cvrs =
324
 
          (os2cp1: ) print os2cp1 2 tmp cvrs =
325
 
          (os2cp2: ) print os2cp2 2 tmp cvrs =
326
 
          [
327
 
            [ 1 0 bitshift (Latin 1)        ]
328
 
            [ 1 1 bitshift (Latin 2)        ]
329
 
            [ 1 2 bitshift (Cyrillic)        ]
330
 
            [ 1 3 bitshift (Greek)        ]
331
 
            [ 1 4 bitshift (Turkish)        ]
332
 
            [ 1 5 bitshift (Hebrew)        ]
333
 
            [ 1 6 bitshift (Arabic)        ]
334
 
            [ 1 7 bitshift (Baltic)        ]
335
 
            [ 1 8 bitshift (Vietnamese)        ]
336
 
            [ 1 16 bitshift (Thai)        ]
337
 
            [ 1 17 bitshift (Japanese)        ]
338
 
            [ 1 18 bitshift (Simplified Chinese)        ]
339
 
            [ 1 19 bitshift (Korean Wansung)        ]
340
 
            [ 1 20 bitshift (Traditional Chinese)        ]
341
 
            [ 1 21 bitshift (Korean Johab)        ]
342
 
            [ 1 31 bitshift (Symbol)        ]
343
 
          ] { % forall
344
 
            dup 0 get os2cp1 and 0 gt { % if
345
 
              (CodePage: ) print 1 get =
346
 
            } {
347
 
                pop
348
 
            } ifelse
349
 
          } forall
350
 
        } if
351
 
      } if
352
 
      pop
353
 
    } if
354
 
  } bind def
355
 
  
356
 
  % ---------------- CJK TrueType font loading ---------------- %
357
 
  
358
 
  % Written by the gs-cjk project
359
 
  
360
 
  % .parsecmap
361
 
  % push an array as a result of reading a CMap file.
362
 
  % the array is of the following form.
363
 
  %   [ [ [ dst src num ] [ dst src num ] ... [ dst src num ] ]
364
 
  %     [ [ dst src num ] [ dst src num ] ... [ dst src num ] ]
365
 
  %     ...
366
 
  %     [ [ dst src num ] [ dst src num ] ... [ dst src num ] ] ]
367
 
  % each array [dst src num] corresponds to each line within
368
 
  % /begin{bf,cid}{char,range}/end{bf,cid}{char,range} pairs.
369
 
  
370
 
  /.parsecmapdict mark
371
 
  
372
 
    CJKV_DEBUG_TT11 { (.parsecmapdict\n) print flush } if
373
 
    % override system operators
374
 
    /findresource { pop } bind
375
 
    /defineresource { pop pop } bind
376
 
    /dict {}
377
 
    /def { pop pop } bind
378
 
    /dup null
379
 
    /begin { pop } bind
380
 
    /end {}
381
 
    /currentdict null
382
 
  
383
 
    % override CMap operators
384
 
    /usecmap { pop } bind
385
 
    /CMapName null
386
 
    /begincmap { [ } bind
387
 
    /endcmap { ] } bind
388
 
    /begincodespacerange { pop mark } bind
389
 
    /endcodespacerange { cleartomark } bind
390
 
    /beginnotdefrange { pop mark } bind
391
 
    /endnotdefrange { cleartomark } bind
392
 
    /beginbfchar { /parsecmapcounter exch def } bind        % for FromCID CMaps
393
 
    /endbfchar {
394
 
      parsecmapcounter dup array exch 1 sub -1 0 {
395
 
        [ 5 3 roll exch .cjkv_strtoint 1 ]
396
 
        2 index 3 1 roll put
397
 
      } for
398
 
    } bind
399
 
    /beginbfrange { begincidrange }                       % for FromCID CMaps
400
 
    /endbfrange { endcidrange }
401
 
    /begincidchar { beginbfchar }                                % for ToCID CMaps
402
 
    /endcidchar { endbfchar }
403
 
    /begincidrange { /parsecmapcounter exch def } bind        % for ToCID CMaps
404
 
    /endcidrange {
405
 
      parsecmapcounter dup array exch 1 sub -1 0 {
406
 
        [ 6 3 roll 3 1 roll .cjkv_strtoint exch .cjkv_strtoint exch 1 index sub 1 add ]
407
 
        2 index 3 1 roll put
408
 
      } for
409
 
    } bind
410
 
  
411
 
    % misc
412
 
    /parsecmapcounter 0
413
 
  
414
 
  .dicttomark def         % .parsecmapdict
415
 
  
416
 
  
417
 
  /.parsecmapfname 100 string def
418
 
  
419
 
  % <CMapName> .parsecmap <array>
420
 
  % Return the contents of the CMap.  If the CMap is not found, empty array
421
 
  % is returned.  Note that usecmap is ignored because of efficiency.
422
 
  /.parsecmap {
423
 
    CJKV_DEBUG_TT11 { (.parsecmap\n) print flush } if
424
 
    /CMap /Category findresource begin
425
 
    //.parsecmapfname ResourceFileName end        % filename
426
 
    dup status {
427
 
      pop pop pop pop
428
 
      _cjkv_type11_util /.parsecmapdict get begin run end
429
 
    } {
430
 
      pop []
431
 
    } ifelse
432
 
  } bind def
433
 
  
434
 
  % .cjkv_buildcmaptab
435
 
  % construct a cmap table using information obtained from horizontal/vertical
436
 
  % CMaps, ToUnicode CMap, and substition data.
437
 
  
438
 
  % cmap /CMap proc .applyCMap cmap
439
 
  /.applyCMap {
440
 
    CJKV_DEBUG_TT11 { (.applyCMap\n) print flush } if
441
 
    exch _cjkv_type11_util /.parsecmap get exec                        % {} [[[].].]
442
 
    dup length 1 sub -1 0 {                % {} [[[].].] len-1 -1 0 {} for
443
 
      1 index exch get                        % {} [[[].].] [[].]
444
 
      dup length 1 sub -1 0 {                % {} [[[].].] [[].] len-1 -1 0 for {}
445
 
        1 index exch get                        % {} [[[].].] [[].] [ cid gid num ]
446
 
        cvx exec cmapglyphs                % {} [[[].].] [[].] cid gid num gmap
447
 
        3 1 roll .cjkv_safegetinterval {        % {} [[[].].] [[].] cid [gid'..]
448
 
          4 index exec dup cmapglyphs 0 get eq 1 index 0 eq or {
449
 
            % found no glyph
450
 
            pop
451
 
          } {
452
 
            % found a glyph
453
 
            5 index exch 2 index exch .cjkv_safeput
454
 
          } ifelse
455
 
          1 add                                % {} [[[].].] [[].] cid++
456
 
        } forall pop
457
 
      } for                                % {} [[[].].] [[].]
458
 
      pop                                        % {} [[[].].]
459
 
    } for                                        % {} [[[].].]
460
 
    pop pop                                %
461
 
  } bind def
462
 
  
463
 
  % cmap /CMap-V .applyvCMap cmap
464
 
  /.applyvCMap {
465
 
    CJKV_DEBUG_TT11 { (.applyvCMap\n) print flush } if
466
 
    _cjkv_type11_tmp /gsubh2v get null ne {
467
 
      { _cjkv_type11_util /.gsublookup get exec } _cjkv_type11_util /.applyCMap get exec
468
 
    } {
469
 
      { } _cjkv_type11_util /.applyCMap get exec
470
 
    } ifelse
471
 
  } bind def
472
 
  
473
 
  % cmap /CMap-H .applyhCMap cmap
474
 
  /.applyhCMap {
475
 
    CJKV_DEBUG_TT11 { (.applyhCMap\n) print flush } if
476
 
    { } _cjkv_type11_util /.applyCMap get exec
477
 
  } bind def
478
 
  
479
 
  % cmap /CMap-V .applyvCMapUnicode cmap
480
 
  /.applyvCMapUnicode {
481
 
    CJKV_DEBUG_TT11 { (.applyvCMapUnicode\n) print flush } if
482
 
    _cjkv_type11_tmp /gsubh2v get null ne {
483
 
      {
484
 
        dup 16#f900 ge
485
 
        1 index 16#ff00 ge 2 index 16#ff9f le and not
486
 
        and not {
487
 
          _cjkv_type11_util /.gsublookup get exec
488
 
        } if
489
 
      } bind _cjkv_type11_util /.applyCMap get exec
490
 
    } {
491
 
      { } _cjkv_type11_util /.applyCMap get exec
492
 
    } ifelse
493
 
  } bind def
494
 
  
495
 
  % cmap /Adobe-*-* .applyCIDToCode cmap
496
 
  /.applyCIDToCode {
497
 
    CJKV_DEBUG_TT11 { (.applyCIDToCode\n) print flush } if
498
 
    _cjkv_type11_util /.parsecmap get exec
499
 
    {
500
 
      {                           % cmap [ dist cid num ]
501
 
        dup 0 get length 2 gt {   % multi-byte dist is not supported yet.
502
 
          pop
503
 
        } {
504
 
          cvx exec exch           % cmap dist num cid
505
 
          cmapglyphs 4 2 roll     % cmap cid cmapglyphs dist num
506
 
          exch .cjkv_strtoint exch
507
 
          .cjkv_safegetinterval        % cmap cid subcmapglyphs
508
 
          {                       % cmap cid gid
509
 
            2 index 2 index       % cmap cid gid cmap cid
510
 
            3 2 roll              % cmap cid cmap cid gid
511
 
            .cjkv_safeput              % cmap cid
512
 
            1 add                 % cmap nextcid
513
 
          } forall pop
514
 
        } ifelse
515
 
      } forall
516
 
    } forall
517
 
  } bind def
518
 
  
519
 
  % cmap /Adobe-*-UCS2 .applyCIDToUnicode cmap
520
 
  /.applyCIDToUnicode {
521
 
    CJKV_DEBUG_TT11 { (.applyCIDToUnicode\n) print flush } if
522
 
    _cjkv_type11_util /.parsecmap get exec
523
 
    {
524
 
      {                           % cmap [ distuni cid num ]
525
 
        dup 0 get length 2 gt     % multi-byte dist is not supported yet.
526
 
        1 index 0 get <fffd> eq   % the value <fffd> is regard as undefined code.
527
 
        or {
528
 
          pop
529
 
        } {
530
 
          cvx exec exch           % cmap distuni num cid
531
 
          cmapglyphs 4 2 roll     % cmap cid cmapglyphs distuni num
532
 
          exch .cjkv_strtoint exch     % cmap cid cmapglyphs distuni num
533
 
          .cjkv_safegetinterval        % cmap cid subcmapglyphs
534
 
          {                       % cmap cid gid
535
 
            2 index 2 index       % cmap cid gid cmap cid
536
 
            3 2 roll              % cmap cid cmap cid gid
537
 
            .cjkv_safeput              % cmap cid
538
 
            1 add                 % cmap nextcid
539
 
          } forall pop
540
 
        } ifelse
541
 
      } forall
542
 
    } forall
543
 
  } bind def
544
 
  
545
 
  /.cjkv_buildcmapdict mark
546
 
    /Adobe-CNS1 <<
547
 
      /Registry (Adobe)
548
 
      /Ordering (CNS1)
549
 
      /CIDCounts [ 14099 17408 17601 18846 18962 ]
550
 
      /Big5 { 0 {
551
 
        /Adobe-CNS1-ETen-B5     _cjkv_type11_util /.applyCIDToCode    get exec
552
 
        /ETen-B5-V              _cjkv_type11_util /.applyvCMap        get exec
553
 
        /ETen-B5-H              _cjkv_type11_util /.applyhCMap        get exec
554
 
      } }
555
 
      /Unicode { 3 {
556
 
        /Adobe-CNS1-UCS2        _cjkv_type11_util /.applyCIDToUnicode get exec
557
 
        /UniCNS-UCS2-V          _cjkv_type11_util /.applyvCMapUnicode get exec
558
 
        /UniCNS-UCS2-H          _cjkv_type11_util /.applyhCMap        get exec
559
 
      } }
560
 
    >>
561
 
    /Adobe-GB1 <<
562
 
      /Registry (Adobe)
563
 
      /Ordering (GB1)
564
 
      /CIDCounts [ 7717 9897 22127 22353 29064 ]
565
 
      /PRC { 2 {
566
 
        /Adobe-GB1-GBK-EUC      _cjkv_type11_util /.applyCIDToCode    get exec
567
 
        /GBK-EUC-V              _cjkv_type11_util /.applyvCMap        get exec
568
 
        /GBK-EUC-H              _cjkv_type11_util /.applyhCMap        get exec
569
 
      } }
570
 
      /Unicode { 4 {
571
 
        /Adobe-GB1-UCS2         _cjkv_type11_util /.applyCIDToUnicode get exec
572
 
        /UniGB-UCS2-V           _cjkv_type11_util /.applyvCMapUnicode get exec
573
 
        /UniGB-UCS2-H           _cjkv_type11_util /.applyhCMap        get exec
574
 
      } }
575
 
    >>
576
 
    /Adobe-Japan1 <<
577
 
      /Registry (Adobe)
578
 
      /Ordering (Japan1)
579
 
      /CIDCounts [ 8284 8359 8720 9354 15444 20317 23058 ]
580
 
      /ShiftJIS { 2 {
581
 
        /Adobe-Japan1-90ms-RKSJ _cjkv_type11_util /.applyCIDToCode    get exec
582
 
        /90ms-RKSJ-V            _cjkv_type11_util /.applyvCMap        get exec
583
 
        /90ms-RKSJ-H            _cjkv_type11_util /.applyhCMap        get exec
584
 
      } }
585
 
      /Unicode { 4 {
586
 
        /Adobe-Japan1-UCS2      _cjkv_type11_util /.applyCIDToUnicode get exec
587
 
        /UniJIS-UCS2-V          _cjkv_type11_util /.applyvCMapUnicode get exec
588
 
        /UniJIS-UCS2-H          _cjkv_type11_util /.applyhCMap        get exec
589
 
      } }
590
 
    >>
591
 
    /Adobe-Japan2 <<
592
 
      /Registry (Adobe)
593
 
      /Ordering (Japan2)
594
 
      /CIDCounts [ 6068 ]
595
 
      /Unicode { 0  {
596
 
        /UniHojo-UCS2-V         _cjkv_type11_util /.applyvCMapUnicode get exec
597
 
        /UniHojo-UCS2-H         _cjkv_type11_util /.applyhCMap        get exec
598
 
      } }
599
 
    >>
600
 
    /Adobe-Korea1 <<
601
 
      /Registry (Adobe)
602
 
      /Ordering (Korea1)
603
 
      /CIDCounts [ 9333 18155 18352 ]
604
 
      /Johab { 1 {
605
 
        /KSC-Johab-V            _cjkv_type11_util /.applyvCMap        get exec
606
 
        /KSC-Johab-H            _cjkv_type11_util /.applyhCMap        get exec
607
 
      } }
608
 
      /Unicode { 2 {
609
 
        /Adobe-Korea1-UCS2      _cjkv_type11_util /.applyCIDToUnicode get exec
610
 
        /UniKS-UCS2-V           _cjkv_type11_util /.applyvCMapUnicode get exec
611
 
        /UniKS-UCS2-H           _cjkv_type11_util /.applyhCMap        get exec
612
 
      } }
613
 
      /Wansung { 1 {
614
 
        /Adobe-Korea1-KSCms-UHC _cjkv_type11_util /.applyCIDToCode    get exec
615
 
        /KSCms-UHC-V            _cjkv_type11_util /.applyvCMap        get exec
616
 
        /KSCms-UHC-H            _cjkv_type11_util /.applyhCMap        get exec
617
 
      } }
618
 
    >>
619
 
    /Identity <<        % ttcmap ordering CIDMap only for specific and rare CJK TTF
620
 
      /Registry (Unregistered)        % Thus Registry value is unpredictable. This
621
 
      /Ordering (Identity)        % CIDFont can be used with Identity-H|V CMap
622
 
      /CIDCounts [ 65535 ]
623
 
      /H { 0 {
624
 
        /Identity-H             _cjkv_type11_util /.applyhCMap        get exec % for ttcmap-order CIDMap
625
 
      } }
626
 
      /V { 0 {
627
 
        /Identity-H             _cjkv_type11_util /.applyvCMap        get exec % for ttcmap-order and vertically-used CIDMap
628
 
      } }
629
 
    >>
630
 
  .dicttomark def
631
 
  
632
 
  /.cjkv_ttencmap <<
633
 
    /Identity              false
634
 
    /Auto                  { 
635
 
                             CJKV_DEBUG_TT11 { (+++ ttencmap->Auto exec\n) print flush } if
636
 
                             _cjkv_type11_util /.cjkv_ttencoding get exec {
637
 
                               dup
638
 
                               _cjkv_type11_util /.cjkv_ttcharset get
639
 
                               exch get
640
 
                             CJKV_DEBUG_TT11 { (+++                exec\n) print flush } if
641
 
                               exec
642
 
                             CJKV_DEBUG_TT11 { (+++                      ok\n) print flush } if
643
 
                               exch true
644
 
                             } {
645
 
                               false
646
 
                             } ifelse
647
 
                           } bind
648
 
    /Adobe-CNS1            { /Adobe-CNS1   _cjkv_type11_util /.cjkv_ttencoding get exec }
649
 
    /Adobe-GB1             { /Adobe-GB1    _cjkv_type11_util /.cjkv_ttencoding get exec }
650
 
    /Adobe-Japan1          { /Adobe-Japan1 _cjkv_type11_util /.cjkv_ttencoding get exec }
651
 
    /Adobe-Japan2          { /Adobe-Japan2 _cjkv_type11_util /.cjkv_ttencoding get exec }
652
 
    /Adobe-Korea1          { /Adobe-Korea1 _cjkv_type11_util /.cjkv_ttencoding get exec }
653
 
    /Adobe-CNS1-Big5       { /Adobe-CNS1   /Big5     true }
654
 
    /Adobe-CNS1-Unicode    { /Adobe-CNS1   /Unicode  true }
655
 
    /Adobe-GB1-PRC         { /Adobe-GB1    /PRC      true }
656
 
    /Adobe-GB1-Unicode     { /Adobe-GB1    /Unicode  true }
657
 
    /Adobe-Japan1-ShiftJIS { /Adobe-Japan1 /ShiftJIS true }
658
 
    /Adobe-Japan1-Unicode  { /Adobe-Japan1 /Unicode  true }
659
 
    /Adobe-Japan2-Unicode  { /Adobe-Japan2 /Unicode  true }
660
 
    /Adobe-Korea1-Johab    { /Adobe-Korea1 /Johab    true }
661
 
    /Adobe-Korea1-Unicode  { /Adobe-Korea1 /Unicode  true }
662
 
    /Adobe-Korea1-Wansung  { /Adobe-Korea1 /Wansung  true }
663
 
    /Identity-H            { /Identity     /H        true }
664
 
    /Identity-V            { /Identity     /V        true }
665
 
  >> def
666
 
  
667
 
  /.cjkv_ttcharset <<
668
 
    /Unicode  { _cjkv_type11_util /.cjkv_detectos2 get exec }
669
 
    /ShiftJIS /Adobe-Japan1
670
 
    /Big5     /Adobe-CNS1
671
 
    /PRC      /Adobe-GB1
672
 
    /Wansung  /Adobe-Korea1
673
 
    /Johab    /Adobe-Korea1
674
 
  >> def
675
 
  
676
 
  /.cjkv_ttencdict <<
677
 
    <00030001> /Unicode
678
 
    <00030002> /ShiftJIS
679
 
    <00030003> /Big5
680
 
    <00030004> /PRC
681
 
    <00030005> /Wansung
682
 
    <00030006> /Johab
683
 
  >> def
684
 
  
685
 
  /.cjkv_ttencoding {
686
 
    CJKV_DEBUG_TT11 { (.cjkv_ttencoding\n) print flush } if
687
 
    _cjkv_type11_util /.cjkv_ttencdict get _cjkv_ttcmap_tmp /cmapsub get 0 4 getinterval .knownget
688
 
  } bind def
689
 
  
690
 
  /.cjkv_ttos2tab [
691
 
    [ 1 20 bitshift /Adobe-CNS1   ]
692
 
    [ 1 18 bitshift /Adobe-GB1    ]
693
 
    [ 1 17 bitshift /Adobe-Japan1 ]
694
 
    [ 1 19 bitshift /Adobe-Korea1 ]
695
 
    [ 1 21 bitshift /Adobe-Korea1 ]
696
 
  ] def
697
 
  
698
 
  /.cjkv_detectos2 {
699
 
    CJKV_DEBUG_TT11 { (.cjkv_detectos2\n) print flush } if
700
 
    /Identity        % default linear ordering to GID, Adobe Identity CIDs
701
 
    os2ver 0 gt {
702
 
      _cjkv_type11_util /.cjkv_ttos2tab get {
703
 
        dup 0 get os2cp1 and 0 ne {
704
 
          1 get exch
705
 
        } if pop
706
 
      } forall
707
 
    } if
708
 
  } bind def
709
 
 
710
 
end readonly def