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 'ss' : ('regular', 'sans'),
55 'bx': ('bold', 'roman'),
56 'bxti' : ('bold', 'italic'),
57 'csc' : ('smallcaps', 'roman'),
58 'r' : ('regular', 'roman'),
59 'ss' : ('regular', 'sansserif'),
60 'tt' : ('regular', 'typewriter'),
61 'ti' : ('regular', 'italic'),
64 def set_defaults (self, name):
67 self.EncodingScheme = 'AdobeStandard'
70 self.family = 'LilyPond'
73 self.setwidth = 'normal'
77 self.xresolution = '0'
78 self.yresolution = '0'
80 self.averagewidth = '0'
82 self.encoding = 'FontSpecific'
84 split = string.split (name, '-')
87 # Adobe FontName = X11 foundry-family-weight-style
89 self.foundry, self.family = split[:2]
91 self.foundry = split[0]
92 self.family = string.join (split[1:-2], ' ')
93 self.weight = string.join (split[2:-1], ' ')
94 self.style = split[-1:][0]
95 self.FamilyName = '%s %s' % (self.family, self.weight)
96 self.designsize = self.style
97 elif name[:2] == 'cm':
98 self.foundry = 'TeX' # Knuth?
99 self.FamilyName = 'Computer Modern'
100 self.family = self.FamilyName
101 m = re.match ('^cm([a-z]*)([0-9]*)', name)
102 self.weight = string.join (self.cm[m.group (1)], ' ')
103 self.designsize = m.group (2)
104 self.style = self.designsize
106 self.FamilyName = name
108 def __init__ (self, x):
109 if type (x) == type ("hallo"):
110 m = re.match ('([-_A-Za-z]*)([0-9]*)', x)
112 self.basename = m.group (1)
113 self.designsize = m.group (2)
114 self.set_defaults (x)
115 elif type (x) == type ({}):
116 self.set_defaults (x['FontName'])
118 self.__dict__[k] = x[k]
120 def __getitem__ (self, key):
121 return self.__dict__[key]
124 return (self.foundry, self.family, self.weight,
125 self.slant, self.setwidth, self.style,
126 self.pixelsize, self.pointsize,
127 self.xresolution, self.yresolution,
128 self.spacing, self.averagewidth,
129 self.registry, self.encoding)
133 # wat een intervaas...
134 ls = sys.stdin.readline ()
135 ls = string.split (ls)
139 if len (ls) and ls[0] == 'sodipodi':
142 elif len (ls) and ls[0] == 'sketch':
146 if not (sketch_p or sodipodi_p):
150 basename = re.sub ('\.pf[ab]', '',filename)
151 fontname = re.sub ('-', ' ',basename)
153 m = re.search ("([0-9]+)$", fontname)
154 designsize = 'normal'
158 designsize = m.group (1)
159 fontbase = re.sub ("([0-9]+)$", "", fontname)
162 # FIXME: Font naming -- what a mess
163 # Check sane naming with xfontsel and gtkfontsel
165 # Adobe's font naming scheme and X11's seem to be conflicting.
166 # Adobe's FontFamily seems to be X11's family + weight
167 # Also, text selection applets like gtkfontsel, gfontview and
168 # GNOME-applications specific ones, display X11's `family'
169 # parameter as `Font', and X11's `Weight' parameter as `Style'.
171 # Using X11 description/convention -- good for xfontsel:
173 # 2 family: LilyPond <basename>
174 # 3 weight: <designsize>
175 # 4 slant: r(oman) =upright
179 # 8 pointsize: 0 (20 crashes xfs, moved to style)
182 # 11 spacing: p(roportional)
185 # 14 encoding: fonstpecific
188 # feta20.pfa -GNU-LilyPond feta-20-r-normal--0-0-0-0-p-0-gnu-fontspecific
190 # However, GNOME (gtkfontsel, gnome apps) seems to want:
194 # 3 weight: <basename>
195 # 4 slant: r(oman) =upright
197 # 6 style: <designsize>
199 # 8 pointsize: 0 (20 crashes xfs, moved to style)
202 # 11 spacing: p(roportional)
205 # 14 encoding: fonstpecific
208 # feta20.pfa -GNU-LilyPond-feta-r-normal--20-0-0-0-p-0-gnu-fontspecific
211 ## ouch, pointsize 20 crashes xfs
212 ## XXXfeta20.pfa -GNU-LilyPond Feta-regular-r-normal--0-20-0-0-p-0-gnu-fontspecific
214 ## feta20.pfa -GNU-LilyPond feta-regular-r-normal-20-0-0-0-0-p-0-gnu-fontspecific
218 #afmfile = find_file (basename + '.afm')
219 afmfile = basename + '.afm'
222 afmfile = os.path.abspath (afmfile)
223 if os.path.exists (afmfile):
224 afm = read_afm_file (afmfile)
225 fontinfo = Font_info (afm.__dict__)
227 fontinfo = Font_info (basename)
229 family_name = string.join (string.split (fontinfo['FamilyName'],
233 print string.join ((os.path.abspath (filename),
235 fontinfo.FamilyName,''
241 # Sketch's lilypond.sfd map:
242 s = string.join ([fontinfo.FontName,
244 '%s %s' % (fontinfo.weight, fontinfo.style),
245 string.join (fontinfo.get_X11 ()[:4], '-'),
246 string.join (fontinfo.get_X11 ()[-2:], '-'),
251 s = string.join ([fontinfo.FamilyName + fontinfo.designsize,
253 '%s %s' % (fontinfo.weight, fontinfo.style),
254 string.join (fontinfo.get_X11 ()[:4], '-'),
255 string.join (fontinfo.get_X11 ()[-2:], '-'),
260 print filename + ' -' + string.join (fontinfo.get_X11 (), '-')