]> git.lizzy.rs Git - plan9front.git/blob - sys/lib/ghostscript/mkcidfm.ps
etherbcm: handle 64-bit host addresses, use PCIWADDR() instead of PADDR()
[plan9front.git] / sys / lib / ghostscript / mkcidfm.ps
1 % Copyright (C) 2004 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: mkcidfm.ps,v 1.1 2004/11/18 06:48:41 ghostgum Exp $
17
18 % Generate a cidfmap file for substituting CID fonts with TrueType 
19 % fonts, based on fonts found in the directory FONTDIR.
20
21 % The directory FONTDIR is searched for fonts whose filename
22 % matches a Path in the cidsubs dictionary.
23 % Any matches are written out as a CID font substitution.
24 %
25 % For each fontname and alias in the fontaliases dictionary,
26 % write out each alias that matches a substituted font.
27 % Where multiple aliases are possible, use the first match.
28 %
29 % Note that the substitutions and aliases in this file were created 
30 % by someone who doesn't understand Chinese, Japanese or Korean.  
31 % The initial list contains only font files found in Windows XP.
32 % Please submit corrections and additions.
33 %
34 % Font filenames must match case.  
35 % All font filenames are currently lower case.
36 %
37 % Usage: gswin32c -q -dBATCH -sFONTDIR=c:/windows/fonts
38 %                -sCIDFMAP=c:/gs/cidfmap mkcidfm.ps
39
40
41 systemdict /FONTDIR known not { /FONTDIR (c:/windows/fonts) def } if
42
43 systemdict /CIDFMAP known { CIDFMAP } { (%stdout) } ifelse
44 /cidfmap exch (w) file def
45
46 % Directory separator as used by filenameforall
47 /dirsep (/) def
48
49 % This dictionary contains a list of font substitutions.
50 % The first matching substitution in the array will be used.
51 /fontaliases
52 <<
53   % Traditional Chinese
54   /MSung-Light [ /MingLiU ]
55   /MSung-Medium [ /MingLiU ]
56   /MHei-Medium [ /MingLiU ]
57   /MKai-Medium [ /Arial-Unicode-MS /MingLiU ]
58
59   % Simplified Chinese
60   /STSong-Light [ /SimSun ]
61   /STFangsong-Light [ /SimSun ]
62   /STHeiti-Regular [ /SimHei ]
63   /STKaiti-Regular [ /SimHei ]
64
65   % Japanese
66   /Ryumin-Light [ /MS-Mincho ]
67   /Ryumin-Medium [ /MS-Mincho ]
68   /GothicBBB-Medium [ /MS-Gothic ]
69   /HeiseiMin-W3 [ /MS-Mincho ]
70   /HeiseiKakuGo-W5 [ /MS-Gothic ]
71
72   % Korean
73   /HYSMyeongJo-Medium [ /Batang ]
74   /HYRGoThic-Medium [ /Gulim ]
75   /HYGoThic-Medium [ /Dotum ]
76 >>
77 def
78
79
80 % This dictionary contains a list of CID substitutions
81 /cidsubs 
82 <<
83   % Simplified Chinese
84   /SimHei
85   <<
86    /FileType /TrueType
87    /Path (simhei.ttf)
88    /SubfontID 0
89    /CSI [(GB1) 2]
90   >>
91
92   /SimSun
93   <<
94    /FileType /TrueType
95    /Path (simsun.ttc)
96    /SubfontID 0
97    /CSI [(GB1) 2]
98   >>
99
100   /NSimSun
101   <<
102    /FileType /TrueType
103    /Path (simsun.ttc)
104    /SubfontID 1
105    /CSI [(GB1) 2]
106   >>
107
108   % Traditional Chinese
109   /MingLiU
110   <<
111    /FileType /TrueType
112    /Path (mingliu.ttc)
113    /SubfontID 0
114    /CSI [(CNS1) 2]
115   >>
116
117   /PMingLiU
118   <<
119    /FileType /TrueType
120    /Path (mingliu.ttc)
121    /SubfontID 1
122    /CSI [(CNS1) 2]
123   >>
124
125   /Arial-Unicode-MS
126   <<
127    /FileType /TrueType
128    /Path (arialuni.ttc)
129    /SubfontID 0
130    /CSI [(CNS1) 2]
131   >>
132
133   % Japanese
134   /MS-Gothic
135   <<
136    /FileType /TrueType
137    /Path (msgothic.ttc)
138    /SubfontID 0
139    /CSI [(Japan1) 3]
140   >>
141
142   /MS-PGothic
143   <<
144    /FileType /TrueType
145    /Path (msgothic.ttc)
146    /SubfontID 1
147    /CSI [(Japan1) 3]
148   >>
149
150   /MS-UI-Gothic
151   <<
152    /FileType /TrueType
153    /Path (msgothic.ttc)
154    /SubfontID 2
155    /CSI [(Japan1) 3]
156   >>
157
158   /MS-Mincho
159   <<
160    /FileType /TrueType
161    /Path (msmincho.ttc)
162    /SubfontID 0
163    /CSI [(Japan1) 3]
164   >>
165
166   /MS-PMincho
167   <<
168    /FileType /TrueType
169    /Path (msmincho.ttc)
170    /SubfontID 1
171    /CSI [(Japan1) 3]
172   >>
173
174   % Korean
175   /Batang
176   <<
177    /FileType /TrueType
178    /Path (batang.ttc)
179    /SubfontID 0
180    /CSI [(Korea1) 3]
181   >>
182
183   /BatangChe
184   <<
185    /FileType /TrueType
186    /Path (batang.ttc)
187    /SubfontID 1
188    /CSI [(Korea1) 3]
189   >>
190
191   /Gungsuh
192   <<
193    /FileType /TrueType
194    /Path (batang.ttc)
195    /SubfontID 2
196    /CSI [(Korea1) 3]
197   >>
198
199   /GungsuhChe
200   <<
201    /FileType /TrueType
202    /Path (batang.ttc)
203    /SubfontID 3
204    /CSI [(Korea1) 3]
205   >>
206
207   /Gulim
208   <<
209    /FileType /TrueType
210    /Path (gulim.ttc)
211    /SubfontID 0
212    /CSI [(Korea1) 3]
213   >>
214
215   /GulimChe
216   <<
217    /FileType /TrueType
218    /Path (gulim.ttc)
219    /SubfontID 1
220    /CSI [(Korea1) 3]
221   >>
222
223   /Dotum
224   <<
225    /FileType /TrueType
226    /Path (gulim.ttc)
227    /SubfontID 2
228    /CSI [(Korea1) 3]
229   >>
230
231   /DotumChe
232   <<
233    /FileType /TrueType
234    /Path (gulim.ttc)
235    /SubfontID 3
236    /CSI [(Korea1) 3]
237   >>
238
239 >>
240 def
241
242
243 % A dictionary for storing the names and paths of found fonts
244 /foundfonts 50 dict def
245
246 % Get the basename of a path
247 % For example, (c:/windows/fonts/msmincho.ps) --> (msmincho.ps)
248 /basename { % path -- subpath
249   { dirsep search
250     {pop pop}
251     {exit}
252     ifelse
253   } loop
254 } def
255
256
257 % Check if a font basename matches one of the possible cid substitutions.  
258 % If it does, add the font and full path to the foundfonts dictionary
259 /checkfont {
260   dup basename
261   cidsubs
262   {
263     /Path get
264     2 index eq  % Match case only
265     {
266       foundfonts exch
267       3 index dup length string copy put
268     }
269     {
270       pop
271     }
272     ifelse
273   }
274   forall
275   pop pop
276 } def
277
278 % Add all matching fonts to foundfonts dictionary
279 /findfonts { % path --
280   dup length 2 add string dup 3 1 roll copy pop
281   dup dup length 2 sub dirsep 0 get put
282   dup dup length 1 sub (*) 0 get put
283   /checkfont load 256 string filenameforall
284 } def
285
286
287 % Write out a cid substition, using the full font path
288 % name is the font name, e.g. /MS-Mincho
289 % path is the full path to the font file, e.g. (c:\windows\fonts\msmincho.ps)
290 % subs is the dictionary for CID font substition, from cidsubs
291 /emitsubs { % name path subs -- 
292   3 -1 roll cidfmap exch write==only % name
293   cidfmap ( << ) writestring
294   % path subs
295   {
296    1 index /Path eq {pop 1 index} if % use full path, not basename
297    exch cidfmap exch write==only cidfmap ( ) writestring 
298    cidfmap exch write==only cidfmap ( ) writestring 
299   } forall
300   cidfmap (>> ;\n) writestring
301   pop
302 } def
303
304 % Write out all known cid substitutions.
305 /writesubs { % ---
306   cidfmap (% Substitutions\n) writestring
307   foundfonts
308   {
309     1 index cidsubs exch known
310     {
311       1 index cidsubs exch get % name path subs
312       emitsubs
313     }
314     {
315       pop pop
316     }
317     ifelse
318   }
319   forall
320 } def
321
322 % Write out aliases for which the cid substituted font exists.
323 /writealiases { % --
324   cidfmap (\n% Aliases\n) writestring
325   fontaliases 
326   {
327     % name aliasarray
328     {
329       % name alias
330       foundfonts 1 index known
331       {
332         1 index cidfmap exch write==only cidfmap ( ) writestring 
333         cidfmap exch write==only cidfmap ( ;\n) writestring
334         exit % after first match
335       }
336       {
337         pop % didn't find this name
338       }
339       ifelse
340     } forall
341     % name
342     pop
343   }
344   forall
345 } def
346
347
348 % Write out a new cidfmap file to stdout
349 /writecidfmap { % path --
350   cidfmap (%!\n% cidfmap generated automatically by mkcidfm.ps from fonts found in\n) writestring
351   cidfmap (%   ) writestring
352   dup cidfmap exch writestring cidfmap (\n\n) writestring
353   findfonts
354   writesubs
355   writealiases
356 } def
357
358
359 FONTDIR writecidfmap