summaryrefslogtreecommitdiff
path: root/Master/tlpkg/tlgs/lib/mkcidfm.ps
blob: 6bf34d8e537b93a159a841abb4ee7ca144d8aeb1 (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
% Copyright (C) 2004 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.
% 
% For more information about licensing, please refer to
% http://www.ghostscript.com/licensing/. For information on
% commercial licensing, go to http://www.artifex.com/licensing/ or
% contact Artifex Software, Inc., 101 Lucas Valley Road #110,
% San Rafael, CA  94903, U.S.A., +1(415)492-9861.

% $Id: mkcidfm.ps 8022 2007-06-05 22:23:38Z giles $

% Generate a cidfmap file for substituting CID fonts with TrueType 
% fonts, based on fonts found in the directory FONTDIR.
% 
% The directory FONTDIR is searched for fonts whose filename
% matches a Path in the cidsubs dictionary.
% Any matches are written out as a CID font substitution.
%
% For each fontname and alias in the fontaliases dictionary,
% write out each alias that matches a substituted font.
% Where multiple aliases are possible, use the first match.
%
% Note that the substitutions and aliases in this file were created 
% by someone who doesn't understand Chinese, Japanese or Korean.  
% The initial list contains only font files found in Windows XP.
% Please submit corrections and additions.
%
% Font filenames must match case.  
% All font filenames are currently lower case.
%
% Usage: gswin32c -q -dBATCH -sFONTDIR=c:/windows/fonts
%                -sCIDFMAP=c:/gs/cidfmap mkcidfm.ps


systemdict /FONTDIR known not { /FONTDIR (c:/windows/fonts) def } if

systemdict /CIDFMAP known { CIDFMAP } { (%stdout) } ifelse
/cidfmap exch (w) file def

% Directory separator as used by filenameforall
/dirsep (/) def

% This dictionary contains a list of font substitutions.
% The first matching substitution in the array will be used.
/fontaliases
<<
  % Traditional Chinese
  /MSung-Light [ /MingLiU ]
  /MSung-Medium [ /MingLiU ]
  /MHei-Medium [ /MingLiU ]
  /MKai-Medium [ /Arial-Unicode-MS /MingLiU ]

  % Simplified Chinese
  /STSong-Light [ /SimSun ]
  /STFangsong-Light [ /SimSun ]
  /STHeiti-Regular [ /SimHei ]
  /STKaiti-Regular [ /SimHei ]

  % Japanese
  /Ryumin-Light [ /MS-Mincho ]
  /Ryumin-Medium [ /MS-Mincho ]
  /GothicBBB-Medium [ /MS-Gothic ]
  /HeiseiMin-W3 [ /MS-Mincho ]
  /HeiseiKakuGo-W5 [ /MS-Gothic ]

  % Korean
  /HYSMyeongJo-Medium [ /Batang ]
  /HYRGoThic-Medium [ /Gulim ]
  /HYGoThic-Medium [ /Dotum ]
>>
def


% This dictionary contains a list of CID substitutions
/cidsubs 
<<
  % Simplified Chinese
  /SimHei
  <<
   /FileType /TrueType
   /Path (simhei.ttf)
   /SubfontID 0
   /CSI [(GB1) 2]
  >>

  /SimSun
  <<
   /FileType /TrueType
   /Path (simsun.ttc)
   /SubfontID 0
   /CSI [(GB1) 2]
  >>

  /NSimSun
  <<
   /FileType /TrueType
   /Path (simsun.ttc)
   /SubfontID 1
   /CSI [(GB1) 2]
  >>

  % Traditional Chinese
  /MingLiU
  <<
   /FileType /TrueType
   /Path (mingliu.ttc)
   /SubfontID 0
   /CSI [(CNS1) 2]
  >>

  /PMingLiU
  <<
   /FileType /TrueType
   /Path (mingliu.ttc)
   /SubfontID 1
   /CSI [(CNS1) 2]
  >>

  /Arial-Unicode-MS
  <<
   /FileType /TrueType
   /Path (arialuni.ttc)
   /SubfontID 0
   /CSI [(CNS1) 2]
  >>

  % Japanese
  /MS-Gothic
  <<
   /FileType /TrueType
   /Path (msgothic.ttc)
   /SubfontID 0
   /CSI [(Japan1) 3]
  >>

  /MS-PGothic
  <<
   /FileType /TrueType
   /Path (msgothic.ttc)
   /SubfontID 1
   /CSI [(Japan1) 3]
  >>

  /MS-UI-Gothic
  <<
   /FileType /TrueType
   /Path (msgothic.ttc)
   /SubfontID 2
   /CSI [(Japan1) 3]
  >>

  /MS-Mincho
  <<
   /FileType /TrueType
   /Path (msmincho.ttc)
   /SubfontID 0
   /CSI [(Japan1) 3]
  >>

  /MS-PMincho
  <<
   /FileType /TrueType
   /Path (msmincho.ttc)
   /SubfontID 1
   /CSI [(Japan1) 3]
  >>

  % Korean
  /Batang
  <<
   /FileType /TrueType
   /Path (batang.ttc)
   /SubfontID 0
   /CSI [(Korea1) 3]
  >>

  /BatangChe
  <<
   /FileType /TrueType
   /Path (batang.ttc)
   /SubfontID 1
   /CSI [(Korea1) 3]
  >>

  /Gungsuh
  <<
   /FileType /TrueType
   /Path (batang.ttc)
   /SubfontID 2
   /CSI [(Korea1) 3]
  >>

  /GungsuhChe
  <<
   /FileType /TrueType
   /Path (batang.ttc)
   /SubfontID 3
   /CSI [(Korea1) 3]
  >>

  /Gulim
  <<
   /FileType /TrueType
   /Path (gulim.ttc)
   /SubfontID 0
   /CSI [(Korea1) 3]
  >>

  /GulimChe
  <<
   /FileType /TrueType
   /Path (gulim.ttc)
   /SubfontID 1
   /CSI [(Korea1) 3]
  >>

  /Dotum
  <<
   /FileType /TrueType
   /Path (gulim.ttc)
   /SubfontID 2
   /CSI [(Korea1) 3]
  >>

  /DotumChe
  <<
   /FileType /TrueType
   /Path (gulim.ttc)
   /SubfontID 3
   /CSI [(Korea1) 3]
  >>

>>
def


% A dictionary for storing the names and paths of found fonts
/foundfonts 50 dict def

% Get the basename of a path
% For example, (c:/windows/fonts/msmincho.ps) --> (msmincho.ps)
/basename { % path -- subpath
  { dirsep search
    {pop pop}
    {exit}
    ifelse
  } loop
} def


% Check if a font basename matches one of the possible cid substitutions.  
% If it does, add the font and full path to the foundfonts dictionary
/checkfont {
  dup basename
  cidsubs
  {
    /Path get
    2 index eq  % Match case only
    {
      foundfonts exch
      3 index dup length string copy put
    }
    {
      pop
    }
    ifelse
  }
  forall
  pop pop
} def

% Add all matching fonts to foundfonts dictionary
/findfonts { % path --
  dup length 2 add string dup 3 1 roll copy pop
  dup dup length 2 sub dirsep 0 get put
  dup dup length 1 sub (*) 0 get put
  /checkfont load 256 string filenameforall
} def


% Write out a cid substition, using the full font path
% name is the font name, e.g. /MS-Mincho
% path is the full path to the font file, e.g. (c:\windows\fonts\msmincho.ps)
% subs is the dictionary for CID font substition, from cidsubs
/emitsubs { % name path subs -- 
  3 -1 roll cidfmap exch write==only % name
  cidfmap ( << ) writestring
  % path subs
  {
   1 index /Path eq {pop 1 index} if % use full path, not basename
   exch cidfmap exch write==only cidfmap ( ) writestring 
   cidfmap exch write==only cidfmap ( ) writestring 
  } forall
  cidfmap (>> ;\n) writestring
  pop
} def

% Write out all known cid substitutions.
/writesubs { % ---
  cidfmap (% Substitutions\n) writestring
  foundfonts
  {
    1 index cidsubs exch known
    {
      1 index cidsubs exch get % name path subs
      emitsubs
    }
    {
      pop pop
    }
    ifelse
  }
  forall
} def

% Write out aliases for which the cid substituted font exists.
/writealiases { % --
  cidfmap (\n% Aliases\n) writestring
  fontaliases 
  {
    % name aliasarray
    {
      % name alias
      foundfonts 1 index known
      {
	1 index cidfmap exch write==only cidfmap ( ) writestring 
	cidfmap exch write==only cidfmap ( ;\n) writestring
	exit % after first match
      }
      {
	pop % didn't find this name
      }
      ifelse
    } forall
    % name
    pop
  }
  forall
} def


% Write out a new cidfmap file to stdout
/writecidfmap { % path --
  cidfmap (%!\n% cidfmap generated automatically by mkcidfm.ps from fonts found in\n) writestring
  cidfmap (%   ) writestring
  dup cidfmap exch writestring cidfmap (\n\n) writestring
  findfonts
  writesubs
  writealiases
} def


FONTDIR writecidfmap