37
34
return (autolines, deps)
42
38
def __init__ (self):
46
def tfm_checksum (fn):
47
sys.stderr.write ("Reading checksum from `%s'\n" % fn)
55
cs = cs + (long (ord (b)) << shift)
60
## ugh. What's font_family supposed to be? It's not an afm thing.
61
41
font_family = 'feta'
62
43
def parse_logfile (fn):
63
44
(autolines, deps) = read_log_file (fn)
48
'filename' : os.path.splitext (os.path.basename (fn))[0]
68
52
for l in autolines:
69
tags = string.split(l, '@:')
53
tags = string.split (l, '@:')
70
54
if tags[0] == 'group':
56
elif tags[0] == 'puorg':
72
58
elif tags[0] == 'char':
61
name = re.sub ('-', 'M', name)
63
name = group + '.' + name
74
'description': tags[1],
75
'name': group + '-' + tags[9],
65
'description': tags[1],
77
67
'code': string.atoi (tags[2]),
78
'breapth':string.atof (tags[3]),
68
'breapth': string.atof (tags[3]),
79
69
'width': string.atof (tags[4]),
80
'depth':string.atof (tags[5]),
81
'height':string.atof (tags[6]),
70
'depth': string.atof (tags[5]),
71
'height': string.atof (tags[6]),
82
72
'wx': string.atof (tags[7]),
83
'wy':string.atof (tags[8]),
73
'wy': string.atof (tags[8]),
85
75
charmetrics.append (m)
86
76
elif tags[0] == 'font':
89
79
# To omit 'GNU' (foundry) from font name proper:
93
83
tags.append ('Regular')
85
encoding = re.sub (' ','-', tags[5])
95
global_info['FontName'] = string.join (name,'-')
88
global_info['design_size'] = string.atof (tags[4])
89
global_info['FontName'] = string.join (name, '-')
96
90
global_info['FullName'] = string.join (name,' ')
97
91
global_info['FamilyName'] = string.join (name[1:-1],
100
94
global_info['Weight'] = tags[4]
102
96
global_info['Weight'] = tags[-1]
103
98
global_info['FontBBox'] = '0 0 1000 1000'
104
99
global_info['Ascender'] = '0'
105
100
global_info['Descender'] = '0'
106
global_info['EncodingScheme'] = 'FontSpecific'
101
global_info['EncodingScheme'] = encoding
103
elif tags[0] == 'parameter':
104
global_info[tags[1]] = tags[2];
108
106
return (global_info, charmetrics, deps)
111
def write_afm_char_metric(file, charmetric):
114
tup = (charmetric['code'],
116
-charmetric['breapth'] *f,
117
-charmetric['depth']*f,
118
charmetric['width']*f,
119
charmetric['height']*f,
120
charmetric['wx'] * f,
121
charmetric['wy'] * f)
123
file.write ('C %d ; N %s ; B %d %d %d %d ; W %d %d ;\n'% tup)
125
def write_afm_header (file):
126
file.write ("StartFontMetrics 2.0\n")
127
file.write ("Comment Automatically generated by mf-to-table.py\n")
129
def write_afm_metric (file, global_info, charmetrics):
130
for (k,v) in global_info.items():
131
file.write ("%s %s\n" % (k,v))
132
file.write ('StartCharMetrics %d\n' % len(charmetrics ))
133
for m in charmetrics:
134
write_afm_char_metric (file,m)
135
file.write ('EndCharMetrics\n')
136
file.write ('EndFontMetrics\n')
139
110
def write_tex_defs (file, global_info, charmetrics):
140
##nm = global_info['FontFamily']
142
112
for m in charmetrics:
143
file.write (r'''\gdef\%s%s{\char%d}%%%s''' % (nm, m['tex'], m['code'],'\n'))
114
texname = re.sub ('[_.]', 'X', m['name'])
115
def digit_to_letter (match):
116
return chr (ord (match.group(1)) - ord ('0') + ord ('A'))
117
texname = re.sub ('([0-9])', digit_to_letter, texname)
118
file.write (r'''\gdef\%s%s{\char%d}%%%s''' % \
119
(nm, texname, m['code'],'\n'))
144
120
file.write ('\\endinput\n')
123
def write_character_lisp_table (file, global_info, charmetrics):
125
def conv_char_metric (charmetric):
128
((bbox . (%f %f %f %f))
131
(attachment . (%f . %f))))
132
""" %(charmetric['name'],
133
-charmetric['breapth'] * f,
134
-charmetric['depth'] * f,
135
charmetric['width'] * f,
136
charmetric['height'] * f,
137
global_info['filename'],
144
for c in charmetrics:
145
file.write (conv_char_metric (c))
148
def write_global_lisp_table (file, 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])
146
163
def write_ps_encoding (name, file, global_info, charmetrics):
147
164
encs = ['.notdef'] * 256
148
165
for m in charmetrics:
149
encs[m['code']] = m['tex']
166
encs[m['code']] = m['name']
151
168
file.write ('/%s [\n' % name)
152
for m in range(0,256):
169
for m in range (0, 256):
153
170
file.write (' /%s %% %d\n' % (encs[m], m))
154
171
file.write ('] def\n')
156
def write_fontlist (file, global_info, charmetrics):
157
##nm = global_info['FontFamily']
161
%% LilyPond file to list all font symbols and the corresponding names
162
%% Automatically generated by mf-to-table.py
163
\score{ \lyrics \new Lyrics { \time %d/8
164
""" % (2*per_line+1))
167
for m in charmetrics:
171
## \musicglyph and \markup require "_" to be escaped differently:
174
scm_string = re.sub('_', r'_', m['name'])
175
tex_string = re.sub ('_', r'\\_' , m['name'])
177
## prevent TeX from interpreting "--" as long dash:
178
tex_string=re.sub('--','-{}-', tex_string)
180
file.write (' \\markup { \\raise #0.75 \\vcenter \\musicglyph #"%s" " %s" } 4 \n' % (scm_string, tex_string))
183
file.write ('\skip 8 \\break\n')
191
\override SeparationItem #'padding = #2
192
minimumVerticalExtent = ##f
196
\remove "Bar_number_engraver"
202
174
def write_deps (file, deps, targets):
205
175
for t in targets:
206
176
t = re.sub ( '^\\./', '', t)
207
177
file.write ('%s '% t)
269
239
base = re.sub ('.tex$', '', texfile_nm)
271
241
for filenm in files:
272
(g,m, deps) = parse_logfile (filenm)
273
cs = tfm_checksum (re.sub ('.log$', '.tfm', filenm))
274
afm = open (afmfile_nm, 'w')
242
(g, m, deps) = parse_logfile (filenm)
276
write_afm_header (afm)
277
afm.write ("Comment TfmCheckSum %d\n" % cs)
278
write_afm_metric (afm, g, m)
280
244
write_tex_defs (open (texfile_nm, 'w'), g, m)
281
245
enc_name = 'FetaEncoding'
282
if re.search ('parmesan', filenm) :
246
if re.search ('parmesan', filenm):
283
247
enc_name = 'ParmesanEncoding'
284
elif re.search ('feta-brace', filenm) :
248
elif re.search ('feta-brace', filenm):
285
249
enc_name = 'FetaBraceEncoding'
250
elif re.search ('feta-alphabet', filenm):
251
enc_name = 'FetaAlphabetEncoding';
288
253
write_ps_encoding (enc_name, open (enc_nm, 'w'), g, m)
290
write_deps (open (depfile_nm, 'wb'), deps, [base + '.dvi', base + '.pfa', base + '.pfb', texfile_nm, afmfile_nm])
292
write_fontlist(open (lyfile_nm, 'w'), g, m)
254
write_character_lisp_table (open (char_lisp_nm, 'w'), g, m)
255
write_global_lisp_table (open (global_lisp_nm, 'w'), g)
257
write_deps (open (depfile_nm, 'wb'), deps,
258
[base + '.log', base + '.dvi', base + '.pfa',
259
base + '.pfb', texfile_nm])