documents and typography: SVG sizes and frames read with the system's fonts, as drawn
This commit is contained in:
3 files changed
+12
-8
No files matched your search
@@ -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);
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in new issue
Block a user