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 'ss' : ('regular', 'sansserif'),
59 'tt' : ('regular', 'typewriter'),
60 'ti' : ('regular', 'italic'),
63 def set_defaults (self, name):
66 self.EncodingScheme = 'AdobeStandard'
69 self.family = 'LilyPond'
72 self.setwidth = 'normal'
76 self.xresolution = '0'
77 self.yresolution = '0'
79 self.averagewidth = '0'
81 self.encoding = 'FontSpecific'
83 split = string.split (name, '-')
86 # Adobe FontName = X11 foundry-family-weight-style
88 self.foundry, self.family = split[:2]
90 self.foundry = split[0]
91 self.family = string.join (split[1:-2], ' ')
92 self.weight = string.join (split[2:-1], ' ')
93 self.style = split[-1:][0]
94 self.FamilyName = '%s %s' % (self.family, self.weight)
95 self.designsize = self.style
96 elif name[:2] == 'cm':
97 self.foundry = 'TeX' # Knuth?
98 self.FamilyName = 'Computer Modern'
99 self.family = self.FamilyName
100 m = re.match ('^cm([a-z]*)([0-9]*)', name)
101 self.weight = string.join (self.cm[m.group (1)], ' ')
102 self.designsize = m.group (2)
103 self.style = self.designsize
105 self.FamilyName = name
107 def __init__ (self, x):
108 if type (x) == type ("hallo"):
109 m = re.match ('([-_A-Za-z]*)([0-9]*)', x)
111 self.basename = m.group (1)
112 self.designsize = m.group (2)
113 self.set_defaults (x)
114 elif type (x) == type ({}):
115 self.set_defaults (x['FontName'])
117 self.__dict__[k] = x[k]
119 def __getitem__ (self, key):
120 return self.__dict__[key]
123 return (self.foundry, self.family, self.weight,
124 self.slant, self.setwidth, self.style,
125 self.pixelsize, self.pointsize,
126 self.xresolution, self.yresolution,
127 self.spacing, self.averagewidth,
128 self.registry, self.encoding)
132 # wat een intervaas...
133 ls = sys.stdin.readline ()
134 ls = string.split (ls)
138 if len (ls) and ls[0] == 'sodipodi':
141 elif len (ls) and ls[0] == 'sketch':
145 if not (sketch_p or sodipodi_p):
149 basename = re.sub ('\.pf[ab]', '',filename)
150 fontname = re.sub ('-', ' ',basename)
152 m = re.search ("([0-9]+)$", fontname)
153 designsize = 'normal'
157 designsize = m.group (1)
158 fontbase = re.sub ("([0-9]+)$", "", fontname)
161 # FIXME: Font naming -- what a mess
162 # Check sane naming with xfontsel and gtkfontsel
164 # Adobe's font naming scheme and X11's seem to be conflicting.
165 # Adobe's FontFamily seems to be X11's family + weight
166 # Also, text selection applets like gtkfontsel, gfontview and
167 # GNOME-applications specific ones, display X11's `family'
168 # parameter as `Font', and X11's `Weight' parameter as `Style'.
170 # Using X11 description/convention -- good for xfontsel:
172 # 2 family: LilyPond <basename>
173 # 3 weight: <designsize>
174 # 4 slant: r(oman) =upright
178 # 8 pointsize: 0 (20 crashes xfs, moved to style)
181 # 11 spacing: p(roportional)
184 # 14 encoding: fonstpecific
187 # feta20.pfa -GNU-LilyPond feta-20-r-normal--0-0-0-0-p-0-gnu-fontspecific
189 # However, GNOME (gtkfontsel, gnome apps) seems to want:
193 # 3 weight: <basename>
194 # 4 slant: r(oman) =upright
196 # 6 style: <designsize>
198 # 8 pointsize: 0 (20 crashes xfs, moved to style)
201 # 11 spacing: p(roportional)
204 # 14 encoding: fonstpecific
207 # feta20.pfa -GNU-LilyPond-feta-r-normal--20-0-0-0-p-0-gnu-fontspecific
210 ## ouch, pointsize 20 crashes xfs
211 ## XXXfeta20.pfa -GNU-LilyPond Feta-regular-r-normal--0-20-0-0-p-0-gnu-fontspecific
213 ## feta20.pfa -GNU-LilyPond feta-regular-r-normal-20-0-0-0-0-p-0-gnu-fontspecific
217 #afmfile = find_file (basename + '.afm')
218 afmfile = basename + '.afm'
221 afmfile = os.path.abspath (afmfile)
222 if os.path.exists (afmfile):
223 afm = read_afm_file (afmfile)
224 fontinfo = Font_info (afm.__dict__)
226 fontinfo = Font_info (basename)
228 family_name = string.join (string.split (fontinfo['FamilyName'],
232 print string.join ((os.path.abspath (filename),
234 fontinfo.FamilyName,''
240 # Sketch's lilypond.sfd map:
241 s = string.join ([fontinfo.FontName,
243 '%s %s' % (fontinfo.weight, fontinfo.style),
244 string.join (fontinfo.get_X11 ()[:4], '-'),
245 string.join (fontinfo.get_X11 ()[-2:], '-'),
250 s = string.join ([fontinfo.FamilyName + fontinfo.designsize,
252 '%s %s' % (fontinfo.weight, fontinfo.style),
253 string.join (fontinfo.get_X11 ()[:4], '-'),
254 string.join (fontinfo.get_X11 ()[-2:], '-'),
259 print filename + ' -' + string.join (fontinfo.get_X11 (), '-')