svg-ultralight 0.33.0__py3-none-any.whl → 0.34.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/__init__.py +8 -0
- svg_ultralight/bounding_boxes/bound_helpers.py +74 -0
- svg_ultralight/layout.py +4 -1
- {svg_ultralight-0.33.0.dist-info → svg_ultralight-0.34.0.dist-info}/METADATA +1 -1
- {svg_ultralight-0.33.0.dist-info → svg_ultralight-0.34.0.dist-info}/RECORD +7 -7
- {svg_ultralight-0.33.0.dist-info → svg_ultralight-0.34.0.dist-info}/WHEEL +0 -0
- {svg_ultralight-0.33.0.dist-info → svg_ultralight-0.34.0.dist-info}/top_level.txt +0 -0
svg_ultralight/__init__.py
CHANGED
|
@@ -8,6 +8,10 @@ from svg_ultralight.bounding_boxes.bound_helpers import (
|
|
|
8
8
|
new_bbox_union,
|
|
9
9
|
new_bound_union,
|
|
10
10
|
new_element_union,
|
|
11
|
+
cut_bbox,
|
|
12
|
+
pad_bbox,
|
|
13
|
+
bbox_dict,
|
|
14
|
+
new_bbox_rect,
|
|
11
15
|
)
|
|
12
16
|
from svg_ultralight.bounding_boxes.supports_bounds import SupportsBounds
|
|
13
17
|
from svg_ultralight.bounding_boxes.type_bound_collection import BoundCollection
|
|
@@ -57,7 +61,9 @@ __all__ = [
|
|
|
57
61
|
"NSMAP",
|
|
58
62
|
"PaddedText",
|
|
59
63
|
"SupportsBounds",
|
|
64
|
+
"bbox_dict",
|
|
60
65
|
"clear_svg_ultralight_cache",
|
|
66
|
+
"cut_bbox",
|
|
61
67
|
"deepcopy_element",
|
|
62
68
|
"format_attr_dict",
|
|
63
69
|
"format_number",
|
|
@@ -68,6 +74,7 @@ __all__ = [
|
|
|
68
74
|
"mat_apply",
|
|
69
75
|
"mat_dot",
|
|
70
76
|
"mat_invert",
|
|
77
|
+
"new_bbox_rect",
|
|
71
78
|
"new_bbox_union",
|
|
72
79
|
"new_bound_union",
|
|
73
80
|
"new_element",
|
|
@@ -77,6 +84,7 @@ __all__ = [
|
|
|
77
84
|
"new_sub_element",
|
|
78
85
|
"new_svg_root",
|
|
79
86
|
"new_svg_root_around_bounds",
|
|
87
|
+
"pad_bbox",
|
|
80
88
|
"pad_text",
|
|
81
89
|
"transform_element",
|
|
82
90
|
"update_element",
|
|
@@ -95,3 +95,77 @@ def new_bound_union(*blems: SupportsBounds | EtreeElement) -> BoundElement:
|
|
|
95
95
|
group = new_element_union(*blems)
|
|
96
96
|
bbox = new_bbox_union(*blems)
|
|
97
97
|
return BoundElement(group, bbox)
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
def _expand_pad(pad: float | tuple[float, ...]) -> tuple[float, float, float, float]:
|
|
101
|
+
"""Expand a float pad argument into a 4-tuple."""
|
|
102
|
+
if isinstance(pad, (int, float)):
|
|
103
|
+
return pad, pad, pad, pad
|
|
104
|
+
if len(pad) == 1:
|
|
105
|
+
return pad[0], pad[0], pad[0], pad[0]
|
|
106
|
+
if len(pad) == 2:
|
|
107
|
+
return pad[0], pad[1], pad[0], pad[1]
|
|
108
|
+
if len(pad) == 3:
|
|
109
|
+
return pad[0], pad[1], pad[2], pad[1]
|
|
110
|
+
return pad[0], pad[1], pad[2], pad[3]
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
def cut_bbox(
|
|
114
|
+
bbox: SupportsBounds,
|
|
115
|
+
*,
|
|
116
|
+
x: float | None = None,
|
|
117
|
+
y: float | None = None,
|
|
118
|
+
x2: float | None = None,
|
|
119
|
+
y2: float | None = None,
|
|
120
|
+
) -> BoundingBox:
|
|
121
|
+
"""Return a new bounding box with updated limits.
|
|
122
|
+
|
|
123
|
+
:param bbox: the original bounding box or bounded element.
|
|
124
|
+
:param x: the new x-coordinate.
|
|
125
|
+
:param y: the new y-coordinate.
|
|
126
|
+
:param x2: the new x2-coordinate.
|
|
127
|
+
:param y2: the new y2-coordinate.
|
|
128
|
+
:return: a new bounding box with the updated limits.
|
|
129
|
+
"""
|
|
130
|
+
x = bbox.x if x is None else x
|
|
131
|
+
y = bbox.y if y is None else y
|
|
132
|
+
x2 = bbox.x2 if x2 is None else x2
|
|
133
|
+
y2 = bbox.y2 if y2 is None else y2
|
|
134
|
+
width = x2 - x
|
|
135
|
+
height = y2 - y
|
|
136
|
+
return BoundingBox(x, y, width, height)
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
def pad_bbox(bbox: SupportsBounds, pad: float | tuple[float, ...]) -> BoundingBox:
|
|
140
|
+
"""Return a new bounding box with padding.
|
|
141
|
+
|
|
142
|
+
:param bbox: the original bounding box or bounded element.
|
|
143
|
+
:param pad: the padding to apply.
|
|
144
|
+
If a single number, the same padding will be applied to all sides.
|
|
145
|
+
If a tuple, will be applied per css rules.
|
|
146
|
+
len = 1 : 0, 0, 0, 0
|
|
147
|
+
len = 2 : 0, 1, 0, 1
|
|
148
|
+
len = 3 : 0, 1, 2, 1
|
|
149
|
+
len = 4 : 0, 1, 2, 3
|
|
150
|
+
:return: a new bounding box with padding applied.
|
|
151
|
+
"""
|
|
152
|
+
t, r, b, l = _expand_pad(pad)
|
|
153
|
+
return cut_bbox(bbox, x=bbox.x - l, y=bbox.y - t, x2=bbox.x2 + r, y2=bbox.y2 + b)
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
def bbox_dict(bbox: SupportsBounds) -> dict[str, float]:
|
|
157
|
+
"""Return a dictionary representation of a bounding box.
|
|
158
|
+
|
|
159
|
+
:param bbox: the bounding box or bound element from which to extract dimensions.
|
|
160
|
+
:return: a dictionary with keys x, y, width, and height.
|
|
161
|
+
"""
|
|
162
|
+
return {"x": bbox.x, "y": bbox.y, "width": bbox.width, "height": bbox.height}
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
def new_bbox_rect(bbox: BoundingBox, **kwargs: float | str) -> EtreeElement:
|
|
166
|
+
"""Return a new rect element with the same dimensions as the bounding box.
|
|
167
|
+
|
|
168
|
+
:param bbox: the bounding box or bound element from which to extract dimensions.
|
|
169
|
+
:param kwargs: additional attributes for the rect element.
|
|
170
|
+
"""
|
|
171
|
+
return new_element("rect", **bbox_dict(bbox), **kwargs)
|
svg_ultralight/layout.py
CHANGED
|
@@ -43,7 +43,10 @@ def expand_pad_arg(pad: PadArg) -> tuple[float, float, float, float]:
|
|
|
43
43
|
return expand_pad_arg([pad])
|
|
44
44
|
as_ms = [m if isinstance(m, Measurement) else Measurement(m) for m in pad]
|
|
45
45
|
as_units = [m.value for m in as_ms]
|
|
46
|
-
|
|
46
|
+
if len(as_units) == 3:
|
|
47
|
+
as_units = [*as_units, as_units[1]]
|
|
48
|
+
else:
|
|
49
|
+
as_units = [as_units[i % len(as_units)] for i in range(4)]
|
|
47
50
|
return as_units[0], as_units[1], as_units[2], as_units[3]
|
|
48
51
|
|
|
49
52
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
svg_ultralight/__init__.py,sha256=
|
|
1
|
+
svg_ultralight/__init__.py,sha256=jqT_dNNvrSJ3SUndR3e323BbdNlZIEu_iIzmr0iwWNw,2500
|
|
2
2
|
svg_ultralight/animate.py,sha256=JSrBm-59BcNXDF0cGgl4-C89eBunjevZnwZxIWt48TU,1112
|
|
3
3
|
svg_ultralight/inkscape.py,sha256=M8yTxXOu4NlXnhsMycvEJiIDpnDeiZ_bZakJBM38ZoU,9152
|
|
4
|
-
svg_ultralight/layout.py,sha256=
|
|
4
|
+
svg_ultralight/layout.py,sha256=FgR45FsHax4xDjGkk9HEVW4OcwhtM8aqw2JUdZs_m7Q,12326
|
|
5
5
|
svg_ultralight/main.py,sha256=6oNkZfD27UMdP-oYqp5agS_IGcYb8NkUZwM9Zdyb3SA,7287
|
|
6
6
|
svg_ultralight/metadata.py,sha256=xR3ObM0QV7OQ90IKvfigR5B6e0JW6GGVGvTlL5NswWI,4211
|
|
7
7
|
svg_ultralight/nsmap.py,sha256=y63upO78Rr-JJT56RWWZuyrsILh6HPoY4GhbYnK1A0g,1244
|
|
@@ -12,7 +12,7 @@ svg_ultralight/string_conversion.py,sha256=WEmpf75RJmJ2lfJluagAz2wPsz6wM8XvTEwkq
|
|
|
12
12
|
svg_ultralight/transformations.py,sha256=7-6NNh6xZ45mM_933fMuQfRGpI7q9Qrt5qse9e6FUek,4036
|
|
13
13
|
svg_ultralight/unit_conversion.py,sha256=g07nhzXdjPvGcJmkhLdFbeDLrSmbI8uFoVgPo7G62Bg,9258
|
|
14
14
|
svg_ultralight/bounding_boxes/__init__.py,sha256=qUEn3r4s-1QNHaguhWhhaNfdP4tl_B6YEqxtiTFuzhQ,78
|
|
15
|
-
svg_ultralight/bounding_boxes/bound_helpers.py,sha256=
|
|
15
|
+
svg_ultralight/bounding_boxes/bound_helpers.py,sha256=1l0-Aw3p-9ru7Pm76Wa9K_ufSPRv54NDTG8WsMo_obQ,6125
|
|
16
16
|
svg_ultralight/bounding_boxes/supports_bounds.py,sha256=fbHV6mGdeIVV3lS15vBKSrHiHKR7DMg4K5X__4LLmCE,4569
|
|
17
17
|
svg_ultralight/bounding_boxes/type_bound_collection.py,sha256=b89TM2UsdaeApyjTQeMbx_FG_WcCiLAImEiHiZ6EWPI,2600
|
|
18
18
|
svg_ultralight/bounding_boxes/type_bound_element.py,sha256=9RdxH8osOlAvPdWR0Ww9NsasHLPYFDs-MbydoV48x4E,2239
|
|
@@ -22,7 +22,7 @@ svg_ultralight/constructors/__init__.py,sha256=YcnO0iBQc19aL8Iemw0Y452MBMBIT2AN5
|
|
|
22
22
|
svg_ultralight/constructors/new_element.py,sha256=VtMz9sPn9rMk6rui5Poysy3vezlOaS-tGIcGbu-SXmY,3406
|
|
23
23
|
svg_ultralight/strings/__init__.py,sha256=Zalrf-ThFz7b7xKELx5lb2gOlBgV-6jk_k_EeSdVCVk,295
|
|
24
24
|
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.
|
|
25
|
+
svg_ultralight-0.34.0.dist-info/METADATA,sha256=MUbU1KYDWS-PKOOwFfkVJlvghN33UlKxW1ucx4NU3_E,8867
|
|
26
|
+
svg_ultralight-0.34.0.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
|
|
27
|
+
svg_ultralight-0.34.0.dist-info/top_level.txt,sha256=se-6yqM_0Yg5orJKvKWdjQZ4iR4G_EjhL7oRgju-fdY,15
|
|
28
|
+
svg_ultralight-0.34.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|