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'
()
| 123 | |
| 124 | |
| 125 | def 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 ──────────────────────────────────────────────────────────────── |
no test coverage detected