mkcidfm.ps 7.1 KB

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