Skip to main content

Python bindings to Inkscape\'s livarot library

Project description

Python 3 bindings to the inkscape libraries lib2geom and livarot.

Installation

manylinux whls have been published to pypi, there's likely a whl for your distro/python version at:

pip install pylivarot

On windows,

python3 setup.py bdist_wheel

should work in theory, but I currently have not gotten this working (boost is not configured right)

Usage

Declaring Path Vectors:

from pylivarot import py2geom

# using a path builder
_path_builder = py2geom.PathBuilder()
_path_builder.moveTo(py2geom.Point(0, 0))
_path_builder.lineTo(py2geom.Point(10, 20))
_path_builder.quadTo(py2geom.Point(10, 20), py2geom.Point(20, 50))
_path_builder.curveTo(py2geom.Point(10, 20), py2geom.Point(20, 50), py2geom.Point(40, 80))        
_path_builder.flush()
result = _path_builder.peek()

# using an SVG d string
diagonal_line = "M 0,0 L 3,3 z"
pv_diagonal_line = py2geom.parse_svg_path(diagonal_line) 

Format an SVG d string:

from pylivarot import py2geom

pv = py2geom.PathVector()
target_d = py2geom.write_svg_path(pv)

Apply a transform:

from pylivarot import py2geom

path_d =  "M 0,0 L 0,2 L 2,2 L 2,0 z"
pv_path = py2geom.parse_svg_path(path_d)
_affine = py2geom.Affine()
_affine *= py2geom.Translate(py2geom.Point(2, 4))
_affine *= py2geom.Rotate(3.14159/4.0) 
for _path in pv_path:
    for _curve in _path:
        _curve.transform(_affine)

Boolean operations

from pylivarot import py2geom, union, intersection, difference

path_v_a = py2geom.parse_svg_path("M 0,0 L 0,2 L 2,2 L 2,0 z")
path_v_b = py2geom.parse_svg_path("M 0.5,0.5 L 0.5,1.5 L 1.5,1.5 L 1.5,0.5 z")

union_pv = union(path_v_a, path_v_b)
inters_pv = intersection(path_v_a, path_v_b)
diff_pv = difference(path_v_a, path_v_b)

Path Vector Bounding box (also works on Paths)

from pylivarot import py2geom

opt_bbox = path_vector.boundsExact() # or pv.boundsFast()
bbox = py2geom.Rect(opt_bbox[py2geom.Dim2.X], opt_bbox[py2geom.Dim2.Y])
print(bbox.left(), bbox.right(), bbox.top(), bbox.bottom(), bbox.width(), bbox.height())

Inkscape's get_outline and get_outline_offset functionality

from pylivarot import py2geom, get_outline, get_outline_offset

outline = get_outline(path_vector)
outline_offset = get_outline_offset(path_vector, stroke_width)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

pylivarot-1.0.1-cp310-cp310-manylinux_2_24_x86_64.whl (2.8 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.24+ x86-64

pylivarot-1.0.1-cp39-cp39-manylinux_2_24_x86_64.whl (2.8 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.24+ x86-64

pylivarot-1.0.1-cp38-cp38-manylinux_2_24_x86_64.whl (2.8 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.24+ x86-64

pylivarot-1.0.1-cp37-cp37m-manylinux_2_24_x86_64.whl (2.8 MB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.24+ x86-64

pylivarot-1.0.1-cp36-cp36m-manylinux_2_24_x86_64.whl (2.8 MB view hashes)

Uploaded CPython 3.6m manylinux: glibc 2.24+ x86-64

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page