3 # ps-to-pfa.py -- make PostScript Type 3 font from separate ps char files
5 # source file of the GNU LilyPond music typesetter
7 # (c) 1998 Jan Nieuwenhuizen <janneke@gnu.org>
25 return name + ' version ' + version;
28 sys.stdout.write (program_id () + '\n')
31 sys.stdout.write ("Usage: %s [options] [files]\n"
32 "ps-to-pfa.py -- make PostScript Type 3 font from separate ps char files\n\n"
34 + " -d, --datadir=DIR use DIR for ps header/footer\n"
35 + " -h, --help print this help\n"
41 (options, files) = getopt.getopt (
42 sys.argv[1:], 'd:', ['help', 'package'])
46 if o== '--help' or o == '-h':
48 elif o == '-d' or o == '--datadir':
56 sys.stderr.write ('[%s' % f)
63 sys.stderr.write ('can\'t open file %s\n ' % f)
66 sys.stderr.write (']')
68 sys.stderr.write ('gulped empty file: %s\n'% f)
73 font = os.path.basename (os.path.splitext (mf)[0])
74 sys.stderr.write ('Font: %s\n'% font)
77 f.write ('%!PS-AdobeFont-3.0: ' + font + '\n')
78 f.write ('%%%%Creator: %s-%s\n' % (name, version))
80 f.write ('/setgray { 1 add } bind def\n'
83 '/FontType 3 def %% Required elements of font\n'
85 '/FontMatrix [.001 0 0 .001 0 0] def\n'
86 '%%/FontMatrix [.01 0 0 .01 0 0] def\n'
87 '%%/FontMatrix [0.1 0 0 0.1 0 0] def\n'
88 '%% /FontBBox [-1000 -1000 1000 1000] def\n'
89 ' /FontBBox [-3000 -3000 3000 3000] def\n'
90 '%% /FontBBox [-300 -300 300 300] def\n'
91 '%%/FontBBox [-30 -30 30 30] def\n'
93 '/Encoding 256 array def %% Trivial encoding vector\n'
94 '0 1 255 {Encoding exch /.notdef put} for\n' % (font))
98 '/BuildGlyph { % Stack contains: font charname\n'
100 '% -750 -750 750 750 % Bounding Box\n'
102 ' -3000 -3000 3000 3000 % Bounding Box\n'
104 '% -300 -300 300 300 % Bounding Box\n'
106 '% -30 -30 30 30 % Bounding Box\n'
108 ' exch /CharProcs get exch % Get CharProcs dictionary\n'
109 ' 2 copy known not {pop /.notdef} if % See if charname is known\n'
110 ' get exec % Execute character procedure\n'
113 '/BuildChar { % Level 1 compatibility\n'
114 ' 1 index /Encoding get exch get\n'
115 ' 1 index /BuildGlyph get exec\n'
119 'end % of font dictionary\n')
121 f.write ('/%s\n' % font)
123 'exch definefont pop % Define the font\n')
127 # chars = os.listdir ()
129 sys.stderr.write ('[')
130 pipe = os.popen ('/bin/ls -1 ' + font + '.[0-9] ' + font + '.[0-9][0-9] ' + font + '.[0-9][0-9][0-9] 2> /dev/null')
134 chars.append (i[0:len (i)-1])
137 '/CharProcs 3 dict def % Subsidiary dictiorary for\n'
138 'CharProcs begin % individual character definitions\n')
139 charprocs = ' /.notdef {} def\n'
143 s = regsub.gsub ('^%.*\n', '', s)
144 s = regsub.gsub ('^showpage\n', '', s)
145 s = regsub.gsub ('^', ' ', s)
146 n = atoi (regsub.gsub ('.*\.', '', i))
147 s = '\n /%s-%d{\n%s} bind def\n' % (font, n, s)
148 encoding = encoding + 'Encoding %d /%s-%d put\n' % (n, font, n)
149 charprocs = charprocs + s
152 f.write ('end % of CharProcs\n')
155 sys.stderr.write (']')
157 ps = outdir + font + '.pfa'
158 ps_file = open (ps, 'w')
162 sys.stderr.write ('\n')
164 sys.stderr.write ('Wrote PostScript font: %s\n'% ps)