svg-ultralight 0.39.1__tar.gz → 0.40.1__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.

Files changed (60) hide show
  1. {svg_ultralight-0.39.1 → svg_ultralight-0.40.1}/.pre-commit-config.yaml +3 -1
  2. {svg_ultralight-0.39.1/src/svg_ultralight.egg-info → svg_ultralight-0.40.1}/PKG-INFO +4 -2
  3. svg_ultralight-0.40.1/dev-requirements.txt +110 -0
  4. {svg_ultralight-0.39.1 → svg_ultralight-0.40.1}/pyproject.toml +11 -4
  5. {svg_ultralight-0.39.1 → svg_ultralight-0.40.1}/src/svg_ultralight/__init__.py +9 -1
  6. {svg_ultralight-0.39.1 → svg_ultralight-0.40.1}/src/svg_ultralight/animate.py +3 -3
  7. svg_ultralight-0.40.1/src/svg_ultralight/bounding_boxes/padded_text_initializers.py +184 -0
  8. {svg_ultralight-0.39.1 → svg_ultralight-0.40.1}/src/svg_ultralight/bounding_boxes/type_bounding_box.py +12 -0
  9. {svg_ultralight-0.39.1 → svg_ultralight-0.40.1}/src/svg_ultralight/bounding_boxes/type_padded_text.py +38 -0
  10. svg_ultralight-0.40.1/src/svg_ultralight/font_tools/__init__.py +5 -0
  11. svg_ultralight-0.40.1/src/svg_ultralight/font_tools/comp_results.py +283 -0
  12. svg_ultralight-0.40.1/src/svg_ultralight/font_tools/font_css.py +82 -0
  13. svg_ultralight-0.40.1/src/svg_ultralight/font_tools/font_info.py +567 -0
  14. svg_ultralight-0.40.1/src/svg_ultralight/font_tools/globs.py +7 -0
  15. {svg_ultralight-0.39.1 → svg_ultralight-0.40.1}/src/svg_ultralight/image_ops.py +4 -2
  16. {svg_ultralight-0.39.1 → svg_ultralight-0.40.1}/src/svg_ultralight/inkscape.py +29 -18
  17. {svg_ultralight-0.39.1 → svg_ultralight-0.40.1}/src/svg_ultralight/main.py +5 -3
  18. {svg_ultralight-0.39.1 → svg_ultralight-0.40.1}/src/svg_ultralight/query.py +8 -37
  19. {svg_ultralight-0.39.1 → svg_ultralight-0.40.1}/src/svg_ultralight/string_conversion.py +69 -1
  20. {svg_ultralight-0.39.1 → svg_ultralight-0.40.1/src/svg_ultralight.egg-info}/PKG-INFO +4 -2
  21. {svg_ultralight-0.39.1 → svg_ultralight-0.40.1}/src/svg_ultralight.egg-info/SOURCES.txt +9 -0
  22. {svg_ultralight-0.39.1 → svg_ultralight-0.40.1}/src/svg_ultralight.egg-info/requires.txt +3 -1
  23. svg_ultralight-0.40.1/tests/conftest.py +32 -0
  24. {svg_ultralight-0.39.1 → svg_ultralight-0.40.1}/tests/test_inkscape.py +5 -12
  25. svg_ultralight-0.40.1/tests/test_padded_text_initializers.py +77 -0
  26. svg_ultralight-0.40.1/tests/test_padding.py +56 -0
  27. {svg_ultralight-0.39.1 → svg_ultralight-0.40.1}/tests/test_queries.py +14 -7
  28. {svg_ultralight-0.39.1 → svg_ultralight-0.40.1}/tests/test_string_conversion.py +40 -3
  29. svg_ultralight-0.39.1/tests/conftest.py +0 -16
  30. {svg_ultralight-0.39.1 → svg_ultralight-0.40.1}/.gitignore +0 -0
  31. {svg_ultralight-0.39.1 → svg_ultralight-0.40.1}/README.md +0 -0
  32. {svg_ultralight-0.39.1 → svg_ultralight-0.40.1}/setup.cfg +0 -0
  33. {svg_ultralight-0.39.1 → svg_ultralight-0.40.1}/src/svg_ultralight/bounding_boxes/__init__.py +0 -0
  34. {svg_ultralight-0.39.1 → svg_ultralight-0.40.1}/src/svg_ultralight/bounding_boxes/bound_helpers.py +0 -0
  35. {svg_ultralight-0.39.1 → svg_ultralight-0.40.1}/src/svg_ultralight/bounding_boxes/supports_bounds.py +0 -0
  36. {svg_ultralight-0.39.1 → svg_ultralight-0.40.1}/src/svg_ultralight/bounding_boxes/type_bound_collection.py +0 -0
  37. {svg_ultralight-0.39.1 → svg_ultralight-0.40.1}/src/svg_ultralight/bounding_boxes/type_bound_element.py +0 -0
  38. {svg_ultralight-0.39.1 → svg_ultralight-0.40.1}/src/svg_ultralight/constructors/__init__.py +0 -0
  39. {svg_ultralight-0.39.1 → svg_ultralight-0.40.1}/src/svg_ultralight/constructors/new_element.py +0 -0
  40. {svg_ultralight-0.39.1 → svg_ultralight-0.40.1}/src/svg_ultralight/layout.py +0 -0
  41. {svg_ultralight-0.39.1 → svg_ultralight-0.40.1}/src/svg_ultralight/metadata.py +0 -0
  42. {svg_ultralight-0.39.1 → svg_ultralight-0.40.1}/src/svg_ultralight/nsmap.py +0 -0
  43. {svg_ultralight-0.39.1 → svg_ultralight-0.40.1}/src/svg_ultralight/py.typed +0 -0
  44. {svg_ultralight-0.39.1 → svg_ultralight-0.40.1}/src/svg_ultralight/root_elements.py +0 -0
  45. {svg_ultralight-0.39.1 → svg_ultralight-0.40.1}/src/svg_ultralight/strings/__init__.py +0 -0
  46. {svg_ultralight-0.39.1 → svg_ultralight-0.40.1}/src/svg_ultralight/strings/svg_strings.py +0 -0
  47. {svg_ultralight-0.39.1 → svg_ultralight-0.40.1}/src/svg_ultralight/transformations.py +0 -0
  48. {svg_ultralight-0.39.1 → svg_ultralight-0.40.1}/src/svg_ultralight/unit_conversion.py +0 -0
  49. {svg_ultralight-0.39.1 → svg_ultralight-0.40.1}/src/svg_ultralight.egg-info/dependency_links.txt +0 -0
  50. {svg_ultralight-0.39.1 → svg_ultralight-0.40.1}/src/svg_ultralight.egg-info/top_level.txt +0 -0
  51. {svg_ultralight-0.39.1 → svg_ultralight-0.40.1}/tests/__init__.py +0 -0
  52. {svg_ultralight-0.39.1 → svg_ultralight-0.40.1}/tests/resources/arrow.svg +0 -0
  53. {svg_ultralight-0.39.1 → svg_ultralight-0.40.1}/tests/test_bounding.py +0 -0
  54. {svg_ultralight-0.39.1 → svg_ultralight-0.40.1}/tests/test_layout.py +0 -0
  55. {svg_ultralight-0.39.1 → svg_ultralight-0.40.1}/tests/test_matrices.py +0 -0
  56. {svg_ultralight-0.39.1 → svg_ultralight-0.40.1}/tests/test_metadata.py +0 -0
  57. {svg_ultralight-0.39.1 → svg_ultralight-0.40.1}/tests/test_new_element.py +0 -0
  58. {svg_ultralight-0.39.1 → svg_ultralight-0.40.1}/tests/test_root_elements.py +0 -0
  59. {svg_ultralight-0.39.1 → svg_ultralight-0.40.1}/tests/test_svg_ultralight.py +0 -0
  60. {svg_ultralight-0.39.1 → svg_ultralight-0.40.1}/tox.ini +0 -0
@@ -92,6 +92,8 @@ repos:
92
92
  # S301 don't use pickle
93
93
  # B028 wants explicit stacklevel on warn
94
94
  # BLE001 Use of `except Exception:` detected
95
+ # ANN401 Any type disallowed
96
+ # FLY002 Consider f-string instead of string join
95
97
  rev: 'v0.11.11'
96
98
  hooks:
97
99
  - id: ruff
@@ -100,7 +102,7 @@ repos:
100
102
  args:
101
103
  - --target-version=py39
102
104
  - --select=ALL
103
- - --ignore=ANN201,ANN202,B905,COM812,D203,D213,I001,ISC003,N802,N806,PGH003,PLR0913,PTH108,S101,S603,PLR2004,S320,S301,B028,BLE001
105
+ - --ignore=ANN201,ANN202,B905,COM812,D203,D213,I001,ISC003,N802,N806,PGH003,PLR0913,PTH108,S101,S603,PLR2004,S320,S301,B028,BLE001,ANN401,FLY002
104
106
  - --fix
105
107
  - --fixable=RUF022
106
108
  - id: ruff
@@ -1,14 +1,16 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: svg-ultralight
3
- Version: 0.39.1
3
+ Version: 0.40.1
4
4
  Summary: a sensible way to create svg files with Python
5
5
  Author-email: Shay Hill <shay_public@hotmail.com>
6
6
  License: MIT
7
7
  Requires-Python: >=3.9
8
8
  Description-Content-Type: text/markdown
9
+ Requires-Dist: cssutils
10
+ Requires-Dist: fonttools
9
11
  Requires-Dist: lxml
10
- Requires-Dist: pillow
11
12
  Requires-Dist: paragraphs
13
+ Requires-Dist: pillow
12
14
  Requires-Dist: types-lxml
13
15
  Requires-Dist: typing-extensions
14
16
  Provides-Extra: dev
@@ -0,0 +1,110 @@
1
+ #
2
+ # This file is autogenerated by pip-compile with Python 3.11
3
+ # by the following command:
4
+ #
5
+ # pip-compile --extra=dev --output-file=dev-requirements.txt --strip-extras pyproject.toml
6
+ #
7
+ argcomplete==3.6.2
8
+ # via commitizen
9
+ beautifulsoup4==4.13.4
10
+ # via types-lxml
11
+ cachetools==6.0.0
12
+ # via tox
13
+ cfgv==3.4.0
14
+ # via pre-commit
15
+ chardet==5.2.0
16
+ # via tox
17
+ charset-normalizer==3.4.2
18
+ # via commitizen
19
+ colorama==0.4.6
20
+ # via
21
+ # commitizen
22
+ # pytest
23
+ # tox
24
+ commitizen==4.8.2
25
+ # via svg-ultralight (pyproject.toml)
26
+ cssselect==1.3.0
27
+ # via types-lxml
28
+ cssutils==2.11.1
29
+ # via svg-ultralight (pyproject.toml)
30
+ decli==0.6.3
31
+ # via commitizen
32
+ distlib==0.3.9
33
+ # via virtualenv
34
+ filelock==3.18.0
35
+ # via
36
+ # tox
37
+ # virtualenv
38
+ fonttools==4.58.1
39
+ # via svg-ultralight (pyproject.toml)
40
+ identify==2.6.12
41
+ # via pre-commit
42
+ iniconfig==2.1.0
43
+ # via pytest
44
+ jinja2==3.1.6
45
+ # via commitizen
46
+ lxml==5.4.0
47
+ # via svg-ultralight (pyproject.toml)
48
+ markupsafe==3.0.2
49
+ # via jinja2
50
+ more-itertools==10.7.0
51
+ # via cssutils
52
+ nodeenv==1.9.1
53
+ # via pre-commit
54
+ packaging==25.0
55
+ # via
56
+ # commitizen
57
+ # pyproject-api
58
+ # pytest
59
+ # tox
60
+ paragraphs==1.0.1
61
+ # via svg-ultralight (pyproject.toml)
62
+ pillow==11.2.1
63
+ # via svg-ultralight (pyproject.toml)
64
+ platformdirs==4.3.8
65
+ # via
66
+ # tox
67
+ # virtualenv
68
+ pluggy==1.6.0
69
+ # via
70
+ # pytest
71
+ # tox
72
+ pre-commit==4.2.0
73
+ # via svg-ultralight (pyproject.toml)
74
+ prompt-toolkit==3.0.51
75
+ # via questionary
76
+ pygments==2.19.1
77
+ # via pytest
78
+ pyproject-api==1.9.1
79
+ # via tox
80
+ pytest==8.4.0
81
+ # via svg-ultralight (pyproject.toml)
82
+ pyyaml==6.0.2
83
+ # via
84
+ # commitizen
85
+ # pre-commit
86
+ questionary==2.1.0
87
+ # via commitizen
88
+ soupsieve==2.7
89
+ # via beautifulsoup4
90
+ termcolor==2.5.0
91
+ # via commitizen
92
+ tomlkit==0.13.2
93
+ # via commitizen
94
+ tox==4.26.0
95
+ # via svg-ultralight (pyproject.toml)
96
+ types-html5lib==1.1.11.20250516
97
+ # via types-lxml
98
+ types-lxml==2025.3.30
99
+ # via svg-ultralight (pyproject.toml)
100
+ typing-extensions==4.14.0
101
+ # via
102
+ # beautifulsoup4
103
+ # svg-ultralight (pyproject.toml)
104
+ # types-lxml
105
+ virtualenv==20.31.2
106
+ # via
107
+ # pre-commit
108
+ # tox
109
+ wcwidth==0.2.13
110
+ # via prompt-toolkit
@@ -1,13 +1,20 @@
1
1
  [project]
2
2
  name = "svg-ultralight"
3
- version = "0.39.1"
3
+ version = "0.40.1"
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" }
7
7
  readme = "README.md"
8
8
  requires-python = ">=3.9"
9
- dependencies = ["lxml", "pillow", "paragraphs", "types-lxml", "typing-extensions"]
10
-
9
+ dependencies = [
10
+ "cssutils",
11
+ "fonttools",
12
+ "lxml",
13
+ "paragraphs",
14
+ "pillow",
15
+ "types-lxml",
16
+ "typing-extensions",
17
+ ]
11
18
  [project.optional-dependencies]
12
19
  dev = ["pytest", "commitizen", "pre-commit", "tox"]
13
20
  images = ["pillow"]
@@ -42,7 +49,7 @@ convention = "pep257"
42
49
 
43
50
  [tool.commitizen]
44
51
  name = "cz_conventional_commits"
45
- version = "0.39.1"
52
+ version = "0.40.1"
46
53
  tag_format = "$version"
47
54
  version_files = ["pyproject.toml:^version"]
48
55
  annotated_tag = true
@@ -14,6 +14,11 @@ from svg_ultralight.bounding_boxes.bound_helpers import (
14
14
  pad_bbox,
15
15
  parse_bound_element,
16
16
  )
17
+ from svg_ultralight.bounding_boxes.padded_text_initializers import (
18
+ pad_text,
19
+ pad_text_ft,
20
+ pad_text_mix,
21
+ )
17
22
  from svg_ultralight.bounding_boxes.supports_bounds import SupportsBounds
18
23
  from svg_ultralight.bounding_boxes.type_bound_collection import BoundCollection
19
24
  from svg_ultralight.bounding_boxes.type_bound_element import BoundElement
@@ -25,6 +30,7 @@ from svg_ultralight.constructors.new_element import (
25
30
  new_sub_element,
26
31
  update_element,
27
32
  )
33
+ from svg_ultralight.font_tools.comp_results import check_font_tools_alignment
28
34
  from svg_ultralight.inkscape import (
29
35
  write_pdf,
30
36
  write_pdf_from_svg,
@@ -39,7 +45,6 @@ from svg_ultralight.query import (
39
45
  clear_svg_ultralight_cache,
40
46
  get_bounding_box,
41
47
  get_bounding_boxes,
42
- pad_text,
43
48
  )
44
49
  from svg_ultralight.root_elements import new_svg_root_around_bounds
45
50
  from svg_ultralight.string_conversion import (
@@ -63,6 +68,7 @@ __all__ = [
63
68
  "PaddedText",
64
69
  "SupportsBounds",
65
70
  "bbox_dict",
71
+ "check_font_tools_alignment",
66
72
  "clear_svg_ultralight_cache",
67
73
  "cut_bbox",
68
74
  "deepcopy_element",
@@ -87,6 +93,8 @@ __all__ = [
87
93
  "new_svg_root_around_bounds",
88
94
  "pad_bbox",
89
95
  "pad_text",
96
+ "pad_text_ft",
97
+ "pad_text_mix",
90
98
  "parse_bound_element",
91
99
  "transform_element",
92
100
  "update_element",
@@ -16,13 +16,13 @@ except ModuleNotFoundError as exc:
16
16
  from typing import TYPE_CHECKING
17
17
 
18
18
  if TYPE_CHECKING:
19
+ import os
19
20
  from collections.abc import Iterable
20
- from pathlib import Path
21
21
 
22
22
 
23
23
  def write_gif(
24
- gif: str | Path,
25
- pngs: Iterable[str] | Iterable[Path] | Iterable[str | Path],
24
+ gif: str | os.PathLike[str],
25
+ pngs: Iterable[str] | Iterable[os.PathLike[str]] | Iterable[str | os.PathLike[str]],
26
26
  duration: float = 100,
27
27
  loop: int = 0,
28
28
  ) -> None:
@@ -0,0 +1,184 @@
1
+ """Functions that create PaddedText instances.
2
+
3
+ Three variants:
4
+
5
+ - `pad_text`: uses Inkscape to measure text bounds
6
+
7
+ - `pad_text_ft`: uses fontTools to measure text bounds (faster, and you get line_gap)
8
+
9
+ - `pad_text_mix`: uses Inkscape and fontTools to give true ascent, descent, and
10
+ line_gap while correcting some of the layout differences between fontTools and
11
+ Inkscape.
12
+
13
+ :author: Shay Hill
14
+ :created: 2025-06-09
15
+ """
16
+
17
+ from __future__ import annotations
18
+
19
+ from copy import deepcopy
20
+ from typing import TYPE_CHECKING
21
+
22
+ from svg_ultralight.bounding_boxes.type_padded_text import PaddedText
23
+ from svg_ultralight.constructors import new_element, update_element
24
+ from svg_ultralight.font_tools.font_info import (
25
+ get_padded_text_info,
26
+ get_svg_font_attributes,
27
+ )
28
+ from svg_ultralight.font_tools.globs import DEFAULT_FONT_SIZE
29
+ from svg_ultralight.query import get_bounding_boxes
30
+ from svg_ultralight.string_conversion import (
31
+ format_attr_dict,
32
+ format_number,
33
+ )
34
+
35
+ if TYPE_CHECKING:
36
+ import os
37
+
38
+ from lxml.etree import (
39
+ _Element as EtreeElement, # pyright: ignore[reportPrivateUsage]
40
+ )
41
+
42
+ DEFAULT_Y_BOUNDS_REFERENCE = "{[|gjpqyf"
43
+
44
+
45
+ def pad_text(
46
+ inkscape: str | os.PathLike[str],
47
+ text_elem: EtreeElement,
48
+ y_bounds_reference: str | None = None,
49
+ *,
50
+ font: str | os.PathLike[str] | None = None,
51
+ ) -> PaddedText:
52
+ r"""Create a PaddedText instance from a text element.
53
+
54
+ :param inkscape: path to an inkscape executable on your local file system
55
+ IMPORTANT: path cannot end with ``.exe``.
56
+ Use something like ``"C:\\Program Files\\Inkscape\\inkscape"``
57
+ :param text_elem: an etree element with a text tag
58
+ :param y_bounds_reference: an optional string to use to determine the ascent and
59
+ capline of the font. The default is a good choice, which approaches or even
60
+ meets the ascent of descent of most fonts without using utf-8 characters. You
61
+ might want to use a letter like "M" or even "x" if you are using an all-caps
62
+ string and want to center between the capline and baseline or if you'd like
63
+ to center between the baseline and x-line.
64
+ :param font: optionally add a path to a font file to use for the text element.
65
+ This is going to conflict with any font-family, font-style, or other
66
+ font-related attributes *except* font-size. You likely want to use
67
+ `font_tools.new_padded_text` if you're going to pass a font path, but you can
68
+ use it here to compare results between `pad_text` and `new_padded_text`.
69
+ :return: a PaddedText instance
70
+ """
71
+ if y_bounds_reference is None:
72
+ y_bounds_reference = DEFAULT_Y_BOUNDS_REFERENCE
73
+ if font is not None:
74
+ _ = update_element(text_elem, **get_svg_font_attributes(font))
75
+ if "font-size" not in text_elem.attrib:
76
+ text_elem.attrib["font-size"] = format_number(DEFAULT_FONT_SIZE)
77
+ rmargin_ref = deepcopy(text_elem)
78
+ capline_ref = deepcopy(text_elem)
79
+ _ = rmargin_ref.attrib.pop("id", None)
80
+ _ = capline_ref.attrib.pop("id", None)
81
+ rmargin_ref.attrib["text-anchor"] = "end"
82
+ capline_ref.text = y_bounds_reference
83
+
84
+ bboxes = get_bounding_boxes(inkscape, text_elem, rmargin_ref, capline_ref)
85
+ bbox, rmargin_bbox, capline_bbox = bboxes
86
+
87
+ tpad = bbox.y - capline_bbox.y
88
+ rpad = -rmargin_bbox.x2
89
+ bpad = capline_bbox.y2 - bbox.y2
90
+ lpad = bbox.x
91
+ return PaddedText(text_elem, bbox, tpad, rpad, bpad, lpad)
92
+
93
+
94
+ def pad_text_ft(
95
+ font: str | os.PathLike[str],
96
+ text: str,
97
+ font_size: float = DEFAULT_FONT_SIZE,
98
+ ascent: float | None = None,
99
+ descent: float | None = None,
100
+ *,
101
+ y_bounds_reference: str | None = None,
102
+ **attributes: str | float,
103
+ ) -> PaddedText:
104
+ """Create a new PaddedText instance using fontTools.
105
+
106
+ :param font: path to a font file.
107
+ :param text: the text of the text element.
108
+ :param font_size: the font size to use.
109
+ :param ascent: the ascent of the font. If not provided, it will be calculated
110
+ from the font file.
111
+ :param descent: the descent of the font. If not provided, it will be calculated
112
+ from the font file.
113
+ :param y_bounds_reference: optional character or string to use as a reference
114
+ for the ascent and descent. If provided, the ascent and descent will be the y
115
+ extents of the capline reference. This argument is provided to mimic the
116
+ behavior of the query module's `pad_text` function. `pad_text` does no
117
+ inspect font files and relies on Inkscape to measure reference characters.
118
+ :param attributes: additional attributes to set on the text element. There is a
119
+ chance these will cause the font element to exceed the BoundingBox of the
120
+ PaddedText instance.
121
+ :return: a PaddedText instance with a line_gap defined.
122
+ """
123
+ attributes_ = format_attr_dict(**attributes)
124
+ attributes_.update(get_svg_font_attributes(font))
125
+ attributes_["font-size"] = attributes_.get("font-size", format_number(font_size))
126
+
127
+ elem = new_element("text", text=text, **attributes_)
128
+ info = get_padded_text_info(
129
+ font, text, font_size, ascent, descent, y_bounds_reference=y_bounds_reference
130
+ )
131
+ return PaddedText(elem, info.bbox, *info.padding, info.line_gap)
132
+
133
+
134
+ def pad_text_mix(
135
+ inkscape: str | os.PathLike[str],
136
+ font: str | os.PathLike[str],
137
+ text: str,
138
+ font_size: float = DEFAULT_FONT_SIZE,
139
+ ascent: float | None = None,
140
+ descent: float | None = None,
141
+ *,
142
+ y_bounds_reference: str | None = None,
143
+ **attributes: str | float,
144
+ ) -> PaddedText:
145
+ """Use Inkscape text bounds and fill missing with fontTools.
146
+
147
+ :param font: path to a font file.
148
+ :param text: the text of the text element.
149
+ :param font_size: the font size to use.
150
+ :param ascent: the ascent of the font. If not provided, it will be calculated
151
+ from the font file.
152
+ :param descent: the descent of the font. If not provided, it will be calculated
153
+ from the font file.
154
+ :param y_bounds_reference: optional character or string to use as a reference
155
+ for the ascent and descent. If provided, the ascent and descent will be the y
156
+ extents of the capline reference. This argument is provided to mimic the
157
+ behavior of the query module's `pad_text` function. `pad_text` does no
158
+ inspect font files and relies on Inkscape to measure reference characters.
159
+ :param attributes: additional attributes to set on the text element. There is a
160
+ chance these will cause the font element to exceed the BoundingBox of the
161
+ PaddedText instance.
162
+ :return: a PaddedText instance with a line_gap defined.
163
+ """
164
+ elem = new_element("text", text=text, **attributes)
165
+ padded_inkscape = pad_text(inkscape, elem, y_bounds_reference, font=font)
166
+ padded_fonttools = pad_text_ft(
167
+ font,
168
+ text,
169
+ font_size,
170
+ ascent,
171
+ descent,
172
+ y_bounds_reference=y_bounds_reference,
173
+ **attributes,
174
+ )
175
+ bbox = padded_inkscape.unpadded_bbox
176
+ rpad = padded_inkscape.rpad
177
+ lpad = padded_inkscape.lpad
178
+ if y_bounds_reference is None:
179
+ tpad = padded_fonttools.tpad
180
+ bpad = padded_fonttools.bpad
181
+ else:
182
+ tpad = padded_inkscape.tpad
183
+ bpad = padded_inkscape.bpad
184
+ return PaddedText(elem, bbox, tpad, rpad, bpad, lpad, padded_fonttools.line_gap)
@@ -41,6 +41,18 @@ class HasBoundingBox(SupportsBounds):
41
41
  y2 = y + self.bbox.base_height
42
42
  return (x, y), (x2, y), (x2, y2), (x, y2)
43
43
 
44
+ def values(self) -> tuple[float, float, float, float]:
45
+ """Get the values of the bounding box.
46
+
47
+ :return: x, y, width, height of the bounding box
48
+ """
49
+ return (
50
+ self.bbox.x,
51
+ self.bbox.y,
52
+ self.bbox.width,
53
+ self.bbox.height,
54
+ )
55
+
44
56
  def _get_transformed_corners(
45
57
  self,
46
58
  ) -> tuple[
@@ -66,6 +66,8 @@ from __future__ import annotations
66
66
 
67
67
  from typing import TYPE_CHECKING
68
68
 
69
+ from paragraphs import par
70
+
69
71
  from svg_ultralight.bounding_boxes.type_bound_element import BoundElement
70
72
  from svg_ultralight.bounding_boxes.type_bounding_box import BoundingBox
71
73
  from svg_ultralight.transformations import new_transformation_matrix, transform_element
@@ -77,6 +79,14 @@ if TYPE_CHECKING:
77
79
 
78
80
  _Matrix = tuple[float, float, float, float, float, float]
79
81
 
82
+ _no_line_gap_msg = par(
83
+ """No line_gap defined. Line gap is an inherent font attribute defined within a
84
+ font file. If this PaddedText instance was created with `pad_text` from reference
85
+ elements, a line_gap was not defined. Reading line_gap from the font file
86
+ requires creating a PaddedText instance with `pad_text_ft` or `pad_text_mixed`.
87
+ You can set an arbitrary line_gap after init with `instance.line_gap = value`."""
88
+ )
89
+
80
90
 
81
91
  class PaddedText(BoundElement):
82
92
  """A line of text with a bounding box and padding."""
@@ -89,6 +99,7 @@ class PaddedText(BoundElement):
89
99
  rpad: float,
90
100
  bpad: float,
91
101
  lpad: float,
102
+ line_gap: float | None = None,
92
103
  ) -> None:
93
104
  """Initialize a PaddedText instance.
94
105
 
@@ -105,6 +116,7 @@ class PaddedText(BoundElement):
105
116
  self.rpad = rpad
106
117
  self.base_bpad = bpad
107
118
  self.lpad = lpad
119
+ self._line_gap = line_gap
108
120
 
109
121
  @property
110
122
  def bbox(self) -> BoundingBox:
@@ -153,6 +165,32 @@ class PaddedText(BoundElement):
153
165
  self.unpadded_bbox.transform(tmat)
154
166
  _ = transform_element(self.elem, tmat)
155
167
 
168
+ @property
169
+ def line_gap(self) -> float:
170
+ """The line gap between this line of text and the next.
171
+
172
+ :return: The line gap between this line of text and the next.
173
+ """
174
+ if self._line_gap is None:
175
+ raise AttributeError(_no_line_gap_msg)
176
+ return self._line_gap
177
+
178
+ @line_gap.setter
179
+ def line_gap(self, value: float) -> None:
180
+ """Set the line gap between this line of text and the next.
181
+
182
+ :param value: The new line gap.
183
+ """
184
+ self._line_gap = value
185
+
186
+ @property
187
+ def leading(self) -> float:
188
+ """The leading of this line of text.
189
+
190
+ :return: The line gap plus the height of this line of text.
191
+ """
192
+ return self.height + self.line_gap
193
+
156
194
  @property
157
195
  def tpad(self) -> float:
158
196
  """The top padding of this line of text.
@@ -0,0 +1,5 @@
1
+ """Mark font_tools as a package.
2
+
3
+ :author: Shay Hill
4
+ :created: 2025-06-04
5
+ """