Typography: a formula picture is as wide as its formula (px, not pt)
CI / site (push) Successful in 36s
CI / platforms (windows-latest) (push) Successful in 4m59s
CI / crate (push) Failing after 12m49s
CI / platforms (ubuntu-24.04) (push) Canceled after 0s

This commit is contained in:
ZacharyZhang-NY committed 2026-10-18 23:00:24 -04:00
1 parent dceca9f3c6
commit e095f06689
3 files changed
+31 -6

No files matched your search

+11 -5
View File
@@ -166,7 +166,9 @@ fn laid(formula: &Formula) -> Result<(String, f32, f32), MathError> {
(list.width * font, (list.height + list.depth) * font, svg)
})?;
let (width, height, svg) = typeset;
Ok((svg, width as f32, height as f32))
let (width, height) = (width as f32, height as f32);
// RaTeX sizes its svg in pt; px keeps one unit.
Ok((wrapped(&svg, [0.0, 0.0, width, height])?, width, height))
}
/// Runs RaTeX's layout; a panic becomes an error.
@@ -187,18 +189,22 @@ fn framed(svg: &str, width: f32, height: f32) -> Result<(String, Size<Pixels>),
let top = ink.top().min(0.0);
let right = ink.right().max(width);
let bottom = ink.bottom().max(height);
let (w, h) = (right - left, bottom - top);
Ok((wrapped(svg, [left, top, w, h])?, size(px(w), px(h))))
}
/// `svg`'s drawing under a root viewing `[left, top, w, h]` in px.
fn wrapped(svg: &str, [left, top, w, h]: [f32; 4]) -> Result<String, MathError> {
let open = svg
.find('>')
.ok_or_else(|| MathError::said("RaTeX wrote no svg tag"))?;
let close = svg
.rfind("</svg>")
.ok_or_else(|| MathError::said("RaTeX left the svg open"))?;
let (w, h) = (right - left, bottom - top);
let reframed = format!(
Ok(format!(
"<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"{left} {top} {w} {h}\" width=\"{w}\" height=\"{h}\">{}</svg>",
&svg[open + 1..close]
);
Ok((reframed, size(px(w), px(h))))
))
}
/// The asset key for `source` at `font` in `window`.