示例#1
0
 def testDecompileToXML(self):
     a = otTables.InsertionMorphAction()
     actionReader = OTTableReader(
         deHexStr("DEAD BEEF 0002 0001 0004 0002 0003 DEAD BEEF"))
     a.decompile(OTTableReader(deHexStr("1234 FC43 0005 0002")), self.font,
                 actionReader)
     toXML = lambda w, f: a.toXML(w, f, {"Test": "Foo"}, "Transition")
     self.assertEqual(getXML(toXML, self.font), self.MORPH_ACTION_XML)
示例#2
0
    def test_getitem(self):
        count = 2
        reader = OTTableReader(b"\x00\xFE\xFF\x00\x00\x00", offset=1)
        converter = otConverters.UInt8("UInt8", 0, None, None)
        recordSize = converter.staticSize
        l = otConverters._LazyList()
        l.reader = reader
        l.pos = l.reader.pos
        l.font = None
        l.conv = converter
        l.recordSize = recordSize
        l.extend(otConverters._MissingItem([i]) for i in range(count))
        reader.advance(count * recordSize)

        self.assertEqual(l[0], 254)
        self.assertEqual(l[1], 255)
示例#3
0
def test_onlineVarStoreBuilder(locations, masterValues):
    axisTags = sorted({k for loc in locations for k in loc})
    model = VariationModel(locations)
    builder = OnlineVarStoreBuilder(axisTags)
    builder.setModel(model)
    varIdxs = []
    for masters in masterValues:
        _, varIdx = builder.storeMasters(masters)
        varIdxs.append(varIdx)

    varStore = builder.finish()
    mapping = varStore.optimize()
    varIdxs = [mapping[varIdx] for varIdx in varIdxs]

    dummyFont = TTFont()
    writer = OTTableWriter()
    varStore.compile(writer, dummyFont)
    data = writer.getAllData()
    reader = OTTableReader(data)
    varStore = VarStore()
    varStore.decompile(reader, dummyFont)

    fvarAxes = [buildAxis(axisTag) for axisTag in axisTags]
    instancer = VarStoreInstancer(varStore, fvarAxes)
    for masters, varIdx in zip(masterValues, varIdxs):
        base, *rest = masters
        for expectedValue, loc in zip(masters, locations):
            instancer.setLocation(loc)
            value = base + instancer[varIdx]
            assert expectedValue == value
    def test_getitem(self):
        count = 2
        reader = OTTableReader(b"\x00\xFE\xFF\x00\x00\x00", offset=1)
        converter = otConverters.UInt8("UInt8", 0, None, None)
        recordSize = converter.staticSize
        l = otConverters._LazyList()
        l.reader = reader
        l.pos = l.reader.pos
        l.font = None
        l.conv = converter
        l.recordSize = recordSize
        l.extend(otConverters._MissingItem([i]) for i in range(count))
        reader.advance(count * recordSize)

        self.assertEqual(l[0], 254)
        self.assertEqual(l[1], 255)
 def test_read_replace_not_ascii(self):
     reader = OTTableReader(b"Hello \xE4 world" + 100 * b"\0")
     with CapturingLogHandler(otConverters.log, "WARNING") as captor:
         data = self.converter.read(reader, self.font, {})
     self.assertEqual(data, "Hello � world")
     self.assertEqual(reader.pos, 64)
     self.assertIn('replaced non-ASCII characters in "Hello � world"',
                   [r.msg for r in captor.records])
示例#6
0
 def testDecompileToXML(self):
     a = otTables.LigatureMorphAction()
     actionReader = OTTableReader(deHexStr("DEADBEEF 7FFFFFFE 80000003"))
     a.decompile(OTTableReader(deHexStr("1234FAB30001")), self.font,
                 actionReader)
     toXML = lambda w, f: a.toXML(w, f, {"Test": "Foo"}, "Transition")
     self.assertEqual(
         getXML(toXML, self.font),
         [
             '<Transition Test="Foo">',
             '  <NewState value="4660"/>',  # 0x1234 = 4660
             '  <Flags value="SetComponent,DontAdvance"/>',
             '  <ReservedFlags value="0x1AB3"/>',
             '  <Action GlyphIndexDelta="-2" Flags="Store"/>',
             '  <Action GlyphIndexDelta="3"/>',
             '</Transition>',
         ])
 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_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"
         })
示例#10
0
 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",
     })
示例#11
0
 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",
     })
示例#12
0
 def testDecompileToXML(self):
     r = otTables.RearrangementMorphAction()
     r.decompile(OTTableReader(deHexStr("1234fffd")), self.font)
     toXML = lambda w, f: r.toXML(w, f, {"Test": "Foo"}, "Transition")
     self.assertEqual(
         getXML(toXML, self.font),
         [
             '<Transition Test="Foo">',
             '  <NewState value="4660"/>',  # 0x1234 = 4660
             '  <Flags value="MarkFirst,DontAdvance,MarkLast"/>',
             '  <ReservedFlags value="0x1FF0"/>',
             '  <Verb value="13"/><!-- ABxCD ⇒ CDxBA -->',
             '</Transition>',
         ])
示例#13
0
 def testDecompileToXML(self):
     a = otTables.ContextualMorphAction()
     a.decompile(OTTableReader(deHexStr("1234f117deadbeef")), self.font)
     toXML = lambda w, f: a.toXML(w, f, {"Test": "Foo"}, "Transition")
     self.assertEqual(
         getXML(toXML, self.font),
         [
             '<Transition Test="Foo">',
             '  <NewState value="4660"/>',  # 0x1234 = 4660
             '  <Flags value="SetMark,DontAdvance"/>',
             '  <ReservedFlags value="0x3117"/>',
             '  <MarkIndex value="57005"/>',  # 0xDEAD = 57005
             '  <CurrentIndex value="48879"/>',  # 0xBEEF = 48879
             '</Transition>',
         ])
示例#14
0
 def test_readArray(self):
     reader = OTTableReader(deHexStr("0002 0001 DEAD 0002"))
     self.assertEqual(self.converter.readArray(reader, self.font, {}, 4),
                      ["B", "A", "glyph57005", "B"])
     self.assertEqual(reader.pos, 8)
示例#15
0
 def test_readUnknownFormat(self):
     reader = OTTableReader(deHexStr("0009"))
     self.assertRaisesRegex(AssertionError, "unsupported lookup format: 9",
                            self.converter.read, reader, self.font, None)
 def test_readLong(self):
     reader = OTTableReader(deHexStr("CA FE BE EF"))
     self.assertEqual(reader.readLong(), -889274641)
     self.assertEqual(reader.pos, 4)
 def test_readUShortArray(self):
     reader = OTTableReader(deHexStr("DE AD BE EF CA FE"))
     self.assertEqual(list(reader.readUShortArray(3)),
                      [0xDEAD, 0xBEEF, 0xCAFE])
     self.assertEqual(reader.pos, 6)
 def test_readUInt8(self):
     reader = OTTableReader(deHexStr("C3"))
     self.assertEqual(reader.readUInt8(), 0xC3)
     self.assertEqual(reader.pos, 1)
 def test_readULong(self):
     reader = OTTableReader(deHexStr("CA FE BE EF"))
     self.assertEqual(reader.readULong(), 0xCAFEBEEF)
     self.assertEqual(reader.pos, 4)
 def test_readUInt24(self):
     reader = OTTableReader(deHexStr("C3 13 37"))
     self.assertEqual(reader.readUInt24(), 0xC31337)
     self.assertEqual(reader.pos, 3)
 def test_readData(self):
     reader = OTTableReader(deHexStr("48 65 6C 6C 6F"))
     self.assertEqual(reader.readData(5), b"Hello")
     self.assertEqual(reader.pos, 5)
 def test_readTag(self):
     reader = OTTableReader(deHexStr("46 6F 6F 64"))
     self.assertEqual(reader.readTag(), "Food")
     self.assertEqual(reader.pos, 4)
示例#23
0
 def test_read(self):
     reader = OTTableReader(deHexStr("FE"))
     self.assertEqual(self.converter.read(reader, self.font, {}), 254)
     self.assertEqual(reader.pos, 1)
示例#24
0
 def test_read(self):
     reader = OTTableReader(b"Hello\0junk after zero byte" + 100 * b"\0")
     self.assertEqual(self.converter.read(reader, self.font, {}), "Hello")
     self.assertEqual(reader.pos, 64)
 def test_getSubReader(self):
     reader = OTTableReader(deHexStr("CAFE F00D"))
     sub = reader.getSubReader(2)
     self.assertEqual(sub.readUShort(), 0xF00D)
     self.assertEqual(reader.readUShort(), 0xCAFE)
示例#26
0
 def test_read(self):
     reader = OTTableReader(deHexStr("0003"))
     self.assertEqual(self.converter.read(reader, self.font, {}), "C")
     self.assertEqual(reader.pos, 2)
 def test_readShort(self):
     reader = OTTableReader(deHexStr("CA FE"))
     self.assertEqual(reader.readShort(), -13570)
     self.assertEqual(reader.pos, 2)
示例#28
0
 def test_read(self):
     reader = OTTableReader(deHexStr("FF0000EE"))
     self.assertEqual(self.converter.read(reader, self.font, {}), -16776978)
     self.assertEqual(reader.pos, 4)
示例#29
0
 def test_read(self):
     font = self.makeFont()
     reader = OTTableReader(deHexStr("0123"))
     self.assertEqual(self.converter.read(reader, font, {}), 0x123)