From bb30911282a44dd00def88190055d7637c6382d7 Mon Sep 17 00:00:00 2001 From: _rqy Date: Fri, 7 Apr 2023 16:30:34 +0800 Subject: [PATCH] realize before layout_math (#637) --- library/src/math/ctx.rs | 5 +++++ library/src/math/mod.rs | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/library/src/math/ctx.rs b/library/src/math/ctx.rs index bad0fe5ab..1a51a8f4a 100644 --- a/library/src/math/ctx.rs +++ b/library/src/math/ctx.rs @@ -1,5 +1,6 @@ use ttf_parser::math::MathValue; use typst::font::{FontStyle, FontWeight}; +use typst::model::realize; use unicode_segmentation::UnicodeSegmentation; use super::*; @@ -173,6 +174,10 @@ impl<'a, 'b, 'v> MathContext<'a, 'b, 'v> { self.outer.chain(&self.local) } + pub fn realize(&mut self, content: &Content) -> SourceResult> { + realize(self.vt, content, self.outer.chain(&self.local)) + } + pub fn style(&mut self, style: MathStyle) { self.style_stack.push((self.style, self.size)); let base_size = TextElem::size_in(self.styles()) / self.style.size.factor(self); diff --git a/library/src/math/mod.rs b/library/src/math/mod.rs index ac9b4eccc..3085b1ae0 100644 --- a/library/src/math/mod.rs +++ b/library/src/math/mod.rs @@ -342,6 +342,11 @@ impl LayoutMath for EquationElem { impl LayoutMath for Content { fn layout_math(&self, ctx: &mut MathContext) -> SourceResult<()> { + if let Some(realized) = ctx.realize(self)? { + realized.layout_math(ctx)?; + return Ok(()); + } + if let Some(children) = self.to_sequence() { for child in children { child.layout_math(ctx)?;