forked from Pythonity/font-awesome-to-png
-
Notifications
You must be signed in to change notification settings - Fork 1
/
export_iconmap.py
26 lines (23 loc) · 910 Bytes
/
export_iconmap.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
import tinycss, re
from uchr import u, uchr
def export_iconmap(filename, prefix):
new_icons = {}
parser = tinycss.make_parser("page3")
try:
stylesheet = parser.parse_stylesheet_file(filename)
except IOError:
print >> sys.stderr, ("Error: CSS file (%s) can't be opened"
% (filename))
exit(1)
is_icon = re.compile(u("\." + prefix + "(.*):before,?"))
for rule in stylesheet.rules:
selector = rule.selector.as_css()
for match in is_icon.finditer(selector):
name = match.groups()[0]
for declaration in rule.declarations:
if declaration.name == u"content":
val = declaration.value.as_css()
if val.startswith('"') and val.endswith('"'):
val = val[1:-1]
new_icons[name] = uchr(int(val[1:], 16))
return new_icons