modified: openstmerge.py
[GalaxyCodeBases.git] / python / etc / woffdown.py
blob99cd633d8abdd0904d674ac0f1b1cac80f9f9876
1 #!/usr/bin/env python3
2 import sys
3 import css_parser
4 import re
5 from pprint import pprint
7 CSSstr='''
8 @font-face {
9 font-family: "Arial";
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");
13 @font-face {
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");
18 '''
20 parser = css_parser.CSSParser()
21 sheet = parser.parseFile('WF-000099-001641.css')
22 #sheet = parser.parseString(CSSstr)
24 fonts = {}
26 for rule in sheet:
27 if rule.type == rule.FONT_FACE_RULE:
28 # find property
29 for property in rule.style:
30 if property.name == 'font-family':
31 font = property.value.strip('"')
32 fonts[font] = {}
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]
38 if format == 'woff':
39 fonts[font] = url
40 else:
41 #print(rule.type)
42 pass
44 #pprint(fonts)
46 for fn in fonts:
47 print(fonts[fn])
48 dfn = fn.replace(' ','_')
49 print(''.join(["\tout=out/",dfn,'.woff.gz']))
51 '''
52 for rule in sheet:
53 if rule.type == rule.FONT_FACE_RULE:
54 # find property
55 for property in rule.style:
56 if property.name == 'font-family':
57 font = property.value.strip('"')
58 fonts[font] = {}
59 if property.name == 'src':
60 for pair in re.findall('url\((.*?)\) format\("(.*?)"\)', property.value):
61 #fonts[font][pair[1]] = pair[0]
62 if pair[1] == 'woff':
63 fonts[font] = 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
73 wtff2otf:
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
83 '''