Esempio n. 1
0
	def test_fromXML_badDeltaFormat(self):
		g = TupleVariation({}, [])
		with CapturingLogHandler(log, "WARNING") as captor:
			for name, attrs, content in parseXML('<delta a="1" b="2"/>'):
				g.fromXML(name, attrs, content)
		self.assertIn("bad delta format: a, b",
		              [r.msg for r in captor.records])
	def test_fromXML_badDeltaFormat(self):
		g = TupleVariation({}, [])
		with CapturingLogHandler(log, "WARNING") as captor:
			for name, attrs, content in parseXML('<delta a="1" b="2"/>'):
				g.fromXML(name, attrs, content)
		self.assertIn("bad delta format: a, b",
		              [r.msg for r in captor.records])
	def test_fromXML_points(self):
		g = TupleVariation({}, [None] * 4)
		for name, attrs, content in parseXML(
				'<coord axis="wdth" min="0.3" value="0.4" max="0.5"/>'
				'<coord axis="wght" value="1.0"/>'
				'<coord axis="opsz" value="-0.7"/>'
				'<delta pt="1" x="33" y="44"/>'
				'<delta pt="2" x="-2" y="170"/>'):
			g.fromXML(name, attrs, content)
		self.assertEqual(AXES, g.axes)
		self.assertEqual([None, (33, 44), (-2, 170), None], g.coordinates)
	def test_fromXML_constants(self):
		g = TupleVariation({}, [None] * 4)
		for name, attrs, content in parseXML(
				'<coord axis="wdth" min="0.3" value="0.4" max="0.5"/>'
				'<coord axis="wght" value="1.0"/>'
				'<coord axis="opsz" value="-0.7"/>'
				'<delta cvt="1" value="42"/>'
				'<delta cvt="2" value="-23"/>'):
			g.fromXML(name, attrs, content)
		self.assertEqual(AXES, g.axes)
		self.assertEqual([None, 42, -23, None], g.coordinates)
Esempio n. 5
0
	def test_fromXML_points(self):
		g = TupleVariation({}, [None] * 4)
		for name, attrs, content in parseXML(
				'<coord axis="wdth" min="0.3" value="0.4" max="0.5"/>'
				'<coord axis="wght" value="1.0"/>'
				'<coord axis="opsz" value="-0.7"/>'
				'<delta pt="1" x="33" y="44"/>'
				'<delta pt="2" x="-2" y="170"/>'):
			g.fromXML(name, attrs, content)
		self.assertEqual(AXES, g.axes)
		self.assertEqual([None, (33, 44), (-2, 170), None], g.coordinates)
Esempio n. 6
0
	def test_fromXML_constants(self):
		g = TupleVariation({}, [None] * 4)
		for name, attrs, content in parseXML(
				'<coord axis="wdth" min="0.3" value="0.4" max="0.5"/>'
				'<coord axis="wght" value="1.0"/>'
				'<coord axis="opsz" value="-0.7"/>'
				'<delta cvt="1" value="42"/>'
				'<delta cvt="2" value="-23"/>'):
			g.fromXML(name, attrs, content)
		self.assertEqual(AXES, g.axes)
		self.assertEqual([None, 42, -23, None], g.coordinates)
Esempio n. 7
0
 def fromXML(self, name, attrs, content, ttFont):
     if name == "version":
         self.majorVersion = int(attrs.get("major", "1"))
         self.minorVersion = int(attrs.get("minor", "0"))
     elif name == "tuple":
         valueCount = len(ttFont["cvt "].values)
         var = TupleVariation({}, [None] * valueCount)
         self.variations.append(var)
         for tupleElement in content:
             if isinstance(tupleElement, tuple):
                 tupleName, tupleAttrs, tupleContent = tupleElement
                 var.fromXML(tupleName, tupleAttrs, tupleContent)
Esempio n. 8
0
 def fromXML(self, name, attrs, content, ttFont):
     if name == "version":
         self.majorVersion = int(attrs.get("major", "1"))
         self.minorVersion = int(attrs.get("minor", "0"))
     elif name == "tuple":
         valueCount = len(ttFont["cvt "].values)
         var = TupleVariation({}, [None] * valueCount)
         self.variations.append(var)
         for tupleElement in content:
             if isinstance(tupleElement, tuple):
                 tupleName, tupleAttrs, tupleContent = tupleElement
                 var.fromXML(tupleName, tupleAttrs, tupleContent)
Esempio n. 9
0
    def test_fromXML_axes_floats(self):
        g = TupleVariation({}, [None] * 4)
        for name, attrs, content in parseXML(
                '<coord axis="wght" min="0.0" value="0.3" max="0.7"/>'
                '<coord axis="wdth" value="0.4"/>'):
            g.fromXML(name, attrs, content)

        self.assertEqual(g.axes["wght"][0], 0)
        self.assertAlmostEqual(g.axes["wght"][1], 0.2999878)
        self.assertAlmostEqual(g.axes["wght"][2], 0.7000122)

        self.assertEqual(g.axes["wdth"][0], 0)
        self.assertAlmostEqual(g.axes["wdth"][1], 0.4000244)
        self.assertAlmostEqual(g.axes["wdth"][2], 0.4000244)