summaryrefslogtreecommitdiff
path: root/wfs.py
diff options
context:
space:
mode:
authorAlex Xu (Hello71) <alex_y_xu@yahoo.ca>2020-07-04 20:27:04 -0400
committerAlex Xu (Hello71) <alex_y_xu@yahoo.ca>2020-07-04 20:27:04 -0400
commitdd3a70f877edd807bd2ab5184b831c2f4335e3e7 (patch)
tree665d6977319eba39bf9a40d34cdd171a98359820 /wfs.py
parente91ab98f976f89ee403097a5c86d77895b683772 (diff)
downloadwfs-dd3a70f877edd807bd2ab5184b831c2f4335e3e7.tar.xz
wfs-dd3a70f877edd807bd2ab5184b831c2f4335e3e7.zip
simplifications and refactoring
Diffstat (limited to 'wfs.py')
-rwxr-xr-xwfs.py19
1 files changed, 7 insertions, 12 deletions
diff --git a/wfs.py b/wfs.py
index 48c033b..c932c3d 100755
--- a/wfs.py
+++ b/wfs.py
@@ -39,7 +39,7 @@ if config['screenshots']:
'font-family:"', font['family'], '";',
'font-weight:', font['weight'], ';',
'font-style:', font['style'], ';',
- 'src: url("', font["fontfile"], '") format("opentype");',
+ 'src: url("', font["fontfile"], '");',
'}'])
REPLACE_FONTS_SCRIPT = ''.join([
@@ -50,7 +50,7 @@ if config['screenshots']:
EXTRACT_SCRIPT = r'''
let whitelist = new Set(arguments[0]);
let walker = document.createTreeWalker(document.body, NodeFilter.SHOW_TEXT);
- let node, dict = new Map();
+ let node, dict = {};
while (node = walker.nextNode()) {
let cs = getComputedStyle(node.parentNode);
let css = k => cs.getPropertyValue(k);
@@ -61,16 +61,11 @@ EXTRACT_SCRIPT = r'''
css('font-style');
if (!whitelist.has(k))
continue;
- const t = node.nodeValue;
- if (dict.has(k))
- for (let c of t)
- dict.get(k).add(c);
- else
- dict.set(k, new Set(t));
+ if (!(k in dict))
+ dict[k] = '';
+ dict[k] += node.nodeValue;
}
- let dict2 = {};
- dict.forEach((v, k) => dict2[k] = [...v.keys()].join(''));
- return dict2;
+ return dict;
'''
DRIVER = None
@@ -159,7 +154,7 @@ def subset(fontdesc, text, fts_opts):
if 'outfile' in fontdesc and flavor in fontdesc['outfile']:
outfile = fontdesc['outfile'][flavor]
else:
- outfile = re.sub(r'\.otf$', f'.subset.{flavor}', fontfile)
+ outfile = re.sub(r'\.[ot]tf$', f'.subset.{flavor}', fontfile)
if outfile == fontfile:
raise Exception('cannot overwrite font file')
ret.append((font, flavor, outfile))