realize before layout_math (#637)

This commit is contained in:
_rqy 2023-04-07 16:30:34 +08:00 committed by GitHub
parent 1c324765e9
commit bb30911282
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 0 deletions

View File

@ -1,5 +1,6 @@
use ttf_parser::math::MathValue; use ttf_parser::math::MathValue;
use typst::font::{FontStyle, FontWeight}; use typst::font::{FontStyle, FontWeight};
use typst::model::realize;
use unicode_segmentation::UnicodeSegmentation; use unicode_segmentation::UnicodeSegmentation;
use super::*; use super::*;
@ -173,6 +174,10 @@ impl<'a, 'b, 'v> MathContext<'a, 'b, 'v> {
self.outer.chain(&self.local) self.outer.chain(&self.local)
} }
pub fn realize(&mut self, content: &Content) -> SourceResult<Option<Content>> {
realize(self.vt, content, self.outer.chain(&self.local))
}
pub fn style(&mut self, style: MathStyle) { pub fn style(&mut self, style: MathStyle) {
self.style_stack.push((self.style, self.size)); self.style_stack.push((self.style, self.size));
let base_size = TextElem::size_in(self.styles()) / self.style.size.factor(self); let base_size = TextElem::size_in(self.styles()) / self.style.size.factor(self);

View File

@ -342,6 +342,11 @@ impl LayoutMath for EquationElem {
impl LayoutMath for Content { impl LayoutMath for Content {
fn layout_math(&self, ctx: &mut MathContext) -> SourceResult<()> { 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() { if let Some(children) = self.to_sequence() {
for child in children { for child in children {
child.layout_math(ctx)?; child.layout_math(ctx)?;