Coverage for gws-app/gws/lib/svg/__init__.py: 100%

2 statements  

« prev     ^ index     » next       coverage.py v7.16.2, created at 2026-10-05 13:35 +0200

1"""SVG drawing and sanitizing. 

2 

3This package creates SVG output for vector features, used when rendering maps and prints. 

4The basic unit is a *fragment*: a list of ``gws.XmlElement`` objects that are not yet wrapped 

5in an ``<svg>`` root element. Fragments from several features can be joined and then converted 

6to a single SVG element or a raster image. 

7 

8Submodules: 

9 

10- ``draw``: builds fragments. ``shape_to_fragment`` draws a shape with a ``gws.Style`` 

11 (geometry, markers, icons and labels), transformed to pixels by a ``gws.MapView``. 

12 ``soup_to_fragment`` builds a fragment from a "soup", a resolution-independent description 

13 of client-side drawings (e.g. dimensions). 

14- ``element``: wraps fragments into SVG elements or images (``fragment_to_element``, 

15 ``fragment_to_image``) and removes unsafe content from SVG input (``normalize_element``, 

16 ``normalize_fragment``), keeping only allowed tags and attributes with valid values. 

17 

18Labels are emitted with a ``z-index`` attribute, so that ``fragment_to_element`` can place them above the geometries. 

19 

20Example:: 

21 

22 import gws.lib.svg 

23 

24 frag = [] 

25 for feature in features: 

26 frag.extend(gws.lib.svg.shape_to_fragment(feature.shape(), view, label='A', style=style)) 

27 el = gws.lib.svg.fragment_to_element(frag) 

28 img = gws.lib.svg.fragment_to_image(frag, (800, 600)) 

29""" 

30 

31from .draw import shape_to_fragment, soup_to_fragment 

32from .element import fragment_to_element, fragment_to_image, normalize_element, normalize_fragment