svg-ultralight 0.50.2__py3-none-any.whl → 0.51.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.

@@ -23,11 +23,12 @@ to 16px.
23
23
  from __future__ import annotations
24
24
 
25
25
  from copy import deepcopy
26
- from typing import TYPE_CHECKING
26
+ from typing import TYPE_CHECKING, overload
27
27
 
28
28
  from svg_ultralight.bounding_boxes.type_padded_text import PaddedText
29
29
  from svg_ultralight.constructors import new_element, update_element
30
30
  from svg_ultralight.font_tools.font_info import (
31
+ FTFontInfo,
31
32
  get_padded_text_info,
32
33
  get_svg_font_attributes,
33
34
  )
@@ -99,6 +100,7 @@ def pad_text(
99
100
  return PaddedText(text_elem, bbox, tpad, rpad, bpad, lpad)
100
101
 
101
102
 
103
+ @overload
102
104
  def pad_text_ft(
103
105
  font: str | os.PathLike[str],
104
106
  text: str,
@@ -109,11 +111,38 @@ def pad_text_ft(
109
111
  y_bounds_reference: str | None = None,
110
112
  attrib: OptionalElemAttribMapping = None,
111
113
  **attributes: ElemAttrib,
112
- ) -> PaddedText:
114
+ ) -> PaddedText: ...
115
+
116
+
117
+ @overload
118
+ def pad_text_ft(
119
+ font: str | os.PathLike[str],
120
+ text: list[str],
121
+ font_size: float | None = None,
122
+ ascent: float | None = None,
123
+ descent: float | None = None,
124
+ *,
125
+ y_bounds_reference: str | None = None,
126
+ attrib: OptionalElemAttribMapping = None,
127
+ **attributes: ElemAttrib,
128
+ ) -> list[PaddedText]: ...
129
+
130
+
131
+ def pad_text_ft(
132
+ font: str | os.PathLike[str],
133
+ text: str | list[str],
134
+ font_size: float | None = None,
135
+ ascent: float | None = None,
136
+ descent: float | None = None,
137
+ *,
138
+ y_bounds_reference: str | None = None,
139
+ attrib: OptionalElemAttribMapping = None,
140
+ **attributes: ElemAttrib,
141
+ ) -> PaddedText | list[PaddedText]:
113
142
  """Create a new PaddedText instance using fontTools.
114
143
 
115
144
  :param font: path to a font file.
116
- :param text: the text of the text element.
145
+ :param text: the text of the text element or a list of text strings.
117
146
  :param font_size: the font size to use.
118
147
  :param ascent: the ascent of the font. If not provided, it will be calculated
119
148
  from the font file.
@@ -130,7 +159,8 @@ def pad_text_ft(
130
159
  :param attributes: additional attributes to set on the text element. There is a
131
160
  chance these will cause the font element to exceed the BoundingBox of the
132
161
  PaddedText instance.
133
- :return: a PaddedText instance with a line_gap defined.
162
+ :return: a PaddedText instance with a line_gap defined. If a list of strings is
163
+ given for parameter `text`, a list of PaddedText instances is returned.
134
164
  """
135
165
  attributes.update(attrib or {})
136
166
  attributes_ = format_attr_dict(**attributes)
@@ -142,11 +172,33 @@ def pad_text_ft(
142
172
  _ = attributes_.pop("font-weight", None)
143
173
  _ = attributes_.pop("font-stretch", None)
144
174
 
145
- info = get_padded_text_info(
146
- font, text, font_size, ascent, descent, y_bounds_reference=y_bounds_reference
147
- )
148
- elem = info.new_element(**attributes_)
149
- return PaddedText(elem, info.bbox, *info.padding, info.line_gap)
175
+ font_info = FTFontInfo(font)
176
+
177
+ try:
178
+ input_one_text_item = False
179
+ if isinstance(text, str):
180
+ input_one_text_item = True
181
+ text = [text]
182
+
183
+ elems: list[PaddedText] = []
184
+ for text_item in text:
185
+ text_info = get_padded_text_info(
186
+ font_info,
187
+ text_item,
188
+ font_size,
189
+ ascent,
190
+ descent,
191
+ y_bounds_reference=y_bounds_reference,
192
+ )
193
+ elem = text_info.new_element(**attributes_)
194
+ elems.append(
195
+ PaddedText(elem, text_info.bbox, *text_info.padding, text_info.line_gap)
196
+ )
197
+ finally:
198
+ font_info.font.close()
199
+ if input_one_text_item:
200
+ return elems[0]
201
+ return elems
150
202
 
151
203
 
152
204
  def pad_text_mix(
@@ -644,7 +644,7 @@ def get_font_size_given_height(font: str | os.PathLike[str], height: float) -> f
644
644
 
645
645
 
646
646
  def get_padded_text_info(
647
- font: str | os.PathLike[str],
647
+ font: str | os.PathLike[str] | FTFontInfo,
648
648
  text: str,
649
649
  font_size: float | None = None,
650
650
  ascent: float | None = None,
@@ -669,7 +669,10 @@ def get_padded_text_info(
669
669
  :return: A FTTextInfo object with the information necessary to create a
670
670
  PaddedText instance: bbox, tpad, rpad, bpad, lpad.
671
671
  """
672
- font_info = FTFontInfo(font)
672
+ if isinstance(font, FTFontInfo):
673
+ font_info = font
674
+ else:
675
+ font_info = FTFontInfo(font)
673
676
  if y_bounds_reference:
674
677
  capline_info = FTTextInfo(font_info, y_bounds_reference, font_size)
675
678
  ascent = -capline_info.bbox.y
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: svg-ultralight
3
- Version: 0.50.2
3
+ Version: 0.51.0
4
4
  Summary: a sensible way to create svg files with Python
5
5
  Author: Shay Hill
6
6
  Author-email: Shay Hill <shay_public@hotmail.com>
@@ -3,7 +3,7 @@ svg_ultralight/animate.py,sha256=pwboos8Z1GFNEGxHxIeeIyxyfRUew5pus2lG3P4MERU,109
3
3
  svg_ultralight/attrib_hints.py,sha256=_p85b77mcmj15IUnsDtgbYJ3FFd-Q1qM2OERv2UEZ20,419
4
4
  svg_ultralight/bounding_boxes/__init__.py,sha256=YNCwgN-Ja2MFoCxIYxC3KZTCx_gFvPfRQ-8zBR5Q9mk,73
5
5
  svg_ultralight/bounding_boxes/bound_helpers.py,sha256=o_NlH3bBU6lvn8KPTvp7hrEDb5OLqwO3t-gc51d44Rk,6583
6
- svg_ultralight/bounding_boxes/padded_text_initializers.py,sha256=9keGI3g6F92dqQEtwHnoVrNrDBREXWmomvzeSnnaY2Q,8594
6
+ svg_ultralight/bounding_boxes/padded_text_initializers.py,sha256=7LD7VzmDSaNA2S9QTW0sNzMwLpjjReWGV0e5f4uglk8,10002
7
7
  svg_ultralight/bounding_boxes/supports_bounds.py,sha256=zoJr7goYEbiVsr5Vl2RlqCsbyBe5RHZGrU0B5WMBRbY,4427
8
8
  svg_ultralight/bounding_boxes/type_bound_collection.py,sha256=vzZPJoUg4Joaj7nTl4VpDFFHihIoBfBNvu6IaIprYKM,2582
9
9
  svg_ultralight/bounding_boxes/type_bound_element.py,sha256=CdbL48NMauCX5qZGlJes3aYFZHyVE3rby99HN-Kr7GI,2147
@@ -13,7 +13,7 @@ svg_ultralight/constructors/__init__.py,sha256=fb-A50G3YTZNMQXpxcCl_QAcfssS0Us06
13
13
  svg_ultralight/constructors/new_element.py,sha256=hVQG7WBHQoTUmGiZNtVadGOitdTFBrHOQeVKKVOWGaA,3526
14
14
  svg_ultralight/font_tools/__init__.py,sha256=b_VSvk5aODzS2wv48EMU2sey_mxq1o1SL8ecWTdy4kc,78
15
15
  svg_ultralight/font_tools/comp_results.py,sha256=KR6RtVGWjGGfHX2d_-XRx_Jr9CQ36kPbQxLVK1yzgTI,10421
16
- svg_ultralight/font_tools/font_info.py,sha256=OclOKrt38FN-3-mk71eCh-aTtcyrb8lzZdCamI0_msg,29243
16
+ svg_ultralight/font_tools/font_info.py,sha256=9nSj8qjzbT3bEe2Qgr-Rtfzb6RyFFCiXHbvv4Oyfxw0,29332
17
17
  svg_ultralight/image_ops.py,sha256=cwR038ECUuiceIrk-9Peh5Ijp4tzjuaV5Y1cvYOt4TI,5454
18
18
  svg_ultralight/inkscape.py,sha256=_aQ42ZQ1JP9TFdHmtxgCRsXvxfZPpdZWTGKEea9BgIU,9336
19
19
  svg_ultralight/layout.py,sha256=yiTAYtSsYywdCObIdjkK3A4fiEYLNPqD3BOQKxfj6gQ,12514
@@ -29,6 +29,6 @@ svg_ultralight/strings/__init__.py,sha256=iaRwr9AF9bPDkG3XvgGRSf8JPAS2GQ8ds9yCNp
29
29
  svg_ultralight/strings/svg_strings.py,sha256=XlXQ5RqueGrROXBI4VzR2cK7e1NdNhYx5S84bgyqFUQ,3132
30
30
  svg_ultralight/transformations.py,sha256=fnPMdMQFgT6OEUIDwb_A7tvuILraPFW1jR9I1RaI1cA,4325
31
31
  svg_ultralight/unit_conversion.py,sha256=Y32GZ5TLkvjDHM2kBw52M8ZxDNlpVSlDkSdRa1S_X-A,8985
32
- svg_ultralight-0.50.2.dist-info/WHEEL,sha256=eh7sammvW2TypMMMGKgsM83HyA_3qQ5Lgg3ynoecH3M,79
33
- svg_ultralight-0.50.2.dist-info/METADATA,sha256=LoXD9iwEiqOnCRFyk2z2oRGfV-yvFp3gYb1x0ojPRPo,8691
34
- svg_ultralight-0.50.2.dist-info/RECORD,,
32
+ svg_ultralight-0.51.0.dist-info/WHEEL,sha256=eh7sammvW2TypMMMGKgsM83HyA_3qQ5Lgg3ynoecH3M,79
33
+ svg_ultralight-0.51.0.dist-info/METADATA,sha256=qvOlGkyOA8KxGifWkMETlzsu--3Nf8qFCyqhet7VoyM,8691
34
+ svg_ultralight-0.51.0.dist-info/RECORD,,