Пример #1
0
 def test_glyph_dispatcher_inserted(self):
     font = Font()
     font.newGlyph("A")
     glyph = font["A"]
     pen = glyph.getPointPen()
     pen.beginPath()
     pen.addPoint((0, 0), segmentType="line")
     pen.addPoint((0, 100), segmentType="line")
     pen.addPoint((100, 100), segmentType="line")
     pen.addPoint((100, 0), segmentType="line")
     pen.endPath()
     contour = glyph[0]
     component = Component()
     glyph.appendComponent(component)
     anchor = Anchor()
     glyph.appendAnchor(anchor)
     guideline = Guideline()
     glyph.appendGuideline(guideline)
     sourceGlyph = glyph
     newFont = Font()
     insertedGlyph = newFont.insertGlyph(sourceGlyph)
     contour = insertedGlyph[0]
     self.assertTrue(contour.getParent(), insertedGlyph)
     self.assertTrue(contour.dispatcher, newFont.dispatcher)
     component = insertedGlyph.components[0]
     self.assertTrue(component.getParent(), insertedGlyph)
     self.assertTrue(component.dispatcher, newFont.dispatcher)
     anchor = insertedGlyph.anchors[0]
     self.assertTrue(anchor.getParent(), insertedGlyph)
     self.assertTrue(anchor.dispatcher, newFont.dispatcher)
     guideline = insertedGlyph.guidelines[0]
     self.assertTrue(guideline.getParent(), insertedGlyph)
     self.assertTrue(guideline.dispatcher, newFont.dispatcher)
Пример #2
0
 def test_glyph_dispatcher_inserted(self):
     font = Font()
     font.newGlyph("A")
     glyph = font["A"]
     pen = glyph.getPointPen()
     pen.beginPath()
     pen.addPoint((0, 0), segmentType="line")
     pen.addPoint((0, 100), segmentType="line")
     pen.addPoint((100, 100), segmentType="line")
     pen.addPoint((100, 0), segmentType="line")
     pen.endPath()
     contour = glyph[0]
     component = Component()
     glyph.appendComponent(component)
     anchor = Anchor()
     glyph.appendAnchor(anchor)
     guideline = Guideline()
     glyph.appendGuideline(guideline)
     sourceGlyph = glyph
     newFont = Font()
     insertedGlyph = newFont.insertGlyph(sourceGlyph)
     contour = insertedGlyph[0]
     self.assertTrue(contour.getParent(), insertedGlyph)
     self.assertTrue(contour.dispatcher, newFont.dispatcher)
     component = insertedGlyph.components[0]
     self.assertTrue(component.getParent(), insertedGlyph)
     self.assertTrue(component.dispatcher, newFont.dispatcher)
     anchor = insertedGlyph.anchors[0]
     self.assertTrue(anchor.getParent(), insertedGlyph)
     self.assertTrue(anchor.dispatcher, newFont.dispatcher)
     guideline = insertedGlyph.guidelines[0]
     self.assertTrue(guideline.getParent(), insertedGlyph)
     self.assertTrue(guideline.dispatcher, newFont.dispatcher)
Пример #3
0
 def test_glyph_dispatcher_new(self):
     font = Font()
     font.newGlyph("A")
     glyph = font["A"]
     pen = glyph.getPointPen()
     pen.beginPath()
     pen.addPoint((0, 0), segmentType="line")
     pen.addPoint((0, 100), segmentType="line")
     pen.addPoint((100, 100), segmentType="line")
     pen.addPoint((100, 0), segmentType="line")
     pen.endPath()
     contour = glyph[0]
     self.assertEqual(contour.getParent(), glyph)
     self.assertEqual(contour.dispatcher, font.dispatcher)
     component = Component()
     glyph.appendComponent(component)
     self.assertEqual(component.getParent(), glyph)
     self.assertEqual(component.dispatcher, font.dispatcher)
     anchor = Anchor()
     glyph.appendAnchor(anchor)
     self.assertEqual(anchor.getParent(), glyph)
     self.assertEqual(anchor.dispatcher, font.dispatcher)
     guideline = Guideline()
     glyph.appendGuideline(guideline)
     self.assertEqual(guideline.getParent(), glyph)
     self.assertEqual(guideline.dispatcher, font.dispatcher)
Пример #4
0
 def test_glyph_dispatcher_new(self):
     font = Font()
     font.newGlyph("A")
     glyph = font["A"]
     pen = glyph.getPointPen()
     pen.beginPath()
     pen.addPoint((0, 0), segmentType="line")
     pen.addPoint((0, 100), segmentType="line")
     pen.addPoint((100, 100), segmentType="line")
     pen.addPoint((100, 0), segmentType="line")
     pen.endPath()
     contour = glyph[0]
     self.assertEqual(contour.getParent(), glyph)
     self.assertEqual(contour.dispatcher, font.dispatcher)
     component = Component()
     glyph.appendComponent(component)
     self.assertEqual(component.getParent(), glyph)
     self.assertEqual(component.dispatcher, font.dispatcher)
     anchor = Anchor()
     glyph.appendAnchor(anchor)
     self.assertEqual(anchor.getParent(), glyph)
     self.assertEqual(anchor.dispatcher, font.dispatcher)
     guideline = Guideline()
     glyph.appendGuideline(guideline)
     self.assertEqual(guideline.getParent(), glyph)
     self.assertEqual(guideline.dispatcher, font.dispatcher)
Пример #5
0
 def test_appendComponent(self):
     glyph = Glyph()
     glyph.dirty = False
     component = Component()
     glyph.appendComponent(component)
     self.assertEqual(len(glyph.components), 1)
     self.assertTrue(glyph.dirty)
     self.assertEqual(component.getParent(), glyph)
Пример #6
0
 def test_appendComponent(self):
     glyph = Glyph()
     glyph.dirty = False
     component = Component()
     glyph.appendComponent(component)
     self.assertEqual(len(glyph.components), 1)
     self.assertTrue(glyph.dirty)
     self.assertEqual(component.getParent(), glyph)
Пример #7
0
class ComponentTest(unittest.TestCase):

    def __init__(self, methodName):
        unittest.TestCase.__init__(self, methodName)

    def setUp(self):
        self.font = Font()
        self.glyph = Glyph()
        self.component = Component(self.glyph)

    def tearDown(self):
        del self.component
        del self.glyph

    def test_getParent(self):
        self.assertEqual(self.component.getParent(), self.glyph)

    def test_font(self):
        self.assertIsNone(self.component.font)
        self.component = Component(self.font.newGlyph("A"))
        self.assertEqual(self.component.font, self.font)
        with self.assertRaises(AttributeError):
            self.component.font = "foo"

    def test_layerSet(self):
        self.assertIsNone(self.component.layerSet)
        self.glyph = self.font.newGlyph("A")
        self.component = Component(self.glyph)
        self.assertEqual(self.component.layerSet, self.glyph.layerSet)
        with self.assertRaises(AttributeError):
            self.component.layerSet = "foo"

    def test_layer(self):
        self.assertIsNone(self.component.layer)
        self.glyph = self.font.newGlyph("A")
        self.component = Component(self.glyph)
        self.assertEqual(self.component.layer, self.glyph.layer)
        with self.assertRaises(AttributeError):
            self.component.layer = "foo"

    def test_glyph(self):
        self.assertIsNone(self.component.layer)
        self.glyph = self.font.newGlyph("A")
        self.component = Component(self.glyph)
        self.assertEqual(self.component.layer, self.glyph.layer)
        with self.assertRaises(AttributeError):
            self.component.layer = "foo"

    def test_bounds(self):
        self.font = Font(getTestFontPath())
        self.glyph = self.font["C"]
        self.component = self.glyph.components[0]
        self.assertEqual(
            self.component.bounds,
            (0.0, 0.0, 350.0, 350.0)
        )
        with self.assertRaises(AttributeError):
            self.component.layer = (0.0, 0.0, 350.0, 350.0)

    def test_controlPointBounds(self):
        self.font = Font(getTestFontPath())
        self.glyph = self.font["C"]
        self.component = self.glyph.components[0]
        self.assertEqual(
            self.component.controlPointBounds,
            (0.0, 0.0, 350.0, 350.0)
        )
        with self.assertRaises(AttributeError):
            self.component.layer = (0.0, 0.0, 350.0, 350.0)

    def test_baseGlyph(self):
        self.assertIsNone(self.component.baseGlyph)

        self.font = Font(getTestFontPath())
        self.glyph = self.font["C"]
        self.component = self.glyph.components[0]
        self.assertEqual(self.component.baseGlyph, "A")
        self.component.baseGlyph = "B"
        self.assertEqual(self.component.baseGlyph, "B")

    def test_transformation(self):
        self.assertEqual(
            self.component.transformation,
            (1, 0, 0, 1, 0, 0)
        )

        self.font = Font(getTestFontPath())
        self.glyph = self.font["C"]
        self.component = self.glyph.components[0]
        self.assertEqual(
            self.component.transformation,
            (0.5, 0, 0, 0.5, 0, 0)
        )
        self.component = self.glyph.components[1]
        self.assertEqual(
            self.component.transformation,
            (0.5, 0, 0, 0.5, 350, 350)
        )

    def test_identifier(self):
        self.assertIsNone(self.component.identifier)
        self.component.identifier = "component 1"
        self.assertEqual(self.component.identifier, "component 1")

    def test_identifiers(self):
        self.assertEqual(sorted(self.glyph.identifiers), [])
        self.component.identifier = "component 1"
        self.assertEqual(sorted(self.glyph.identifiers), ["component 1"])

    def test_duplicate_identifier_error(self):
        glyph = self.glyph
        component = self.component
        component.identifier = "component 1"
        self.assertEqual(component.identifier, "component 1")
        component = Component(glyph)
        with self.assertRaises(AssertionError):
            component.identifier = "component 1"
        component.identifier = "component 2"
        self.assertEqual(sorted(glyph.identifiers),
                         ["component 1", "component 2"])
        component.identifier = "not component 2 anymore"
        self.assertEqual(component.identifier, "component 2")
        self.assertEqual(sorted(glyph.identifiers),
                         ["component 1", "component 2"])
        component.identifier = None
        self.assertEqual(component.identifier, "component 2")
        self.assertEqual(sorted(glyph.identifiers),
                         ["component 1", "component 2"])
Пример #8
0
class ComponentTest(unittest.TestCase):
    def __init__(self, methodName):
        unittest.TestCase.__init__(self, methodName)

    def setUp(self):
        self.font = Font()
        self.glyph = Glyph()
        self.component = Component(self.glyph)

    def tearDown(self):
        del self.component
        del self.glyph

    def test_getParent(self):
        self.assertEqual(self.component.getParent(), self.glyph)

    def test_font(self):
        self.assertIsNone(self.component.font)
        self.component = Component(self.font.newGlyph("A"))
        self.assertEqual(self.component.font, self.font)
        with self.assertRaises(AttributeError):
            self.component.font = "foo"

    def test_layerSet(self):
        self.assertIsNone(self.component.layerSet)
        self.glyph = self.font.newGlyph("A")
        self.component = Component(self.glyph)
        self.assertEqual(self.component.layerSet, self.glyph.layerSet)
        with self.assertRaises(AttributeError):
            self.component.layerSet = "foo"

    def test_layer(self):
        self.assertIsNone(self.component.layer)
        self.glyph = self.font.newGlyph("A")
        self.component = Component(self.glyph)
        self.assertEqual(self.component.layer, self.glyph.layer)
        with self.assertRaises(AttributeError):
            self.component.layer = "foo"

    def test_glyph(self):
        self.assertIsNone(self.component.layer)
        self.glyph = self.font.newGlyph("A")
        self.component = Component(self.glyph)
        self.assertEqual(self.component.layer, self.glyph.layer)
        with self.assertRaises(AttributeError):
            self.component.layer = "foo"

    def test_bounds(self):
        self.font = Font(getTestFontPath())
        self.glyph = self.font["C"]
        self.component = self.glyph.components[0]
        self.assertEqual(self.component.bounds, (0.0, 0.0, 350.0, 350.0))
        with self.assertRaises(AttributeError):
            self.component.layer = (0.0, 0.0, 350.0, 350.0)

    def test_controlPointBounds(self):
        self.font = Font(getTestFontPath())
        self.glyph = self.font["C"]
        self.component = self.glyph.components[0]
        self.assertEqual(self.component.controlPointBounds,
                         (0.0, 0.0, 350.0, 350.0))
        with self.assertRaises(AttributeError):
            self.component.layer = (0.0, 0.0, 350.0, 350.0)

    def test_baseGlyph(self):
        self.assertIsNone(self.component.baseGlyph)

        self.font = Font(getTestFontPath())
        self.glyph = self.font["C"]
        self.component = self.glyph.components[0]
        self.assertEqual(self.component.baseGlyph, "A")
        self.component.baseGlyph = "B"
        self.assertEqual(self.component.baseGlyph, "B")

    def test_transformation(self):
        self.assertEqual(self.component.transformation, (1, 0, 0, 1, 0, 0))

        self.font = Font(getTestFontPath())
        self.glyph = self.font["C"]
        self.component = self.glyph.components[0]
        self.assertEqual(self.component.transformation, (0.5, 0, 0, 0.5, 0, 0))
        self.component = self.glyph.components[1]
        self.assertEqual(self.component.transformation,
                         (0.5, 0, 0, 0.5, 350, 350))

    def test_identifier(self):
        self.assertIsNone(self.component.identifier)
        self.component.identifier = "component 1"
        self.assertEqual(self.component.identifier, "component 1")

    def test_identifiers(self):
        self.assertEqual(sorted(self.glyph.identifiers), [])
        self.component.identifier = "component 1"
        self.assertEqual(sorted(self.glyph.identifiers), ["component 1"])

    def test_duplicate_identifier_error(self):
        glyph = self.glyph
        component = self.component
        component.identifier = "component 1"
        self.assertEqual(component.identifier, "component 1")
        component = Component(glyph)
        with self.assertRaises(AssertionError):
            component.identifier = "component 1"
        component.identifier = "component 2"
        self.assertEqual(sorted(glyph.identifiers),
                         ["component 1", "component 2"])
        component.identifier = "not component 2 anymore"
        self.assertEqual(component.identifier, "component 2")
        self.assertEqual(sorted(glyph.identifiers),
                         ["component 1", "component 2"])
        component.identifier = None
        self.assertEqual(component.identifier, "component 2")
        self.assertEqual(sorted(glyph.identifiers),
                         ["component 1", "component 2"])