• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python
2
3from __future__ import print_function, division, absolute_import
4
5import sys
6import xml.etree.ElementTree as ET
7
8# Can we extract this from HTML element itself? I couldn't.
9namespaces = {
10	'ft': 'https://github.com/OpenType/fonttest',
11	'xlink': 'http://www.w3.org/1999/xlink',
12}
13def ns(s):
14	ns,s = s.split(':')
15	return '{%s}%s' % (namespaces[ns], s)
16
17def unistr(s):
18	return ','.join('U+%04X' % ord(c) for c in s)
19
20def glyphstr(glyphs):
21	out = []
22	for glyphname,x,y in glyphs:
23		if x or y:
24			out.append('%s@%d,%d' % (glyphname, x, y))
25		else:
26			out.append(glyphname)
27	return '['+'|'.join(out)+']'
28
29html = ET.fromstring(sys.stdin.read())
30found = False
31
32for elt in html.findall(".//*[@class='expected'][@ft:id]", namespaces):
33	found = True
34	name = elt.get(ns('ft:id'))
35	text = elt.get(ns('ft:render'))
36	font = elt.get(ns('ft:font'))
37	variations = elt.get(ns('ft:var'), '').replace(':', '=').replace(';', ',')
38	glyphs = []
39	for use in elt.findall(".//use"):
40		x = int(use.get('x'))
41		y = int(use.get('y'))
42		href = use.get(ns('xlink:href'))
43		assert href[0] == '#'
44		glyphname = '.'.join(href[1:].split('/')[1].split('.')[1:])
45		glyphs.append((glyphname, x, y))
46	opts = '--font-size=1000 --ned --remove-default-ignorables --font-funcs=ft'
47	if variations:
48		opts = opts + ' --variations=%s' % variations
49	print ("../fonts/%s:%s:%s:%s" % (font, opts, unistr(text), glyphstr(glyphs)))
50
51for elt in html.findall(".//*[@class='should-not-crash'][@ft:id]", namespaces):
52	found = True
53	name = elt.get(ns('ft:id'))
54	text = elt.get(ns('ft:render'))
55	font = elt.get(ns('ft:font'))
56	variations = elt.get(ns('ft:var'), '').replace(':', '=').replace(';', ',')
57	opts = ''
58	if variations:
59		opts = '--variations=%s' % variations
60	print ("../fonts/%s:%s:%s:*" % (font, opts, unistr(text)))
61
62sys.exit(0 if found else 1)
63