typography and documents: formula and diagram SVG for export; a diagram label without a font is an error
This commit is contained in:
5 files changed
+100
-3
No files matched your search
@@ -116,6 +116,18 @@ impl Asset for Typesetter {
|
||||
}
|
||||
}
|
||||
|
||||
/// `source` as black outlined SVG, for export.
|
||||
pub fn formula_svg(source: &str, display: bool) -> Result<String, MathError> {
|
||||
let formula = Formula {
|
||||
source: source.to_owned().into(),
|
||||
display,
|
||||
rgba: 0x0000_00ff,
|
||||
font: 1600,
|
||||
scale: 100,
|
||||
};
|
||||
svg(&formula).map(|(svg, _)| svg)
|
||||
}
|
||||
|
||||
/// The formula as outlined SVG holding all ink; its size.
|
||||
fn svg(formula: &Formula) -> Result<(String, Size<Pixels>), MathError> {
|
||||
let ast = parsed(&formula.source)?;
|
||||
|
||||
@@ -177,3 +177,11 @@ fn a_shared_formula_stays_until_its_last_holder_leaves(cx: &mut gpui::TestAppCon
|
||||
flush(cx);
|
||||
assert!(!cached("c^2", cx), "the last holder freed it");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_exported_formula_is_black_outlines() {
|
||||
let svg = formula_svg(r"\sqrt{x}", true).expect("typesets");
|
||||
assert!(svg.starts_with("<svg") && !svg.contains("<text"), "{svg}");
|
||||
assert!(svg.contains("0,0,0"), "black: {svg}");
|
||||
assert!(formula_svg(r"\frac{", false).is_err());
|
||||
}
|
||||
@@ -26,7 +26,7 @@ pub use formatted::{
|
||||
pub use inline::{Blockquote, Code, Highlight, Kbd, KbdCombo};
|
||||
pub use link::{ExternalLink, Link};
|
||||
pub(crate) use math::failed;
|
||||
pub use math::{Latex, MathError};
|
||||
pub use math::{Latex, MathError, formula_svg};
|
||||
pub use rolling::AnimatedNumber;
|
||||
pub use select::SelectableText;
|
||||
pub use text::{Caption, Heading, Label, Overline, Paragraph, Subtitle, Title, literal, tabular};
|
||||
Reference in new issue
Block a user