inkex.paths module

functions for digesting paths into a simple list structure

class inkex.paths.Arc(rx, ry, x_axis_rotation, large_arc, sweep, x, y)[source]

Bases: inkex.paths.AbsolutePathCommand

Special Arc segment

property args

Returns path command arguments as tuple of floats

control_points(first: inkex.transforms.Vector2d, prev: inkex.transforms.Vector2d, prev_prev: inkex.transforms.Vector2d) Generator[inkex.transforms.Vector2d, None, None][source]

Returns list of path command control points

end_point(first: inkex.transforms.Vector2d, prev: inkex.transforms.Vector2d) inkex.transforms.Vector2d[source]

Returns last control point of path command

nargs = 7
reverse(first, prev)[source]
to_curves(prev: inkex.transforms.Vector2d, prev_prev: inkex.transforms.Vector2d = Vector2d(0, 0)) List[inkex.paths.Curve][source]

Convert this arc into bezier curves

to_relative(prev: inkex.transforms.Vector2d) inkex.paths.arc[source]

Return absolute counterpart for absolute commands or copy for relative

transform(transform: inkex.transforms.Transform) inkex.paths.Arc[source]

Returns new transformed segment

Parameters

transform – a transformation to apply

update_bounding_box(first, last_two_points, bbox)[source]

Enlarges given bbox to contain path element.

Parameters
  • first ((tuple of float)) – first point of path. Required to calculate Z segment

  • last_two_points ((list of tuple)) – list with last two control points in abs coords.

  • bbox ((BoundingBox)) – bounding box to update

class inkex.paths.CubicSuperPath(items)[source]

Bases: list

A conversion of a path into a predictable list of cubic curves which can be operated on as a list of simplified instructions.

When converting back into a path, all lines, arcs etc will be converted to curve instructions.

Structure is held as [SubPath[(point_a, bezier, point_b), …]], …]

_clean(lst)[source]

Recursively clean lists so they have the same type

property _first
append(item, force_shift=False)[source]

Accept multiple different formats for the data

static collinear(a, b, c)[source]

Checks if points a, b, c lie on the same line

static is_line(previous, segment)[source]

Check whether csp segment (two points) has retracted handles or the handles can be retracted without loss of information (i.e. both handles lie on the line)

static is_on(a, b, c)[source]

Checks if point a is on the line between points b and c

to_path(curves_only=False)[source]

Convert the super path back to an svg path

to_segments(curves_only=False)[source]

Generate a set of segments for this cubic super path

transform(transform)[source]

Apply a transformation matrix to this super path

static within(b, a, c)[source]

Checks if float b is between a and c

class inkex.paths.Curve(x2, y2, x3, y3, x4, y4)[source]

Bases: inkex.paths.AbsolutePathCommand

Absolute Curved Line segment

property args

Returns path command arguments as tuple of floats

control_points(first: inkex.transforms.Vector2d, prev: inkex.transforms.Vector2d, prev_prev: inkex.transforms.Vector2d) Generator[inkex.transforms.Vector2d, None, None][source]

Returns list of path command control points

end_point(first, prev)[source]

Returns last control point of path command

nargs = 6
reverse(first, prev)[source]
to_bez()[source]

Returns the list of coords for SuperPath

to_curve(prev: inkex.transforms.Vector2d, prev_prev: Optional[inkex.transforms.Vector2d] = Vector2d(0, 0)) inkex.paths.Curve[source]

No conversion needed, pass-through, returns self

to_relative(prev: inkex.transforms.Vector2d) inkex.paths.curve[source]

Return absolute counterpart for absolute commands or copy for relative

transform(transform: inkex.transforms.Transform) inkex.paths.Curve[source]

Returns new transformed segment

Parameters

transform – a transformation to apply

update_bounding_box(first, last_two_points, bbox)[source]

Enlarges given bbox to contain path element.

Parameters
  • first ((tuple of float)) – first point of path. Required to calculate Z segment

  • last_two_points ((list of tuple)) – list with last two control points in abs coords.

  • bbox ((BoundingBox)) – bounding box to update

class inkex.paths.Horz(x)[source]

Bases: inkex.paths.AbsolutePathCommand

Horizontal Line segment

property args

Returns path command arguments as tuple of floats

control_points(first: inkex.transforms.Vector2d, prev: inkex.transforms.Vector2d, prev_prev: inkex.transforms.Vector2d) Generator[inkex.transforms.Vector2d, None, None][source]

Returns list of path command control points

end_point(first: inkex.transforms.Vector2d, prev: inkex.transforms.Vector2d) inkex.transforms.Vector2d[source]

Returns last control point of path command

nargs = 1
reverse(first, prev)[source]
to_curve(prev: inkex.transforms.Vector2d, prev_prev: Optional[inkex.transforms.Vector2d] = Vector2d(0, 0)) inkex.paths.Curve[source]

Convert a horizontal line into a curve

to_line(prev: inkex.transforms.Vector2d) inkex.paths.Line[source]

Return this path command as a Line instead

to_non_shorthand(prev: inkex.transforms.Vector2d, prev_control: inkex.transforms.Vector2d) inkex.paths.Line[source]

Return an absolute non-shorthand command

to_relative(prev: inkex.transforms.Vector2d) inkex.paths.horz[source]

Return absolute counterpart for absolute commands or copy for relative

transform(transformation: inkex.paths.Pathlike) inkex.paths.Pathlike[source]

Returns new transformed segment

Parameters

transform – a transformation to apply

update_bounding_box(first, last_two_points, bbox)[source]

Enlarges given bbox to contain path element.

Parameters
  • first ((tuple of float)) – first point of path. Required to calculate Z segment

  • last_two_points ((list of tuple)) – list with last two control points in abs coords.

  • bbox ((BoundingBox)) – bounding box to update

exception inkex.paths.InvalidPath[source]

Bases: ValueError

Raised when given an invalid path string

class inkex.paths.Line(x, y)[source]

Bases: inkex.paths.AbsolutePathCommand

Line segment

property args

Returns path command arguments as tuple of floats

control_points(first: inkex.transforms.Vector2d, prev: inkex.transforms.Vector2d, prev_prev: inkex.transforms.Vector2d) Generator[inkex.transforms.Vector2d, None, None][source]

Returns list of path command control points

end_point(first: inkex.transforms.Vector2d, prev: inkex.transforms.Vector2d) inkex.transforms.Vector2d[source]

Returns last control point of path command

nargs = 2
reverse(first, prev)[source]
to_curve(prev: inkex.transforms.Vector2d, prev_prev: Optional[inkex.transforms.Vector2d] = Vector2d(0, 0)) inkex.paths.Curve[source]

Convert command to Curve Curve().to_curve() returns a copy

to_relative(prev: inkex.transforms.Vector2d) inkex.paths.line[source]

Return absolute counterpart for absolute commands or copy for relative

transform(transform: inkex.paths.Line) inkex.paths.Line[source]

Returns new transformed segment

Parameters

transform – a transformation to apply

update_bounding_box(first, last_two_points, bbox)[source]

Enlarges given bbox to contain path element.

Parameters
  • first ((tuple of float)) – first point of path. Required to calculate Z segment

  • last_two_points ((list of tuple)) – list with last two control points in abs coords.

  • bbox ((BoundingBox)) – bounding box to update

class inkex.paths.Move(x, y)[source]

Bases: inkex.paths.AbsolutePathCommand

Move pen segment without a line

property args

Returns path command arguments as tuple of floats

control_points(first: inkex.transforms.Vector2d, prev: inkex.transforms.Vector2d, prev_prev: inkex.transforms.Vector2d) Generator[inkex.transforms.Vector2d, None, None][source]

Returns list of path command control points

end_point(first: inkex.transforms.Vector2d, prev: inkex.transforms.Vector2d) inkex.transforms.Vector2d[source]

Returns last control point of path command

nargs = 2
next_command

alias of inkex.paths.Line

reverse(first, prev)[source]
to_curve(prev: inkex.transforms.Vector2d, prev_prev: Optional[inkex.transforms.Vector2d] = Vector2d(0, 0)) inkex.paths.Curve[source]

Convert command to Curve Curve().to_curve() returns a copy

to_relative(prev: inkex.transforms.Vector2d) inkex.paths.move[source]

Return absolute counterpart for absolute commands or copy for relative

transform(transform: inkex.transforms.Transform) inkex.paths.Move[source]

Returns new transformed segment

Parameters

transform – a transformation to apply

update_bounding_box(first, last_two_points, bbox)[source]

Enlarges given bbox to contain path element.

Parameters
  • first ((tuple of float)) – first point of path. Required to calculate Z segment

  • last_two_points ((list of tuple)) – list with last two control points in abs coords.

  • bbox ((BoundingBox)) – bounding box to update

class inkex.paths.Path(path_d=None)[source]

Bases: list

A list of segment commands which combine to draw a shape

class PathCommandProxy(command, first_point, previous_end_point, prev2_control_point)[source]

Bases: object

A handy class for Path traverse and coordinate access

Reduces number of arguments in user code compared to bare PathCommand methods

property args
property control_points
property end_point
property is_absolute
property is_relative
property letter
property name
property next_command
reverse()[source]
to_curve()[source]
to_curves()[source]
_to_absolute(shorthand)[source]
Parameters

shorthand ((bool)) – If false, then convert all shorthand commands to non-shorthand.

append(cmd)[source]

Append a command to this path including any chained commands

bounding_box() Optional[inkex.transforms.BoundingBox][source]

Return bounding box of the Path

close()[source]

Attempt to close the last path segment

property control_points
copy()[source]

Make a copy

property end_points
classmethod parse_string(path_d)[source]

Parse a path string and generate segment objects

proxy_iterator()[source]

Yields AugmentedPathIterator

Return type

Iterator[ Path.PathCommandProxy ]

reverse()[source]

Returns a reversed path

rotate(deg, center=None, inplace=False)[source]

Rotate the path around the given point

scale(x, y, inplace=False)[source]

Scale all coords in this path by the given amounts

to_absolute()[source]

Convert this path to use only absolute coordinates

to_arrays()[source]

Returns path in format of parsePath output, returning arrays of absolute command data

Deprecated since version 1.0: This is compatibility function for older API. Should not be used in new code

to_non_shorthand() inkex.paths.Path[source]

Convert this path to use only absolute non-shorthand coordinates

to_relative()[source]

Convert this path to use only relative coordinates

to_superpath()[source]

Convert this path into a cubic super path

transform(transform, inplace=False)[source]

Convert to new path

translate(x, y, inplace=False)[source]

Move all coords in this path by the given amount

class inkex.paths.Quadratic(x2, y2, x3, y3)[source]

Bases: inkex.paths.AbsolutePathCommand

Absolute Quadratic Curved Line segment

property args

Returns path command arguments as tuple of floats

control_points(first: inkex.transforms.Vector2d, prev: inkex.transforms.Vector2d, prev_prev: inkex.transforms.Vector2d) Generator[inkex.transforms.Vector2d, None, None][source]

Returns list of path command control points

end_point(first: inkex.transforms.Vector2d, prev: inkex.transforms.Vector2d) inkex.transforms.Vector2d[source]

Returns last control point of path command

nargs = 4
reverse(first, prev)[source]
to_curve(prev: inkex.transforms.Vector2d, prev_prev: inkex.transforms.Vector2d = Vector2d(0, 0)) inkex.paths.Curve[source]

Attempt to convert a quadratic to a curve

to_relative(prev: inkex.transforms.Vector2d) inkex.paths.quadratic[source]

Return absolute counterpart for absolute commands or copy for relative

transform(transform: inkex.transforms.Transform) inkex.paths.Quadratic[source]

Returns new transformed segment

Parameters

transform – a transformation to apply

update_bounding_box(first, last_two_points, bbox)[source]

Enlarges given bbox to contain path element.

Parameters
  • first ((tuple of float)) – first point of path. Required to calculate Z segment

  • last_two_points ((list of tuple)) – list with last two control points in abs coords.

  • bbox ((BoundingBox)) – bounding box to update

class inkex.paths.Smooth(x3, y3, x4, y4)[source]

Bases: inkex.paths.AbsolutePathCommand

Absolute Smoothed Curved Line segment

property args

Returns path command arguments as tuple of floats

control_points(first: inkex.transforms.Vector2d, prev: inkex.transforms.Vector2d, prev_prev: inkex.transforms.Vector2d) Generator[inkex.transforms.Vector2d, None, None][source]

Returns list of path command control points

end_point(first, prev)[source]

Returns last control point of path command

nargs = 4
reverse(first, prev)[source]
to_curve(prev: inkex.transforms.Vector2d, prev_prev: inkex.transforms.Vector2d = Vector2d(0, 0)) inkex.paths.Curve[source]

Convert this Smooth curve to a regular curve by creating a mirror set of nodes based on the previous node. Previous should be a curve.

to_non_shorthand(prev: inkex.transforms.Vector2d, prev_control: inkex.transforms.Vector2d) inkex.paths.Curve[source]

Return an absolute non-shorthand command

to_relative(prev: inkex.transforms.Vector2d) inkex.paths.smooth[source]

Return absolute counterpart for absolute commands or copy for relative

transform(transform: inkex.transforms.Transform) inkex.paths.Smooth[source]

Returns new transformed segment

Parameters

transform – a transformation to apply

update_bounding_box(first, last_two_points, bbox)[source]

Enlarges given bbox to contain path element.

Parameters
  • first ((tuple of float)) – first point of path. Required to calculate Z segment

  • last_two_points ((list of tuple)) – list with last two control points in abs coords.

  • bbox ((BoundingBox)) – bounding box to update

class inkex.paths.TepidQuadratic(x3, y3)[source]

Bases: inkex.paths.AbsolutePathCommand

Continued Quadratic Line segment

property args

Returns path command arguments as tuple of floats

control_points(first: inkex.transforms.Vector2d, prev: inkex.transforms.Vector2d, prev_prev: inkex.transforms.Vector2d) Generator[inkex.transforms.Vector2d, None, None][source]

Returns list of path command control points

end_point(first: inkex.transforms.Vector2d, prev: inkex.transforms.Vector2d) inkex.transforms.Vector2d[source]

Returns last control point of path command

nargs = 2
reverse(first, prev)[source]
to_curve(prev: inkex.transforms.Vector2d, prev_prev: inkex.transforms.Vector2d = Vector2d(0, 0)) inkex.paths.Curve[source]

Convert command to Curve Curve().to_curve() returns a copy

to_non_shorthand(prev: inkex.transforms.Vector2d, prev_control: inkex.transforms.Vector2d) inkex.paths.AbsolutePathCommand[source]

Return an absolute non-shorthand command

to_quadratic(prev: inkex.transforms.Vector2d, prev_prev: inkex.transforms.Vector2d) inkex.paths.Quadratic[source]

Convert this continued quadratic into a full quadratic

to_relative(prev: inkex.transforms.Vector2d) inkex.paths.tepidQuadratic[source]

Return absolute counterpart for absolute commands or copy for relative

transform(transform: inkex.transforms.Transform) inkex.paths.TepidQuadratic[source]

Returns new transformed segment

Parameters

transform – a transformation to apply

update_bounding_box(first, last_two_points, bbox)[source]

Enlarges given bbox to contain path element.

Parameters
  • first ((tuple of float)) – first point of path. Required to calculate Z segment

  • last_two_points ((list of tuple)) – list with last two control points in abs coords.

  • bbox ((BoundingBox)) – bounding box to update

class inkex.paths.Vert(y)[source]

Bases: inkex.paths.AbsolutePathCommand

Vertical Line segment

property args

Returns path command arguments as tuple of floats

control_points(first: inkex.transforms.Vector2d, prev: inkex.transforms.Vector2d, prev_prev: inkex.transforms.Vector2d) Generator[inkex.transforms.Vector2d, None, None][source]

Returns list of path command control points

end_point(first: inkex.transforms.Vector2d, prev: inkex.transforms.Vector2d) inkex.transforms.Vector2d[source]

Returns last control point of path command

nargs = 1
reverse(first, prev)[source]
to_curve(prev: inkex.transforms.Vector2d, prev_prev: Optional[inkex.transforms.Vector2d] = Vector2d(0, 0)) inkex.paths.Curve[source]

Convert a horizontal line into a curve

to_line(prev: inkex.transforms.Vector2d) inkex.paths.Line[source]

Return this path command as a line instead

to_non_shorthand(prev: inkex.transforms.Vector2d, prev_control: inkex.transforms.Vector2d) inkex.paths.Line[source]

Return an absolute non-shorthand command

to_relative(prev: inkex.transforms.Vector2d) inkex.paths.vert[source]

Return absolute counterpart for absolute commands or copy for relative

transform(transform: inkex.paths.Pathlike) inkex.paths.Pathlike[source]

Returns new transformed segment

Parameters

transform – a transformation to apply

update_bounding_box(first, last_two_points, bbox)[source]

Enlarges given bbox to contain path element.

Parameters
  • first ((tuple of float)) – first point of path. Required to calculate Z segment

  • last_two_points ((list of tuple)) – list with last two control points in abs coords.

  • bbox ((BoundingBox)) – bounding box to update

class inkex.paths.ZoneClose[source]

Bases: inkex.paths.AbsolutePathCommand

Close segment to finish a path

property args

Returns path command arguments as tuple of floats

control_points(first: inkex.transforms.Vector2d, prev: inkex.transforms.Vector2d, prev_prev: inkex.transforms.Vector2d) Generator[inkex.transforms.Vector2d, None, None][source]

Returns list of path command control points

end_point(first: inkex.transforms.Vector2d, prev: inkex.transforms.Vector2d) inkex.transforms.Vector2d[source]

Returns last control point of path command

nargs = 0
next_command

alias of inkex.paths.Move

reverse(first, prev)[source]
to_curve(prev: inkex.transforms.Vector2d, prev_prev: Optional[inkex.transforms.Vector2d] = Vector2d(0, 0)) inkex.paths.Curve[source]

Convert command to Curve Curve().to_curve() returns a copy

to_relative(prev: inkex.transforms.Vector2d) inkex.paths.zoneClose[source]

Return absolute counterpart for absolute commands or copy for relative

transform(transform: inkex.transforms.Transform) inkex.paths.ZoneClose[source]

Returns new transformed segment

Parameters

transform – a transformation to apply

update_bounding_box(first, last_two_points, bbox)[source]

Enlarges given bbox to contain path element.

Parameters
  • first ((tuple of float)) – first point of path. Required to calculate Z segment

  • last_two_points ((list of tuple)) – list with last two control points in abs coords.

  • bbox ((BoundingBox)) – bounding box to update

class inkex.paths.arc(rx, ry, x_axis_rotation, large_arc, sweep, dx, dy)[source]

Bases: inkex.paths.RelativePathCommand

Relative Arc line segment

property args

Returns path command arguments as tuple of floats

nargs = 7
reverse(first, prev)[source]
to_absolute(prev: inkex.transforms.Vector2d) inkex.paths.Arc[source]

Return relative counterpart for relative commands or copy for absolute

class inkex.paths.curve(dx2, dy2, dx3, dy3, dx4, dy4)[source]

Bases: inkex.paths.RelativePathCommand

Relative curved line segment

property args

Returns path command arguments as tuple of floats

nargs = 6
reverse(first, prev)[source]
to_absolute(prev: inkex.transforms.Vector2d) inkex.paths.Curve[source]

Return relative counterpart for relative commands or copy for absolute

class inkex.paths.horz(dx)[source]

Bases: inkex.paths.RelativePathCommand

Relative horz line segment

property args

Returns path command arguments as tuple of floats

nargs = 1
reverse(first, prev)[source]
to_absolute(prev: inkex.transforms.Vector2d) inkex.paths.Horz[source]

Return relative counterpart for relative commands or copy for absolute

to_line(prev: inkex.transforms.Vector2d) inkex.paths.Line[source]

Return this path command as a Line instead

to_non_shorthand(prev: inkex.transforms.Vector2d, prev_control: inkex.transforms.Vector2d) inkex.paths.Line[source]

Return an absolute non-shorthand command

class inkex.paths.line(dx, dy)[source]

Bases: inkex.paths.RelativePathCommand

Relative line segment

property args

Returns path command arguments as tuple of floats

nargs = 2
reverse(first, prev)[source]
to_absolute(prev: inkex.transforms.Vector2d) inkex.paths.Line[source]

Return relative counterpart for relative commands or copy for absolute

class inkex.paths.move(dx, dy)[source]

Bases: inkex.paths.RelativePathCommand

Relative move segment

property args

Returns path command arguments as tuple of floats

nargs = 2
next_command

alias of inkex.paths.line

reverse(first, prev)[source]
to_absolute(prev: inkex.transforms.Vector2d) inkex.paths.Move[source]

Return relative counterpart for relative commands or copy for absolute

class inkex.paths.quadratic(dx2, dy2, dx3, dy3)[source]

Bases: inkex.paths.RelativePathCommand

Relative quadratic line segment

property args

Returns path command arguments as tuple of floats

nargs = 4
reverse(first, prev)[source]
to_absolute(prev: inkex.transforms.Vector2d) inkex.paths.Quadratic[source]

Return relative counterpart for relative commands or copy for absolute

class inkex.paths.smooth(dx3, dy3, dx4, dy4)[source]

Bases: inkex.paths.RelativePathCommand

Relative smoothed curved line segment

property args

Returns path command arguments as tuple of floats

nargs = 4
reverse(first, prev)[source]
to_absolute(prev: inkex.transforms.Vector2d) inkex.paths.Smooth[source]

Return relative counterpart for relative commands or copy for absolute

to_non_shorthand(prev: inkex.transforms.Vector2d, prev_control: inkex.transforms.Vector2d) inkex.paths.Curve[source]

Return an absolute non-shorthand command

class inkex.paths.tepidQuadratic(dx3, dy3)[source]

Bases: inkex.paths.RelativePathCommand

Relative continued quadratic line segment

property args

Returns path command arguments as tuple of floats

nargs = 2
reverse(first, prev)[source]
to_absolute(prev: inkex.transforms.Vector2d) inkex.paths.TepidQuadratic[source]

Return relative counterpart for relative commands or copy for absolute

to_non_shorthand(prev: inkex.transforms.Vector2d, prev_control: inkex.transforms.Vector2d) inkex.paths.AbsolutePathCommand[source]

Return an absolute non-shorthand command

class inkex.paths.vert(dy)[source]

Bases: inkex.paths.RelativePathCommand

Relative vertical line segment

property args

Returns path command arguments as tuple of floats

nargs = 1
reverse(first, prev)[source]
to_absolute(prev: inkex.transforms.Vector2d) inkex.paths.Vert[source]

Return relative counterpart for relative commands or copy for absolute

to_line(prev: inkex.transforms.Vector2d) inkex.paths.Line[source]

Return this path command as a line instead

to_non_shorthand(prev: inkex.transforms.Vector2d, prev_control: inkex.transforms.Vector2d) inkex.paths.Line[source]

Return an absolute non-shorthand command

class inkex.paths.zoneClose[source]

Bases: inkex.paths.RelativePathCommand

Same as above (svg says no difference)

property args

Returns path command arguments as tuple of floats

nargs = 0
next_command

alias of inkex.paths.Move

reverse(first, prev)[source]
to_absolute(prev)[source]

Return relative counterpart for relative commands or copy for absolute