summaryrefslogtreecommitdiffstats
path: root/examples/fontforge-old/FFlistGlyphinfo.py
blob: 883d0337c422ffdc5c9bb8445c47e874a46b1a9b (plain)
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
53
54
55
56
57
58
59
60
61
#!/usr/bin/env python3
'FontForge: List all the data in a glyph object in key, value pairs'
__url__ = 'https://github.com/silnrsi/pysilfont'
__copyright__ = 'Copyright (c) 2015 SIL International (https://www.sil.org)'
__license__ = 'Released under the MIT License (https://opensource.org/licenses/MIT)'
__author__ = 'David Raymond'

import fontforge, types, sys
from silfont.core import execute

argspec = [
    ('font',{'help': 'Input font file'}, {'type': 'infont'}),
    ('-o','--output',{'help': 'Output text file'}, {'type': 'outfile', 'def': 'glyphinfo.txt'})]


def doit(args) :
    font=args.font
    outf = args.output

    glyphn = raw_input("Glyph name or number: ")

    while glyphn:

        isglyph=True
        if not(glyphn in font):
            try:
                glyphn=int(glyphn)
            except ValueError:
                isglyph=False
            else:
                if not(glyphn in font):
                    isglyph=False

        if isglyph:
            g=font[glyphn]
            outf.write("\n%s\n\n" % glyphn)
            # Write to file all normal key,value pairs - exclude __ and built in functions
            for k in dir(g):
                if k[0:2] == "__": continue
                attrk=getattr(g,k)
                if attrk is None: continue
                tk=type(attrk)
                if tk == types.BuiltinFunctionType: continue
                if k == "ttinstrs": # ttinstr values are not printable characters
                    outf.write("%s,%s\n" % (k,"<has values>"))
                else:
                    outf.write("%s,%s\n" % (k,attrk))
            # Write out all normal keys where value is none
            for k in dir(g):
                attrk=getattr(g,k)
                if attrk is None:
                    outf.write("%s,%s\n" % (k,attrk))
        else:
            print "Invalid glyph"

        glyphn = raw_input("Glyph name or number: ")
    print "done"
    outf.close

def cmd() : execute("FF",doit,argspec) 
if __name__ == "__main__": cmd()