gws.lib.svg

Source code: gws.lib.svg

Submodules

Package Contents

gws.lib.svg.fragment_to_element(fragment: list[gws.XmlElement], atts: dict = None) gws.XmlElement

Convert an SVG fragment to an SVG element.

gws.lib.svg.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.

gws.lib.svg.sanitize_element(el: gws.XmlElement) gws.XmlElement | None

Remove unsafe stuff from an SVG element.

gws.lib.svg.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”).

gws.lib.svg.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)