def test_removeGuideline(self): font = Font(getTestFontPath()) guideline1 = Guideline(guidelineDict={"x": 100}) guideline2 = Guideline(guidelineDict={"y": 200}) font.guidelines = [guideline1, guideline2] font.removeGuideline(guideline1) self.assertEqual(font.guidelines, [guideline2])
def test_insertGuideline(self): font = Font(getTestFontPath()) guideline1 = Guideline(guidelineDict={"x": 100}) font.insertGuideline(0, guideline1) self.assertEqual([dict(guideline) for guideline in font.guidelines], [{ 'x': 100 }]) guideline2 = Guideline(guidelineDict={"y": 200}) font.insertGuideline(0, guideline2) self.assertEqual([dict(guideline) for guideline in font.guidelines], [{ 'y': 200 }, { 'x': 100 }]) guideline3 = Guideline(guidelineDict={"y": 100}) font.insertGuideline(2, guideline3) self.assertEqual([dict(guideline) for guideline in font.guidelines], [{ 'y': 200 }, { 'x': 100 }, { 'y': 100 }])
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)
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)
def test_guidelineIndex(self): font = Font(getTestFontPath()) guideline1 = Guideline(guidelineDict={"x": 100}) guideline2 = Guideline(guidelineDict={"y": 200}) font.guidelines = [guideline1, guideline2] self.assertEqual(font.guidelineIndex(guideline1), 0) self.assertEqual(font.guidelineIndex(guideline2), 1)
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)
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)
def test_angle(self): g = Guideline() g.angle = 100 self.assertEqual(g.angle, 100) self.assertTrue(g.dirty) g.angle = None self.assertIsNone(g.angle) self.assertTrue(g.dirty)
def test_color(self): g = Guideline() g.color = "1,1,1,1" self.assertEqual(g.color, "1,1,1,1") self.assertTrue(g.dirty) g.color = None self.assertIsNone(g.color) self.assertTrue(g.dirty)
def test_name(self): g = Guideline() g.name = "foo" self.assertEqual(g.name, "foo") self.assertTrue(g.dirty) g.name = None self.assertIsNone(g.name) self.assertTrue(g.dirty)
def test_angle(self): g = Guideline() g.angle = 100 self.assertEqual(g.angle, 100) self.assertTrue(g.dirty) g.angle = None self.assertIsNone(g.angle) self.assertTrue(g.dirty)
def test_y(self): g = Guideline() g.y = 100 self.assertEqual(g.y, 100) self.assertTrue(g.dirty) g.y = None self.assertIsNone(g.y) self.assertTrue(g.dirty)
def test_x(self): g = Guideline() g.x = 100 self.assertEqual(g.x, 100) self.assertTrue(g.dirty) g.x = None self.assertIsNone(g.x) self.assertTrue(g.dirty)
def test_color(self): g = Guideline() g.color = "1,1,1,1" self.assertEqual(g.color, "1,1,1,1") self.assertTrue(g.dirty) g.color = None self.assertIsNone(g.color) self.assertTrue(g.dirty)
def test_name(self): g = Guideline() g.name = "foo" self.assertEqual(g.name, "foo") self.assertTrue(g.dirty) g.name = None self.assertIsNone(g.name) self.assertTrue(g.dirty)
def test_x(self): g = Guideline() g.x = 100 self.assertEqual(g.x, 100) self.assertTrue(g.dirty) g.x = None self.assertIsNone(g.x) self.assertTrue(g.dirty)
def test_appendGuideline(self): glyph = Glyph() glyph.dirty = False guideline = Guideline() glyph.appendGuideline(guideline) self.assertEqual(len(glyph.guidelines), 1) self.assertTrue(glyph.dirty) self.assertEqual(guideline.getParent(), glyph)
def test_y(self): g = Guideline() g.y = 100 self.assertEqual(g.y, 100) self.assertTrue(g.dirty) g.y = None self.assertIsNone(g.y) self.assertTrue(g.dirty)
def test_clearGuidelines(self): font = Font(getTestFontPath()) guideline1 = Guideline(guidelineDict={"x": 100}) guideline2 = Guideline(guidelineDict={"y": 200}) font.guidelines = [guideline1, guideline2] self.assertEqual(font.guidelines, [guideline1, guideline2]) font.clearGuidelines() self.assertEqual(font.guidelines, [])
def test_appendGuideline(self): glyph = Glyph() glyph.dirty = False guideline = Guideline() glyph.appendGuideline(guideline) self.assertEqual(len(glyph.guidelines), 1) self.assertTrue(glyph.dirty) self.assertEqual(guideline.getParent(), glyph)
def test_appendGuideline(self): font = Font(getTestFontPath()) guideline1 = Guideline(guidelineDict={"x": 100}) font.appendGuideline(guideline1) self.assertEqual(font.guidelines, [{'x': 100}]) guideline2 = Guideline(guidelineDict={"y": 200}) font.appendGuideline(guideline2) self.assertEqual(font.guidelines, [{'x': 100}, {'y': 200}]) guideline3 = Guideline(guidelineDict={"y": 100}) font.appendGuideline(guideline3) self.assertEqual(font.guidelines, [{'x': 100}, {'y': 200}, {'y': 100}])
def test_identifier(self): g = Guideline() self.assertIsNone(g.identifier) g.generateIdentifier() self.assertIsNotNone(g.identifier) self.assertTrue(g.dirty)
def test_identifier(self): g = Guideline() self.assertIsNone(g.identifier) g.generateIdentifier() self.assertIsNotNone(g.identifier) self.assertTrue(g.dirty)
def test_dirty(self): g = Guideline() self.assertFalse(g.dirty)
def test_identifiers(self): glyph = Glyph() pointPen = glyph.getPointPen() pointPen.beginPath(identifier="contour 1") pointPen.addPoint((0, 0), identifier="point 1") pointPen.addPoint((0, 0), identifier="point 2") pointPen.endPath() pointPen.beginPath(identifier="contour 2") pointPen.endPath() pointPen.addComponent("A", (1, 1, 1, 1, 1, 1), identifier="component 1") pointPen.addComponent("A", (1, 1, 1, 1, 1, 1), identifier="component 2") guideline = Guideline() guideline.identifier = "guideline 1" glyph.appendGuideline(guideline) guideline = Guideline() guideline.identifier = "guideline 2" glyph.appendGuideline(guideline) self.assertEqual([contour.identifier for contour in glyph], ["contour 1", "contour 2"]) self.assertEqual([point.identifier for point in glyph[0]], ["point 1", "point 2"]) self.assertEqual( [component.identifier for component in glyph.components], ["component 1", "component 2"]) with self.assertRaises(AssertionError): pointPen.beginPath(identifier="contour 1") pointPen.endPath() pointPen.beginPath() pointPen.addPoint((0, 0)) with self.assertRaises(AssertionError): pointPen.addPoint((0, 0), identifier="point 1") pointPen.endPath() with self.assertRaises(AssertionError): pointPen.addComponent("A", (1, 1, 1, 1, 1, 1), identifier="component 1") g = Guideline() g.identifier = "guideline 1" with self.assertRaises(AssertionError): glyph.appendGuideline(g) self.assertEqual(sorted(glyph.identifiers), [ "component 1", "component 2", "contour 1", "contour 2", "guideline 1", "guideline 2", "point 1", "point 2" ]) glyph.removeContour(glyph[0]) self.assertEqual(sorted(glyph.identifiers), [ "component 1", "component 2", "contour 2", "guideline 1", "guideline 2" ]) glyph.removeComponent(glyph.components[0]) self.assertEqual( sorted(glyph.identifiers), ["component 2", "contour 2", "guideline 1", "guideline 2"]) glyph.removeGuideline(glyph.guidelines[0]) self.assertEqual(sorted(glyph.identifiers), ["component 2", "contour 2", "guideline 2"])
def test_identifiers(self): glyph = Glyph() pointPen = glyph.getPointPen() pointPen.beginPath(identifier="contour 1") pointPen.addPoint((0, 0), identifier="point 1") pointPen.addPoint((0, 0), identifier="point 2") pointPen.endPath() pointPen.beginPath(identifier="contour 2") pointPen.endPath() pointPen.addComponent("A", (1, 1, 1, 1, 1, 1), identifier="component 1") pointPen.addComponent("A", (1, 1, 1, 1, 1, 1), identifier="component 2") guideline = Guideline() guideline.identifier = "guideline 1" glyph.appendGuideline(guideline) guideline = Guideline() guideline.identifier = "guideline 2" glyph.appendGuideline(guideline) self.assertEqual([contour.identifier for contour in glyph], ["contour 1", "contour 2"]) self.assertEqual([point.identifier for point in glyph[0]], ["point 1", "point 2"]) self.assertEqual( [component.identifier for component in glyph.components], ["component 1", "component 2"]) with self.assertRaises(AssertionError): pointPen.beginPath(identifier="contour 1") pointPen.endPath() pointPen.beginPath() pointPen.addPoint((0, 0)) with self.assertRaises(AssertionError): pointPen.addPoint((0, 0), identifier="point 1") pointPen.endPath() with self.assertRaises(AssertionError): pointPen.addComponent("A", (1, 1, 1, 1, 1, 1), identifier="component 1") g = Guideline() g.identifier = "guideline 1" with self.assertRaises(AssertionError): glyph.appendGuideline(g) self.assertEqual( sorted(glyph.identifiers), ["component 1", "component 2", "contour 1", "contour 2", "guideline 1", "guideline 2", "point 1", "point 2"]) glyph.removeContour(glyph[0]) self.assertEqual( sorted(glyph.identifiers), ["component 1", "component 2", "contour 2", "guideline 1", "guideline 2"]) glyph.removeComponent(glyph.components[0]) self.assertEqual( sorted(glyph.identifiers), ["component 2", "contour 2", "guideline 1", "guideline 2"]) glyph.removeGuideline(glyph.guidelines[0]) self.assertEqual( sorted(glyph.identifiers), ["component 2", "contour 2", "guideline 2"])
def test_instance(self): g = Guideline(guidelineDict=dict( x=1, y=2, angle=3, name="4", identifier="5", color="1,1,1,1")) self.assertEqual((g.x, g.y, g.angle, g.name, g.identifier, g.color), (1, 2, 3, '4', '5', '1,1,1,1'))