documents and typography: SVG sizes and frames read with the system's fonts, as drawn
CI / platforms (windows-latest) (push) Failing after 9s
CI / site (push) Successful in 23s
CI / crate (push) Failing after 12m18s
CI / platforms (ubuntu-24.04) (push) Canceled after 0s

This commit is contained in:
ZacharyZhang-NY committed 2026-10-12 11:55:54 -04:00
1 parent 8234fcdeb2
commit 50a59d2620
3 files changed
+12 -8

No files matched your search

+10 -6
View File
@@ -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<String, SharedString> {
flatten(&svg(&chart)?)
}
/// `svg` with markers and text as paths any reader draws.
pub(crate) fn flatten(svg: &str) -> Result<String, SharedString> {
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<String, SharedString> {
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);
+1 -1
View File
@@ -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,
+1 -1
View File
@@ -180,7 +180,7 @@ fn guarded<T>(lay: impl FnOnce() -> T) -> Result<T, MathError> {
/// `svg` reframed around its ink and layout box.
fn framed(svg: &str, width: f32, height: f32) -> Result<(String, Size<Pixels>), 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);