-
Notifications
You must be signed in to change notification settings - Fork 10
/
parse.py
39 lines (29 loc) · 925 Bytes
/
parse.py
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
#! /usr/bin/python
import sys
from xml.dom import minidom
font_file = sys.argv[1]
font_name = font_file.split('/')[-1].replace('.svg', '')
doc = minidom.parse(font_file)
swift_output_string = """
internal struct Font {
static let FontName = "%s"
}
public enum Icon: String {
""" % font_name
temp_list = []
glyph_count = 0
for glyph in doc.getElementsByTagName('glyph'):
name = glyph.getAttribute('glyph-name')
if name and name not in temp_list:
temp_list.append(name)
if(name[0].isdigit()):
name = "_"+name
name = name.title().replace('-', '')
unicode = glyph.getAttribute('unicode')
unicode = unicode.encode('unicode-escape').decode()
unicode = unicode.replace('u', 'u{') + '}'
swift_output_string += ' case %s = "%s"\n' % (name, unicode)
glyph_count += 1
swift_output_string += '}'
print(swift_output_string)
doc.unlink()