diff options
| author | Laurenz <laurmaedje@gmail.com> | 2023-03-29 19:21:01 +0200 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2023-03-29 19:21:01 +0200 |
| commit | 24e26b8c771f09965422cf7b0acde3d694811f7e (patch) | |
| tree | 6df2866174723e8ace3f97bbb91967c8fa975174 /library | |
| parent | e13fc04c3e973da60d5f4e9cc6fc38105cd2ddf9 (diff) | |
Fix styling of text operators
Diffstat (limited to 'library')
| -rw-r--r-- | library/src/math/ctx.rs | 24 | ||||
| -rw-r--r-- | library/src/math/mod.rs | 3 | ||||
| -rw-r--r-- | library/src/math/op.rs | 5 |
3 files changed, 16 insertions, 16 deletions
diff --git a/library/src/math/ctx.rs b/library/src/math/ctx.rs index aed826b5..904c4333 100644 --- a/library/src/math/ctx.rs +++ b/library/src/math/ctx.rs @@ -124,11 +124,11 @@ impl<'a, 'b, 'v> MathContext<'a, 'b, 'v> { .into_frame()) } - pub fn layout_text(&mut self, elem: &TextElem) -> SourceResult<()> { + pub fn layout_text(&mut self, elem: &TextElem) -> SourceResult<MathFragment> { let text = elem.text(); let span = elem.span(); let mut chars = text.chars(); - if let Some(glyph) = chars + let fragment = if let Some(glyph) = chars .next() .filter(|_| chars.next().is_none()) .map(|c| self.style.styled_char(c)) @@ -139,9 +139,9 @@ impl<'a, 'b, 'v> MathContext<'a, 'b, 'v> { && glyph.class == Some(MathClass::Large) { let height = scaled!(self, display_operator_min_height); - self.push(glyph.stretch_vertical(self, height, Abs::zero())); + glyph.stretch_vertical(self, height, Abs::zero()).into() } else { - self.push(glyph); + glyph.into() } } else if text.chars().all(|c| c.is_ascii_digit()) { // Numbers aren't that difficult. @@ -151,7 +151,7 @@ impl<'a, 'b, 'v> MathContext<'a, 'b, 'v> { fragments.push(GlyphFragment::new(self, c, span).into()); } let frame = MathRow::new(fragments).to_frame(self); - self.push(FrameFragment::new(self, frame)); + FrameFragment::new(self, frame).into() } else { // Anything else is handled by Typst's standard text layout. let spaced = text.graphemes(true).count() > 1; @@ -161,14 +161,12 @@ impl<'a, 'b, 'v> MathContext<'a, 'b, 'v> { } let text: EcoString = text.chars().map(|c| style.styled_char(c)).collect(); let frame = self.layout_content(&TextElem::packed(text).spanned(span))?; - self.push( - FrameFragment::new(self, frame) - .with_class(MathClass::Alphabetic) - .with_spaced(spaced), - ); - } - - Ok(()) + FrameFragment::new(self, frame) + .with_class(MathClass::Alphabetic) + .with_spaced(spaced) + .into() + }; + Ok(fragment) } pub fn styles(&self) -> StyleChain { diff --git a/library/src/math/mod.rs b/library/src/math/mod.rs index b4a5b156..286d189a 100644 --- a/library/src/math/mod.rs +++ b/library/src/math/mod.rs @@ -331,7 +331,8 @@ impl LayoutMath for Content { } if let Some(elem) = self.to::<TextElem>() { - ctx.layout_text(elem)?; + let fragment = ctx.layout_text(elem)?; + ctx.push(fragment); return Ok(()); } diff --git a/library/src/math/op.rs b/library/src/math/op.rs index e8db0c5d..2d8266cc 100644 --- a/library/src/math/op.rs +++ b/library/src/math/op.rs @@ -35,9 +35,10 @@ pub struct OpElem { impl LayoutMath for OpElem { fn layout_math(&self, ctx: &mut MathContext) -> SourceResult<()> { - let frame = ctx.layout_content(&TextElem::packed(self.text()))?; + let fragment = + ctx.layout_text(&TextElem::new(self.text()).spanned(self.span()))?; ctx.push( - FrameFragment::new(ctx, frame) + FrameFragment::new(ctx, fragment.to_frame()) .with_class(MathClass::Large) .with_limits(self.limits(ctx.styles())), ); |
