MCPcopy Create free account
hub / github.com/SLiCAP/SLiCAP_python / svg_line_height

Function svg_line_height

SLiCAP/schematic/latex_label.py:125–147  ·  view source on GitHub ↗

Return the viewBox height (in SVG units) of a single-line LaTeX expression. Renders '$x$' once and caches the result. This gives the natural height of one line of math as produced by the pdflatex + pdf2svg pipeline, so callers can derive a scale factor without hard-coding pdf2svg'

()

Source from the content-addressed store, hash-verified

123
124
125def svg_line_height() -> float | None:
126 """
127 Return the viewBox height (in SVG units) of a single-line LaTeX expression.
128
129 Renders '$x$' once and caches the result. This gives the natural height
130 of one line of math as produced by the pdflatex + pdf2svg pipeline, so
131 callers can derive a scale factor without hard-coding pdf2svg's unit system.
132 Returns None when the pipeline is unavailable.
133 """
134 if not LATEX_AVAILABLE:
135 return None
136 global _reference_line_height
137 if _reference_line_height is not None:
138 return _reference_line_height
139 svg = _render_cached("x")
140 if svg is None:
141 return None
142 from PySide6.QtSvg import QSvgRenderer
143 from PySide6.QtCore import QByteArray
144 r = QSvgRenderer(QByteArray(svg))
145 if r.isValid() and r.viewBoxF().height() > 0:
146 _reference_line_height = r.viewBoxF().height()
147 return _reference_line_height
148
149
150# ── public API ────────────────────────────────────────────────────────────────

Callers 4

set_svgMethod · 0.85
_compute_natural_sizeMethod · 0.85
_compute_natural_sizeMethod · 0.85
_compute_natural_sizeMethod · 0.85

Calls 1

_render_cachedFunction · 0.85

Tested by

no test coverage detected