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'
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
87 self.foundry, self.family = split[:2]
89 self.foundry = split[0]
90 self.family = string.join (split[1:-2], ' ')
91 self.weight = string.join (split[2:-1], ' ')
92 self.style = split[-1:][0]
93 self.FamilyName = '%s %s' % (self.family, self.weight)
94 self.designsize = self.style
95 elif name[:2] == 'cm':
96 self.foundry = 'TeX' # Knuth?
97 self.FamilyName = 'Computer Modern'
98 self.family = self.FamilyName
99 m = re.match ('^cm([a-z]*)([0-9]*)', name)
100 self.weight = string.join (self.cm[m.group (1)], ' ')
101 self.designsize = m.group (2)
102 self.style = self.designsize
104 self.FamilyName = name
106 def __init__ (self, x):
107 if type (x) == type ("hallo"):
108 m = re.match ('([-_A-Za-z]*)([0-9]*)', x)
110 self.basename = m.group (1)
111 self.designsize = m.group (2)
112 self.set_defaults (x)
113 elif type (x) == type ({}):
114 self.set_defaults (x['FontName'])
116 self.__dict__[k] = x[k]
118 def __getitem__ (self, key):
119 return self.__dict__[key]
122 return (self.foundry, self.family, self.weight,
123 self.slant, self.setwidth, self.style,
124 self.pixelsize, self.pointsize,
125 self.xresolution, self.yresolution,
126 self.spacing, self.averagewidth,
127 self.registry, self.encoding)
131 # wat een intervaas...
132 ls = sys.stdin.readline ()
133 ls = string.split (ls)
136 if len (ls) and ls[0] == 'sketch':
144 basename = re.sub ('\.pf[ab]', '',filename)
145 fontname = re.sub ('-', ' ',basename)
147 m = re.search ("([0-9]+)$", fontname)
148 designsize = 'normal'
152 designsize = m.group (1)
153 fontbase = re.sub ("([0-9]+)$", "", fontname)
156 # FIXME: Font naming -- what a mess
157 # Check sane naming with xfontsel and gtkfontsel
159 # Adobe's font naming scheme and X11's seem to be conflicting.
160 # Adobe's FontFamily seems to be X11's family + weight
161 # Also, text selection applets like gtkfontsel, gfontview and
162 # GNOME-applications specific ones, display X11's `family'
163 # parameter as `Font', and X11's `Weight' parameter as `Style'.
165 # Using X11 description/convention -- good for xfontsel:
167 # 2 family: LilyPond <basename>
168 # 3 weight: <designsize>
169 # 4 slant: r(oman) =upright
173 # 8 pointsize: 0 (20 crashes xfs, moved to style)
176 # 11 spacing: p(roportional)
179 # 14 encoding: fonstpecific
182 # feta20.pfa -GNU-LilyPond feta-20-r-normal--0-0-0-0-p-0-gnu-fontspecific
184 # However, GNOME (gtkfontsel, gnome apps) seems to want:
188 # 3 weight: <basename>
189 # 4 slant: r(oman) =upright
191 # 6 style: <designsize>
193 # 8 pointsize: 0 (20 crashes xfs, moved to style)
196 # 11 spacing: p(roportional)
199 # 14 encoding: fonstpecific
202 # feta20.pfa -GNU-LilyPond-feta-r-normal--20-0-0-0-p-0-gnu-fontspecific
205 ## ouch, pointsize 20 crashes xfs
206 ## XXXfeta20.pfa -GNU-LilyPond Feta-regular-r-normal--0-20-0-0-p-0-gnu-fontspecific
208 ## feta20.pfa -GNU-LilyPond feta-regular-r-normal-20-0-0-0-0-p-0-gnu-fontspecific
212 #afmfile = find_file (basename + '.afm')
213 afmfile = basename + '.afm'
216 afmfile = os.path.abspath (afmfile)
217 if os.path.exists (afmfile):
218 afm = read_afm_file (afmfile)
219 fontinfo = Font_info (afm.__dict__)
221 fontinfo = Font_info (basename)
223 family_name = string.join (string.split (fontinfo['FamilyName'],
226 print filename + ' -' + string.join (fontinfo.get_X11 (), '-')
229 # Sketch's lilypond.sfd map:
230 s = string.join ([fontinfo.FontName,
232 '%s %s' % (fontinfo.weight, fontinfo.style),
233 string.join (fontinfo.get_X11 ()[:4], '-'),
234 string.join (fontinfo.get_X11 ()[-2:], '-'),
239 s = string.join ([fontinfo.FamilyName + fontinfo.designsize,
241 '%s %s' % (fontinfo.weight, fontinfo.style),
242 string.join (fontinfo.get_X11 ()[:4], '-'),
243 string.join (fontinfo.get_X11 ()[-2:], '-'),