| 1 |
from fontFeatures import Positioning, ValueRecord |
| 2 |
from lxml import etree |
| 3 |
|
| 4 |
import unittest |
| 5 |
|
| 6 |
|
| 7 |
class TestPositioning(unittest.TestCase): |
| 8 |
def roundTrip(self, thing): |
| 9 |
rt = thing.__class__.fromXML(thing.toXML()) |
| 10 |
self.assertEqual(rt.asFea(), thing.asFea()) |
| 11 |
|
| 12 |
def test_single(self): |
| 13 |
v = ValueRecord(xAdvance=120) |
| 14 |
s = Positioning(["a"], [v]) |
| 15 |
self.assertEqual(s.asFea(), "pos a 120;") |
| 16 |
print(etree.tostring(s.toXML())) |
| 17 |
self.assertEqual( |
| 18 |
etree.tostring(s.toXML()), |
| 19 |
'<positioning><glyphs><slot><glyph>a</glyph></slot></glyphs><positions><valuerecord xAdvance="120"/></positions></positioning>'.encode( |
| 20 |
"utf-8" |
| 21 |
), |
| 22 |
) |
| 23 |
self.roundTrip(s) |
| 24 |
|
| 25 |
def test_single_class(self): |
| 26 |
v = ValueRecord(xPlacement=120) |
| 27 |
s = Positioning([["a", "b"]], [v]) |
| 28 |
self.assertEqual(s.asFea(), "pos [a b] <120 0 0 0>;") |
| 29 |
|
| 30 |
def test_kern(self): |
| 31 |
v = ValueRecord(xAdvance=120) |
| 32 |
s = Positioning(["a", "b"], [v, ValueRecord()]) |
| 33 |
self.assertEqual(s.asFea(), "pos a b 120;") |