svg-ultralight 0.31.0__py3-none-any.whl → 0.32.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of svg-ultralight might be problematic. Click here for more details.
- svg_ultralight/import_svg.py +50 -0
- svg_ultralight/layout.py +1 -1
- {svg_ultralight-0.31.0.dist-info → svg_ultralight-0.32.0.dist-info}/METADATA +1 -1
- {svg_ultralight-0.31.0.dist-info → svg_ultralight-0.32.0.dist-info}/RECORD +6 -5
- {svg_ultralight-0.31.0.dist-info → svg_ultralight-0.32.0.dist-info}/WHEEL +0 -0
- {svg_ultralight-0.31.0.dist-info → svg_ultralight-0.32.0.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"""Import an svg file as a BoundElement.
|
|
2
|
+
|
|
3
|
+
:author: Shay Hill
|
|
4
|
+
:created: 2024-05-28
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
from typing import TYPE_CHECKING
|
|
10
|
+
|
|
11
|
+
from lxml import etree
|
|
12
|
+
|
|
13
|
+
from svg_ultralight.bounding_boxes.type_bound_element import BoundElement
|
|
14
|
+
from svg_ultralight.bounding_boxes.type_bounding_box import BoundingBox
|
|
15
|
+
from svg_ultralight.constructors import new_element
|
|
16
|
+
|
|
17
|
+
if TYPE_CHECKING:
|
|
18
|
+
import os
|
|
19
|
+
|
|
20
|
+
from lxml.etree import _Element as EtreeElement # type: ignore
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def _get_bounds_from_viewbox(root: EtreeElement) -> BoundingBox:
|
|
24
|
+
"""Get the BoundingBox from the viewbox attribute of the root element.
|
|
25
|
+
|
|
26
|
+
:param root: The root element of the svg.
|
|
27
|
+
:return: The BoundingBox of the svg.
|
|
28
|
+
"""
|
|
29
|
+
viewbox = root.attrib.get("viewBox")
|
|
30
|
+
if viewbox is None:
|
|
31
|
+
msg = "SVG file has no viewBox attribute. Failed to create BoundingBox."
|
|
32
|
+
raise ValueError(msg)
|
|
33
|
+
x, y, width, height = map(float, viewbox.split())
|
|
34
|
+
return BoundingBox(x, y, width, height)
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def import_svg(svg: str | os.PathLike[str]) -> BoundElement:
|
|
38
|
+
"""Import an svg file as a BoundElement.
|
|
39
|
+
|
|
40
|
+
:param svg: The path to the svg file.
|
|
41
|
+
:return: The BoundElement representation of the svg.
|
|
42
|
+
|
|
43
|
+
The viewbox of the svg is used to create the BoundingBox of the BoundElement.
|
|
44
|
+
"""
|
|
45
|
+
tree = etree.parse(svg)
|
|
46
|
+
root = tree.getroot()
|
|
47
|
+
bbox = _get_bounds_from_viewbox(root)
|
|
48
|
+
root_as_elem = new_element("g")
|
|
49
|
+
root_as_elem.extend(root)
|
|
50
|
+
return BoundElement(root_as_elem, bbox)
|
svg_ultralight/layout.py
CHANGED
|
@@ -99,7 +99,7 @@ def _infer_scale(
|
|
|
99
99
|
* print_h == 0 / viewbox_h > 0
|
|
100
100
|
|
|
101
101
|
The print area is invalid, but there is special handling for this. Interpret
|
|
102
|
-
viewbox units as print_w.native_unit and
|
|
102
|
+
viewbox units as print_w.native_unit and determine print area from viewbox area 1
|
|
103
103
|
to 1.
|
|
104
104
|
|
|
105
105
|
>>> _infer_scale(Measurement("in"), Measurement("in"), 1, 2)
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
svg_ultralight/__init__.py,sha256=iuI06A3lFqv0L7EoUfaKqYDg-z0HUlxPATBavtOmexs,2181
|
|
2
2
|
svg_ultralight/animate.py,sha256=fE-zRU_uFrZIL9W78fcGz7qmrts8fz5UoWEy7b4xb44,1144
|
|
3
|
+
svg_ultralight/import_svg.py,sha256=TVLbinch2g0RN-OlWyGXoQEO6vc2I_LsMXpOchwTJzE,1548
|
|
3
4
|
svg_ultralight/inkscape.py,sha256=M8yTxXOu4NlXnhsMycvEJiIDpnDeiZ_bZakJBM38ZoU,9152
|
|
4
|
-
svg_ultralight/layout.py,sha256=
|
|
5
|
+
svg_ultralight/layout.py,sha256=RBFJl6cIN6BYqXea5powEl2A4ZIxUJ0mtVoURkSZy_E,12240
|
|
5
6
|
svg_ultralight/main.py,sha256=6oNkZfD27UMdP-oYqp5agS_IGcYb8NkUZwM9Zdyb3SA,7287
|
|
6
7
|
svg_ultralight/metadata.py,sha256=Mxgxrxe1Ar4kp2wTT29aadxgHNFaaNLABo29jStiWDg,4201
|
|
7
8
|
svg_ultralight/nsmap.py,sha256=y63upO78Rr-JJT56RWWZuyrsILh6HPoY4GhbYnK1A0g,1244
|
|
@@ -22,7 +23,7 @@ svg_ultralight/constructors/__init__.py,sha256=YcnO0iBQc19aL8Iemw0Y452MBMBIT2AN5
|
|
|
22
23
|
svg_ultralight/constructors/new_element.py,sha256=VtMz9sPn9rMk6rui5Poysy3vezlOaS-tGIcGbu-SXmY,3406
|
|
23
24
|
svg_ultralight/strings/__init__.py,sha256=Zalrf-ThFz7b7xKELx5lb2gOlBgV-6jk_k_EeSdVCVk,295
|
|
24
25
|
svg_ultralight/strings/svg_strings.py,sha256=RYKMxOHq9abbZyGcFqsElBGLrBX-EjjNxln3s_ibi30,1296
|
|
25
|
-
svg_ultralight-0.
|
|
26
|
-
svg_ultralight-0.
|
|
27
|
-
svg_ultralight-0.
|
|
28
|
-
svg_ultralight-0.
|
|
26
|
+
svg_ultralight-0.32.0.dist-info/METADATA,sha256=9WclLO21GeJDItp9VbWfeYHgzJ60q-w0-aEjjmnPf6A,8871
|
|
27
|
+
svg_ultralight-0.32.0.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
|
|
28
|
+
svg_ultralight-0.32.0.dist-info/top_level.txt,sha256=se-6yqM_0Yg5orJKvKWdjQZ4iR4G_EjhL7oRgju-fdY,15
|
|
29
|
+
svg_ultralight-0.32.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|