diff --git a/src/documents/diagram.rs b/src/documents/diagram.rs index 8904066..e4bea73 100644 --- a/src/documents/diagram.rs +++ b/src/documents/diagram.rs @@ -54,7 +54,7 @@ impl Asset for Drawer { let renderer = cx.svg_renderer(); async move { let svg = svg(&chart)?; - let tree = usvg::Tree::from_data(svg.as_bytes(), &usvg::Options::default()) + let tree = usvg::Tree::from_data(svg.as_bytes(), &options()) .map_err(|error| SharedString::from(format!("{error}")))?; let shape = size(px(tree.size().width()), px(tree.size().height())); let picture = renderer @@ -107,13 +107,17 @@ pub fn diagram_svg(source: &str) -> Result { flatten(&svg(&chart)?) } -/// `svg` with markers and text as paths any reader draws. -pub(crate) fn flatten(svg: &str) -> Result { - let options = usvg::Options { +/// usvg reading with the system's fonts. +pub(crate) fn options() -> usvg::Options<'static> { + usvg::Options { fontdb: fonts(), ..usvg::Options::default() - }; - let tree = usvg::Tree::from_data(svg.as_bytes(), &options) + } +} + +/// `svg` with markers and text as paths any reader draws. +pub(crate) fn flatten(svg: &str) -> Result { + let tree = usvg::Tree::from_data(svg.as_bytes(), &options()) .map_err(|error| SharedString::from(format!("{error}")))?; // A letter without a font vanishes: say so. let (mut kept, mut lost) = (0, 0); diff --git a/src/documents/mod.rs b/src/documents/mod.rs index 8f33f90..254ada7 100644 --- a/src/documents/mod.rs +++ b/src/documents/mod.rs @@ -33,8 +33,8 @@ pub(crate) use blocks::source; pub use blocks::{Align, BlockData, BlockEditor, BlockEvent, BlockKind, Media}; pub use contents::outline; pub use counts::{ReadingTime, WordCount}; -pub(crate) use diagram::flatten; pub use diagram::{Diagram, diagram_svg}; +pub(crate) use diagram::{flatten, options as svg_options}; pub use document::{ Attachment, DocumentEvent, DocumentHeading, DocumentLook, LARGEST_READ, MarkdownDocument, TableEdit, TableRefusal, diff --git a/src/typography/math.rs b/src/typography/math.rs index 87bf6ed..95b9655 100644 --- a/src/typography/math.rs +++ b/src/typography/math.rs @@ -180,7 +180,7 @@ fn guarded(lay: impl FnOnce() -> T) -> Result { /// `svg` reframed around its ink and layout box. fn framed(svg: &str, width: f32, height: f32) -> Result<(String, Size), MathError> { - let tree = usvg::Tree::from_data(svg.as_bytes(), &usvg::Options::default()) + let tree = usvg::Tree::from_data(svg.as_bytes(), &crate::documents::svg_options()) .map_err(|error| MathError::said(format!("{error}")))?; let ink = tree.root().abs_stroke_bounding_box(); let left = ink.left().min(0.0);