svg_path_editor.path_operations#
Functions#
|
Reverse the drawing direction of a path or sub-path. |
Optimize the relative/absolute representation of a path. |
|
|
Optimize the representation of an SVG path. |
Module Contents#
- svg_path_editor.path_operations.reverse_path(svg, subpath_of_item=None)[source]#
Reverse the drawing direction of a path or sub-path.
- Parameters:
svg (SvgPath) – Input path.
subpath_of_item (int | None) – Index of an item within the sub-path to reverse, or
Noneto reverse the entire path.
- Returns:
A new path with the selected segment reversed. Geometry is preserved, but command types and relative/absolute representation may change.
- Return type:
- svg_path_editor.path_operations.optimize_relative_absolute(svg)[source]#
Optimize the relative/absolute representation of a path.
Each command is toggled between relative and absolute form, and the representation that yields a shorter minified path string is kept.
- svg_path_editor.path_operations.optimize_path(svg, *, remove_useless_commands=False, remove_orphan_dots=False, use_shorthands=False, use_horizontal_and_vertical_lines=False, use_relative_absolute=False, use_reverse=False, use_close_path=False)[source]#
Optimize the representation of an SVG path.
The function can apply several optional passes that can be enabled using the parameters.
- Parameters:
svg (SvgPath) – Input path.
remove_useless_commands (bool) – Remove redundant
M/Zcommands and degenerateL/H/Vsegments.remove_orphan_dots (bool) – Remove empty closed subpaths (
Mimmediately followed byZ).use_shorthands (bool) – Convert eligible
C/Qsegments toS/Twhere possible.use_horizontal_and_vertical_lines (bool) – Replace
LwithHorVwhere possible.use_relative_absolute (bool) – Choose between relative and absolute commands per segment to minimize size.
use_reverse (bool) – Reverse the path direction if that yields a shorter minified representation. This can affect stroked paths.
use_close_path (bool) – Convert final line segments that return to start into
Z. This can affect stroked paths.
- Returns:
A new, possibly shorter, but geometrically equivalent path.
- Return type: