Exemplo n.º 1
0
 def test_appendAnchor(self):
     glyph = Glyph()
     glyph.dirty = False
     anchor = Anchor()
     glyph.appendAnchor(anchor)
     self.assertEqual(len(glyph.anchors), 1)
     self.assertTrue(glyph.dirty)
     self.assertEqual(anchor.getParent(), glyph)
Exemplo n.º 2
0
 def test_appendAnchor(self):
     glyph = Glyph()
     glyph.dirty = False
     anchor = Anchor()
     glyph.appendAnchor(anchor)
     self.assertEqual(len(glyph.anchors), 1)
     self.assertTrue(glyph.dirty)
     self.assertEqual(anchor.getParent(), glyph)
Exemplo n.º 3
0
def getGlyphFromDict(glyph_dict):
    g = Glyph()
    
    # Set attributes
    
    g.height = glyph_dict.get('height', 0)
    g.lib = glyph_dict.get('lib', {})
    g.name = glyph_dict.get('name', '')
    g.note = glyph_dict.get('note', None)
    g.unicode = glyph_dict.get('unicode', None)
    g.unicodes = glyph_dict.get('unicodes', [])
    g.width = glyph_dict.get('width', 0)
    
    # Draw the outlines with a pen
    pen = g.getPointPen()
    
    for contour in glyph_dict.get('contours', []):
        pen.beginPath()
        for point in contour:
            pen.addPoint(
                (
                    point.get('x'),
                    point.get('y')
                ),
                segmentType = point.get('type', None),
                name = point.get('name', None),
                smooth = point.get('smooth', None),
            )
        pen.endPath()
    
    # Add components
    
    for component in glyph_dict.get('components', []):
        c = Component()
        c.baseGlyph = component.get('ref', '')
        c.transformation = component.get('transformation', (1, 0, 0, 1, 0, 0))
        g.appendComponent(c)
    
    # Add anchors
    
    for anchor in glyph_dict.get('anchors', []):
        a = Anchor(anchorDict = anchor)
        g.appendAnchor(a)
    
    # Return the completed glyph object
    
    return g