コード例 #1
0
def test_addComponent_decompose_with_transform():
    pen = SVGPathPen(glyphSet={"a": DummyGlyph()})
    pen.addComponent("a", Affine2D(2, 0, 0, 2, 0, 0))

    assert pen.path.d == (
        "M0,0 L0,20 L20,20 L20,0 Z "
        "M0,30 C0,40 20,40 20,30 Z "
        "M0,-10 Q0,-16 3,-18 Q6,-20 10,-20 Q14,-20 17,-18 Q20,-16 20,-10")
コード例 #2
0
def test_addComponent_decompose():
    pen = SVGPathPen(glyphSet={"a": DummyGlyph()})
    pen.addComponent("a", Affine2D.identity())

    assert pen.path.d == (
        "M0,0 L0,10 L10,10 L10,0 Z "
        "M0,15 C0,20 10,20 10,15 Z "
        "M0,-5 Q0,-8 1.5,-9 Q3,-10 5,-10 Q7,-10 8.5,-9 Q10,-8 10,-5")
コード例 #3
0
def test_draw_onto_existing_path():
    path = SVGPath(d="M0,0 L0,10 L10,10 L10,0 Z")
    pen = SVGPathPen(path=path)

    pen.moveTo((0, 15))
    pen.lineTo((5, 20))
    pen.lineTo((10, 15))
    pen.closePath()

    assert path.d == "M0,0 L0,10 L10,10 L10,0 Z M0,15 L5,20 L10,15 Z"
コード例 #4
0
ファイル: colr_to_svg.py プロジェクト: yisibl/nanoemoji
def _draw_svg_path(
    svg_path: etree.Element,
    glyph_set: ttLib.ttFont._TTGlyphSet,
    glyph_name: str,
    font_to_vbox: Affine2D,
):
    # use glyph set to resolve references in composite glyphs
    svg_pen = SVGPathPen(glyph_set)
    # wrap svg pen with "filter" pen mapping coordinates from UPEM to SVG space
    transform_pen = transformPen.TransformPen(svg_pen, font_to_vbox)

    glyph = glyph_set[glyph_name]
    glyph.draw(transform_pen)

    svg_path.attrib["d"] = svg_pen.path.d
コード例 #5
0
def _draw_svg_path(
    svg_path: etree.Element,
    view_box: Rect,
    ttfont: ttLib.TTFont,
    glyph_name: str,
    glyph_set: ttLib.ttFont._TTGlyphSet,
):
    # use glyph set to resolve references in composite glyphs
    svg_pen = SVGPathPen(glyph_set)
    # wrap svg pen with "filter" pen mapping coordinates from UPEM to SVG space
    upem_to_vbox = _emsquare_to_viewbox(ttfont["head"].unitsPerEm, view_box)
    transform_pen = transformPen.TransformPen(svg_pen, upem_to_vbox)

    glyph = glyph_set[glyph_name]
    glyph.draw(transform_pen)

    svg_path.attrib["d"] = svg_pen.path.d
コード例 #6
0
def test_roundtrip_path_with_pen(d):
    path = SVGPath(d=d)
    pen = SVGPathPen()
    draw_svg_path(path, pen)
    assert pen.path.d == d
コード例 #7
0
def test_addComponent_missing():
    pen = SVGPathPen(glyphSet={"a": DummyGlyph()})

    with pytest.raises(KeyError):
        pen.addComponent("b", Affine2D.identity())
コード例 #8
0
def test_draw_svg_close_subpaths():
    path = SVGPath(d="M0,0 L0,10 L10,10 L10,0 M12,0 L12,10 L22,10 L22,0")
    pen = SVGPathPen()
    draw_svg_path(path, pen, close_subpaths=True)
    assert pen.path.d == "M0,0 L0,10 L10,10 L10,0 Z M12,0 L12,10 L22,10 L22,0 Z"