2018-01-10 00:54:12 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
2018-03-29 08:18:47 +00:00
|
|
|
from __future__ import print_function, division, absolute_import
|
|
|
|
|
2018-01-10 00:54:12 +00:00
|
|
|
import sys
|
|
|
|
import xml.etree.ElementTree as ET
|
|
|
|
|
|
|
|
# Can we extract this from HTML element itself? I couldn't.
|
|
|
|
namespaces = {
|
|
|
|
'ft': 'https://github.com/OpenType/fonttest',
|
|
|
|
'xlink': 'http://www.w3.org/1999/xlink',
|
|
|
|
}
|
|
|
|
def ns(s):
|
|
|
|
ns,s = s.split(':')
|
|
|
|
return '{%s}%s' % (namespaces[ns], s)
|
|
|
|
|
|
|
|
def unistr(s):
|
|
|
|
return ','.join('U+%04X' % ord(c) for c in s)
|
|
|
|
|
|
|
|
def glyphstr(glyphs):
|
|
|
|
out = []
|
|
|
|
for glyphname,x,y in glyphs:
|
|
|
|
if x or y:
|
|
|
|
out.append('%s@%d,%d' % (glyphname, x, y))
|
|
|
|
else:
|
|
|
|
out.append(glyphname)
|
|
|
|
return '['+'|'.join(out)+']'
|
|
|
|
|
|
|
|
html = ET.fromstring(sys.stdin.read())
|
|
|
|
found = False
|
2018-10-04 10:13:55 +00:00
|
|
|
|
2018-01-10 00:54:12 +00:00
|
|
|
for elt in html.findall(".//*[@class='expected'][@ft:id]", namespaces):
|
|
|
|
found = True
|
|
|
|
name = elt.get(ns('ft:id'))
|
|
|
|
text = elt.get(ns('ft:render'))
|
|
|
|
font = elt.get(ns('ft:font'))
|
2018-10-04 10:09:45 +00:00
|
|
|
variations = elt.get(ns('ft:var'), '').replace(':', '=').replace(';', ',')
|
2018-01-10 00:54:12 +00:00
|
|
|
glyphs = []
|
|
|
|
for use in elt.findall(".//use"):
|
|
|
|
x = int(use.get('x'))
|
|
|
|
y = int(use.get('y'))
|
|
|
|
href = use.get(ns('xlink:href'))
|
|
|
|
assert href[0] == '#'
|
|
|
|
glyphname = '.'.join(href[1:].split('/')[1].split('.')[1:])
|
|
|
|
glyphs.append((glyphname, x, y))
|
2018-01-10 02:35:20 +00:00
|
|
|
opts = '--font-size=1000 --ned --remove-default-ignorables --font-funcs=ft'
|
2018-10-04 10:09:45 +00:00
|
|
|
if variations:
|
|
|
|
opts = opts + ' --variations=%s' % variations
|
2018-01-10 02:22:08 +00:00
|
|
|
print ("../fonts/%s:%s:%s:%s" % (font, opts, unistr(text), glyphstr(glyphs)))
|
2018-01-10 00:54:12 +00:00
|
|
|
|
2018-10-04 10:13:55 +00:00
|
|
|
for elt in html.findall(".//*[@class='should-not-crash'][@ft:id]", namespaces):
|
|
|
|
found = True
|
|
|
|
name = elt.get(ns('ft:id'))
|
|
|
|
text = elt.get(ns('ft:render'))
|
|
|
|
font = elt.get(ns('ft:font'))
|
|
|
|
variations = elt.get(ns('ft:var'), '').replace(':', '=').replace(';', ',')
|
|
|
|
opts = ''
|
|
|
|
if variations:
|
|
|
|
opts = '--variations=%s' % variations
|
|
|
|
print ("../fonts/%s:%s:%s:*" % (font, opts, unistr(text)))
|
|
|
|
|
2018-01-10 00:54:12 +00:00
|
|
|
sys.exit(0 if found else 1)
|