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>
16 def read_log_file (fn):
17 str = open (fn).read ()
18 str = re.sub ('\n', '', str)
19 str = re.sub ('[\t ]+', ' ', str)
23 def include_func (match, d = deps):
24 d.append (match.group (1))
27 def auto_func (match, a = autolines):
28 a.append (match.group (1))
31 str = re.sub ('\\(([/a-z.A-Z_0-9-]+\\.mf)', include_func, str)
32 str = re.sub ('@{(.*?)@}', auto_func, str)
34 return (autolines, deps)
43 def parse_logfile (fn):
44 (autolines, deps) = read_log_file (fn)
48 'filename' : os.path.splitext (os.path.basename (fn))[0]
53 tags = string.split (l, '@:')
54 if tags[0] == 'group':
56 elif tags[0] == 'puorg':
58 elif tags[0] == 'char':
62 name = group + '.' + name
64 'description': tags[1],
66 'code': string.atoi (tags[2]),
67 'breapth': string.atof (tags[3]),
68 'width': string.atof (tags[4]),
69 'depth': string.atof (tags[5]),
70 'height': string.atof (tags[6]),
71 'wx': string.atof (tags[7]),
72 'wy': string.atof (tags[8]),
74 charmetrics.append (m)
75 elif tags[0] == 'font':
77 font_family = (tags[3])
78 # To omit 'GNU' (foundry) from font name proper:
82 tags.append ('Regular')
84 encoding = re.sub (' ','-', tags[5])
87 global_info['design_size'] = string.atof (tags[4])
88 global_info['FontName'] = string.join (name, '-')
89 global_info['FullName'] = string.join (name,' ')
90 global_info['FamilyName'] = string.join (name[1:-1],
93 global_info['Weight'] = tags[4]
95 global_info['Weight'] = tags[-1]
97 global_info['FontBBox'] = '0 0 1000 1000'
98 global_info['Ascender'] = '0'
99 global_info['Descender'] = '0'
100 global_info['EncodingScheme'] = encoding
102 elif tags[0] == 'parameter':
103 global_info[tags[1]] = tags[2];
105 return (global_info, charmetrics, deps)
111 def write_character_lisp_table (file, global_info, charmetrics):
113 def conv_char_metric (charmetric):
116 ((bbox . (%f %f %f %f))
119 (attachment . (%f . %f))))
120 """ %(charmetric['name'],
121 -charmetric['breapth'] * f,
122 -charmetric['depth'] * f,
123 charmetric['width'] * f,
124 charmetric['height'] * f,
125 global_info['filename'],
132 for c in charmetrics:
133 file.write (conv_char_metric (c))
136 def write_global_lisp_table (file, global_info):
139 keys = ['staffsize', 'stafflinethickness', 'staff_space',
140 'linethickness', 'black_notehead_width', 'ledgerlinethickness',
145 if global_info.has_key (k):
146 str = str + "(%s . %s)\n" % (k,global_info[k])
151 def write_ps_encoding (name, file, global_info, charmetrics):
152 encs = ['.notdef'] * 256
153 for m in charmetrics:
154 encs[m['code']] = m['name']
156 file.write ('/%s [\n' % name)
157 for m in range (0, 256):
158 file.write (' /%s %% %d\n' % (encs[m], m))
159 file.write ('] def\n')
162 def write_deps (file, deps, targets):
164 t = re.sub ( '^\\./', '', t)
165 file.write ('%s '% t)
168 file.write ('%s ' % d)
173 sys.stdout.write(r"""Usage: mf-to-table [OPTIONS] LOGFILEs
175 Generate feta metrics table from preparated feta log.
178 -d, --dep=FILE print dependency info to FILE
179 -h, --help print this help
180 -l, --ly=FILE name output table
181 -o, --outdir=DIR prefix for dependency info
182 -p, --package=DIR specify package
189 getopt.getopt (sys.argv[1:],
191 ['enc=', 'outdir=', 'dep=', 'lisp=',
193 'debug', 'help', 'package='])
205 if o == '--dep' or o == '-d':
207 elif o == '--outdir' or o == '-o':
211 elif o == '--global-lisp':
215 elif o== '--help' or o == '-h':
223 base = os.path.splitext (lyfile_nm)[0]
226 (g, m, deps) = parse_logfile (filenm)
228 enc_name = 'FetaEncoding'
229 if re.search ('parmesan', filenm):
230 enc_name = 'ParmesanEncoding'
231 elif re.search ('feta-brace', filenm):
232 enc_name = 'FetaBraceEncoding'
233 elif re.search ('feta-alphabet', filenm):
234 enc_name = 'FetaAlphabetEncoding';
236 write_ps_encoding (enc_name, open (enc_nm, 'w'), g, m)
237 write_character_lisp_table (open (char_lisp_nm, 'w'), g, m)
238 write_global_lisp_table (open (global_lisp_nm, 'w'), g)
240 write_deps (open (depfile_nm, 'wb'), deps,
241 [base + '.log', base + '.dvi', base + '.pfa',