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 character_lisp_table (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'],
133 for c in charmetrics:
134 s += conv_char_metric (c)
139 def global_lisp_table (global_info):
142 keys = ['staffsize', 'stafflinethickness', 'staff_space',
143 'linethickness', 'black_notehead_width', 'ledgerlinethickness',
148 if global_info.has_key (k):
149 str = str + "(%s . %s)\n" % (k,global_info[k])
154 def ps_encoding (name, global_info, charmetrics):
155 encs = ['.notdef'] * 256
156 for m in charmetrics:
157 encs[m['code']] = m['name']
160 s = ('/%s [\n' % name)
161 for m in range (0, 256):
162 s += (' /%s %% %d\n' % (encs[m], m))
166 def get_deps (deps, targets):
169 t = re.sub ( '^\\./', '', t)
178 sys.stdout.write(r"""Usage: mf-to-table [OPTIONS] LOGFILEs
180 Generate feta metrics table from preparated feta log.
183 -d, --dep=FILE print dependency info to FILE
184 -h, --help print this help
185 -l, --ly=FILE name output table
186 -o, --outdir=DIR prefix for dependency info
187 -p, --package=DIR specify package
194 getopt.getopt (sys.argv[1:],
196 ['enc=', 'outdir=', 'dep=', 'lisp=',
198 'debug', 'help', 'package='])
210 if o == '--dep' or o == '-d':
212 elif o == '--outdir' or o == '-o':
216 elif o == '--global-lisp':
220 elif o== '--help' or o == '-h':
228 base = os.path.splitext (lyfile_nm)[0]
231 (g, m, deps) = parse_logfile (filenm)
233 enc_name = 'FetaEncoding'
234 if re.search ('parmesan', filenm):
235 enc_name = 'ParmesanEncoding'
236 elif re.search ('feta-brace', filenm):
237 enc_name = 'FetaBraceEncoding'
238 elif re.search ('feta-alphabet', filenm):
239 enc_name = 'FetaAlphabetEncoding';
241 open (enc_nm, 'w').write (ps_encoding (enc_name, g, m))
242 open (char_lisp_nm, 'w').write (character_lisp_table (g, m))
243 open (global_lisp_nm, 'w').write (global_lisp_table (g))
245 open (depfile_nm, 'wb').write (get_deps (deps,
246 [base + '.log', base + '.dvi', base + '.pfa',