From 010cc2effc2fd0e1c4e52d5c914cb4d74506bc0a Mon Sep 17 00:00:00 2001 From: Laurenz Date: Wed, 9 Nov 2022 18:16:59 +0100 Subject: New block spacing model --- library/src/math/mod.rs | 36 +++++++----------------------------- 1 file changed, 7 insertions(+), 29 deletions(-) (limited to 'library/src/math/mod.rs') diff --git a/library/src/math/mod.rs b/library/src/math/mod.rs index ae3c4a9a..bcf09c04 100644 --- a/library/src/math/mod.rs +++ b/library/src/math/mod.rs @@ -5,9 +5,8 @@ mod tex; use std::fmt::Write; use self::tex::{layout_tex, Texify}; -use crate::layout::BlockSpacing; use crate::prelude::*; -use crate::text::{FallbackList, FontFamily, TextNode}; +use crate::text::FontFamily; /// A piece of a mathematical formula. #[derive(Debug, Clone, Hash)] @@ -18,15 +17,8 @@ pub struct MathNode { pub display: bool, } -#[node(Show, Finalize, LayoutInline, Texify)] +#[node(Show, LayoutInline, Texify)] impl MathNode { - /// The spacing above display math. - #[property(resolve, shorthand(around))] - pub const ABOVE: Option = Some(Ratio::one().into()); - /// The spacing below display math. - #[property(resolve, shorthand(around))] - pub const BELOW: Option = Some(Ratio::one().into()); - fn field(&self, name: &str) -> Option { match name { "display" => Some(Value::Bool(self.display)), @@ -40,27 +32,13 @@ impl Show for MathNode { self.clone().pack() } - fn show(&self, _: Tracked, _: StyleChain) -> SourceResult { - Ok(self.clone().pack()) - } -} - -impl Finalize for MathNode { - fn finalize( - &self, - _: Tracked, - styles: StyleChain, - mut realized: Content, - ) -> SourceResult { - realized = realized.styled( - TextNode::FAMILY, - FallbackList(vec![FontFamily::new("NewComputerModernMath")]), - ); + fn show(&self, _: Tracked, styles: StyleChain) -> SourceResult { + let mut map = StyleMap::new(); + map.set_family(FontFamily::new("NewComputerModernMath"), styles); + let mut realized = self.clone().pack().styled_with_map(map); if self.display { - realized = realized - .aligned(Axes::with_x(Some(Align::Center.into()))) - .spaced(styles.get(Self::ABOVE), styles.get(Self::BELOW)) + realized = realized.aligned(Axes::with_x(Some(Align::Center.into()))) } Ok(realized) -- cgit v1.2.3