From b2d6cb58dcffbe297fecf07c2e8d8db5a0340c05 Mon Sep 17 00:00:00 2001 From: sitandr <60141933+sitandr@users.noreply.github.com> Date: Sat, 26 Aug 2023 18:36:52 +0300 Subject: Fix weak spacing broken in math (#1966) --- crates/typst-library/src/math/mod.rs | 9 +++++---- crates/typst/src/model/content.rs | 15 ++++++++++++++- 2 files changed, 19 insertions(+), 5 deletions(-) (limited to 'crates') diff --git a/crates/typst-library/src/math/mod.rs b/crates/typst-library/src/math/mod.rs index 1f87ff81..40df524f 100644 --- a/crates/typst-library/src/math/mod.rs +++ b/crates/typst-library/src/math/mod.rs @@ -418,11 +418,12 @@ impl LayoutMath for Content { return realized.layout_math(ctx); } - if let Some(children) = self.to_sequence() { + if self.is_sequence() { let mut bb = BehavedBuilder::new(); - for child in children { - bb.push(child.clone(), StyleChain::default()); - } + self.sequence_recursive_for_each(&mut |child: &Content| { + bb.push(child.clone(), StyleChain::default()) + }); + for (child, _) in bb.finish().0.iter() { child.layout_math(ctx)?; } diff --git a/crates/typst/src/model/content.rs b/crates/typst/src/model/content.rs index 0c79d02c..f1600f25 100644 --- a/crates/typst/src/model/content.rs +++ b/crates/typst/src/model/content.rs @@ -85,12 +85,25 @@ impl Content { /// Access the children if this is a sequence. pub fn to_sequence(&self) -> Option> { - if !self.is::() { + if !self.is_sequence() { return None; } Some(self.attrs.iter().filter_map(Attr::child)) } + pub fn is_sequence(&self) -> bool { + self.is::() + } + + /// Also auto expands sequence of sequences into flat sequence + pub fn sequence_recursive_for_each(&self, f: &mut impl FnMut(&Self)) { + if let Some(childs) = self.to_sequence() { + childs.for_each(|c| c.sequence_recursive_for_each(f)); + } else { + f(self); + } + } + /// Access the child and styles. pub fn to_styled(&self) -> Option<(&Content, &Styles)> { if !self.is::() { -- cgit v1.2.3