Exemplo n.º 1
0
def test_splitMarkBasePos():
    from fontTools.otlLib.builder import buildAnchor, buildMarkBasePosSubtable

    marks = {
        "acutecomb": (0, buildAnchor(0, 600)),
        "gravecomb": (0, buildAnchor(0, 590)),
        "cedillacomb": (1, buildAnchor(0, 0)),
    }
    bases = {
        "a": {
            0: buildAnchor(350, 500),
            1: None,
        },
        "c": {
            0: buildAnchor(300, 700),
            1: buildAnchor(300, 0),
        },
    }
    glyphOrder = ["a", "c", "acutecomb", "gravecomb", "cedillacomb"]
    glyphMap = {g: i for i, g in enumerate(glyphOrder)}

    oldSubTable = buildMarkBasePosSubtable(marks, bases, glyphMap)
    oldSubTable.MarkCoverage.Format = oldSubTable.BaseCoverage.Format = 1
    newSubTable = otTables.MarkBasePos()

    ok = otTables.splitMarkBasePos(oldSubTable,
                                   newSubTable,
                                   overflowRecord=None)

    assert ok
    assert oldSubTable.Format == newSubTable.Format
    assert oldSubTable.MarkCoverage.glyphs == ["acutecomb", "gravecomb"]
    assert newSubTable.MarkCoverage.glyphs == ["cedillacomb"]
    assert newSubTable.MarkCoverage.Format == 1
    assert oldSubTable.BaseCoverage.glyphs == newSubTable.BaseCoverage.glyphs
    assert newSubTable.BaseCoverage.Format == 1
    assert oldSubTable.ClassCount == newSubTable.ClassCount == 1
    assert oldSubTable.MarkArray.MarkCount == 2
    assert newSubTable.MarkArray.MarkCount == 1
    assert oldSubTable.BaseArray.BaseCount == newSubTable.BaseArray.BaseCount
    assert newSubTable.BaseArray.BaseRecord[0].BaseAnchor[0] is None
    assert newSubTable.BaseArray.BaseRecord[1].BaseAnchor[0] == buildAnchor(
        300, 0)
Exemplo n.º 2
0
def test_splitMarkBasePos():
	from fontTools.otlLib.builder import buildAnchor, buildMarkBasePosSubtable

	marks = {
		"acutecomb": (0, buildAnchor(0, 600)),
		"gravecomb": (0, buildAnchor(0, 590)),
		"cedillacomb": (1, buildAnchor(0, 0)),
	}
	bases = {
		"a": {
			0: buildAnchor(350, 500),
			1: None,
		},
		"c": {
			0: buildAnchor(300, 700),
			1: buildAnchor(300, 0),
		},
	}
	glyphOrder = ["a", "c", "acutecomb", "gravecomb", "cedillacomb"]
	glyphMap = {g: i for i, g in enumerate(glyphOrder)}

	oldSubTable = buildMarkBasePosSubtable(marks, bases, glyphMap)
	oldSubTable.MarkCoverage.Format = oldSubTable.BaseCoverage.Format = 1
	newSubTable = otTables.MarkBasePos()

	ok = otTables.splitMarkBasePos(oldSubTable, newSubTable, overflowRecord=None)

	assert ok
	assert oldSubTable.Format == newSubTable.Format
	assert oldSubTable.MarkCoverage.glyphs == [
		"acutecomb", "gravecomb"
	]
	assert newSubTable.MarkCoverage.glyphs == ["cedillacomb"]
	assert newSubTable.MarkCoverage.Format == 1
	assert oldSubTable.BaseCoverage.glyphs == newSubTable.BaseCoverage.glyphs
	assert newSubTable.BaseCoverage.Format == 1
	assert oldSubTable.ClassCount == newSubTable.ClassCount == 1
	assert oldSubTable.MarkArray.MarkCount == 2
	assert newSubTable.MarkArray.MarkCount == 1
	assert oldSubTable.BaseArray.BaseCount == newSubTable.BaseArray.BaseCount
	assert newSubTable.BaseArray.BaseRecord[0].BaseAnchor[0] is None
	assert newSubTable.BaseArray.BaseRecord[1].BaseAnchor[0] == buildAnchor(300, 0)
Exemplo n.º 3
0
 def test_buildMarkBasePosSubtable(self):
     anchor = builder.buildAnchor
     marks = {
         "acute": (0, anchor(300, 700)),
         "cedilla": (1, anchor(300, -100)),
         "grave": (0, anchor(300, 700)),
     }
     bases = {
         # Make sure we can handle missing entries.
         "A": {},  # no entry for any markClass
         "B": {
             0: anchor(500, 900)
         },  # only markClass 0 specified
         "C": {
             1: anchor(500, -10)
         },  # only markClass 1 specified
         "a": {
             0: anchor(500, 400),
             1: anchor(500, -20)
         },
         "b": {
             0: anchor(500, 800),
             1: anchor(500, -20)
         },
     }
     table = builder.buildMarkBasePosSubtable(marks, bases, self.GLYPHMAP)
     assert getXML(table.toXML) == [
         '<MarkBasePos Format="1">',
         "  <MarkCoverage>",
         '    <Glyph value="grave"/>',
         '    <Glyph value="acute"/>',
         '    <Glyph value="cedilla"/>',
         "  </MarkCoverage>",
         "  <BaseCoverage>",
         '    <Glyph value="A"/>',
         '    <Glyph value="B"/>',
         '    <Glyph value="C"/>',
         '    <Glyph value="a"/>',
         '    <Glyph value="b"/>',
         "  </BaseCoverage>",
         "  <!-- ClassCount=2 -->",
         "  <MarkArray>",
         "    <!-- MarkCount=3 -->",
         '    <MarkRecord index="0">',  # grave
         '      <Class value="0"/>',
         '      <MarkAnchor Format="1">',
         '        <XCoordinate value="300"/>',
         '        <YCoordinate value="700"/>',
         "      </MarkAnchor>",
         "    </MarkRecord>",
         '    <MarkRecord index="1">',  # acute
         '      <Class value="0"/>',
         '      <MarkAnchor Format="1">',
         '        <XCoordinate value="300"/>',
         '        <YCoordinate value="700"/>',
         "      </MarkAnchor>",
         "    </MarkRecord>",
         '    <MarkRecord index="2">',  # cedilla
         '      <Class value="1"/>',
         '      <MarkAnchor Format="1">',
         '        <XCoordinate value="300"/>',
         '        <YCoordinate value="-100"/>',
         "      </MarkAnchor>",
         "    </MarkRecord>",
         "  </MarkArray>",
         "  <BaseArray>",
         "    <!-- BaseCount=5 -->",
         '    <BaseRecord index="0">',  # A
         '      <BaseAnchor index="0" empty="1"/>',
         '      <BaseAnchor index="1" empty="1"/>',
         "    </BaseRecord>",
         '    <BaseRecord index="1">',  # B
         '      <BaseAnchor index="0" Format="1">',
         '        <XCoordinate value="500"/>',
         '        <YCoordinate value="900"/>',
         "      </BaseAnchor>",
         '      <BaseAnchor index="1" empty="1"/>',
         "    </BaseRecord>",
         '    <BaseRecord index="2">',  # C
         '      <BaseAnchor index="0" empty="1"/>',
         '      <BaseAnchor index="1" Format="1">',
         '        <XCoordinate value="500"/>',
         '        <YCoordinate value="-10"/>',
         "      </BaseAnchor>",
         "    </BaseRecord>",
         '    <BaseRecord index="3">',  # a
         '      <BaseAnchor index="0" Format="1">',
         '        <XCoordinate value="500"/>',
         '        <YCoordinate value="400"/>',
         "      </BaseAnchor>",
         '      <BaseAnchor index="1" Format="1">',
         '        <XCoordinate value="500"/>',
         '        <YCoordinate value="-20"/>',
         "      </BaseAnchor>",
         "    </BaseRecord>",
         '    <BaseRecord index="4">',  # b
         '      <BaseAnchor index="0" Format="1">',
         '        <XCoordinate value="500"/>',
         '        <YCoordinate value="800"/>',
         "      </BaseAnchor>",
         '      <BaseAnchor index="1" Format="1">',
         '        <XCoordinate value="500"/>',
         '        <YCoordinate value="-20"/>',
         "      </BaseAnchor>",
         "    </BaseRecord>",
         "  </BaseArray>",
         "</MarkBasePos>",
     ]
Exemplo n.º 4
0
def test_splitMarkBasePos():
    from fontTools.otlLib.builder import buildAnchor, buildMarkBasePosSubtable

    marks = {
        "acutecomb": (0, buildAnchor(0, 600)),
        "gravecomb": (0, buildAnchor(0, 590)),
        "cedillacomb": (1, buildAnchor(0, 0)),
    }
    bases = {
        "a": {
            0: buildAnchor(350, 500),
            1: None,
        },
        "c": {
            0: buildAnchor(300, 700),
            1: buildAnchor(300, 0),
        },
    }
    glyphOrder = ["a", "c", "acutecomb", "gravecomb", "cedillacomb"]
    glyphMap = {g: i for i, g in enumerate(glyphOrder)}

    oldSubTable = buildMarkBasePosSubtable(marks, bases, glyphMap)
    newSubTable = otTables.MarkBasePos()

    ok = otTables.splitMarkBasePos(oldSubTable,
                                   newSubTable,
                                   overflowRecord=None)

    assert ok

    assert getXML(oldSubTable.toXML) == [
        '<MarkBasePos Format="1">',
        '  <MarkCoverage>',
        '    <Glyph value="acutecomb"/>',
        '    <Glyph value="gravecomb"/>',
        '  </MarkCoverage>',
        '  <BaseCoverage>',
        '    <Glyph value="a"/>',
        '    <Glyph value="c"/>',
        '  </BaseCoverage>',
        '  <!-- ClassCount=1 -->',
        '  <MarkArray>',
        '    <!-- MarkCount=2 -->',
        '    <MarkRecord index="0">',
        '      <Class value="0"/>',
        '      <MarkAnchor Format="1">',
        '        <XCoordinate value="0"/>',
        '        <YCoordinate value="600"/>',
        '      </MarkAnchor>',
        '    </MarkRecord>',
        '    <MarkRecord index="1">',
        '      <Class value="0"/>',
        '      <MarkAnchor Format="1">',
        '        <XCoordinate value="0"/>',
        '        <YCoordinate value="590"/>',
        '      </MarkAnchor>',
        '    </MarkRecord>',
        '  </MarkArray>',
        '  <BaseArray>',
        '    <!-- BaseCount=2 -->',
        '    <BaseRecord index="0">',
        '      <BaseAnchor index="0" Format="1">',
        '        <XCoordinate value="350"/>',
        '        <YCoordinate value="500"/>',
        '      </BaseAnchor>',
        '    </BaseRecord>',
        '    <BaseRecord index="1">',
        '      <BaseAnchor index="0" Format="1">',
        '        <XCoordinate value="300"/>',
        '        <YCoordinate value="700"/>',
        '      </BaseAnchor>',
        '    </BaseRecord>',
        '  </BaseArray>',
        '</MarkBasePos>',
    ]

    assert getXML(newSubTable.toXML) == [
        '<MarkBasePos Format="1">',
        '  <MarkCoverage>',
        '    <Glyph value="cedillacomb"/>',
        '  </MarkCoverage>',
        '  <BaseCoverage>',
        '    <Glyph value="a"/>',
        '    <Glyph value="c"/>',
        '  </BaseCoverage>',
        '  <!-- ClassCount=1 -->',
        '  <MarkArray>',
        '    <!-- MarkCount=1 -->',
        '    <MarkRecord index="0">',
        '      <Class value="0"/>',
        '      <MarkAnchor Format="1">',
        '        <XCoordinate value="0"/>',
        '        <YCoordinate value="0"/>',
        '      </MarkAnchor>',
        '    </MarkRecord>',
        '  </MarkArray>',
        '  <BaseArray>',
        '    <!-- BaseCount=2 -->',
        '    <BaseRecord index="0">',
        '      <BaseAnchor index="0" empty="1"/>',
        '    </BaseRecord>',
        '    <BaseRecord index="1">',
        '      <BaseAnchor index="0" Format="1">',
        '        <XCoordinate value="300"/>',
        '        <YCoordinate value="0"/>',
        '      </BaseAnchor>',
        '    </BaseRecord>',
        '  </BaseArray>',
        '</MarkBasePos>',
    ]
Exemplo n.º 5
0
    def test_buildMarkBasePosSubtable(self):
        anchor = builder.buildAnchor
        marks = {
            "acute": (0, anchor(300, 700)),
            "cedilla": (1, anchor(300, -100)),
            "grave": (0, anchor(300, 700))
        }
        bases = {
            # Make sure we can handle missing entries.
            "A": {},  # no entry for any markClass
            "B": {0: anchor(500, 900)},  # only markClass 0 specified
            "C": {1: anchor(500, -10)},  # only markClass 1 specified

            "a": {0: anchor(500, 400), 1: anchor(500, -20)},
            "b": {0: anchor(500, 800), 1: anchor(500, -20)}
        }
        table = builder.buildMarkBasePosSubtable(marks, bases, self.GLYPHMAP)
        self.maxDiff = None
        self.assertEqual(getXML(table.toXML),
                         '<MarkBasePos Format="1">'
                         '  <MarkCoverage>'
                         '    <Glyph value="grave"/>'
                         '    <Glyph value="acute"/>'
                         '    <Glyph value="cedilla"/>'
                         '  </MarkCoverage>'
                         '  <BaseCoverage>'
                         '    <Glyph value="A"/>'
                         '    <Glyph value="B"/>'
                         '    <Glyph value="C"/>'
                         '    <Glyph value="a"/>'
                         '    <Glyph value="b"/>'
                         '  </BaseCoverage>'
                         '  <!-- ClassCount=2 -->'
                         '  <MarkArray>'
                         '    <!-- MarkCount=3 -->'
                         '    <MarkRecord index="0">'  # grave
                         '      <Class value="0"/>'
                         '      <MarkAnchor Format="1">'
                         '        <XCoordinate value="300"/>'
                         '        <YCoordinate value="700"/>'
                         '      </MarkAnchor>'
                         '    </MarkRecord>'
                         '    <MarkRecord index="1">'  # acute
                         '      <Class value="0"/>'
                         '      <MarkAnchor Format="1">'
                         '        <XCoordinate value="300"/>'
                         '        <YCoordinate value="700"/>'
                         '      </MarkAnchor>'
                         '    </MarkRecord>'
                         '    <MarkRecord index="2">'  # cedilla
                         '      <Class value="1"/>'
                         '      <MarkAnchor Format="1">'
                         '        <XCoordinate value="300"/>'
                         '        <YCoordinate value="-100"/>'
                         '      </MarkAnchor>'
                         '    </MarkRecord>'
                         '  </MarkArray>'
                         '  <BaseArray>'
                         '    <!-- BaseCount=5 -->'
                         '    <BaseRecord index="0">'  # A
                         '      <BaseAnchor index="0" empty="1"/>'
                         '      <BaseAnchor index="1" empty="1"/>'
                         '    </BaseRecord>'
                         '    <BaseRecord index="1">'  # B
                         '      <BaseAnchor index="0" Format="1">'
                         '        <XCoordinate value="500"/>'
                         '        <YCoordinate value="900"/>'
                         '      </BaseAnchor>'
                         '      <BaseAnchor index="1" empty="1"/>'
                         '    </BaseRecord>'
                         '    <BaseRecord index="2">'  # C
                         '      <BaseAnchor index="0" empty="1"/>'
                         '      <BaseAnchor index="1" Format="1">'
                         '        <XCoordinate value="500"/>'
                         '        <YCoordinate value="-10"/>'
                         '      </BaseAnchor>'
                         '    </BaseRecord>'
                         '    <BaseRecord index="3">'  # a
                         '      <BaseAnchor index="0" Format="1">'
                         '        <XCoordinate value="500"/>'
                         '        <YCoordinate value="400"/>'
                         '      </BaseAnchor>'
                         '      <BaseAnchor index="1" Format="1">'
                         '        <XCoordinate value="500"/>'
                         '        <YCoordinate value="-20"/>'
                         '      </BaseAnchor>'
                         '    </BaseRecord>'
                         '    <BaseRecord index="4">'  # b
                         '      <BaseAnchor index="0" Format="1">'
                         '        <XCoordinate value="500"/>'
                         '        <YCoordinate value="800"/>'
                         '      </BaseAnchor>'
                         '      <BaseAnchor index="1" Format="1">'
                         '        <XCoordinate value="500"/>'
                         '        <YCoordinate value="-20"/>'
                         '      </BaseAnchor>'
                         '    </BaseRecord>'
                         '  </BaseArray>'
                         '</MarkBasePos>')