コード例 #1
0
def writeGlyphPath(glyph, get_d=False):
    #
    path_d = ''
    svgGlyphAttrib = {}
    #
    if glyph.box:
        t_x = glyph.box[3]
        t_y = glyph.box[2]
    else:
        t_x = 0
        t_y = 0
    #
    if get_d:
        #
        pen = SVGPathPen(glyph)
        glyph.draw(pen)
        pathCommands = pen.getCommands()
        #
        path = pt_parse_path(pathCommands)
        #
        rev_path = path.d()
        #
        return rev_path
        #
    else:
        #
        path_d = _writeD(glyph, svgGlyphAttrib, t_x, t_y)
        #
        svgGlyph = ET.Element("path", attrib=svgGlyphAttrib)
        #
        return svgGlyph
コード例 #2
0
def _writeD(glyph, attrib, _x, _y):

	pen = SVGPathPen(glyph)
	glyph.draw(pen)
	pathCommands = pen.getCommands()
	#
	if pathCommands:
		#
		path = pt_parse_path(pathCommands)
		#
		rev_path = path.d()
		#
		flip_path = formatPath(flipPath(parsePath(rev_path), horizontal=True, vertical=False))
		#
		attrib["d"] = flip_path
		#
	else:
		#
		attrib["d"] = "Z"
		#
	return flip_path
コード例 #3
0
ファイル: glyphs.py プロジェクト: musca1997/ufo2svg
def _writeD(glyph, attrib):
    """
    >>> from defcon import Glyph
    >>> attrib = {}
    >>> glyph = Glyph()
    >>> _writeD(glyph, attrib)
    >>> attrib
    {}
    >>> pen = glyph.getPen()
    >>> pen.moveTo((-10, -10))
    >>> pen.lineTo((-10, 10))
    >>> pen.lineTo((10, 10))
    >>> pen.lineTo((10, -10))
    >>> pen.closePath()
    >>> _writeD(glyph, attrib)
    >>> attrib
    {'d': 'M-10 -10V10H10V-10Z'}
    """
    pen = SVGPathPen(glyph.getParent())
    glyph.draw(pen)
    pathCommands = pen.getCommands()
    if pathCommands:
        attrib["d"] = pathCommands