-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.py
More file actions
89 lines (83 loc) · 2.87 KB
/
Copy pathindex.py
File metadata and controls
89 lines (83 loc) · 2.87 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import os
import re
'''
Indexer for Latin-1 font packs.
surprisingly badly documented for one of my scripts.. sorry.
- it is 'documented in code', I suppose.
'''
sourceDir = '.'
prefix = 'ezFBfont_'
dirname = os.getcwd().split('/')[-1]
families = []
heights = []
outmap = {}
namewidth = 0
famwidth = 0
charsets = {
'time':'time',
'num':'numeric',
'upper':'uppercase',
'ascii':'ascii',
'supp':'supplemental',
'latin':'latin-1',
'full':'full',
}
csets = charsets.keys()
foundsets = []
# Find our font files
sources = os.scandir(sourceDir)
for family in sources:
if family.is_dir() and (family.name != '__pycache__') and family.name[0].islower():
famname = family.name.replace('new-century-','').replace('-extended','')
if famname not in families:
families.append(famname)
famwidth = max(famwidth, len(famname))
setlist = os.scandir(family)
for cset in setlist:
if cset.name not in charsets.keys():
print('unknown: set "{}" in {}'.format(cset.name, famname))
continue
if cset.name not in foundsets:
foundsets.append(cset.name)
for font in os.scandir(cset):
if font.name[:len(prefix)] != prefix:
continue
namewidth = max(namewidth, len(font.name))
height = int(font.name.split('_')[-1].split('.')[0])
if height not in heights:
heights.append(height)
outmap[font.name] = {'family':famname,
'cset':cset.name,
'height':height}
heights.sort()
families.sort()
if len(foundsets) == 0:
# nothing found; simply exit
exit()
print('Micropython font module tree for: {}\n'.format(dirname))
cols = 'Size: {:>{}} {:>{}}'.format('Family', famwidth, 'Name', namewidth)
# Show us the money
for cset in csets:
if cset not in foundsets:
continue
h = '{} character set'.format(charsets[cset].capitalize())
print('{}\n{}\n{}'.format(h, '-' * len(h), cols))
for height in heights:
# scan matching fonts at this height)
fontlist = []
for font in outmap:
if (outmap[font]['height'] == height) and (outmap[font]['cset'] == cset):
fontlist.append(font)
if len(fontlist) == 0:
continue
print(' {:3d}px:'.format(height))
for font in fontlist:
famstr = font.split('_')[1:-1]
if 'B' in famstr[0]:
style = ' (bold)'
elif 'R' in famstr[0] or famstr[1] == 'Regular':
style = ' (regular)'
else:
style = ''
print(' {:>{}} {:.>{}}{}'.format(outmap[font]['family'], famwidth, font, namewidth, style))
print()