File: afm.py

package info (click to toggle)
mftrace 1.2.20%2Bgit20191022.3b4bc2e-2
  • links: PTS
  • area: main
  • in suites: bullseye
  • size: 260 kB
  • sloc: python: 1,212; ansic: 559; sh: 8; makefile: 7
file content (52 lines) | stat: -rw-r--r-- 1,574 bytes parent folder | download | duplicates (2)
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# this file is part of mftrace - a tool to generate scalable fonts from bitmaps  
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2
# as published by the Free Software Foundation
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Library General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc.,

# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 

# Copyright (c)  2001--2006 by
#  Han-Wen Nienhuys, Jan Nieuwenhuizen



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)