Debian Codegraph @

tests/test_anchors.py

raw
1 from fontFeatures import Attachment, FontFeatures
2 from lxml import etree
3 import re
4
5 import unittest
6
7
8 def assertSufficientlyEqual(s1, s2):
9 def alltrim(a):
10 a = re.sub("lookupflag 0;", "", a)
11 a = re.sub("#.*", "", a)
12 a = re.sub("\\s+", " ", a)
13 a = re.sub("table GDEF.*GDEF;", "", a)
14 a = re.sub(" ; ", " ", a)
15 return a.strip()
16
17 assert alltrim(s1) == alltrim(s2)
18
19
20 class TestAnchors(unittest.TestCase):
21 def roundTrip(self, thing):
22 rt = thing.__class__.fromXML(thing.toXML())
23 self.assertEqual(rt.asFea(), thing.asFea())
24
25 def test_markbase(self):
26 s = Attachment("top", "top_", {"A": (679, 1600)}, {"acutecomb": (-570, 1290)})
27 assertSufficientlyEqual(
28 s.asFea(), " pos base A <anchor 679 1600> mark @top_top_;\n"
29 )
30 self.assertEqual(s.involved_glyphs, set(["A", "acutecomb"]))
31 self.assertEqual(
32 etree.tostring(s.toXML()),
33 '<attachment basename="top" markname="top_"><base name="A" anchorX="679" anchorY="1600"/><mark name="acutecomb" anchorX="-570" anchorY="1290"/></attachment>'.encode(
34 "utf-8"
35 ),
36 )
37 self.roundTrip(s)