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

@@ -16,6 +16,7 @@ from svg_ultralight.bounding_boxes.type_bound_element import BoundElement
16
16
  from svg_ultralight.bounding_boxes.type_bounding_box import BoundingBox, HasBoundingBox
17
17
  from svg_ultralight.bounding_boxes.type_padded_text import PaddedText
18
18
  from svg_ultralight.constructors import new_element
19
+ from svg_ultralight.layout import PadArg, expand_pad_arg
19
20
 
20
21
  if TYPE_CHECKING:
21
22
  import os
@@ -94,19 +95,6 @@ def new_bound_union(*blems: SupportsBounds | EtreeElement) -> BoundElement:
94
95
  return BoundElement(group, bbox)
95
96
 
96
97
 
97
- def _expand_pad(pad: float | tuple[float, ...]) -> tuple[float, float, float, float]:
98
- """Expand a float pad argument into a 4-tuple."""
99
- if isinstance(pad, (int, float)):
100
- return pad, pad, pad, pad
101
- if len(pad) == 1:
102
- return pad[0], pad[0], pad[0], pad[0]
103
- if len(pad) == 2:
104
- return pad[0], pad[1], pad[0], pad[1]
105
- if len(pad) == 3:
106
- return pad[0], pad[1], pad[2], pad[1]
107
- return pad[0], pad[1], pad[2], pad[3]
108
-
109
-
110
98
  def cut_bbox(
111
99
  bbox: SupportsBounds,
112
100
  *,
@@ -133,7 +121,7 @@ def cut_bbox(
133
121
  return BoundingBox(x, y, width, height)
134
122
 
135
123
 
136
- def pad_bbox(bbox: SupportsBounds, pad: float | tuple[float, ...]) -> BoundingBox:
124
+ def pad_bbox(bbox: SupportsBounds, pad: PadArg) -> BoundingBox:
137
125
  """Return a new bounding box with padding.
138
126
 
139
127
  :param bbox: the original bounding box or bounded element.
@@ -146,7 +134,7 @@ def pad_bbox(bbox: SupportsBounds, pad: float | tuple[float, ...]) -> BoundingBo
146
134
  len = 4 : 0, 1, 2, 3
147
135
  :return: a new bounding box with padding applied.
148
136
  """
149
- top, right, bottom, left = _expand_pad(pad)
137
+ top, right, bottom, left = expand_pad_arg(pad)
150
138
  return cut_bbox(
151
139
  bbox, x=bbox.x - left, y=bbox.y - top, x2=bbox.x2 + right, y2=bbox.y2 + bottom
152
140
  )
@@ -49,6 +49,7 @@ DEFAULT_Y_BOUNDS_REFERENCE = "{[|gjpqyf"
49
49
  # element.
50
50
  DEFAULT_FONT_SIZE_FOR_PAD_TEXT = 12.0 # Default font size for pad_text if not specified
51
51
 
52
+
52
53
  def pad_text(
53
54
  inkscape: str | os.PathLike[str],
54
55
  text_elem: EtreeElement,
@@ -80,7 +81,7 @@ def pad_text(
80
81
  if font is not None:
81
82
  _ = update_element(text_elem, **get_svg_font_attributes(font))
82
83
  if "font-size" not in text_elem.attrib:
83
- text_elem.attrib["font-size"] = format_number(DEFAULT_FONT_SIZE)
84
+ text_elem.attrib["font-size"] = format_number(DEFAULT_FONT_SIZE_FOR_PAD_TEXT)
84
85
  rmargin_ref = deepcopy(text_elem)
85
86
  capline_ref = deepcopy(text_elem)
86
87
  _ = rmargin_ref.attrib.pop("id", None)
@@ -123,7 +123,15 @@ if TYPE_CHECKING:
123
123
  logging.getLogger("fontTools").setLevel(logging.ERROR)
124
124
 
125
125
 
126
- _ESCAPE_CHARS = {"&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;", "'": "&apos;"}
126
+ _ESCAPE_CHARS = {
127
+ "&": "&amp;",
128
+ "<": "&lt;",
129
+ ">": "&gt;",
130
+ '"': "&quot;",
131
+ "'": "&apos;",
132
+ "{": "&#123", # valid, but stops MS File Explorer from thumbnailing an svg
133
+ "}": "&#125", # valid, but stops MS File Explorer from thumbnailing an svg
134
+ }
127
135
 
128
136
 
129
137
  def _sanitize_svg_data_text(text: str) -> str:
@@ -376,8 +384,8 @@ class FTFontInfo:
376
384
  :param dx: An optional x translation to apply to the glyph.
377
385
  :return: The svg path data for the character.
378
386
  """
387
+ glyph_name = self.get_glyph_name(char)
379
388
  glyph_set = self.font.getGlyphSet()
380
- glyph_name = self.font.getBestCmap().get(ord(char))
381
389
  path_pen = PathPen(glyph_set)
382
390
  _ = glyph_set[glyph_name].draw(path_pen)
383
391
  svgd = path_pen.svgd
@@ -397,8 +405,8 @@ class FTFontInfo:
397
405
  same, but when they disagree, this method is more accurate. Additionally,
398
406
  some fonts do not have a glyf table, so this method is more robust.
399
407
  """
408
+ glyph_name = self.get_glyph_name(char)
400
409
  glyph_set = self.font.getGlyphSet()
401
- glyph_name = self.font.getBestCmap().get(ord(char))
402
410
  bounds_pen = BoundsPen(glyph_set)
403
411
  _ = glyph_set[glyph_name].draw(bounds_pen)
404
412
  pen_bounds = cast("None | tuple[int, int, int, int]", bounds_pen.bounds)
@@ -1,9 +1,9 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: svg-ultralight
3
- Version: 0.47.0
3
+ Version: 0.48.0
4
4
  Summary: a sensible way to create svg files with Python
5
5
  Author-email: Shay Hill <shay_public@hotmail.com>
6
- License: MIT
6
+ License-Expression: MIT
7
7
  Requires-Python: >=3.9
8
8
  Description-Content-Type: text/markdown
9
9
  Requires-Dist: cssutils
@@ -14,8 +14,8 @@ svg_ultralight/string_conversion.py,sha256=NWguHAmuKWON7Fh2EkVDfMIwp-jk6k7SW8hAU
14
14
  svg_ultralight/transformations.py,sha256=q-9GC01fh8vXyddjpDlal9BfebMuMWGl46ubg-0FalU,4510
15
15
  svg_ultralight/unit_conversion.py,sha256=g07nhzXdjPvGcJmkhLdFbeDLrSmbI8uFoVgPo7G62Bg,9258
16
16
  svg_ultralight/bounding_boxes/__init__.py,sha256=qUEn3r4s-1QNHaguhWhhaNfdP4tl_B6YEqxtiTFuzhQ,78
17
- svg_ultralight/bounding_boxes/bound_helpers.py,sha256=iCinp_kFsxi29gJEMnDZpKs13Fj1fj8SWqbbWO94UTI,7203
18
- svg_ultralight/bounding_boxes/padded_text_initializers.py,sha256=7vH9eKFrH2d1EkLpealxW2v9Bp5_Juib4X82zpe3faY,8786
17
+ svg_ultralight/bounding_boxes/bound_helpers.py,sha256=fu1_AluqnILYgbfzde_tBEqEpFTNRBmWBo_5qz_hUIs,6772
18
+ svg_ultralight/bounding_boxes/padded_text_initializers.py,sha256=Bk0xyOXcClMVXZee_1YFiza_aVL9KZax7BIPNBsQqfw,8801
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,10 +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=iH63Ey9zT5MXWmokcq51FPBCwF8cig9dMSIN7G76Qpg,29858
28
+ svg_ultralight/font_tools/font_info.py,sha256=rDaKT9FTZr6OgWntoObQxAxM23n4Gz6vRJLc0yZ90u8,30023
29
29
  svg_ultralight/strings/__init__.py,sha256=BMGhF1pulscIgkiYvZLr6kPRR0L4lW0jUNFxkul4_EM,295
30
30
  svg_ultralight/strings/svg_strings.py,sha256=FQNxNmMkR2M-gCFo_woQKXLgCHi3ncUlRMiaRR_a9nQ,1978
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,,
31
+ svg_ultralight-0.48.0.dist-info/METADATA,sha256=XtJST6sTXMexQOq57fILqtfJoc1G_4zbgLQiLoQNKQs,9063
32
+ svg_ultralight-0.48.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
33
+ svg_ultralight-0.48.0.dist-info/top_level.txt,sha256=se-6yqM_0Yg5orJKvKWdjQZ4iR4G_EjhL7oRgju-fdY,15
34
+ svg_ultralight-0.48.0.dist-info/RECORD,,