1
0

rollconv.ps 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  1. %!
  2. % Copyright (C) 1995, 1996 Aladdin Enterprises. All rights reserved.
  3. % $Id: rollconv.ps,v 1.1 2000/03/09 08:40:40 lpd Exp $
  4. % Utility program for converting Japanese fonts produced by Macromedia's
  5. % Rollup program to Type 0 fonts suitable for use with Ghostscript.
  6. %
  7. % Rollup produces the following files, where xxx is the font name:
  8. % xxx-H, xxx-SA, xxx-SB, xxx-SK, xxx-SR, xxx-UG
  9. % JIS83-1_COD
  10. % JIS83-1_CSA
  11. % The _COD and _CSA files are large files containing the actual
  12. % character outline data; they may theoretically be shared between
  13. % multiple fonts.
  14. %
  15. % rollconv.ps converts the above to files named:
  16. % fff.ps
  17. % fff.COD
  18. % fff.CSA
  19. % fff.CSR
  20. % where fff is a font file name provided by the user at conversion time.
  21. % The fff.ps file is the actual font file to be loaded with `run'
  22. % or placed in a Fontmap or a directory named by [GS_]FONTPATH;
  23. % the other two files must be present at runtime in a directory that is
  24. % on Ghostscript's search path (-I, GS_LIB, GS_LIB_DEFAULT).
  25. %
  26. % The normal way to invoke this program is
  27. % gsnd -- rollconv.ps xxx fff InDir CDir OutDir
  28. % (assuming that gsnd is an alias for gs -dNODISPLAY), where:
  29. % xxx is the font name;
  30. % fff is the base part of the output file name;
  31. % InDir is the name of the directory containing the xxx-* input files;
  32. % CDir is the name of the directory containing the _COD and _CSA
  33. % input files (typically the same as InDir);
  34. % OutDir is the name of the directory where the output should be written
  35. % (OutDir must already exist).
  36. % For example:
  37. % gsnd -- rollconv.ps HGGothicBPRO gothic /gs/k/rufonts/Gothic \
  38. % /gs/k/rufonts/Gothic /gs/k/gsfonts
  39. % To suppress output messages, you may insert -q:
  40. % gsnd -q -- rollconv.ps ...
  41. %
  42. % This program assumes that the files have been FTP'ed from a Macintosh and
  43. % therefore have 128 bytes of garbage at the beginning. If you have
  44. % transferred them in some manner that avoids this, change true to false
  45. % in the following line.
  46. /fromMac true def
  47. % The FontName of the converted font is xxx-83pv-RKSJ-H. In order to
  48. % use a converted font with Ghostscript, you may either load it explicitly
  49. % at run time, e.g.,
  50. % (gothic.ps) run
  51. % or you may add an entry to the Fontmap file, in the form:
  52. % /HGGothicBPRO-83pv-RKSJ-H (gothic.ps) ;
  53. % which will allow the font to be loaded automatically. After
  54. % loading the font, by either method, you can select it in the usual way:
  55. % /HGGothicBPRO-83pv-RKSJ-H findfont 36 scalefont setfont
  56. % or
  57. % /HGGothicBPRO-83pv-RKSJ-H 36 selectfont
  58. /macrfile % <filename> macrfile <file>
  59. { (r) file
  60. fromMac
  61. { % Get rid of the initial Mac garbage (128 characters).
  62. % The garbage at the end is unpredictable,
  63. % so we'll just have to hope that it's all nulls.
  64. dup =string 0 128 getinterval readstring pop pop
  65. }
  66. if
  67. } bind def
  68. /convert % <FName> <OutBase> <InDir> <CDir> <OutDir> convert -
  69. { /OutDir exch def
  70. /CDir exch def
  71. /InDir exch def
  72. /OutBase exch def
  73. /FName exch def
  74. /inprefix InDir (/) concatstrings FName concatstrings (-) concatstrings def
  75. /inh inprefix (H) concatstrings def
  76. % Open the output file.
  77. /OutDot OutDir (/) concatstrings OutBase concatstrings (.) concatstrings def
  78. /outname OutDot (ps) concatstrings def
  79. QUIET not { (Writing ) print outname = flush } if
  80. /cdfromstr (\(pgfonts/) FName concatstrings (-JIS83-1_) concatstrings def
  81. /cdstr (\() OutBase concatstrings (.) concatstrings def
  82. /out outname (w) file def
  83. /buffer 65000 string def
  84. % Copy the initial comments from the input file.
  85. inh macrfile
  86. { dup =string readline pop
  87. out 1 index writestring out (\n) writestring
  88. (%%EndComments) eq { exit } if
  89. }
  90. loop
  91. % Write out our preamble.
  92. out (
  93. currentpacking true setpacking
  94. userdict /AltsysCFD3 known { (%END) .skipeof } if
  95. userdict /AltsysCFD3 25 dict dup begin
  96. /beint { 0 exch { exch 8 bitshift add } forall } bind def
  97. /rfile { findlibfile { exch pop } { (r) file } ifelse } bind def
  98. /str 500 string def
  99. /AltRO { } def
  100. /BuildCh % <font> <ccode> <bias> BuildCh -
  101. { /bias exch def /ccode exch def begin % font
  102. ccode dup 255 and dup bias lt exch 252 gt or { pop 127 } if
  103. dup -8 bitshift -67 mul add % subfonts have 189 chars, not 256
  104. bias sub buildch1
  105. } bind def
  106. /BuildChr % <font> <ccode> BuildChr -
  107. { /ccode exch def begin % font
  108. ccode buildch1
  109. } bind def
  110. /buildch1
  111. { 6 mul PGOffsets add
  112. FileNames 0 get rfile dup dup 4 -1 roll setfileposition
  113. (xxxxxx) readstring pop exch closefile
  114. dup 1 3 getinterval beint % COD offset
  115. exch 4 2 getinterval beint % length
  116. dup 0 eq
  117. { pop pop currentdict end
  118. 1000 0 0 0 1 1 0 -1000 500 1000 setcachedevice2
  119. }
  120. { dup str length gt { /str 1 index string store } if
  121. FileNames 1 get rfile dup dup % offset length file file file
  122. 5 -1 roll setfileposition % length file file
  123. str 0 5 -1 roll getinterval readstring pop pop closefile
  124. currentdict end ccode str 1183615869 internaldict /CCRun get exec
  125. }
  126. ifelse
  127. } bind def
  128. /privates 100 dict def
  129. /BuildPr % <stdhw> <stdvw> BuildPr <dict>
  130. { 2 copy 1000 mul add privates 1 index known
  131. { privates exch get 3 1 roll pop pop
  132. }
  133. { 7 dict begin
  134. /MinFeature{16 16}executeonly def
  135. /BlueValues BlueValues def
  136. /StdVW 3 -1 roll 1 array astore def
  137. /StdHW 3 -1 roll 1 array astore def
  138. /password 5839 def
  139. /LanguageGroup 1 def
  140. /Subrs Subrs def
  141. currentdict readonly end
  142. privates 2 index 2 index put exch pop
  143. }
  144. ifelse
  145. } bind def
  146. /FullEncoding
  147. systemdict { pop } forall
  148. systemdict length 512 sub 1 255 { (x) dup 0 4 -1 roll put cvn } for
  149. 768 packedarray def
  150. /BlueValues[-250 -250 1100 1100]readonly def
  151. /BuildChar{AltsysCFD3 begin 64 BuildCh end}bind def
  152. /CharStrings 1 dict
  153. dup /.notdef (¿1pyÊ8�å) noaccess put
  154. readonly def
  155. /CDevProc
  156. { pop pop pop pop 0 exch -1000 exch 2 div currentfont /FontBBox get 3 get
  157. } bind def
  158. /FontMatrix[0.001 0.0 0.0 0.001 0.0 0.0]readonly def
  159. /Subrs [
  160. (¿1p|=-“D\âR) noaccess
  161. (¿1py¼öUz) noaccess
  162. (¿1py½Äži) noaccess
  163. (¿1pù) noaccess
  164. (¿1p|35r·I) noaccess
  165. ] noaccess def
  166. end put
  167. %END
  168. ) writestring
  169. % Locate and copy the definition of NotDefFont.
  170. out (
  171. FontDirectory /NotDefFont known { (%END) .skipeof } if
  172. ) writestring
  173. { dup =string readline pop
  174. dup (/NotDefFont) eq { exit } if pop
  175. }
  176. loop out exch writestring out (\n) writestring
  177. { dup =string readline pop
  178. (definefont) search { pop pop pop exit } if
  179. out exch writestring out (\n) writestring
  180. }
  181. loop out (definefont pop
  182. %END
  183. ) writestring
  184. % Copy the definitions of the subfonts, moving the
  185. % CharStrings of the Roman supplement to an external file.
  186. % Stack for pattern procedures: infile line
  187. /CSRName OutDot (CSR) concatstrings def
  188. /csr CSRName (w) file def
  189. QUIET not { (Writing ) print CSRName = flush } if
  190. /encoding 256 array def
  191. /patterns [
  192. % Patterns specific to the Roman supplement, in which
  193. % the outlines are in an eexec section.
  194. { (/Encoding 256 array) {
  195. pop out (/Encoding ) writestring
  196. { dup buffer readline pop
  197. dup (dup) search { exit } if pop pop
  198. }
  199. loop
  200. { % Stack: infile dupline postdup (dup) predup
  201. pop pop exch pop
  202. % The top element of the stack is a string beginning with
  203. % an index and value to put into the Encoding.
  204. token pop exch token pop exch pop encoding 3 1 roll put
  205. dup buffer readline pop
  206. dup (dup) search not { pop exit } if
  207. }
  208. loop
  209. out encoding cvx write== out ( cvlit ) writestring
  210. out exch writestring out (\n) writestring
  211. } }
  212. { (/FontType 1 def) {
  213. pop out (/FontType 4 def\n) writestring
  214. out (/BuildChar{AltsysCFD3 begin BuildChr end}bind def\n) writestring
  215. out (/FileNames[) writestring
  216. 2 { out OutBase (.CSR) concatstrings write==only } repeat
  217. out (]def\n) writestring
  218. } }
  219. { (currentfile eexec) {
  220. pop out (systemdict begin\n) writestring
  221. dup 55665 /eexecDecode filter
  222. } }
  223. { (dup/CharStrings ) {
  224. % Copy the individual CharStrings to the CSR file,
  225. % recording the lengths and offsets.
  226. pop out (dup/CharStrings AltsysCFD3 /CharStrings get put\n) writestring
  227. /offsets 256 dict def
  228. { dup token pop % char name
  229. dup dup type /nametype eq exch xcheck not and not { pop exit } if
  230. 1 index token pop % length of binary data
  231. 2 index token pop pop % skip RD
  232. 2 index buffer 0 3 index getinterval readstring pop % charstring
  233. offsets 3 index csr fileposition 16 bitshift 4 index add put
  234. csr exch writestring pop pop
  235. dup buffer readline pop pop % skip ND
  236. }
  237. loop
  238. % We skipped the 'end'; skip the 'readonly put' as well.
  239. 2 { dup token pop pop } repeat
  240. out (dup/PGOffsets ) writestring
  241. out csr fileposition write=only
  242. out ( put\n) writestring
  243. encoding
  244. { offsets exch .knownget not { 0 } if
  245. 2 { csr 0 write } repeat
  246. 4 { dup -24 bitshift csr exch write 8 bitshift } repeat pop
  247. }
  248. forall
  249. } }
  250. { (/OtherSubrs[) {
  251. pop
  252. { dup buffer readline pop
  253. (]noaccess def) search { pop pop pop exit } if pop
  254. }
  255. loop
  256. } }
  257. { (/Subrs 5 array) {
  258. pop out (/Subrs AltsysCFD3 /Subrs get def\n) writestring
  259. 6 { dup buffer readline pop pop } repeat
  260. } }
  261. { (currentfile closefile) {
  262. pop out (end % systemdict\n) writestring
  263. closefile
  264. } }
  265. % Patterns for other supplements.
  266. { (pgfonts/) {
  267. { cdfromstr search not { exit } if
  268. out exch writestring pop out cdstr writestring
  269. }
  270. loop out exch writestring out (\n) writestring
  271. } }
  272. { (/BuildChar{AltsysCFD3 begin 64 BuildCh end}bind def) {
  273. pop out (\t/BuildChar AltsysCFD3 /BuildChar get def\n) writestring
  274. } }
  275. { (/CDevProc{pop pop pop pop 0 exch -1000 exch 2 div ) {
  276. pop out (\t/CDevProc AltsysCFD3 /CDevProc get def\n) writestring
  277. } }
  278. { (/CharStrings 1 dict dup begin) {
  279. pop out (\t/CharStrings AltsysCFD3 /CharStrings get def\n) writestring
  280. 2 { dup buffer readline pop pop } repeat
  281. } }
  282. { (/FontMatrix[0.001 0.0 0.0 0.001 0.0 0.0]def) {
  283. pop out (\t/FontMatrix AltsysCFD3 /FontMatrix get def\n) writestring
  284. } }
  285. { (/Private 14 dict dup begin) {
  286. pop out (\t/Private) writestring
  287. { dup buffer readline pop
  288. (end def) search { pop pop pop exit } if
  289. (/Std) search
  290. { pop pop dup length 3 sub 3 exch getinterval
  291. (]) search pop out ( ) writestring out exch writestring pop
  292. }
  293. if pop
  294. }
  295. loop out ( AltsysCFD3 begin BuildPr end def\n) writestring
  296. } }
  297. { (UniqueID) { pop } }
  298. { () {
  299. out exch writestring out (\n) writestring
  300. } }
  301. ] def
  302. [ (SR) (SA) (SK) (SB) (UG) ]
  303. { 0 1 255 { encoding exch /.notdef put } for
  304. inprefix exch concatstrings macrfile
  305. { dup buffer readline not { pop exit } if
  306. /patterns load
  307. { 2 copy 0 get search { pop pop pop 1 get exec exit } if pop pop }
  308. forall
  309. }
  310. loop closefile
  311. }
  312. forall
  313. csr closefile
  314. % Copy the definition of the root font.
  315. dup buffer readstring pop out exch writestring closefile
  316. out (
  317. setpacking
  318. ) writestring
  319. out closefile
  320. % Remove the Mac garbage from the outline files.
  321. [ (COD) (CSA) ]
  322. { CDir (/) concatstrings (JIS83-1_) concatstrings
  323. 1 index concatstrings macrfile
  324. exch OutDot exch concatstrings
  325. QUIET not { (Writing ) print dup = flush } if
  326. (w) file
  327. % Stack: infile outfile
  328. { 1 index buffer readstring exch
  329. % Stack: infile outfile noteof substring
  330. 2 index exch writestring not { exit } if
  331. }
  332. loop closefile closefile
  333. }
  334. forall
  335. } bind def
  336. % If the program was invoked from the command line, run it now.
  337. [ shellarguments
  338. { counttomark 5 eq
  339. { convert
  340. QUIET not { (Done.\n) print flush } if
  341. }
  342. { cleartomark
  343. (Usage: gsnd -- rollconv.ps FName OutBase InDir CDir OutDir\n) print
  344. ( e.g.: gsnd -- rollconv.ps HGMinchoE mincho HGfonts/Mincho HGfonts/Mincho HGfonts/gs\n) print flush
  345. mark
  346. }
  347. ifelse
  348. }
  349. if pop