3 # mf-to-table.py -- convert spacing info in MF logs .afm and .tex
5 # source file of the GNU LilyPond music typesetter
7 # (c) 1997 Han-Wen Nienhuys <hanwen@cs.uu.nl>
17 postfixes
= ['log', 'dvi', '2602gf', 'tfm']
19 def read_log_file (fn
):
20 str = open (fn
).read ()
21 str = re
.sub ('\n', '', str)
22 str = re
.sub ('[\t ]+', ' ', str)
26 def include_func (match
, d
= deps
):
27 d
.append (match
.group (1))
30 def auto_func (match
, a
= autolines
):
31 a
.append (match
.group (1))
34 str = re
.sub ('\(([a-zA-Z_0-9-]+\.mf)', include_func
, str)
35 str = re
.sub ('@{(.*?)@}', auto_func
, str)
37 return (autolines
, deps
)
46 def parse_logfile (fn
):
47 (autolines
, deps
) = read_log_file (fn
)
53 tags
= string
.split(l
, '@:')
54 if tags
[0] == 'group':
56 elif tags
[0] == 'char':
58 'description': tags
[1],
59 'name': group
+ '-' + tags
[7],
61 'code': string
.atoi (tags
[2]),
62 'breapth':string
.atof (tags
[3]),
63 'width': string
.atof (tags
[4]),
64 'depth':string
.atof (tags
[5]),
65 'height':string
.atof (tags
[6])
67 charmetrics
.append (m
)
68 elif tags
[0] == 'font':
69 global_info
['FontName'] = string
.join (tags
[1:])
70 global_info
['FontFamily']=tags
[1]
72 return (global_info
, charmetrics
, deps
)
75 def write_afm_char_metric(file, charmetric
):
78 tup
= (charmetric
['code'],
79 charmetric
['width'] + charmetric
['breapth'],
81 -charmetric
['breapth'] *f
,
82 -charmetric
['depth']*f
,
83 charmetric
['width']*f
,
84 charmetric
['height']*f
)
87 file.write ('C %d ; WX %d ; N %s ; B %d %d %d %d ;\n'% tup
)
89 def write_afm_metric (file, global_info
, charmetrics
):
92 Comment Automatically generated by mf-to-table.py
94 for (k
,v
) in global_info
.items():
95 file.write ("%s %s\n" % (k
,v
))
96 file.write ('StartCharMetrics %d\n' % len(charmetrics
))
98 write_afm_char_metric (file,m
)
99 file.write ('EndCharMetrics\n')
100 file.write ('EndFontMetrics %d\n')
103 def write_tex_defs (file, global_info
, charmetrics
):
104 nm
= global_info
['FontFamily']
105 for m
in charmetrics
:
106 file.write (r
'''\def\%s%s{\char%d}%s''' % (nm
, m
['tex'], m
['code'],'\n'))
109 def write_deps (file, deps
, targets
):
111 file.write ('%s '% t
)
114 file.write ('%s ' % d
)
118 sys
.stdout
.write(r
"""Usage: mf-to-table [options] LOGFILEs
119 Generate feta metrics table from preparated feta log\n
121 -a, --afm=FILE .afm file
122 -d, --dep=FILE print dependency info to FILE
123 -h, --help print this help
124 -l, --ly=FILE name output table
125 -o, --outdir=DIR prefix for dependency info
126 -p, --package=DIR specify package
127 -t, --tex=FILE name output tex chardefs"""
133 (options
, files
) = getopt
.getopt(
134 sys
.argv
[1:], 'a:d:hl:o:p:t:',
135 ['afm=', 'outdir=', 'dep=', 'tex=', 'debug', 'help', 'package='])
146 if o
== '--dep' or o
== '-d':
148 elif o
== '--outdir' or o
== '-o':
150 elif o
== '--tex' or o
== '-t':
152 elif o
== '--help' or o
== '-h':
154 elif o
=='--afm' or o
== '-a':
158 elif o
== '-p' or o
== '--package':
165 (g
,m
, deps
) = parse_logfile (filenm
)
166 afm
= open (afmfile_nm
, 'w')
167 write_afm_metric (afm
, g
,m
)
168 write_tex_defs (open (texfile_nm
, 'w'), g
, m
)
169 write_deps (open (depfile_nm
, 'wb'), deps
, [texfile_nm
, afmfile_nm
])