Exemplo n.º 1
0
 def makeFont(self, variations):
     glyphs = [".notdef", "space", "I"]
     Axis = getTableModule("fvar").Axis
     Glyph = getTableModule("glyf").Glyph
     glyf, fvar, gvar = newTable("glyf"), newTable("fvar"), newTable("gvar")
     font = FakeFont(glyphs)
     font.tables = {"glyf": glyf, "gvar": gvar, "fvar": fvar}
     glyf.glyphs = {glyph: Glyph() for glyph in glyphs}
     glyf.glyphs["I"].coordinates = [(10, 10), (10, 20), (20, 20), (20, 10)]
     fvar.axes = [Axis(), Axis()]
     fvar.axes[0].axisTag, fvar.axes[1].axisTag = "wght", "wdth"
     gvar.variations = variations
     return font, gvar
Exemplo n.º 2
0
class AATLookupTest(unittest.TestCase):
    font = FakeFont(".notdef A B C D E F G H A.alt B.alt".split())
    converter = otConverters.AATLookup("AATLookup",
                                       0,
                                       None,
                                       tableClass=otConverters.GlyphID)

    def __init__(self, methodName):
        unittest.TestCase.__init__(self, methodName)
        # Python 3 renamed assertRaisesRegexp to assertRaisesRegex,
        # and fires deprecation warnings if a program uses the old name.
        if not hasattr(self, "assertRaisesRegex"):
            self.assertRaisesRegex = self.assertRaisesRegexp

    def test_readFormat0(self):
        reader = OTTableReader(deHexStr("0000 0000 0001 0002 0000 7D00 0001"))
        self.assertEqual(
            self.converter.read(reader, self.font, None), {
                ".notdef": ".notdef",
                "A": "A",
                "B": "B",
                "C": ".notdef",
                "D": "glyph32000",
                "E": "A"
            })

    def test_readFormat2(self):
        reader = OTTableReader(
            deHexStr("0002 0006 0002 000C 0001 0006 "
                     "0002 0001 0003 "  # glyph A..B: map to C
                     "0007 0005 0008 "  # glyph E..G: map to H
                     "FFFF FFFF FFFF"))  # end of search table
        self.assertEqual(self.converter.read(reader, self.font, None), {
            "A": "C",
            "B": "C",
            "E": "H",
            "F": "H",
            "G": "H",
        })

    def test_readFormat4(self):
        reader = OTTableReader(
            deHexStr("0004 0006 0003 000C 0001 0006 "
                     "0002 0001 001E "  # glyph 1..2: mapping at offset 0x1E
                     "0005 0004 001E "  # glyph 4..5: mapping at offset 0x1E
                     "FFFF FFFF FFFF "  # end of search table
                     "0007 0008"))  # offset 0x18: glyphs [7, 8] = [G, H]
        self.assertEqual(self.converter.read(reader, self.font, None), {
            "A": "G",
            "B": "H",
            "D": "G",
            "E": "H",
        })

    def test_readFormat6(self):
        reader = OTTableReader(
            deHexStr("0006 0004 0002 0008 0001 0004 "
                     "0003 0001 "  # C --> A
                     "0005 0002 "  # E --> B
                     "FFFF FFFF"))  # end of search table
        self.assertEqual(self.converter.read(reader, self.font, None), {
            "C": "A",
            "E": "B",
        })

    def test_readFormat8(self):
        reader = OTTableReader(
            deHexStr("0008 "
                     "0003 0003 "  # first: C, count: 3
                     "0007 0001 0002"))  # [G, A, B]
        self.assertEqual(self.converter.read(reader, self.font, None), {
            "C": "G",
            "D": "A",
            "E": "B",
        })

    def test_readUnknownFormat(self):
        reader = OTTableReader(deHexStr("0009"))
        self.assertRaisesRegex(AssertionError, "unsupported lookup format: 9",
                               self.converter.read, reader, self.font, None)

    def test_writeFormat0(self):
        writer = OTTableWriter()
        font = FakeFont(".notdef A B C".split())
        self.converter.write(writer, font, {}, {
            ".notdef": ".notdef",
            "A": "C",
            "B": "C",
            "C": "A"
        })
        self.assertEqual(writer.getData(),
                         deHexStr("0000 0000 0003 0003 0001"))

    def test_writeFormat2(self):
        writer = OTTableWriter()
        font = FakeFont(".notdef A B C D E F G H".split())
        self.converter.write(writer, font, {}, {
            "B": "C",
            "C": "C",
            "D": "C",
            "E": "C",
            "G": "A",
            "H": "A",
        })
        self.assertEqual(
            writer.getData(),
            deHexStr(
                "0002 "  # format=2
                "0006 "  # binSrchHeader.unitSize=6
                "0002 "  # binSrchHeader.nUnits=2
                "000C "  # binSrchHeader.searchRange=12
                "0001 "  # binSrchHeader.entrySelector=1
                "0000 "  # binSrchHeader.rangeShift=0
                "0005 0002 0003 "  # segments[0].lastGlyph=E, firstGlyph=B, value=C
                "0008 0007 0001 "  # segments[1].lastGlyph=H, firstGlyph=G, value=A
                "FFFF FFFF 0000 "  # segments[2]=<END>
            ))

    def test_writeFormat6(self):
        writer = OTTableWriter()
        font = FakeFont(".notdef A B C D E".split())
        self.converter.write(writer, font, {}, {
            "A": "C",
            "C": "B",
            "D": "D",
            "E": "E",
        })
        self.assertEqual(
            writer.getData(),
            deHexStr("0006 "  # format=6
                     "0004 "  # binSrchHeader.unitSize=4
                     "0004 "  # binSrchHeader.nUnits=4
                     "0010 "  # binSrchHeader.searchRange=16
                     "0002 "  # binSrchHeader.entrySelector=2
                     "0000 "  # binSrchHeader.rangeShift=0
                     "0001 0003 "  # entries[0].glyph=A, .value=C
                     "0003 0002 "  # entries[1].glyph=C, .value=B
                     "0004 0004 "  # entries[2].glyph=D, .value=D
                     "0005 0005 "  # entries[3].glyph=E, .value=E
                     "FFFF 0000 "  # entries[4]=<END>
                     ))

    def test_writeFormat8(self):
        writer = OTTableWriter()
        font = FakeFont(".notdef A B C D E F G H".split())
        self.converter.write(writer, font, {}, {
            "B": "B",
            "C": "A",
            "D": "B",
            "E": "C",
            "F": "B",
            "G": "A",
        })
        self.assertEqual(
            writer.getData(),
            deHexStr(
                "0008 "  # format=8
                "0002 "  # firstGlyph=B
                "0006 "  # glyphCount=6
                "0002 0001 0002 0003 0002 0001"  # valueArray=[B, A, B, C, B, A]
            ))

    def test_xmlRead(self):
        value = self.converter.xmlRead({}, [
            ("Lookup", {
                "glyph": "A",
                "value": "A.alt"
            }, []),
            ("Lookup", {
                "glyph": "B",
                "value": "B.alt"
            }, []),
        ], self.font)
        self.assertEqual(value, {"A": "A.alt", "B": "B.alt"})

    def test_xmlWrite(self):
        writer = makeXMLWriter()
        self.converter.xmlWrite(writer,
                                self.font,
                                value={
                                    "A": "A.alt",
                                    "B": "B.alt"
                                },
                                name="Foo",
                                attrs=[("attr", "val")])
        xml = writer.file.getvalue().decode("utf-8").splitlines()
        self.assertEqual(xml, [
            '<Foo attr="val">',
            '  <Lookup glyph="A" value="A.alt"/>',
            '  <Lookup glyph="B" value="B.alt"/>',
            '</Foo>',
        ])
Exemplo n.º 3
0
 def setUp(self):
     self.font = FakeFont(['.notdef', 'A', 'B', 'C', 'D'])
     self.maxDiff = None
Exemplo n.º 4
0
 def test_decompile_toXML_version_1_1(self):
     table = newTable('STAT')
     table.decompile(STAT_DATA_VERSION_1_1,
                     font=FakeFont(['.notdef']))
     self.assertEqual(getXML(table.toXML), STAT_XML_VERSION_1_1)
Exemplo n.º 5
0
 def setUpClass(cls):
     cls.maxDiff = None
     cls.font = FakeFont(['.notdef'] + ['g.%d' % i for i in range (1, 910)])
Exemplo n.º 6
0
 def setUp(self):
     self.glyphs = ".notdef G G.alt1 G.alt2 Z Z.fina".split()
     self.font = FakeFont(self.glyphs)
Exemplo n.º 7
0
 def setUp(self):
     self.glyphs = ".notdef A B C D E a b c d e".split()
     self.font = FakeFont(self.glyphs)
Exemplo n.º 8
0
def overflowing_font():
    return FakeFont(["glyph%i" % i for i in range(105)])
Exemplo n.º 9
0
 def setUpClass(cls):
     cls.maxDiff = None
     cls.font = FakeFont(['.nodef', 'A', 'B', 'C'])
Exemplo n.º 10
0
 def setUpClass(cls):
     cls.maxDiff = None
     glyphs = ['.notdef'] + ['g.%d' % i for i in range(1, 140)]
     glyphs[11], glyphs[13] = 'parenleft', 'parenright'
     glyphs[135], glyphs[136] = 'parenleft.vertical', 'parenright.vertical'
     cls.font = FakeFont(glyphs)
Exemplo n.º 11
0
 def setUpClass(cls):
     cls.maxDiff = None
     glyphs = ['.notdef'] + ['X.alt%d' for g in range(1, 50)]
     glyphs[10] = 'C'
     glyphs[43] = 'A'
     cls.font = FakeFont(glyphs)
Exemplo n.º 12
0
 def test_compile_fromXML_version_1_1(self):
     table = newTable('STAT')
     font = FakeFont(['.notdef'])
     for name, attrs, content in parseXML(STAT_XML_VERSION_1_1):
         table.fromXML(name, attrs, content, font=font)
     self.assertEqual(table.compile(font), STAT_DATA_VERSION_1_1)
Exemplo n.º 13
0
 def test_compile_fromXML_format3(self):
     table = newTable('STAT')
     font = FakeFont(['.notdef'])
     for name, attrs, content in parseXML(STAT_XML_AXIS_VALUE_FORMAT3):
         table.fromXML(name, attrs, content, font=font)
     self.assertEqual(table.compile(font), STAT_DATA_AXIS_VALUE_FORMAT3)
Exemplo n.º 14
0
 def test_compile_fromXML_withAxisJunk(self):
     table = newTable('STAT')
     font = FakeFont(['.notdef'])
     for name, attrs, content in parseXML(STAT_XML_WITH_AXIS_JUNK):
         table.fromXML(name, attrs, content, font=font)
     self.assertEqual(table.compile(font), STAT_DATA_WITH_AXIS_JUNK)
Exemplo n.º 15
0
 def setUp(self):
     self.font = FakeFont(['.notdef', 'meh'])
Exemplo n.º 16
0
 def setUpClass(cls):
     cls.maxDiff = None
     cls.font = FakeFont(['.notdef'] +
                         [g for g in 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'])
Exemplo n.º 17
0
def font():
    return FakeFont(list("ABCDEFGHIJKLMNOPQRSTUVWXYZ"
                         "abcdefghijklmnopqrstuvwxyz"))
Exemplo n.º 18
0
 def test_decompile_toXML(self):
     table = newTable('STAT')
     table.decompile(STAT_DATA, font=FakeFont(['.notdef']))
     self.maxDiff = None
     self.assertEqual(getXML(table.toXML), STAT_XML)
Exemplo n.º 19
0
 def setUpClass(cls):
     cls.maxDiff = None
     cls.font = FakeFont(['.notdef', 'A', 'B', 'C', 'D', 'E', 'F', 'G'])
Exemplo n.º 20
0
 def test_decompile_toXML_withAxisJunk(self):
     table = newTable('STAT')
     table.decompile(STAT_DATA_WITH_AXIS_JUNK, font=FakeFont(['.notdef']))
     self.assertEqual(getXML(table.toXML), STAT_XML_WITH_AXIS_JUNK)
Exemplo n.º 21
0
 def setUp(self):
     self.glyphs = ".notdef c f i t c_t f_f f_i f_f_i".split()
     self.font = FakeFont(self.glyphs)
Exemplo n.º 22
0
 def test_decompile_toXML_format3(self):
     table = newTable('STAT')
     table.decompile(STAT_DATA_AXIS_VALUE_FORMAT3,
                     font=FakeFont(['.notdef']))
     self.assertEqual(getXML(table.toXML), STAT_XML_AXIS_VALUE_FORMAT3)
Exemplo n.º 23
0
 def setUp(self):
     self.font = FakeFont(['.notdef', 'A', 'B', 'C'])
Exemplo n.º 24
0
 def setUpClass(cls):
     cls.maxDiff = None
     cls.font = FakeFont(['.notdef', 'f_r', 'X', 'f_f_l'])