:tocdepth: 3 :py:mod:`gws.lib.svg` ===================== .. py:module:: gws.lib.svg **Source code:** :source:`gws.lib.svg` Submodules ---------- .. toctree:: :titlesonly: :maxdepth: 1 draw/index.rst element/index.rst Package Contents ---------------- .. py:function:: fragment_to_element(fragment: list[gws.XmlElement], atts: dict = None) -> gws.XmlElement Convert an SVG fragment to an SVG element. .. py:function:: fragment_to_image(fragment: list[gws.XmlElement], size: gws.Size, mime=gws.lib.mime.PNG) -> gws.lib.image.Image Convert an SVG fragment to a raster image. .. py:function:: sanitize_element(el: gws.XmlElement) -> Optional[gws.XmlElement] Remove unsafe stuff from an SVG element. .. py:function:: shape_to_fragment(shape: gws.Shape, view: gws.MapView, label: str = None, style: gws.Style = None) -> list[gws.XmlElement] Convert a shape to a list of XmlElements (a "fragment"). .. py:function:: soup_to_fragment(view: gws.MapView, points: list[gws.Point], tags: list) -> list[gws.XmlElement] Convert an svg "soup" to a list of XmlElements (a "fragment"). A soup has two components: - a list of points, in the map coordinate system - a list of tuples suitable for `xmlx.tag` input (tag-name, {atts}, child1, child2....) The idea is to represent client-side svg drawings (e.g. dimensions) in a resolution-independent way First, points are converted to pixels using the view's transform. Then, each tag's attributes are iterated. If any attribute value is an array, it's assumed to be a 'function'. The first element is a function name, the rest are arguments. Attribute 'functions' are - ['x', n] - returns points[n][0] - ['y', n] - returns points[n][1] - ['r', p1, p2, r] - computes a slope between points[p1] points[p2] and returns a string `rotate(slope, points[r].x, points[r].y)`