svg_path_editor.path_operations =============================== .. py:module:: svg_path_editor.path_operations Functions --------- .. autoapisummary:: svg_path_editor.path_operations.reverse_path svg_path_editor.path_operations.optimize_relative_absolute svg_path_editor.path_operations.optimize_path Module Contents --------------- .. py:function:: reverse_path(svg, subpath_of_item = None) Reverse the drawing direction of a path or sub-path. :param svg: Input path. :param subpath_of_item: Index of an item within the sub-path to reverse, or ``None`` to 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. .. py:function:: optimize_relative_absolute(svg) 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. :param svg: Input path. :returns: A new path with possibly changed relative/absolute commands. Geometry is preserved; only representation changes. .. py:function:: 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) Optimize the representation of an SVG path. The function can apply several optional passes that can be enabled using the parameters. :param svg: Input path. :param remove_useless_commands: Remove redundant ``M``/``Z`` commands and degenerate ``L``/``H``/``V`` segments. :param remove_orphan_dots: Remove empty closed subpaths (``M`` immediately followed by ``Z``). :param use_shorthands: Convert eligible ``C``/``Q`` segments to ``S``/``T`` where possible. :param use_horizontal_and_vertical_lines: Replace ``L`` with ``H`` or ``V`` where possible. :param use_relative_absolute: Choose between relative and absolute commands per segment to minimize size. :param use_reverse: Reverse the path direction if that yields a shorter minified representation. This can affect stroked paths. :param use_close_path: Convert final line segments that return to start into ``Z``. This can affect stroked paths. :returns: A new, possibly shorter, but geometrically equivalent path.