Ejemplo n.º 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)
Ejemplo n.º 2
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)
Ejemplo n.º 3
0
	def test_decompileDeltas(self):
		decompileDeltas = TupleVariation.decompileDeltas_
		# 83 = zero values (0x80), count = 4 (1 + 0x83 & 0x3F)
		self.assertEqual(([0, 0, 0, 0], 1), decompileDeltas(4, deHexStr("83"), 0))
		# 41 01 02 FF FF = signed 16-bit values (0x40), count = 2 (1 + 0x41 & 0x3F)
		self.assertEqual(([258, -1], 5), decompileDeltas(2, deHexStr("41 01 02 FF FF"), 0))
		# 01 81 07 = signed 8-bit values, count = 2 (1 + 0x01 & 0x3F)
		self.assertEqual(([-127, 7], 3), decompileDeltas(2, deHexStr("01 81 07"), 0))
		# combination of all three encodings, preceded and followed by 4 bytes of unused data
		data = deHexStr("DE AD BE EF 83 40 01 02 01 81 80 DE AD BE EF")
		self.assertEqual(([0, 0, 0, 0, 258, -127, -128], 11), decompileDeltas(7, data, 4))
Ejemplo n.º 4
0
	def test_decompileDeltas(self):
		decompileDeltas = TupleVariation.decompileDeltas_
		# 83 = zero values (0x80), count = 4 (1 + 0x83 & 0x3F)
		self.assertEqual(([0, 0, 0, 0], 1), decompileDeltas(4, deHexStr("83"), 0))
		# 41 01 02 FF FF = signed 16-bit values (0x40), count = 2 (1 + 0x41 & 0x3F)
		self.assertEqual(([258, -1], 5), decompileDeltas(2, deHexStr("41 01 02 FF FF"), 0))
		# 01 81 07 = signed 8-bit values, count = 2 (1 + 0x01 & 0x3F)
		self.assertEqual(([-127, 7], 3), decompileDeltas(2, deHexStr("01 81 07"), 0))
		# combination of all three encodings, preceded and followed by 4 bytes of unused data
		data = deHexStr("DE AD BE EF 83 40 01 02 01 81 80 DE AD BE EF")
		self.assertEqual(([0, 0, 0, 0, 258, -127, -128], 11), decompileDeltas(7, data, 4))
Ejemplo n.º 5
0
    def test_decompile_additional_SB(self):
        font = self.makeFont(numGlyphs=4, numberOfMetrics=2)
        metrics = deHexStr("02A2 FFF5 0278 004F")
        extraSideBearings = deHexStr("0036 FFFC")
        data = metrics + extraSideBearings

        mtxTable = newTable(self.tag)
        mtxTable.decompile(data, font)

        self.assertEqual(mtxTable['A'], (674, -11))
        self.assertEqual(mtxTable['B'], (632, 79))
        # all following have same width as the previous
        self.assertEqual(mtxTable['C'], (632, 54))
        self.assertEqual(mtxTable['D'], (632, -4))
Ejemplo n.º 6
0
    def test_decompile_additional_SB(self):
        font = self.makeFont(numGlyphs=4, numberOfMetrics=2)
        metrics = deHexStr("02A2 FFF5 0278 004F")
        extraSideBearings = deHexStr("0036 FFFC")
        data = metrics + extraSideBearings

        mtxTable = newTable(self.tag)
        mtxTable.decompile(data, font)

        self.assertEqual(mtxTable['A'], (674, -11))
        self.assertEqual(mtxTable['B'], (632, 79))
        # all following have same width as the previous
        self.assertEqual(mtxTable['C'], (632, 54))
        self.assertEqual(mtxTable['D'], (632, -4))
Ejemplo n.º 7
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>',
     ])
Ejemplo n.º 8
0
	def test_decompileCoord_roundTrip(self):
		# Make sure we are not affected by https://github.com/behdad/fonttools/issues/286
		data = deHexStr("7F B9 80 35")
		values, _ = TupleVariation.decompileCoord_(["wght", "wdth"], data, 0)
		axisValues = {axis:(val, val, val) for axis, val in  values.items()}
		var = TupleVariation(axisValues, [None] * 4)
		self.assertEqual("7F B9 80 35", hexencode(var.compileCoord(["wght", "wdth"])))
Ejemplo n.º 9
0
 def test_decompileOffsets_shortFormat(self):
     decompileOffsets = gvarClass.decompileOffsets_
     data = deHexStr("00 11 22 33 44 55 66 77 88 99 aa bb")
     self.assertEqual(
         [2 * 0x0011, 2 * 0x2233, 2 * 0x4455, 2 * 0x6677, 2 * 0x8899, 2 * 0xAABB],
         list(decompileOffsets(data, tableFormat=0, glyphCount=5)),
     )
Ejemplo n.º 10
0
	def test_decompileCoord_roundTrip(self):
		# Make sure we are not affected by https://github.com/fonttools/fonttools/issues/286
		data = deHexStr("7F B9 80 35")
		values, _ = TupleVariation.decompileCoord_(["wght", "wdth"], data, 0)
		axisValues = {axis:(val, val, val) for axis, val in  values.items()}
		var = TupleVariation(axisValues, [None] * 4)
		self.assertEqual("7F B9 80 35", hexencode(var.compileCoord(["wght", "wdth"])))
Ejemplo n.º 11
0
 def test_decompileOffsets_shortFormat(self):
     decompileOffsets = table__g_v_a_r.decompileOffsets_
     data = deHexStr("00 11 22 33 44 55 66 77 88 99 aa bb")
     self.assertEqual([
         2 * 0x0011, 2 * 0x2233, 2 * 0x4455, 2 * 0x6677, 2 * 0x8899,
         2 * 0xaabb
     ], list(decompileOffsets(data, tableFormat=0, glyphCount=5)))
Ejemplo n.º 12
0
 def test_decompileCoord(self):
     decompileCoord = GlyphVariation.decompileCoord_
     data = deHexStr("DE AD C0 00 20 00 DE AD")
     self.assertEqual(({
         "wght": -1.0,
         "wdth": 0.5
     }, 6), decompileCoord(["wght", "wdth"], data, 2))
Ejemplo n.º 13
0
 def test_decompileOffsets_longFormat(self):
     decompileOffsets = table__g_v_a_r.decompileOffsets_
     data = deHexStr("00 11 22 33 44 55 66 77 88 99 aa bb")
     self.assertEqual([0x00112233, 0x44556677, 0x8899aabb],
                      list(
                          decompileOffsets(data,
                                           tableFormat=1,
                                           glyphCount=2)))
Ejemplo n.º 14
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>',
         ])
Ejemplo n.º 15
0
	def test_decompilePoints_shouldAcceptBadPointNumbers(self):
		decompilePoints = TupleVariation.decompilePoints_
		# 2 points; first run: [3, 9].
		numPointsInGlyph = 8
		with CapturingLogHandler(log, "WARNING") as captor:
			decompilePoints(numPointsInGlyph,
			                deHexStr("02 01 03 06"), 0, "cvar")
		self.assertIn("point 9 out of range in 'cvar' table",
		              [r.msg for r in captor.records])
Ejemplo n.º 16
0
	def test_decompilePoints_shouldAcceptBadPointNumbers(self):
		decompilePoints = TupleVariation.decompilePoints_
		# 2 points; first run: [3, 9].
		numPointsInGlyph = 8
		with CapturingLogHandler(log, "WARNING") as captor:
			decompilePoints(numPointsInGlyph,
			                deHexStr("02 01 03 06"), 0, "cvar")
		self.assertIn("point 9 out of range in 'cvar' table",
		              [r.msg for r in captor.records])
Ejemplo n.º 17
0
 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"
     })
Ejemplo n.º 18
0
 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",
     })
Ejemplo n.º 19
0
    def test_decompile(self):
        font = self.makeFont(numGlyphs=3, numberOfMetrics=3)
        data = deHexStr("02A2 FFF5 0278 004F 02C6 0036")

        mtxTable = newTable(self.tag)
        mtxTable.decompile(data, font)

        self.assertEqual(mtxTable['A'], (674, -11))
        self.assertEqual(mtxTable['B'], (632, 79))
        self.assertEqual(mtxTable['C'], (710, 54))
Ejemplo n.º 20
0
 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",
     })
Ejemplo n.º 21
0
 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"))
Ejemplo n.º 22
0
 def testCompileActions_shouldShareSubsequences(self):
     state = otTables.AATState()
     t = state.Transitions = {i: otTables.LigatureMorphAction()
                              for i in range(3)}
     ligs = [otTables.LigAction() for _ in range(3)]
     for i, lig in enumerate(ligs):
         lig.GlyphIndexDelta = i
     t[0].Actions = ligs[1:2]
     t[1].Actions = ligs[0:3]
     t[2].Actions = ligs[1:3]
     actions, actionIndex = t[0].compileActions(self.font, [state])
     self.assertEqual(actions,
                      deHexStr("00000000 00000001 80000002 80000001"))
     self.assertEqual(actionIndex, {
         deHexStr("00000000 00000001 80000002"): 0,
         deHexStr("00000001 80000002"): 1,
         deHexStr("80000002"): 2,
         deHexStr("80000001"): 3,
     })
Ejemplo n.º 23
0
	def test_decompileCoords(self):
		decompileCoords = GlyphVariation.decompileCoords_
		axes = ["wght", "wdth", "opsz"]
		coords = [
			{"wght":  1.0, "wdth": 0.0, "opsz": 0.5},
			{"wght": -1.0, "wdth": 0.0, "opsz": 0.25},
			{"wght":  0.0, "wdth": -1.0, "opsz": 1.0}
		]
		data = deHexStr("DE AD 40 00 00 00 20 00 C0 00 00 00 10 00 00 00 C0 00 40 00")
		self.assertEqual((coords, 20), decompileCoords(axes, numCoords=3, data=data, offset=2))
Ejemplo n.º 24
0
    def test_decompile(self):
        font = self.makeFont(numGlyphs=3, numberOfMetrics=3)
        data = deHexStr("02A2 FFF5 0278 004F 02C6 0036")

        mtxTable = newTable(self.tag)
        mtxTable.decompile(data, font)

        self.assertEqual(mtxTable['A'], (674, -11))
        self.assertEqual(mtxTable['B'], (632, 79))
        self.assertEqual(mtxTable['C'], (710, 54))
Ejemplo n.º 25
0
 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",
     })
Ejemplo n.º 26
0
 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",
     })
Ejemplo n.º 27
0
    def test_compile_format_unknown(self, version, st_length, expected):
        kern = newTable("kern")
        kern.version = version
        kern.kernTables = []

        for unknown_fmt, kern_data in zip((4, 5), ("1234 5678", "9ABC DEF0")):
            if version > 0:
                coverage = 0
                header_fmt = deHexStr("%08X %02X %02X %04X" %
                                      (st_length, coverage, unknown_fmt, 0))
            else:
                coverage = 1
                header_fmt = deHexStr("%04X %04X %02X %02X" %
                                      (0, st_length, unknown_fmt, coverage))
            st = KernTable_format_unkown(unknown_fmt)
            st.data = header_fmt + deHexStr(kern_data)
            kern.kernTables.append(st)

        data = kern.compile(font)
        assert data == expected
Ejemplo n.º 28
0
 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"
         })
Ejemplo n.º 29
0
 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"))
Ejemplo n.º 30
0
    def test_compile_round_float_values(self):
        font = self.makeFont(numGlyphs=3, numberOfMetrics=2)
        mtxTable = font[self.tag] = newTable(self.tag)
        mtxTable.metrics = {
            'A': (0.5, 0.5),  # round -> (1, 1)
            'B': (0.1, 0.9),  # round -> (0, 1)
            'C': (0.1, 0.1),  # round -> (0, 0)
        }

        data = mtxTable.compile(font)

        self.assertEqual(data, deHexStr("0001 0001 0000 0001 0000"))
Ejemplo n.º 31
0
    def test_compile_round_float_values(self):
        font = self.makeFont(numGlyphs=3, numberOfMetrics=2)
        mtxTable = font[self.tag] = newTable(self.tag)
        mtxTable.metrics = {
            'A': (0.5, 0.5),  # round -> (0, 0)
            'B': (0.1, 0.9),  # round -> (0, 1)
            'C': (0.1, 0.1),  # round -> (0, 0)
        }

        data = mtxTable.compile(font)

        self.assertEqual(data, deHexStr("0000 0000 0000 0001 0000"))
Ejemplo n.º 32
0
 def testDecompileToXML(self):
     r = otTables.RearrangementMorphAction()
     r.decompile(OTTableReader(deHexStr("1234fffd")),
                 self.font, actionReader=None)
     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>',
     ])
Ejemplo n.º 33
0
    def test_decompile_possibly_negative_advance(self):
        font = self.makeFont(numGlyphs=1, numberOfMetrics=1)
        # we warn if advance is > 0x7FFF as it might be interpreted as signed
        # by some authoring tools
        data = deHexStr("8000 0000")
        mtxTable = newTable(self.tag)

        with CapturingLogHandler(log, "WARNING") as captor:
            mtxTable.decompile(data, font)

        self.assertTrue(
            len([r for r in captor.records
                 if "has a huge advance" in r.msg]) == 1)
Ejemplo n.º 34
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",
     })
Ejemplo n.º 35
0
    def test_compile_additional_SB(self):
        font = self.makeFont(numGlyphs=4, numberOfMetrics=1)
        mtxTable = font[self.tag] = newTable(self.tag)
        mtxTable.metrics = {
            'A': (632, -11),
            'B': (632, 79),
            'C': (632, 54),
            'D': (632, -4),
        }

        data = mtxTable.compile(font)

        self.assertEqual(data, deHexStr("0278 FFF5 004F 0036 FFFC"))
Ejemplo n.º 36
0
 def testCompileActions_shouldShareSubsequences(self):
     state = otTables.AATState()
     t = state.Transitions = {
         i: otTables.LigatureMorphAction()
         for i in range(3)
     }
     ligs = [otTables.LigAction() for _ in range(3)]
     for i, lig in enumerate(ligs):
         lig.GlyphIndexDelta = i
     t[0].Actions = ligs[1:2]
     t[1].Actions = ligs[0:3]
     t[2].Actions = ligs[1:3]
     actions, actionIndex = t[0].compileActions(self.font, [state])
     self.assertEqual(actions,
                      deHexStr("00000000 00000001 80000002 80000001"))
     self.assertEqual(
         actionIndex, {
             deHexStr("00000000 00000001 80000002"): 0,
             deHexStr("00000001 80000002"): 1,
             deHexStr("80000002"): 2,
             deHexStr("80000001"): 3,
         })
Ejemplo n.º 37
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",
     })
Ejemplo n.º 38
0
    def test_compile_format_unknown(self, version, st_length, expected):
        kern = newTable("kern")
        kern.version = version
        kern.kernTables = []

        for unknown_fmt, kern_data in zip((4, 5), ("1234 5678", "9ABC DEF0")):
            if version > 0:
                coverage = 0
                header_fmt = deHexStr(
                    "%08X %02X %02X %04X" % (
                        st_length, coverage, unknown_fmt, 0))
            else:
                coverage = 1
                header_fmt = deHexStr(
                    "%04X %04X %02X %02X" % (
                        0, st_length, unknown_fmt, coverage))
            st = KernTable_format_unkown(unknown_fmt)
            st.data = header_fmt + deHexStr(kern_data)
            kern.kernTables.append(st)

        data = kern.compile(font)
        assert data == expected
Ejemplo n.º 39
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",
     })
Ejemplo n.º 40
0
    def test_decompile_possibly_negative_advance(self):
        font = self.makeFont(numGlyphs=1, numberOfMetrics=1)
        # we warn if advance is > 0x7FFF as it might be interpreted as signed
        # by some authoring tools
        data = deHexStr("8000 0000")
        mtxTable = newTable(self.tag)

        with CapturingLogHandler(log, "WARNING") as captor:
            mtxTable.decompile(data, font)

        self.assertTrue(
            len([r for r in captor.records
                if "has a huge advance" in r.msg]) == 1)
Ejemplo n.º 41
0
    def test_compile_additional_SB(self):
        font = self.makeFont(numGlyphs=4, numberOfMetrics=1)
        mtxTable = font[self.tag] = newTable(self.tag)
        mtxTable.metrics = {
            'A': (632, -11),
            'B': (632, 79),
            'C': (632, 54),
            'D': (632, -4),
        }

        data = mtxTable.compile(font)

        self.assertEqual(data, deHexStr("0278 FFF5 004F 0036 FFFC"))
Ejemplo n.º 42
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",
     })
Ejemplo n.º 43
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>',
         ])
Ejemplo n.º 44
0
 def testDecompileToXML(self):
     a = otTables.ContextualMorphAction()
     a.decompile(OTTableReader(deHexStr("1234f117deadbeef")),
                 self.font, actionReader=None)
     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>',
     ])
Ejemplo n.º 45
0
def _readRowImageData(bitmapObject, name, attrs, content, ttFont):
    bitDepth = safeEval(attrs["bitDepth"])
    metrics = SmallGlyphMetrics()
    metrics.width = safeEval(attrs["width"])
    metrics.height = safeEval(attrs["height"])

    dataRows = []
    for element in content:
        if not isinstance(element, tuple):
            continue
        name, attr, content = element
        # Chop off 'imagedata' from the tag to get just the option.
        if name == "row":
            dataRows.append(deHexStr(attr["value"]))
    bitmapObject.setRows(dataRows, bitDepth=bitDepth, metrics=metrics)
Ejemplo n.º 46
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>',
         ])
Ejemplo n.º 47
0
def _readRowImageData(bitmapObject, name, attrs, content, ttFont):
	bitDepth = safeEval(attrs['bitDepth'])
	metrics = SmallGlyphMetrics()
	metrics.width = safeEval(attrs['width'])
	metrics.height = safeEval(attrs['height'])

	dataRows = []
	for element in content:
		if not isinstance(element, tuple):
			continue
		name, attr, content = element
		# Chop off 'imagedata' from the tag to get just the option.
		if name == 'row':
			dataRows.append(deHexStr(attr['value']))
	bitmapObject.setRows(dataRows, bitDepth=bitDepth, metrics=metrics)
Ejemplo n.º 48
0
    def test_compile_no_header_table(self):
        font = TTFont()
        maxp = font['maxp'] = newTable('maxp')
        maxp.numGlyphs = 3
        font.glyphOrder = [chr(i) for i in range(65, 68)]
        mtxTable = font[self.tag] = newTable(self.tag)
        mtxTable.metrics = {
            "A": (400, 30),
            "B": (400, 40),
            "C": (400, 50),
        }

        self.assertNotIn(self.tableClass.headerTag, font)

        data = mtxTable.compile(font)

        self.assertEqual(data, deHexStr("0190 001E 0190 0028 0190 0032"))
Ejemplo n.º 49
0
    def test_compile(self):
        # we set the wrong 'numberOfMetrics' to check it gets adjusted
        font = self.makeFont(numGlyphs=3, numberOfMetrics=4)
        mtxTable = font[self.tag] = newTable(self.tag)
        mtxTable.metrics = {
            'A': (674, -11),
            'B': (632, 79),
            'C': (710, 54),
        }

        data = mtxTable.compile(font)

        self.assertEqual(data, deHexStr("02A2 FFF5 0278 004F 02C6 0036"))

        headerTable = font[self.tableClass.headerTag]
        self.assertEqual(
            getattr(headerTable, self.tableClass.numberOfMetricsName), 3)
Ejemplo n.º 50
0
 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]
     ))
Ejemplo n.º 51
0
    def test_compile(self):
        # we set the wrong 'numberOfMetrics' to check it gets adjusted
        font = self.makeFont(numGlyphs=3, numberOfMetrics=4)
        mtxTable = font[self.tag] = newTable(self.tag)
        mtxTable.metrics = {
            'A': (674, -11),
            'B': (632, 79),
            'C': (710, 54),
        }

        data = mtxTable.compile(font)

        self.assertEqual(data, deHexStr("02A2 FFF5 0278 004F 02C6 0036"))

        headerTable = font[self.tableClass.headerTag]
        self.assertEqual(
            getattr(headerTable, self.tableClass.numberOfMetricsName), 3)
Ejemplo n.º 52
0
    def test_decompile_no_header_table(self):
        font = TTFont()
        maxp = font['maxp'] = newTable('maxp')
        maxp.numGlyphs = 3
        font.glyphOrder = ["A", "B", "C"]

        self.assertNotIn(self.tableClass.headerTag, font)

        data = deHexStr("0190 001E 0190 0028 0190 0032")
        mtxTable = newTable(self.tag)
        mtxTable.decompile(data, font)

        self.assertEqual(mtxTable.metrics, {
            "A": (400, 30),
            "B": (400, 40),
            "C": (400, 50),
        })
Ejemplo n.º 53
0
    def test_compile_no_header_table(self):
        font = TTFont()
        maxp = font['maxp'] = newTable('maxp')
        maxp.numGlyphs = 3
        font.glyphOrder = [chr(i) for i in range(65, 68)]
        mtxTable = font[self.tag] = newTable(self.tag)
        mtxTable.metrics = {
            "A": (400, 30),
            "B": (400, 40),
            "C": (400, 50),
        }

        self.assertNotIn(self.tableClass.headerTag, font)

        data = mtxTable.compile(font)

        self.assertEqual(data, deHexStr("0190 001E 0190 0028 0190 0032"))
Ejemplo n.º 54
0
 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]
         ))
Ejemplo n.º 55
0
    def test_decompile_no_header_table(self):
        font = TTFont()
        maxp = font['maxp'] = newTable('maxp')
        maxp.numGlyphs = 3
        font.glyphOrder = ["A", "B", "C"]

        self.assertNotIn(self.tableClass.headerTag, font)

        data = deHexStr("0190 001E 0190 0028 0190 0032")
        mtxTable = newTable(self.tag)
        mtxTable.decompile(data, font)

        self.assertEqual(
            mtxTable.metrics,
            {
                "A": (400, 30),
                "B": (400, 40),
                "C": (400, 50),
            }
        )
Ejemplo n.º 56
0
 def testCompileActions_shouldShareSubsequences(self):
     state = otTables.AATState()
     t = state.Transitions = {i: otTables.InsertionMorphAction()
                              for i in range(3)}
     t[1].CurrentInsertionAction = []
     t[0].MarkedInsertionAction = ['A']
     t[1].CurrentInsertionAction = ['C', 'D']
     t[1].MarkedInsertionAction = ['B']
     t[2].CurrentInsertionAction = ['B', 'C', 'D']
     t[2].MarkedInsertionAction = ['C', 'D']
     actions, actionIndex = t[0].compileActions(self.font, [state])
     self.assertEqual(actions, deHexStr('0002 0003 0004 0001'))
     self.assertEqual(actionIndex, {
         ('A',): 3,
         ('B',): 0,
         ('B', 'C'): 0,
         ('B', 'C', 'D'): 0,
         ('C',): 1,
         ('C', 'D'): 1,
         ('D',): 2,
     })
Ejemplo n.º 57
0
 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>
     ))
Ejemplo n.º 58
0
 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>
     ))
Ejemplo n.º 59
0
 def test_decompileCoords(self):
     decompileCoords = GlyphVariation.decompileCoords_
     axes = ["wght", "wdth", "opsz"]
     coords = [{
         "wght": 1.0,
         "wdth": 0.0,
         "opsz": 0.5
     }, {
         "wght": -1.0,
         "wdth": 0.0,
         "opsz": 0.25
     }, {
         "wght": 0.0,
         "wdth": -1.0,
         "opsz": 1.0
     }]
     data = deHexStr(
         "DE AD 40 00 00 00 20 00 C0 00 00 00 10 00 00 00 C0 00 40 00")
     self.assertEqual((coords, 20),
                      decompileCoords(axes,
                                      numCoords=3,
                                      data=data,
                                      offset=2))
Ejemplo n.º 60
0
 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>
                  ))