You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

383 lines
12 KiB

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