diff options
-rwxr-xr-x | wfs.py | 19 |
1 files changed, 7 insertions, 12 deletions
@@ -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)) |