File: afm.py

package info (click to toggle)
mftrace 1.1.5-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 272 kB
  • ctags: 274
  • sloc: python: 1,113; ansic: 557; makefile: 53; sh: 11
file content (31 lines) | stat: -rw-r--r-- 644 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import re
import sys

# Read some global vars 
class Afm_reader:
	def __init__ (self, lines):
		self.lines = lines

	def get_afm (self):
		afm = Afm_font_metric ()
		for i in self.lines[:20]:
			m = re.match ('([^ \t\n]*)[ \t]*(.*[^ \t\n])', i)
			if m and m.group (1):
				key = m.group (1)
				value = m.group (2)
				if key != 'Comment':
					afm.__dict__[key] = value
		return afm

class Afm_font_metric:
	def __init__ (self):
		pass
	
def read_afm_file (filename):
	reader = Afm_reader (open (filename).readlines ())
	return reader.get_afm ()

if __name__ == '__main__':
	i = read_afm_file  (sys.argv[1])
	print i, i.FullName, i.FontName