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

@@ -10,6 +10,12 @@ Three variants:
10
10
  line_gap while correcting some of the layout differences between fontTools and
11
11
  Inkscape.
12
12
 
13
+ There is a default font size for pad_text if an element is passed. There is also a
14
+ default for the other pad_text_ functions, but it taken from the font file and is
15
+ usually 1024, so it won't be easy to miss. The default for standard pad_text is to
16
+ prevent surprises if Inksape defaults to font-size 12pt while your browser defaults
17
+ to 16px.
18
+
13
19
  :author: Shay Hill
14
20
  :created: 2025-06-09
15
21
  """
@@ -25,7 +31,6 @@ from svg_ultralight.font_tools.font_info import (
25
31
  get_padded_text_info,
26
32
  get_svg_font_attributes,
27
33
  )
28
- from svg_ultralight.font_tools.globs import DEFAULT_FONT_SIZE
29
34
  from svg_ultralight.query import get_bounding_boxes
30
35
  from svg_ultralight.string_conversion import format_attr_dict, format_number
31
36
 
@@ -40,6 +45,9 @@ if TYPE_CHECKING:
40
45
 
41
46
  DEFAULT_Y_BOUNDS_REFERENCE = "{[|gjpqyf"
42
47
 
48
+ # A default font size for pad_text if font-size is not specified in the reference
49
+ # element.
50
+ DEFAULT_FONT_SIZE_FOR_PAD_TEXT = 12.0 # Default font size for pad_text if not specified
43
51
 
44
52
  def pad_text(
45
53
  inkscape: str | os.PathLike[str],
@@ -93,7 +101,7 @@ def pad_text(
93
101
  def pad_text_ft(
94
102
  font: str | os.PathLike[str],
95
103
  text: str,
96
- font_size: float = DEFAULT_FONT_SIZE,
104
+ font_size: float | None = None,
97
105
  ascent: float | None = None,
98
106
  descent: float | None = None,
99
107
  *,
@@ -144,7 +152,7 @@ def pad_text_mix(
144
152
  inkscape: str | os.PathLike[str],
145
153
  font: str | os.PathLike[str],
146
154
  text: str,
147
- font_size: float = DEFAULT_FONT_SIZE,
155
+ font_size: float | None = None,
148
156
  ascent: float | None = None,
149
157
  descent: float | None = None,
150
158
  *,
@@ -110,7 +110,6 @@ from svg_path_data import format_svgd_shortest, get_cpts_from_svgd, get_svgd_fro
110
110
 
111
111
  from svg_ultralight.bounding_boxes.type_bounding_box import BoundingBox
112
112
  from svg_ultralight.constructors.new_element import new_element
113
- from svg_ultralight.font_tools.globs import DEFAULT_FONT_SIZE
114
113
  from svg_ultralight.string_conversion import format_numbers
115
114
 
116
115
  if TYPE_CHECKING:
@@ -499,7 +498,7 @@ class FTTextInfo:
499
498
  self,
500
499
  font: str | os.PathLike[str] | FTFontInfo,
501
500
  text: str,
502
- font_size: float,
501
+ font_size: float | None = None,
503
502
  ascent: float | None = None,
504
503
  descent: float | None = None,
505
504
  ) -> None:
@@ -509,7 +508,7 @@ class FTTextInfo:
509
508
  else:
510
509
  self._font = FTFontInfo(font)
511
510
  self._text = text.rstrip(" ")
512
- self._font_size = font_size
511
+ self._font_size = font_size or self._font.units_per_em
513
512
  self._ascent = ascent
514
513
  self._descent = descent
515
514
 
@@ -638,7 +637,7 @@ def get_font_size_given_height(font: str | os.PathLike[str], height: float) -> f
638
637
  def get_padded_text_info(
639
638
  font: str | os.PathLike[str],
640
639
  text: str,
641
- font_size: float = DEFAULT_FONT_SIZE,
640
+ font_size: float | None = None,
642
641
  ascent: float | None = None,
643
642
  descent: float | None = None,
644
643
  *,
@@ -32,6 +32,7 @@ from lxml import etree
32
32
 
33
33
  from svg_ultralight import NSMAP
34
34
  from svg_ultralight.bounding_boxes.bound_helpers import bbox_dict
35
+ from svg_ultralight.bounding_boxes.type_bound_element import BoundElement
35
36
  from svg_ultralight.bounding_boxes.type_bounding_box import BoundingBox
36
37
  from svg_ultralight.constructors import new_element
37
38
 
@@ -113,11 +114,11 @@ def _get_svg_embedded_image_str(image: ImageType) -> str:
113
114
  return "data:image/png;base64," + base64_encoded_result_str
114
115
 
115
116
 
116
- def new_image_elem_in_bbox(
117
+ def new_image_blem(
117
118
  filename: str | os.PathLike[str],
118
119
  bbox: BoundingBox | None = None,
119
120
  center: tuple[float, float] | None = None,
120
- ) -> EtreeElement:
121
+ ) -> BoundElement:
121
122
  """Create a new svg image element inside a bounding box.
122
123
 
123
124
  :param filename: filename of source image
@@ -125,7 +126,7 @@ def new_image_elem_in_bbox(
125
126
  :param center: center point for cropping. Proportions of image width and image
126
127
  height, so the default value, (0.5, 0.5), is the true center of the image.
127
128
  (0.4, 0.5) would crop 20% off the right side of the image.
128
- :return: an etree image element with the cropped image embedded
129
+ :return: a BoundElement element with the cropped image embedded
129
130
  """
130
131
  image = Image.open(filename)
131
132
  if bbox is None:
@@ -135,4 +136,21 @@ def new_image_elem_in_bbox(
135
136
  svg_image.set(
136
137
  etree.QName(NSMAP["xlink"], "href"), _get_svg_embedded_image_str(image)
137
138
  )
138
- return svg_image
139
+ return BoundElement(svg_image, bbox)
140
+
141
+
142
+ def new_image_elem_in_bbox(
143
+ filename: str | os.PathLike[str],
144
+ bbox: BoundingBox | None = None,
145
+ center: tuple[float, float] | None = None,
146
+ ) -> EtreeElement:
147
+ """Create a new svg image element inside a bounding box.
148
+
149
+ :param filename: filename of source image
150
+ :param bbox: bounding box for the image
151
+ :param center: center point for cropping. Proportions of image width and image
152
+ height, so the default value, (0.5, 0.5), is the true center of the image.
153
+ (0.4, 0.5) would crop 20% off the right side of the image.
154
+ :return: an etree image element with the cropped image embedded
155
+ """
156
+ return new_image_blem(filename, bbox, center).elem
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: svg-ultralight
3
- Version: 0.45.6
3
+ Version: 0.47.0
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
@@ -1,7 +1,7 @@
1
1
  svg_ultralight/__init__.py,sha256=3YdTZfa0xUDrPCbOVyx39D9ENks-JEtsi9DFZzvaTf0,2755
2
2
  svg_ultralight/animate.py,sha256=SMcQkeWAP9dD08Iyzy9qGG8Qk1p-14WfrB7WSN8Pj_4,1133
3
3
  svg_ultralight/attrib_hints.py,sha256=oCF20eG06vg2Tuapk1A14ovN7ZqZoZ43d-um_Zh0BPs,418
4
- svg_ultralight/image_ops.py,sha256=fFztGYHVunyS4ipdW4uafXctfjzLs-m6hHqKw0wDj00,4819
4
+ svg_ultralight/image_ops.py,sha256=M8E-aZ7SDYg_0wjQHJyo3GfJ-nYEE-fpRe__96jg1kU,5610
5
5
  svg_ultralight/inkscape.py,sha256=ySCxWnQwEt1sosa1b4mEkR-ugpfoAeg9gs1OLPS69iI,9597
6
6
  svg_ultralight/layout.py,sha256=7LV2I3u4EhqSc6ASvgwDtTZyV-Y1qt2wtvRtH2uKVAE,12799
7
7
  svg_ultralight/main.py,sha256=zaqWc5y9tsJoyNhpX2gIHKj1ZGEcfJebxNCcRQyoziU,7857
@@ -15,7 +15,7 @@ svg_ultralight/transformations.py,sha256=q-9GC01fh8vXyddjpDlal9BfebMuMWGl46ubg-0
15
15
  svg_ultralight/unit_conversion.py,sha256=g07nhzXdjPvGcJmkhLdFbeDLrSmbI8uFoVgPo7G62Bg,9258
16
16
  svg_ultralight/bounding_boxes/__init__.py,sha256=qUEn3r4s-1QNHaguhWhhaNfdP4tl_B6YEqxtiTFuzhQ,78
17
17
  svg_ultralight/bounding_boxes/bound_helpers.py,sha256=iCinp_kFsxi29gJEMnDZpKs13Fj1fj8SWqbbWO94UTI,7203
18
- svg_ultralight/bounding_boxes/padded_text_initializers.py,sha256=LytVTNwdkJvh914DXIzB4zfrbk563K30ODlk8BmuotA,8328
18
+ svg_ultralight/bounding_boxes/padded_text_initializers.py,sha256=7vH9eKFrH2d1EkLpealxW2v9Bp5_Juib4X82zpe3faY,8786
19
19
  svg_ultralight/bounding_boxes/supports_bounds.py,sha256=T7LGse58fDBgmlzupSC63C1ZMXjFbyzBTsTUaqD_4Sw,4513
20
20
  svg_ultralight/bounding_boxes/type_bound_collection.py,sha256=NAEpqo9H9ewhuLcOmBnMWUE0zQ1t4bvckovgvWy6hIo,2645
21
21
  svg_ultralight/bounding_boxes/type_bound_element.py,sha256=Sc-R0uXkb0aS8-OcyM5pDukKhFUka0G6KCp6LcYDcIU,2204
@@ -25,11 +25,10 @@ svg_ultralight/constructors/__init__.py,sha256=XLOInLhzMERWNnFAs-itMs-OZrBOpvQth
25
25
  svg_ultralight/constructors/new_element.py,sha256=kGRaVsT1yugADUCKz3NjFW_14Ts1M8UQeLPTarTXtBY,3529
26
26
  svg_ultralight/font_tools/__init__.py,sha256=NX3C0vvoB-G4S-h1f0NLWePjYAMMR37D1cl_G4WBjHc,83
27
27
  svg_ultralight/font_tools/comp_results.py,sha256=gFxdqY1D5z8MGt1UyWOK8O_t50AHgg-B846uWdzoLco,10687
28
- svg_ultralight/font_tools/font_info.py,sha256=-MEEM8Jslirevocv97RNRaArxaP3xeNiB7ZllKmXRjU,29886
29
- svg_ultralight/font_tools/globs.py,sha256=JdrrGMqDtD4WcY7YGUWV43DUW63RVev-x9vWqsQUhxU,119
28
+ svg_ultralight/font_tools/font_info.py,sha256=iH63Ey9zT5MXWmokcq51FPBCwF8cig9dMSIN7G76Qpg,29858
30
29
  svg_ultralight/strings/__init__.py,sha256=BMGhF1pulscIgkiYvZLr6kPRR0L4lW0jUNFxkul4_EM,295
31
30
  svg_ultralight/strings/svg_strings.py,sha256=FQNxNmMkR2M-gCFo_woQKXLgCHi3ncUlRMiaRR_a9nQ,1978
32
- svg_ultralight-0.45.6.dist-info/METADATA,sha256=lizhXDXGBSAm-VJD-ygcGbZ3mkmGARO5ssLw56A9llw,9052
33
- svg_ultralight-0.45.6.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
34
- svg_ultralight-0.45.6.dist-info/top_level.txt,sha256=se-6yqM_0Yg5orJKvKWdjQZ4iR4G_EjhL7oRgju-fdY,15
35
- svg_ultralight-0.45.6.dist-info/RECORD,,
31
+ svg_ultralight-0.47.0.dist-info/METADATA,sha256=Un6DiA1noLMt3jcL_nYZEfzoMXC5P9K9F8TsdTHGzxI,9052
32
+ svg_ultralight-0.47.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
33
+ svg_ultralight-0.47.0.dist-info/top_level.txt,sha256=se-6yqM_0Yg5orJKvKWdjQZ4iR4G_EjhL7oRgju-fdY,15
34
+ svg_ultralight-0.47.0.dist-info/RECORD,,
@@ -1,7 +0,0 @@
1
- """Global values for working with fonts.
2
-
3
- :author: Shay Hill
4
- :created: 2025-06-09
5
- """
6
-
7
- DEFAULT_FONT_SIZE = 12.0