5 ## make a fonts.scale file.
16 # Read some global vars
18 def __init__ (self, filename):
19 self.filename = filename
20 self.lines = open (self.filename).readlines ()
23 afm = Afm_font_metric (self.filename)
24 for i in self.lines[:20]:
25 m = re.match ('([^ \t\n]*)[ \t]*(.*[^ \t\n])', i)
30 afm.__dict__[key] = value
33 class Afm_font_metric:
34 def __init__ (self, filename):
35 m = re.match ('.*/(.+)', filename)
36 self.filename = m.group (1)
37 m = re.match ('([-_A-Za-z]*)([0-9]*)', self.filename)
38 self.name = m.group (1) + m.group (2)
39 self.basename = m.group (1)
40 self.designsize = m.group (2)
42 def read_afm_file (filename):
43 reader = Afm_reader (filename)
44 return reader.get_afm ()
46 #if __name__ == '__main__':
47 # i = read_afm_file (sys.argv[1])
48 # print i, i.FullName, i.FontName
54 'bx': ('bold', 'roman'),
55 'bxti' : ('bold', 'italic'),
56 'csc' : ('smallcaps', 'roman'),
57 'r' : ('regular', 'roman'),
58 'tt' : ('regular', 'typewriter'),
59 'ti' : ('regular', 'italic'),
62 def set_defaults (self, name):
65 self.EncodingScheme = 'AdobeStandard'
68 self.family = 'LilyPond'
71 self.setwidth = 'normal'
73 self.pixelsize = '' # '0'
75 self.xresolution = '0'
76 self.yresolution = '0'
78 self.averagewidth = '0'
80 self.encoding = 'FontSpecific'
82 split = string.split (name, '-')
85 # Adobe FontName = X11 foundry-family-weight-style
86 self.foundry, self.family = split[:2]
87 self.weight = string.join (split[2:-1], ' ')
88 self.style = split[-1:][0]
89 self.FamilyName = '%s %s' % (self.family, self.weight)
90 self.designsize = self.style
91 elif name[:2] == 'cm':
92 self.foundry = 'TeX' # Knuth?
93 self.FamilyName = 'Computer Modern'
94 self.family = self.FamilyName
95 m = re.match ('^cm([a-z]*)([0-9]*)', name)
96 self.weight = string.join (self.cm[m.group (1)], ' ')
97 self.designsize = m.group (2)
98 self.style = self.designsize
100 self.FamilyName = name
102 def __init__ (self, x):
103 if type (x) == type ("hallo"):
104 m = re.match ('([-_A-Za-z]*)([0-9]*)', x)
106 self.basename = m.group (1)
107 self.designsize = m.group (2)
108 self.set_defaults (x)
109 elif type (x) == type ({}):
110 self.set_defaults (x['FontName'])
112 self.__dict__[k] = x[k]
114 def __getitem__ (self, key):
115 return self.__dict__[key]
118 return (self.foundry, self.family, self.weight,
119 self.slant, self.setwidth, self.style,
120 self.pixelsize, self.pointsize,
121 self.xresolution, self.yresolution,
122 self.spacing, self.averagewidth,
123 self.registry, self.encoding)
127 # wat een intervaas...
128 ls = sys.stdin.readline ()
129 ls = string.split (ls)
132 if len (ls) and ls[0] == 'sketch':
140 basename = re.sub ('\.pf[ab]', '',filename)
141 fontname = re.sub ('-', ' ',basename)
143 m = re.search ("([0-9]+)$", fontname)
144 designsize = 'normal'
148 designsize = m.group (1)
149 fontbase = re.sub ("([0-9]+)$", "", fontname)
152 # FIXME: Font naming -- what a mess
153 # Check sane naming with xfontsel and gtkfontsel
155 # Adobe's font naming scheme and X11's seem to be conflicting.
156 # Adobe's FontFamily seems to be X11's family + weight
157 # Also, text selection applets like gtkfontsel, gfontview and
158 # GNOME-applications specific ones, display X11's `family'
159 # parameter as `Font', and X11's `Weight' parameter as `Style'.
161 # Using X11 description/convention -- good for xfontsel:
163 # family: LilyPond <basename>
164 # weight: <designsize>
165 # slant: r(oman) =upright
169 # pointsize: 0 (20 crashes xfs, moved to style)
172 # spacing: p(roportional)
175 # encoding: fonstpecific
178 # feta20.pfa -GNU-LilyPond feta-20-r-normal--0-0-0-0-p-0-gnu-fontspecific
180 # However, GNOME (gtkfontsel, gnome apps) seems to want:
185 # slant: r(oman) =upright
187 # style: <designsize>
189 # pointsize: 0 (20 crashes xfs, moved to style)
192 # spacing: p(roportional)
195 # encoding: fonstpecific
198 # feta20.pfa -GNU-LilyPond-feta-r-normal--20-0-0-0-p-0-gnu-fontspecific
201 ## ouch, pointsize 20 crashes xfs
202 ## XXXfeta20.pfa -GNU-LilyPond Feta-regular-r-normal--0-20-0-0-p-0-gnu-fontspecific
204 ## feta20.pfa -GNU-LilyPond feta-regular-r-normal-20-0-0-0-0-p-0-gnu-fontspecific
208 #afmfile = find_file (basename + '.afm')
209 afmfile = basename + '.afm'
212 afmfile = os.path.abspath (afmfile)
213 if os.path.exists (afmfile):
214 afm = read_afm_file (afmfile)
215 fontinfo = Font_info (afm.__dict__)
217 fontinfo = Font_info (basename)
219 family_name = string.join (string.split (fontinfo['FamilyName'],
222 print filename + ' -' + string.join (fontinfo.get_X11 (), '-')
225 # Sketch's lilypond.sfd map:
226 s = string.join ([fontinfo.FontName,
228 '%s %s' % (fontinfo.weight, fontinfo.style),
229 string.join (fontinfo.get_X11 ()[:5], '-'),
230 string.join (fontinfo.get_X11 ()[:-2], '-'),
235 s = string.join ([fontinfo.FamilyName,
237 '%s %s' % (fontinfo.weight, fontinfo.style),
238 string.join (fontinfo.get_X11 ()[:5], '-'),
239 string.join (fontinfo.get_X11 ()[:-2], '-'),