2 % Copyright (C) 1995, 1996 Aladdin Enterprises. All rights reserved.
4 % $Id: rollconv.ps,v 1.4 2002/05/01 23:15:23 igor Exp $
5 % Utility program for converting Japanese fonts produced by Macromedia's
6 % Rollup program to Type 0 fonts suitable for use with Ghostscript.
8 % Rollup produces the following files, where xxx is the font name:
9 % xxx-H, xxx-SA, xxx-SB, xxx-SK, xxx-SR, xxx-UG
12 % The _COD and _CSA files are large files containing the actual
13 % character outline data; they may theoretically be shared between
16 % rollconv.ps converts the above to files named:
21 % where fff is a font file name provided by the user at conversion time.
22 % The fff.ps file is the actual font file to be loaded with `run'
23 % or placed in a Fontmap or a directory named by [GS_]FONTPATH;
24 % the other two files must be present at runtime in a directory that is
25 % on Ghostscript's search path (-I, GS_LIB, GS_LIB_DEFAULT).
27 % The normal way to invoke this program is
28 % gsnd -- rollconv.ps xxx fff InDir CDir OutDir
29 % (assuming that gsnd is an alias for gs -dNODISPLAY), where:
30 % xxx is the font name;
31 % fff is the base part of the output file name;
32 % InDir is the name of the directory containing the xxx-* input files;
33 % CDir is the name of the directory containing the _COD and _CSA
34 % input files (typically the same as InDir);
35 % OutDir is the name of the directory where the output should be written
36 % (OutDir must already exist).
38 % gsnd -- rollconv.ps HGGothicBPRO gothic /gs/k/rufonts/Gothic \
39 % /gs/k/rufonts/Gothic /gs/k/gsfonts
40 % To suppress output messages, you may insert -q:
41 % gsnd -q -- rollconv.ps ...
43 % This program assumes that the files have been FTP'ed from a Macintosh and
44 % therefore have 128 bytes of garbage at the beginning. If you have
45 % transferred them in some manner that avoids this, change true to false
46 % in the following line.
48 % The FontName of the converted font is xxx-83pv-RKSJ-H. In order to
49 % use a converted font with Ghostscript, you may either load it explicitly
52 % or you may add an entry to the Fontmap file, in the form:
53 % /HGGothicBPRO-83pv-RKSJ-H (gothic.ps) ;
54 % which will allow the font to be loaded automatically. After
55 % loading the font, by either method, you can select it in the usual way:
56 % /HGGothicBPRO-83pv-RKSJ-H findfont 36 scalefont setfont
58 % /HGGothicBPRO-83pv-RKSJ-H 36 selectfont
61 /macrfile % <filename> macrfile <file>
64 { % Get rid of the initial Mac garbage (128 characters).
65 % The garbage at the end is unpredictable,
66 % so we'll just have to hope that it's all nulls.
67 dup =string 0 128 getinterval readstring pop pop
72 /convert % <FName> <OutBase> <InDir> <CDir> <OutDir> convert -
79 /inprefix InDir (/) concatstrings FName concatstrings (-) concatstrings def
80 /inh inprefix (H) concatstrings def
82 % Open the output file.
84 /OutDot OutDir (/) concatstrings OutBase concatstrings (.) concatstrings def
85 /outname OutDot (ps) concatstrings def
86 QUIET not { (Writing ) print outname = flush } if
87 /cdfromstr (\(pgfonts/) FName concatstrings (-JIS83-1_) concatstrings def
88 /cdstr (\() OutBase concatstrings (.) concatstrings def
89 /out outname (w) file def
90 /buffer 65000 string def
92 % Copy the initial comments from the input file.
95 { dup =string readline pop
96 out 1 index writestring out (\n) writestring
97 (%%EndComments) eq { exit } if
101 % Write out our preamble.
104 currentpacking true setpacking
105 userdict /AltsysCFD3 known { (%END) .skipeof } if
106 userdict /AltsysCFD3 25 dict dup begin
107 /beint { 0 exch { exch 8 bitshift add } forall } bind def
108 /rfile { findlibfile { exch pop } { (r) file } ifelse } bind def
111 /BuildCh % <font> <ccode> <bias> BuildCh -
112 { /bias exch def /ccode exch def begin % font
113 ccode dup 255 and dup bias lt exch 252 gt or { pop 127 } if
114 dup -8 bitshift -67 mul add % subfonts have 189 chars, not 256
117 /BuildChr % <font> <ccode> BuildChr -
118 { /ccode exch def begin % font
122 { 6 mul PGOffsets add
123 FileNames 0 get rfile dup dup 4 -1 roll setfileposition
124 (xxxxxx) readstring pop exch closefile
125 dup 1 3 getinterval beint % COD offset
126 exch 4 2 getinterval beint % length
128 { pop pop currentdict end
129 1000 0 0 0 1 1 0 -1000 500 1000 setcachedevice2
131 { dup str length gt { /str 1 index string store } if
132 FileNames 1 get rfile dup dup % offset length file file file
133 5 -1 roll setfileposition % length file file
134 str 0 5 -1 roll getinterval readstring pop pop closefile
135 currentdict end ccode str 1183615869 internaldict /CCRun get exec
139 /privates 100 dict def
140 /BuildPr % <stdhw> <stdvw> BuildPr <dict>
141 { 2 copy 1000 mul add privates 1 index known
142 { privates exch get 3 1 roll pop pop
145 /MinFeature{16 16}executeonly def
146 /BlueValues BlueValues def
147 /StdVW 3 -1 roll 1 array astore def
148 /StdHW 3 -1 roll 1 array astore def
152 currentdict readonly end
153 privates 2 index 2 index put exch pop
158 systemdict { pop } forall
159 systemdict length 512 sub 1 255 { (x) dup 0 4 -1 roll put cvn } for
161 /BlueValues[-250 -250 1100 1100]readonly def
162 /BuildChar{AltsysCFD3 begin 64 BuildCh end}bind def
164 dup /.notdef (
\10¿1pyÊ8
\8få) noaccess put
167 { pop pop pop pop 0 exch -1000 exch 2 div currentfont /FontBBox get 3 get
169 /FontMatrix[0.001 0.0 0.0 0.001 0.0 0.0]readonly def
171 (
\10¿1p|
\10\14\10=-
\93D\âR) noaccess
172 (
\10¿1py¼öUz) noaccess
173 (
\10¿1py½Ä
\9ei) noaccess
175 (
\10¿1p|
\1735r
\11·
\ 5I) noaccess
181 % Locate and copy the definition of NotDefFont.
184 FontDirectory /NotDefFont known { (%END) .skipeof } if
186 { dup =string readline pop
187 dup (/NotDefFont) eq { exit } if pop
189 loop out exch writestring out (\n) writestring
190 { dup =string readline pop
191 (definefont) search { pop pop pop exit } if
192 out exch writestring out (\n) writestring
194 loop out (definefont pop
198 % Copy the definitions of the subfonts, moving the
199 % CharStrings of the Roman supplement to an external file.
200 % Stack for pattern procedures: infile line
202 /CSRName OutDot (CSR) concatstrings def
203 /csr CSRName (w) file def
204 QUIET not { (Writing ) print CSRName = flush } if
206 /encoding 256 array def
209 % Patterns specific to the Roman supplement, in which
210 % the outlines are in an eexec section.
211 { (/Encoding 256 array) {
212 pop out (/Encoding ) writestring
213 { dup buffer readline pop
214 dup (dup) search { exit } if pop pop
217 { % Stack: infile dupline postdup (dup) predup
219 % The top element of the stack is a string beginning with
220 % an index and value to put into the Encoding.
221 token pop exch token pop exch pop encoding 3 1 roll put
222 dup buffer readline pop
223 dup (dup) search not { pop exit } if
226 out encoding cvx write== out ( cvlit ) writestring
227 out exch writestring out (\n) writestring
229 { (/FontType 1 def) {
230 pop out (/FontType 4 def\n) writestring
231 out (/BuildChar{AltsysCFD3 begin BuildChr end}bind def\n) writestring
232 out (/FileNames[) writestring
233 2 { out OutBase (.CSR) concatstrings write==only } repeat
234 out (]def\n) writestring
236 { (currentfile eexec) {
237 pop out (systemdict begin\n) writestring
238 dup //.eexec_param_dict /eexecDecode filter
240 { (dup/CharStrings ) {
241 % Copy the individual CharStrings to the CSR file,
242 % recording the lengths and offsets.
243 pop out (dup/CharStrings AltsysCFD3 /CharStrings get put\n) writestring
244 /offsets 256 dict def
245 { dup token pop % char name
246 dup dup type /nametype eq exch xcheck not and not { pop exit } if
247 1 index token pop % length of binary data
248 2 index token pop pop % skip RD
249 2 index buffer 0 3 index getinterval readstring pop % charstring
250 offsets 3 index csr fileposition 16 bitshift 4 index add put
251 csr exch writestring pop pop
252 dup buffer readline pop pop % skip ND
255 % We skipped the 'end'; skip the 'readonly put' as well.
256 2 { dup token pop pop } repeat
257 out (dup/PGOffsets ) writestring
258 out csr fileposition write=only
259 out ( put\n) writestring
261 { offsets exch .knownget not { 0 } if
262 2 { csr 0 write } repeat
263 4 { dup -24 bitshift csr exch write 8 bitshift } repeat pop
269 { dup buffer readline pop
270 (]noaccess def) search { pop pop pop exit } if pop
275 pop out (/Subrs AltsysCFD3 /Subrs get def\n) writestring
276 6 { dup buffer readline pop pop } repeat
278 { (currentfile closefile) {
279 pop out (end % systemdict\n) writestring
282 % Patterns for other supplements.
284 { cdfromstr search not { exit } if
285 out exch writestring pop out cdstr writestring
287 loop out exch writestring out (\n) writestring
289 { (/BuildChar{AltsysCFD3 begin 64 BuildCh end}bind def) {
290 pop out (\t/BuildChar AltsysCFD3 /BuildChar get def\n) writestring
292 { (/CDevProc{pop pop pop pop 0 exch -1000 exch 2 div ) {
293 pop out (\t/CDevProc AltsysCFD3 /CDevProc get def\n) writestring
295 { (/CharStrings 1 dict dup begin) {
296 pop out (\t/CharStrings AltsysCFD3 /CharStrings get def\n) writestring
297 2 { dup buffer readline pop pop } repeat
299 { (/FontMatrix[0.001 0.0 0.0 0.001 0.0 0.0]def) {
300 pop out (\t/FontMatrix AltsysCFD3 /FontMatrix get def\n) writestring
302 { (/Private 14 dict dup begin) {
303 pop out (\t/Private) writestring
304 { dup buffer readline pop
305 (end def) search { pop pop pop exit } if
307 { pop pop dup length 3 sub 3 exch getinterval
308 (]) search pop out ( ) writestring out exch writestring pop
312 loop out ( AltsysCFD3 begin BuildPr end def\n) writestring
314 { (UniqueID) { pop } }
316 out exch writestring out (\n) writestring
319 [ (SR) (SA) (SK) (SB) (UG) ]
320 { 0 1 255 { encoding exch /.notdef put } for
321 inprefix exch concatstrings macrfile
322 { dup buffer readline not { pop exit } if
324 { 2 copy 0 get search { pop pop pop 1 get exec exit } if pop pop }
332 % Copy the definition of the root font.
334 dup buffer readstring pop out exch writestring closefile
340 % Remove the Mac garbage from the outline files.
343 { CDir (/) concatstrings (JIS83-1_) concatstrings
344 1 index concatstrings macrfile
345 exch OutDot exch concatstrings
346 QUIET not { (Writing ) print dup = flush } if
348 % Stack: infile outfile
349 { 1 index buffer readstring exch
350 % Stack: infile outfile noteof substring
351 2 index exch writestring not { exit } if
353 loop closefile closefile
359 % If the program was invoked from the command line, run it now.
363 QUIET not { (Done.\n) print flush } if
366 (Usage: gsnd -- rollconv.ps FName OutBase InDir CDir OutDir\n) print
367 ( e.g.: gsnd -- rollconv.ps HGMinchoE mincho HGfonts/Mincho HGfonts/Mincho HGfonts/gs\n) print flush