svg-ultralight 0.45.3__tar.gz → 0.45.5__tar.gz
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-0.45.3/src/svg_ultralight.egg-info → svg_ultralight-0.45.5}/PKG-INFO +1 -1
- {svg_ultralight-0.45.3 → svg_ultralight-0.45.5}/pyproject.toml +2 -2
- {svg_ultralight-0.45.3 → svg_ultralight-0.45.5}/src/svg_ultralight/bounding_boxes/type_padded_text.py +36 -0
- {svg_ultralight-0.45.3 → svg_ultralight-0.45.5}/src/svg_ultralight/image_ops.py +6 -3
- {svg_ultralight-0.45.3 → svg_ultralight-0.45.5/src/svg_ultralight.egg-info}/PKG-INFO +1 -1
- svg_ultralight-0.45.5/tests/test_bound_element.py +84 -0
- svg_ultralight-0.45.3/tests/test_bound_element.py +0 -31
- {svg_ultralight-0.45.3 → svg_ultralight-0.45.5}/.gitignore +0 -0
- {svg_ultralight-0.45.3 → svg_ultralight-0.45.5}/.pre-commit-config.yaml +0 -0
- {svg_ultralight-0.45.3 → svg_ultralight-0.45.5}/README.md +0 -0
- {svg_ultralight-0.45.3 → svg_ultralight-0.45.5}/dev-requirements.txt +0 -0
- {svg_ultralight-0.45.3 → svg_ultralight-0.45.5}/experiments/encode_fonts3.txt +0 -0
- {svg_ultralight-0.45.3 → svg_ultralight-0.45.5}/experiments/font_css.py +0 -0
- {svg_ultralight-0.45.3 → svg_ultralight-0.45.5}/setup.cfg +0 -0
- {svg_ultralight-0.45.3 → svg_ultralight-0.45.5}/src/svg_ultralight/__init__.py +0 -0
- {svg_ultralight-0.45.3 → svg_ultralight-0.45.5}/src/svg_ultralight/animate.py +0 -0
- {svg_ultralight-0.45.3 → svg_ultralight-0.45.5}/src/svg_ultralight/attrib_hints.py +0 -0
- {svg_ultralight-0.45.3 → svg_ultralight-0.45.5}/src/svg_ultralight/bounding_boxes/__init__.py +0 -0
- {svg_ultralight-0.45.3 → svg_ultralight-0.45.5}/src/svg_ultralight/bounding_boxes/bound_helpers.py +0 -0
- {svg_ultralight-0.45.3 → svg_ultralight-0.45.5}/src/svg_ultralight/bounding_boxes/padded_text_initializers.py +0 -0
- {svg_ultralight-0.45.3 → svg_ultralight-0.45.5}/src/svg_ultralight/bounding_boxes/supports_bounds.py +0 -0
- {svg_ultralight-0.45.3 → svg_ultralight-0.45.5}/src/svg_ultralight/bounding_boxes/type_bound_collection.py +0 -0
- {svg_ultralight-0.45.3 → svg_ultralight-0.45.5}/src/svg_ultralight/bounding_boxes/type_bound_element.py +0 -0
- {svg_ultralight-0.45.3 → svg_ultralight-0.45.5}/src/svg_ultralight/bounding_boxes/type_bounding_box.py +0 -0
- {svg_ultralight-0.45.3 → svg_ultralight-0.45.5}/src/svg_ultralight/constructors/__init__.py +0 -0
- {svg_ultralight-0.45.3 → svg_ultralight-0.45.5}/src/svg_ultralight/constructors/new_element.py +0 -0
- {svg_ultralight-0.45.3 → svg_ultralight-0.45.5}/src/svg_ultralight/font_tools/__init__.py +0 -0
- {svg_ultralight-0.45.3 → svg_ultralight-0.45.5}/src/svg_ultralight/font_tools/comp_results.py +0 -0
- {svg_ultralight-0.45.3 → svg_ultralight-0.45.5}/src/svg_ultralight/font_tools/font_info.py +0 -0
- {svg_ultralight-0.45.3 → svg_ultralight-0.45.5}/src/svg_ultralight/font_tools/globs.py +0 -0
- {svg_ultralight-0.45.3 → svg_ultralight-0.45.5}/src/svg_ultralight/inkscape.py +0 -0
- {svg_ultralight-0.45.3 → svg_ultralight-0.45.5}/src/svg_ultralight/layout.py +0 -0
- {svg_ultralight-0.45.3 → svg_ultralight-0.45.5}/src/svg_ultralight/main.py +0 -0
- {svg_ultralight-0.45.3 → svg_ultralight-0.45.5}/src/svg_ultralight/metadata.py +0 -0
- {svg_ultralight-0.45.3 → svg_ultralight-0.45.5}/src/svg_ultralight/nsmap.py +0 -0
- {svg_ultralight-0.45.3 → svg_ultralight-0.45.5}/src/svg_ultralight/py.typed +0 -0
- {svg_ultralight-0.45.3 → svg_ultralight-0.45.5}/src/svg_ultralight/query.py +0 -0
- {svg_ultralight-0.45.3 → svg_ultralight-0.45.5}/src/svg_ultralight/root_elements.py +0 -0
- {svg_ultralight-0.45.3 → svg_ultralight-0.45.5}/src/svg_ultralight/string_conversion.py +0 -0
- {svg_ultralight-0.45.3 → svg_ultralight-0.45.5}/src/svg_ultralight/strings/__init__.py +0 -0
- {svg_ultralight-0.45.3 → svg_ultralight-0.45.5}/src/svg_ultralight/strings/svg_strings.py +0 -0
- {svg_ultralight-0.45.3 → svg_ultralight-0.45.5}/src/svg_ultralight/transformations.py +0 -0
- {svg_ultralight-0.45.3 → svg_ultralight-0.45.5}/src/svg_ultralight/unit_conversion.py +0 -0
- {svg_ultralight-0.45.3 → svg_ultralight-0.45.5}/src/svg_ultralight.egg-info/SOURCES.txt +0 -0
- {svg_ultralight-0.45.3 → svg_ultralight-0.45.5}/src/svg_ultralight.egg-info/dependency_links.txt +0 -0
- {svg_ultralight-0.45.3 → svg_ultralight-0.45.5}/src/svg_ultralight.egg-info/requires.txt +0 -0
- {svg_ultralight-0.45.3 → svg_ultralight-0.45.5}/src/svg_ultralight.egg-info/top_level.txt +0 -0
- {svg_ultralight-0.45.3 → svg_ultralight-0.45.5}/tests/__init__.py +0 -0
- {svg_ultralight-0.45.3 → svg_ultralight-0.45.5}/tests/conftest.py +0 -0
- {svg_ultralight-0.45.3 → svg_ultralight-0.45.5}/tests/resources/arrow.svg +0 -0
- {svg_ultralight-0.45.3 → svg_ultralight-0.45.5}/tests/test_bounding.py +0 -0
- {svg_ultralight-0.45.3 → svg_ultralight-0.45.5}/tests/test_inkscape.py +0 -0
- {svg_ultralight-0.45.3 → svg_ultralight-0.45.5}/tests/test_layout.py +0 -0
- {svg_ultralight-0.45.3 → svg_ultralight-0.45.5}/tests/test_matrices.py +0 -0
- {svg_ultralight-0.45.3 → svg_ultralight-0.45.5}/tests/test_metadata.py +0 -0
- {svg_ultralight-0.45.3 → svg_ultralight-0.45.5}/tests/test_new_element.py +0 -0
- {svg_ultralight-0.45.3 → svg_ultralight-0.45.5}/tests/test_padded_text_initializers.py +0 -0
- {svg_ultralight-0.45.3 → svg_ultralight-0.45.5}/tests/test_padding.py +0 -0
- {svg_ultralight-0.45.3 → svg_ultralight-0.45.5}/tests/test_queries.py +0 -0
- {svg_ultralight-0.45.3 → svg_ultralight-0.45.5}/tests/test_root_elements.py +0 -0
- {svg_ultralight-0.45.3 → svg_ultralight-0.45.5}/tests/test_string_conversion.py +0 -0
- {svg_ultralight-0.45.3 → svg_ultralight-0.45.5}/tests/test_svg_ultralight.py +0 -0
- {svg_ultralight-0.45.3 → svg_ultralight-0.45.5}/tox.ini +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "svg-ultralight"
|
|
3
|
-
version = "0.45.
|
|
3
|
+
version = "0.45.5"
|
|
4
4
|
description = "a sensible way to create svg files with Python"
|
|
5
5
|
authors = [{ name = "Shay Hill", email = "shay_public@hotmail.com" }]
|
|
6
6
|
license = { text = "MIT" }
|
|
@@ -53,7 +53,7 @@ convention = "pep257"
|
|
|
53
53
|
|
|
54
54
|
[tool.commitizen]
|
|
55
55
|
name = "cz_conventional_commits"
|
|
56
|
-
version = "0.45.
|
|
56
|
+
version = "0.45.5"
|
|
57
57
|
tag_format = "$version"
|
|
58
58
|
version_files = ["pyproject.toml:^version"]
|
|
59
59
|
annotated_tag = true
|
|
@@ -64,6 +64,7 @@ enough to lay out text on a business card.
|
|
|
64
64
|
|
|
65
65
|
from __future__ import annotations
|
|
66
66
|
|
|
67
|
+
import math
|
|
67
68
|
from typing import TYPE_CHECKING
|
|
68
69
|
|
|
69
70
|
from paragraphs import par
|
|
@@ -223,6 +224,41 @@ class PaddedText(BoundElement):
|
|
|
223
224
|
"""
|
|
224
225
|
self.base_bpad = value / self.unpadded_bbox.scale[1]
|
|
225
226
|
|
|
227
|
+
@property
|
|
228
|
+
def scale(self) -> tuple[float, float]:
|
|
229
|
+
"""Get scale of the bounding box.
|
|
230
|
+
|
|
231
|
+
:return: uniform scale of the bounding box
|
|
232
|
+
|
|
233
|
+
Use caution, the scale attribute can cause errors in intuition. Changing
|
|
234
|
+
width or height will change the scale attribute, but not the x or y values.
|
|
235
|
+
The scale setter, on the other hand, will work in the tradational manner.
|
|
236
|
+
I.e., x => x*scale, y => y*scale, x2 => x*scale, y2 => y*scale, width =>
|
|
237
|
+
width*scale, height => height*scale, scale => scale*scale. This matches how
|
|
238
|
+
scale works in almost every other context.
|
|
239
|
+
"""
|
|
240
|
+
xx, xy, yx, yy, *_ = self.unpadded_bbox.transformation
|
|
241
|
+
return math.sqrt(xx * xx + xy * xy), math.sqrt(yx * yx + yy * yy)
|
|
242
|
+
|
|
243
|
+
@scale.setter
|
|
244
|
+
def scale(self, value: tuple[float, float]) -> None:
|
|
245
|
+
"""Scale the bounding box by a uniform factor.
|
|
246
|
+
|
|
247
|
+
:param value: new scale value
|
|
248
|
+
|
|
249
|
+
Don't miss this! You are setting the scale, not scaling the scale! If you
|
|
250
|
+
have a previously defined scale other than 1, this is probably not what you
|
|
251
|
+
want. Most of the time, you will want to use the *= operator.
|
|
252
|
+
|
|
253
|
+
`scale = 2` -> ignore whatever scale was previously defined and set scale to 2
|
|
254
|
+
`scale *= 2` -> make it twice as big as it was.
|
|
255
|
+
"""
|
|
256
|
+
new_scale = (
|
|
257
|
+
value[0] / self.unpadded_bbox.scale[0],
|
|
258
|
+
value[1] / self.unpadded_bbox.scale[1],
|
|
259
|
+
)
|
|
260
|
+
self.transform(scale=new_scale)
|
|
261
|
+
|
|
226
262
|
@property
|
|
227
263
|
def width(self) -> float:
|
|
228
264
|
"""The width of this line of text with padding.
|
|
@@ -70,7 +70,7 @@ def _symmetric_crop(
|
|
|
70
70
|
|
|
71
71
|
|
|
72
72
|
def _crop_image_to_bbox_ratio(
|
|
73
|
-
image: ImageType, bbox: BoundingBox, center: tuple[float, float] | None
|
|
73
|
+
image: ImageType, bbox: BoundingBox, center: tuple[float, float] | None
|
|
74
74
|
) -> ImageType:
|
|
75
75
|
"""Crop an image to the ratio of a bounding box.
|
|
76
76
|
|
|
@@ -116,8 +116,8 @@ def _get_svg_embedded_image_str(image: ImageType) -> str:
|
|
|
116
116
|
|
|
117
117
|
def new_image_elem_in_bbox(
|
|
118
118
|
filename: str | os.PathLike[str],
|
|
119
|
-
bbox: BoundingBox,
|
|
120
|
-
center: tuple[float, float] | None,
|
|
119
|
+
bbox: BoundingBox | None = None,
|
|
120
|
+
center: tuple[float, float] | None = None,
|
|
121
121
|
) -> EtreeElement:
|
|
122
122
|
"""Create a new svg image element inside a bounding box.
|
|
123
123
|
|
|
@@ -128,6 +128,9 @@ def new_image_elem_in_bbox(
|
|
|
128
128
|
(0.4, 0.5) would crop 20% off the right side of the image.
|
|
129
129
|
:return: an etree image element with the cropped image embedded
|
|
130
130
|
"""
|
|
131
|
+
image = Image.open(filename)
|
|
132
|
+
if bbox is None:
|
|
133
|
+
bbox = BoundingBox(0, 0, image.width, image.height)
|
|
131
134
|
image = _crop_image_to_bbox_ratio(Image.open(filename), bbox, center)
|
|
132
135
|
svg_image = new_element("image", **bbox_dict(bbox))
|
|
133
136
|
svg_image.set(
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"""Test methods for BoundElement instances.
|
|
2
|
+
|
|
3
|
+
:author: Shay Hill
|
|
4
|
+
:created: 2025-07-29
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from svg_ultralight.bounding_boxes.type_bounding_box import BoundingBox
|
|
8
|
+
from svg_ultralight.bounding_boxes.type_padded_text import PaddedText
|
|
9
|
+
from svg_ultralight.bounding_boxes.type_bound_element import BoundElement
|
|
10
|
+
from svg_ultralight.constructors import new_element
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class TestTransforms:
|
|
14
|
+
"""Test methods for BoundElement instances."""
|
|
15
|
+
|
|
16
|
+
def test_matrix(self) -> None:
|
|
17
|
+
"""Test the transform method."""
|
|
18
|
+
bbox = BoundingBox(0, 0, 100, 100)
|
|
19
|
+
bbox.transform(transformation=(1, 2, 3, 4, 5, 6))
|
|
20
|
+
assert bbox.transformation == (1, 2, 3, 4, 5, 6)
|
|
21
|
+
|
|
22
|
+
def test_scale_float(self) -> None:
|
|
23
|
+
"""Test the scale method with a float."""
|
|
24
|
+
bbox = BoundingBox(0, 0, 100, 100)
|
|
25
|
+
bbox.transform(scale=2.0)
|
|
26
|
+
assert bbox.transformation == (2.0, 0.0, 0.0, 2.0, 0.0, 0.0)
|
|
27
|
+
|
|
28
|
+
def test_scale_int(self) -> None:
|
|
29
|
+
"""Test the scale method with an int."""
|
|
30
|
+
bbox = BoundingBox(0, 0, 100, 100)
|
|
31
|
+
bbox.transform(scale=2)
|
|
32
|
+
assert bbox.transformation == (2.0, 0.0, 0.0, 2.0, 0.0, 0.0)
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
class TestSetScale:
|
|
36
|
+
"""Test methods for BoundElement instances."""
|
|
37
|
+
|
|
38
|
+
def test_sets_not_transforms(self) -> None:
|
|
39
|
+
"""The new scale is the new scale, regardless of the old scale."""
|
|
40
|
+
bbox = BoundingBox(0, 0, 100, 100)
|
|
41
|
+
bbox.scale = (2, 2)
|
|
42
|
+
assert bbox.scale == (2.0, 2.0)
|
|
43
|
+
bbox.scale = (3, 3)
|
|
44
|
+
assert bbox.scale == (3.0, 3.0)
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
class TestBoundElement:
|
|
48
|
+
"""Test methods for BoundElement instances."""
|
|
49
|
+
|
|
50
|
+
def test_set_scale(self) -> None:
|
|
51
|
+
"""Test the set_scale method."""
|
|
52
|
+
elem = new_element("rect", width=100, height=100)
|
|
53
|
+
bbox = BoundingBox(0, 0, 100, 100)
|
|
54
|
+
blem = BoundElement(elem, bbox)
|
|
55
|
+
blem.scale = (2, 2)
|
|
56
|
+
assert blem.scale == (2.0, 2.0)
|
|
57
|
+
|
|
58
|
+
def test_transform(self) -> None:
|
|
59
|
+
"""Test the transform method."""
|
|
60
|
+
elem = new_element("rect", width=100, height=100)
|
|
61
|
+
bbox = BoundingBox(0, 0, 100, 100)
|
|
62
|
+
blem = BoundElement(elem, bbox)
|
|
63
|
+
blem.transform(scale=5)
|
|
64
|
+
assert blem.scale == (5.0, 5.0)
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
class TestPaddedText:
|
|
68
|
+
"""Text that padded text instances scale like bound elements."""
|
|
69
|
+
|
|
70
|
+
def test_set_scale(self) -> None:
|
|
71
|
+
"""Test the set_scale method."""
|
|
72
|
+
elem = new_element("rect", width=100, height=100)
|
|
73
|
+
bbox = BoundingBox(0, 0, 100, 100)
|
|
74
|
+
blem = PaddedText(elem, bbox, 1, 2, 3, 4)
|
|
75
|
+
blem.scale = (2, 2)
|
|
76
|
+
assert blem.scale == (2.0, 2.0)
|
|
77
|
+
|
|
78
|
+
def test_transform(self) -> None:
|
|
79
|
+
"""Test the transform method."""
|
|
80
|
+
elem = new_element("rect", width=100, height=100)
|
|
81
|
+
bbox = BoundingBox(0, 0, 100, 100)
|
|
82
|
+
blem = PaddedText(elem, bbox, 1, 2, 3, 4)
|
|
83
|
+
blem.transform(scale=5)
|
|
84
|
+
assert blem.scale == (5.0, 5.0)
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
"""Test methods for BoundElement instances.
|
|
2
|
-
|
|
3
|
-
:author: Shay Hill
|
|
4
|
-
:created: 2025-07-29
|
|
5
|
-
"""
|
|
6
|
-
|
|
7
|
-
from svg_ultralight.bounding_boxes.type_bounding_box import BoundingBox
|
|
8
|
-
|
|
9
|
-
class TestTransforms:
|
|
10
|
-
"""Test methods for BoundElement instances."""
|
|
11
|
-
|
|
12
|
-
def test_matrix(self) -> None:
|
|
13
|
-
"""Test the transform method."""
|
|
14
|
-
bbox = BoundingBox(0, 0, 100, 100)
|
|
15
|
-
bbox.transform(transformation=(1, 2, 3, 4, 5, 6))
|
|
16
|
-
assert bbox.transformation == (1, 2, 3, 4, 5, 6)
|
|
17
|
-
|
|
18
|
-
def test_scale_float(self) -> None:
|
|
19
|
-
"""Test the scale method with a float."""
|
|
20
|
-
bbox = BoundingBox(0, 0, 100, 100)
|
|
21
|
-
bbox.transform(scale=2.0)
|
|
22
|
-
assert bbox.transformation == (2.0, 0.0, 0.0, 2.0, 0.0, 0.0)
|
|
23
|
-
|
|
24
|
-
def test_scale_int(self) -> None:
|
|
25
|
-
"""Test the scale method with an int."""
|
|
26
|
-
bbox = BoundingBox(0, 0, 100, 100)
|
|
27
|
-
bbox.transform(scale=2)
|
|
28
|
-
assert bbox.transformation == (2.0, 0.0, 0.0, 2.0, 0.0, 0.0)
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{svg_ultralight-0.45.3 → svg_ultralight-0.45.5}/src/svg_ultralight/bounding_boxes/__init__.py
RENAMED
|
File without changes
|
{svg_ultralight-0.45.3 → svg_ultralight-0.45.5}/src/svg_ultralight/bounding_boxes/bound_helpers.py
RENAMED
|
File without changes
|
|
File without changes
|
{svg_ultralight-0.45.3 → svg_ultralight-0.45.5}/src/svg_ultralight/bounding_boxes/supports_bounds.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{svg_ultralight-0.45.3 → svg_ultralight-0.45.5}/src/svg_ultralight/constructors/new_element.py
RENAMED
|
File without changes
|
|
File without changes
|
{svg_ultralight-0.45.3 → svg_ultralight-0.45.5}/src/svg_ultralight/font_tools/comp_results.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{svg_ultralight-0.45.3 → svg_ultralight-0.45.5}/src/svg_ultralight.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|