3 # mf-to-table.py -- convert spacing info in MF logs .
5 # source file of the GNU LilyPond music typesetter
7 # (c) 1997--2007 Han-Wen Nienhuys <hanwen@cs.uu.nl>
15 def read_log_file (fn):
16 str = open (fn).read ()
17 str = re.sub ('\n', '', str)
18 str = re.sub ('[\t ]+', ' ', str)
22 def include_func (match, d = deps):
23 d.append (match.group (1))
26 def auto_func (match, a = autolines):
27 a.append (match.group (1))
30 str = re.sub ('\\(([/a-z.A-Z_0-9-]+\\.mf)', include_func, str)
31 str = re.sub ('@{(.*?)@}', auto_func, str)
33 return (autolines, deps)
42 def parse_logfile (fn):
43 autolines, deps = read_log_file (fn)
47 'filename' : os.path.splitext (os.path.basename (fn))[0]
53 if tags[0] == 'group':
55 elif tags[0] == 'puorg':
57 elif tags[0] == 'char':
61 name = group + '.' + name
63 'description': tags[1],
65 'code': int (tags[2]),
66 'breapth': float (tags[3]),
67 'width': float (tags[4]),
68 'depth': float (tags[5]),
69 'height': float (tags[6]),
70 'wx': float (tags[7]),
71 'wy': float (tags[8]),
73 charmetrics.append (m)
74 elif tags[0] == 'font':
76 font_family = (tags[3])
77 # To omit 'GNU' (foundry) from font name proper:
81 tags.append ('Regular')
83 encoding = re.sub (' ','-', tags[5])
86 global_info['design_size'] = float (tags[4])
87 global_info['FontName'] = '-'.join (name)
88 global_info['FullName'] = ' '.join (name)
89 global_info['FamilyName'] = '-'.join (name[1:-1])
91 global_info['Weight'] = tags[4]
93 global_info['Weight'] = tags[-1]
95 global_info['FontBBox'] = '0 0 1000 1000'
96 global_info['Ascender'] = '0'
97 global_info['Descender'] = '0'
98 global_info['EncodingScheme'] = encoding
100 elif tags[0] == 'parameter':
101 global_info[tags[1]] = tags[2];
103 return (global_info, charmetrics, deps)
107 def character_lisp_table (global_info, charmetrics):
109 def conv_char_metric (charmetric):
112 ((bbox . (%f %f %f %f))
115 (attachment . (%f . %f))))
116 """ %(charmetric['name'],
117 -charmetric['breapth'] * f,
118 -charmetric['depth'] * f,
119 charmetric['width'] * f,
120 charmetric['height'] * f,
121 global_info['filename'],
129 for c in charmetrics:
130 s += conv_char_metric (c)
135 def global_lisp_table (global_info):
138 keys = ['staffsize', 'stafflinethickness', 'staff_space',
139 'linethickness', 'black_notehead_width', 'ledgerlinethickness',
144 if global_info.has_key (k):
145 str = str + "(%s . %s)\n" % (k,global_info[k])
150 def ps_encoding (name, global_info, charmetrics):
151 encs = ['.notdef'] * 256
152 for m in charmetrics:
153 encs[m['code']] = m['name']
156 s = ('/%s [\n' % name)
157 for m in range (0, 256):
158 s += (' /%s %% %d\n' % (encs[m], m))
162 def get_deps (deps, targets):
165 t = re.sub ( '^\\./', '', t)
174 sys.stdout.write(r"""Usage: mf-to-table [OPTIONS] LOGFILEs
176 Generate feta metrics table from preparated feta log.
179 -d, --dep=FILE print dependency info to FILE
180 -h, --help print this help
181 -l, --ly=FILE name output table
182 -o, --outdir=DIR prefix for dependency info
183 -p, --package=DIR specify package
190 getopt.getopt (sys.argv[1:],
192 ['enc=', 'outdir=', 'dep=', 'lisp=',
194 'debug', 'help', 'package='])
206 if o == '--dep' or o == '-d':
208 elif o == '--outdir' or o == '-o':
212 elif o == '--global-lisp':
216 elif o== '--help' or o == '-h':
224 base = os.path.splitext (lyfile_nm)[0]
227 (g, m, deps) = parse_logfile (filenm)
229 enc_name = 'FetaEncoding'
230 if re.search ('parmesan', filenm):
231 enc_name = 'ParmesanEncoding'
232 elif re.search ('feta-brace', filenm):
233 enc_name = 'FetaBraceEncoding'
234 elif re.search ('feta-alphabet', filenm):
235 enc_name = 'FetaAlphabetEncoding';
237 open (enc_nm, 'w').write (ps_encoding (enc_name, g, m))
238 open (char_lisp_nm, 'w').write (character_lisp_table (g, m))
239 open (global_lisp_nm, 'w').write (global_lisp_table (g))
241 open (depfile_nm, 'wb').write (get_deps (deps,
242 [base + '.log', base + '.dvi', base + '.pfa',