3 # mf-to-table.py -- convert spacing info in MF logs .
5 # This file is part of LilyPond, the GNU music typesetter.
7 # Copyright (C) 1997--2011 Han-Wen Nienhuys <hanwen@cs.uu.nl>
9 # LilyPond is free software: you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation, either version 3 of the License, or
12 # (at your option) any later version.
14 # LilyPond is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
28 def read_log_file (fn):
29 str = open (fn).read ()
30 str = re.sub ('\n', '', str)
31 str = re.sub ('[\t ]+', ' ', str)
35 def include_func (match, d = deps):
36 d.append (match.group (1))
39 def auto_func (match, a = autolines):
40 a.append (match.group (1))
43 str = re.sub ('\\(([/a-z.A-Z_0-9-]+\\.mf)', include_func, str)
44 str = re.sub ('@{(.*?)@}', auto_func, str)
46 return (autolines, deps)
55 def parse_logfile (fn):
56 autolines, deps = read_log_file (fn)
60 'filename' : os.path.splitext (os.path.basename (fn))[0]
66 if tags[0] == 'group':
68 elif tags[0] == 'puorg':
70 elif tags[0] == 'char':
74 name = group + '.' + name
76 'description': tags[1],
78 'code': int (tags[2]),
79 'breapth': float (tags[3]),
80 'width': float (tags[4]),
81 'depth': float (tags[5]),
82 'height': float (tags[6]),
83 'wx': float (tags[7]),
84 'wy': float (tags[8]),
86 charmetrics.append (m)
87 elif tags[0] == 'font':
89 font_family = (tags[3])
90 # To omit 'GNU' (foundry) from font name proper:
94 tags.append ('Regular')
96 encoding = re.sub (' ','-', tags[5])
99 global_info['design_size'] = float (tags[4])
100 global_info['FontName'] = '-'.join (name)
101 global_info['FullName'] = ' '.join (name)
102 global_info['FamilyName'] = '-'.join (name[1:-1])
104 global_info['Weight'] = tags[4]
106 global_info['Weight'] = tags[-1]
108 global_info['FontBBox'] = '0 0 1000 1000'
109 global_info['Ascender'] = '0'
110 global_info['Descender'] = '0'
111 global_info['EncodingScheme'] = encoding
113 elif tags[0] == 'parameter':
114 global_info[tags[1]] = tags[2];
116 return (global_info, charmetrics, deps)
120 def character_lisp_table (global_info, charmetrics):
122 def conv_char_metric (charmetric):
125 ((bbox . (%f %f %f %f))
128 (attachment . (%f . %f))))
129 """ %(charmetric['name'],
130 -charmetric['breapth'] * f,
131 -charmetric['depth'] * f,
132 charmetric['width'] * f,
133 charmetric['height'] * f,
134 global_info['filename'],
142 for c in charmetrics:
143 s += conv_char_metric (c)
148 def global_lisp_table (global_info):
151 keys = ['staffsize', 'stafflinethickness', 'staff_space',
152 'linethickness', 'black_notehead_width', 'ledgerlinethickness',
157 if global_info.has_key (k):
158 str = str + "(%s . %s)\n" % (k,global_info[k])
163 def ps_encoding (name, global_info, charmetrics):
164 encs = ['.notdef'] * 256
165 for m in charmetrics:
166 encs[m['code']] = m['name']
169 s = ('/%s [\n' % name)
170 for m in range (0, 256):
171 s += (' /%s %% %d\n' % (encs[m], m))
175 def get_deps (deps, targets):
178 t = re.sub ( '^\\./', '', t)
187 sys.stdout.write(r"""Usage: mf-to-table [OPTIONS] LOGFILEs
189 Generate feta metrics table from preparated feta log.
192 -d, --dep=FILE print dependency info to FILE
193 -h, --help print this help
194 -l, --ly=FILE name output table
195 -o, --outdir=DIR prefix for dependency info
196 -p, --package=DIR specify package
203 getopt.getopt (sys.argv[1:],
205 ['enc=', 'outdir=', 'dep=', 'lisp=',
207 'debug', 'help', 'package='])
219 if o == '--dep' or o == '-d':
221 elif o == '--outdir' or o == '-o':
225 elif o == '--global-lisp':
229 elif o== '--help' or o == '-h':
237 base = os.path.splitext (lyfile_nm)[0]
240 (g, m, deps) = parse_logfile (filenm)
242 enc_name = 'FetaEncoding'
243 if re.search ('parmesan', filenm):
244 enc_name = 'ParmesanEncoding'
245 elif re.search ('feta-noteheads', filenm):
246 enc_name = 'FetaNoteheadsEncoding'
247 elif re.search ('feta-flags', filenm):
248 enc_name = 'FetaFlagsEncoding'
249 elif re.search ('feta-brace', filenm):
250 enc_name = 'FetaBraceEncoding'
251 elif re.search ('feta-alphabet', filenm):
252 enc_name = 'FetaAlphabetEncoding';
254 open (enc_nm, 'w').write (ps_encoding (enc_name, g, m))
255 open (char_lisp_nm, 'w').write (character_lisp_table (g, m))
256 open (global_lisp_nm, 'w').write (global_lisp_table (g))
258 open (depfile_nm, 'wb').write (get_deps (deps,
259 [base + '.log', base + '.dvi', base + '.pfa',