3 from __future__ import print_function
5 import xml.etree.ElementTree as ET
7 # Can we extract this from HTML element itself? I couldn't.
9 'ft': 'https://github.com/OpenType/fonttest',
10 'xlink': 'http://www.w3.org/1999/xlink',
14 return '{%s}%s' % (namespaces[ns], s)
17 return ','.join('U+%04X' % ord(c) for c in s)
21 for glyphname,x,y in glyphs:
23 out.append('%s@%d,%d' % (glyphname, x, y))
26 return '['+'|'.join(out)+']'
28 html = ET.fromstring(sys.stdin.read())
30 for elt in html.findall(".//*[@class='expected'][@ft:id]", namespaces):
32 name = elt.get(ns('ft:id'))
33 text = elt.get(ns('ft:render'))
34 font = elt.get(ns('ft:font'))
35 vars = elt.get(ns('ft:var'), '').replace(':', '=').replace(';', ',')
37 for use in elt.findall(".//use"):
40 href = use.get(ns('xlink:href'))
42 glyphname = '.'.join(href[1:].split('/')[1].split('.')[1:])
43 glyphs.append((glyphname, x, y))
44 opts = '--font-size=1000 --ned --remove-default-ignorables --font-funcs=ft'
46 opts = opts + ' --variations=%s' % vars
47 print ("../fonts/%s:%s:%s:%s" % (font, opts, unistr(text), glyphstr(glyphs)))
49 sys.exit(0 if found else 1)