Ejemplo n.º 1
0
 def test_glyph(self):
     self.assertIsNone(self.contour.glyph)
     self.contour = Contour(self.glyph)
     self.assertEqual(self.contour.glyph, self.glyph)
     glyph = Glyph()
     self.contour = Contour()
     self.contour.glyph = glyph
     self.assertEqual(self.contour.glyph, glyph)
     with self.assertRaises(AssertionError):
         self.contour.glyph = self.glyph
Ejemplo n.º 2
0
    def addAnchors(self, glyph, base):
        anchors = base.anchors
        glyph.clearAnchors()
        if glyph.name == 'uniE272':
            m = 1
        markAnchors = [
            'markAbove', 'markBelow', 'markAbove_1', 'markAbove_2',
            'markBelow_1', 'markBelow_2', '_markAbove', '_markBelow',
            '_markAbove_1', '_markAbove_2', '_markBelow_1', '_markBelow_2',
            '_hamzaAbove', 'hamzaAbove', '_hamzaBelow', 'hamzaBelow'
            # 'markAboveMark','markBelowMark','_markAboveMark','_markBelowMark'
        ]
        if len(anchors):
            for anchor in anchors:
                if anchor.name in markAnchors:
                    anc = glyph.instantiateAnchor()
                    anc.x = anchor.x
                    anc.y = anchor.y
                    anc.name = anchor.name
                    glyph.appendAnchor(anc)

                    c = Contour()
                    c.addPoint((anchor.x, anchor.y),
                               name=anchor.name,
                               segmentType="move")
                    glyph.appendContour(c)

                else:
                    continue
Ejemplo n.º 3
0
 def test_layer(self):
     self.assertIsNone(self.contour.layer)
     self.contour = Contour(self.glyph)
     self.assertIsNotNone(self.contour.layer)
     self.assertEqual(self.contour.layer, self.glyph.layer)
     with self.assertRaises(AttributeError):
         self.contour.layer = "foo"
Ejemplo n.º 4
0
 def test_appendContour(self):
     glyph = Glyph()
     glyph.dirty = False
     contour = Contour()
     glyph.appendContour(contour)
     self.assertEqual(len(glyph), 1)
     self.assertTrue(glyph.dirty)
     self.assertEqual(contour.getParent(), glyph)
Ejemplo n.º 5
0
 def test_open(self):
     font = Font(getTestFontPath("TestOpenContour.ufo"))
     glyph = font["A"]
     self.assertTrue(glyph[0].open)
     self.assertFalse(glyph[1].open)
     self.assertTrue(glyph[2].open)
     self.assertFalse(glyph[3].open)
     contour = Contour()
     self.assertTrue(contour.open)
Ejemplo n.º 6
0
 def test_identifier(self):
     glyph = Glyph()
     contour = Contour()
     glyph.appendContour(contour)
     contour.identifier = "contour 1"
     self.assertEqual(contour.identifier, "contour 1")
     self.assertEqual(sorted(glyph.identifiers), ["contour 1"])
     contour = Contour()
     glyph.appendContour(contour)
     with self.assertRaises(AssertionError):
         contour.identifier = "contour 1"
     contour.identifier = "contour 2"
     self.assertEqual(sorted(glyph.identifiers), ["contour 1", "contour 2"])
     contour.identifier = "not contour 2 anymore"
     self.assertEqual(contour.identifier, "contour 2")
     self.assertEqual(sorted(glyph.identifiers), ["contour 1", "contour 2"])
     contour.identifier = None
     self.assertEqual(contour.identifier, "contour 2")
     self.assertEqual(sorted(glyph.identifiers), ["contour 1", "contour 2"])
Ejemplo n.º 7
0
    def set_active(self, state):
        """Activate/Deactivate the Bezier Pen Tool"""
        if state is True:
            self.is_active = True
            self.contour = Contour()
            self.contour.dirty = True
            self.editor.add_contour(self.contour)
            self.connect_editor()
        else:
            self.contour.dirty = False
            self.is_active = False
            self.disconnect_editor()

        globals.TOOL_ACTIVE['BezierPenTool'] = state
Ejemplo n.º 8
0
 def createAnchors(self):
     factor = self.getFactorOfUPM()
     for g in self.UFO:
         try:
             sampleGlyph = self.templateUFO[g.name]
             g.anchors = copy.deepcopy(sampleGlyph.anchors)
             for point in g.anchors:
                 point.x *= factor
                 point.y *= factor
             for point in sampleGlyph.anchors:
                 xVal = point.x * factor
                 yVal = point.y * factor
                 c = Contour()
                 c.addPoint((xVal, yVal), name=point.name, segmentType="move")
                 g.appendContour(c)
         except:
             pass
Ejemplo n.º 9
0
 def test_font(self):
     self.assertIsNone(self.contour.font)
     self.contour = Contour(self.glyph)
     self.assertEqual(self.contour.font, self.font)
     with self.assertRaises(AttributeError):
         self.contour.font = "foo"
Ejemplo n.º 10
0
 def test_getParent(self):
     self.assertIsNone(self.contour.getParent())
     self.contour = Contour(self.glyph)
     self.assertEqual(self.contour.getParent(), self.glyph)
Ejemplo n.º 11
0
 def setUp(self):
     self.font = Font()
     self.glyph = self.font.newGlyph("A")
     self.contour = Contour()
Ejemplo n.º 12
0
def create_contour(contour_path):
    contour = Contour()
    for point in map(create_point, contour_path):
        contour.appendPoint(point)
    return contour