5 from pprint
import pprint
10 src: url("https://www.com/test1.eot");
11 src: url("https://www.com/test1.eot?#iefix") format("embedded-opentype"), url("https://www.com/test1.woff2") format("woff2"), url("https://www.com/test1.woff") format("woff"), url("https://www.com/test1.svg") format("svg");
14 font-family: "Arial Italic";
15 src: url("www.com/test2.eot");
16 src: url("www.com/test2.eot?#iefix") format("embedded-opentype"), url("www.com/test2.woff2") format("woff2"), url("www.com/test2.woff") format("woff"), url("www.com/test2.svg") format("svg");
20 parser
= css_parser
.CSSParser()
21 sheet
= parser
.parseFile('WF-000099-001641.css')
22 #sheet = parser.parseString(CSSstr)
27 if rule
.type == rule
.FONT_FACE_RULE
:
29 for property in rule
.style
:
30 if property.name
== 'font-family':
31 font
= property.value
.strip('"')
33 if property.name
== 'src':
34 for i
in range(0, property.propertyValue
.length
, 2):
35 url
= property.propertyValue
[i
].absoluteUri
36 format
= re
.findall('^format\("(.*?)"\)$', property.propertyValue
[i
+ 1].value
)[0]
37 #fonts[font][pair[1]] = pair[0]
48 dfn
= fn
.replace(' ','_')
49 print(''.join(["\tout=out/",dfn
,'.woff.gz']))
53 if rule.type == rule.FONT_FACE_RULE:
55 for property in rule.style:
56 if property.name == 'font-family':
57 font = property.value.strip('"')
59 if property.name == 'src':
60 for pair in re.findall('url\((.*?)\) format\("(.*?)"\)', property.value):
61 #fonts[font][pair[1]] = pair[0]
65 uri可以读,但是cssfunction还是得regex,不如直接全部regex解决……
67 if property.name == 'src':
68 for i in range(0, property.propertyValue.length, 2):
69 url = property.propertyValue[i].absoluteUri
70 format = re.findall('"(.*?)"', property.propertyValue[i + 1].value)[0]
71 fonts[font][format] = url
74 https://github.com/hanikesn/woff2otf/blob/master/woff2otf.py
75 https://github.com/samboy/WOFF
77 https://github.com/google/woff2
80 otf2otc: (https://github.com/fonttools/fonttools/issues/17)
81 https://github.com/adobe-type-tools/afdko/blob/develop/python/afdko/otf2otc.py
82 https://github.com/googlei18n/nototools/blob/master/nototools/ttc_utils.py