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

@@ -383,7 +383,7 @@ class FTTextInfo:
383
383
  @property
384
384
  def bpad(self) -> float:
385
385
  """Return the bottom padding for the text."""
386
- return self.descent - self.bbox.y2
386
+ return -self.descent - self.bbox.y2
387
387
 
388
388
  @property
389
389
  def lpad(self) -> float:
@@ -433,8 +433,8 @@ def get_padded_text_info(
433
433
  :param font_size: the font size to use.
434
434
  :param ascent: the ascent of the font. If not provided, it will be calculated
435
435
  from the font file.
436
- :param descent: the descent of the font. If not provided, it will be calculated
437
- from the font file.
436
+ :param descent: the descent of the font, usually a negative number. If not
437
+ provided, it will be calculated from the font file.
438
438
  :param y_bounds_reference: optional character or string to use as a reference
439
439
  for the ascent and descent. If provided, the ascent and descent will be the y
440
440
  extents of the capline reference. This argument is provided to mimic the
@@ -447,7 +447,7 @@ def get_padded_text_info(
447
447
  if y_bounds_reference:
448
448
  capline_info = FTTextInfo(font_info, y_bounds_reference, font_size)
449
449
  ascent = -capline_info.bbox.y
450
- descent = capline_info.bbox.y2
450
+ descent = -capline_info.bbox.y2
451
451
 
452
452
  return FTTextInfo(font_info, text, font_size, ascent, descent)
453
453
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: svg-ultralight
3
- Version: 0.40.1
3
+ Version: 0.41.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
@@ -24,12 +24,11 @@ svg_ultralight/constructors/__init__.py,sha256=XLOInLhzMERWNnFAs-itMs-OZrBOpvQth
24
24
  svg_ultralight/constructors/new_element.py,sha256=hRUW2hR_BTkthEqPClYV7-IeFe9iv2zwb6ehp1k1xDk,3475
25
25
  svg_ultralight/font_tools/__init__.py,sha256=NX3C0vvoB-G4S-h1f0NLWePjYAMMR37D1cl_G4WBjHc,83
26
26
  svg_ultralight/font_tools/comp_results.py,sha256=iEDbExO3D7ffo0NZxrqf-WjtzUCJZbdHmqwjjac4laY,10444
27
- svg_ultralight/font_tools/font_css.py,sha256=oKChLEwE18q-rKrt7hEkpBzGQBp8u9VWFxPpIKH67o4,2780
28
- svg_ultralight/font_tools/font_info.py,sha256=8bXdsbIY2rbZ3Q1UnxR3B4nPf31MZivS40mEOcCsb44,20849
27
+ svg_ultralight/font_tools/font_info.py,sha256=00iNrJwWH2-de9CbaG1TqulRFmp_3aOyjRAlqOpT0II,20878
29
28
  svg_ultralight/font_tools/globs.py,sha256=JdrrGMqDtD4WcY7YGUWV43DUW63RVev-x9vWqsQUhxU,119
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.40.1.dist-info/METADATA,sha256=ApD3fiKFCGDJNCBHNNo5wRrzoh5y_vz124GmnZnkAnQ,9022
33
- svg_ultralight-0.40.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
34
- svg_ultralight-0.40.1.dist-info/top_level.txt,sha256=se-6yqM_0Yg5orJKvKWdjQZ4iR4G_EjhL7oRgju-fdY,15
35
- svg_ultralight-0.40.1.dist-info/RECORD,,
31
+ svg_ultralight-0.41.0.dist-info/METADATA,sha256=jJ9sHbqg4zJ3WcCuAMbiGb69FEtUcpZappC5LeZYl3Y,9022
32
+ svg_ultralight-0.41.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
33
+ svg_ultralight-0.41.0.dist-info/top_level.txt,sha256=se-6yqM_0Yg5orJKvKWdjQZ4iR4G_EjhL7oRgju-fdY,15
34
+ svg_ultralight-0.41.0.dist-info/RECORD,,
@@ -1,82 +0,0 @@
1
- """Link local fonts as css in an svg file.
2
-
3
- :author: Shay Hill
4
- :created: 2025-06-04
5
- """
6
-
7
- # pyright: reportUnknownMemberType = false
8
- # pyright: reportAttributeAccessIssue = false
9
- # pyright: reportUnknownArgumentType = false
10
- # pyright: reportUnknownVariableType = false
11
- # pyright: reportUnknownParameterType = false
12
- # pyright: reportMissingTypeStubs = false
13
-
14
- from __future__ import annotations
15
-
16
- from pathlib import Path
17
- from typing import TYPE_CHECKING
18
-
19
- import cssutils
20
-
21
- from svg_ultralight.constructors import new_element
22
- from svg_ultralight.string_conversion import encode_to_css_class_name
23
-
24
- if TYPE_CHECKING:
25
- import os
26
-
27
- from lxml.etree import (
28
- _Element as EtreeElement, # pyright: ignore[reportPrivateUsage]
29
- )
30
-
31
-
32
- def _get_class_names_from_stylesheet(
33
- stylesheet: cssutils.css.CSSStyleSheet,
34
- ) -> list[str]:
35
- """Extract all class names from a given CSS stylesheet.
36
-
37
- :param stylesheet: A cssutils.css.CSSStyleSheet object.
38
- :return: A list of class names (without the leading dot).
39
- """
40
- class_names: list[str] = []
41
- for rule in stylesheet.cssRules:
42
- if rule.type == rule.STYLE_RULE:
43
- selectors = (s.strip() for s in rule.selectorText.split(","))
44
- class_names.extend(s[1:] for s in selectors if s.startswith("."))
45
- return class_names
46
-
47
-
48
- def add_svg_font_class(root: EtreeElement, font: str | os.PathLike[str]) -> str:
49
- """Add a css class for the font to the root element.
50
-
51
- :param root: The root element of the SVG document.
52
- :param font: Path to the font file.
53
- :return: The class name for the font, e.g., "bahnschrift_2e_ttf"
54
- """
55
- assert Path(font).exists()
56
- family_name = encode_to_css_class_name(Path(font).stem)
57
- class_name = encode_to_css_class_name(Path(font).name)
58
- style = root.find("style")
59
- if style is None:
60
- style = new_element("style", type="text/css")
61
- root.insert(0, style)
62
- css = style.text or ""
63
-
64
- stylesheet = cssutils.parseString(css)
65
- existing_class_names = _get_class_names_from_stylesheet(stylesheet)
66
- if class_name in existing_class_names:
67
- return class_name
68
-
69
- font_face_rule = cssutils.css.CSSFontFaceRule()
70
- font_face_rule.style = cssutils.css.CSSStyleDeclaration()
71
- font_face_rule.style["font-family"] = f'"{family_name}"'
72
- font_face_rule.style["src"] = rf"url('{Path(font).as_posix()}')"
73
- stylesheet.add(font_face_rule)
74
-
75
- style_rule = cssutils.css.CSSStyleRule(selectorText=f".{class_name}")
76
- style_rule.style = cssutils.css.CSSStyleDeclaration()
77
- style_rule.style["font-family"] = f'"{family_name}"'
78
- stylesheet.add(style_rule)
79
-
80
- style.text = stylesheet.cssText.decode("utf-8")
81
-
82
- return class_name