summaryrefslogtreecommitdiff
path: root/crates/typst-layout/src/math
diff options
context:
space:
mode:
Diffstat (limited to 'crates/typst-layout/src/math')
-rw-r--r--crates/typst-layout/src/math/accent.rs6
-rw-r--r--crates/typst-layout/src/math/attach.rs12
-rw-r--r--crates/typst-layout/src/math/cancel.rs2
-rw-r--r--crates/typst-layout/src/math/frac.rs6
-rw-r--r--crates/typst-layout/src/math/lr.rs9
-rw-r--r--crates/typst-layout/src/math/mat.rs8
-rw-r--r--crates/typst-layout/src/math/mod.rs13
-rw-r--r--crates/typst-layout/src/math/root.rs3
-rw-r--r--crates/typst-layout/src/math/stretch.rs2
-rw-r--r--crates/typst-layout/src/math/text.rs2
-rw-r--r--crates/typst-layout/src/math/underover.rs20
11 files changed, 40 insertions, 43 deletions
diff --git a/crates/typst-layout/src/math/accent.rs b/crates/typst-layout/src/math/accent.rs
index 0ebe785f..951870d6 100644
--- a/crates/typst-layout/src/math/accent.rs
+++ b/crates/typst-layout/src/math/accent.rs
@@ -16,7 +16,7 @@ pub fn layout_accent(
styles: StyleChain,
) -> SourceResult<()> {
let cramped = style_cramped();
- let mut base = ctx.layout_into_fragment(elem.base(), styles.chain(&cramped))?;
+ let mut base = ctx.layout_into_fragment(&elem.base, styles.chain(&cramped))?;
// Try to replace a glyph with its dotless variant.
if let MathFragment::Glyph(glyph) = &mut base {
@@ -29,8 +29,8 @@ pub fn layout_accent(
let width = elem.size(styles).relative_to(base.width());
- let Accent(c) = elem.accent();
- let mut glyph = GlyphFragment::new(ctx, styles, *c, elem.span());
+ let Accent(c) = elem.accent;
+ let mut glyph = GlyphFragment::new(ctx, styles, c, elem.span());
// Try to replace accent glyph with flattened variant.
let flattened_base_height = scaled!(ctx, styles, flattened_accent_base_height);
diff --git a/crates/typst-layout/src/math/attach.rs b/crates/typst-layout/src/math/attach.rs
index 263fc5c6..8a67d53b 100644
--- a/crates/typst-layout/src/math/attach.rs
+++ b/crates/typst-layout/src/math/attach.rs
@@ -29,7 +29,7 @@ pub fn layout_attach(
let elem = merged.as_ref().unwrap_or(elem);
let stretch = stretch_size(styles, elem);
- let mut base = ctx.layout_into_fragment(elem.base(), styles)?;
+ let mut base = ctx.layout_into_fragment(&elem.base, styles)?;
let sup_style = style_for_superscript(styles);
let sup_style_chain = styles.chain(&sup_style);
let tl = elem.tl(sup_style_chain);
@@ -95,7 +95,7 @@ pub fn layout_primes(
ctx: &mut MathContext,
styles: StyleChain,
) -> SourceResult<()> {
- match *elem.count() {
+ match elem.count {
count @ 1..=4 => {
let c = match count {
1 => '′',
@@ -134,7 +134,7 @@ pub fn layout_scripts(
ctx: &mut MathContext,
styles: StyleChain,
) -> SourceResult<()> {
- let mut fragment = ctx.layout_into_fragment(elem.body(), styles)?;
+ let mut fragment = ctx.layout_into_fragment(&elem.body, styles)?;
fragment.set_limits(Limits::Never);
ctx.push(fragment);
Ok(())
@@ -148,7 +148,7 @@ pub fn layout_limits(
styles: StyleChain,
) -> SourceResult<()> {
let limits = if elem.inline(styles) { Limits::Always } else { Limits::Display };
- let mut fragment = ctx.layout_into_fragment(elem.body(), styles)?;
+ let mut fragment = ctx.layout_into_fragment(&elem.body, styles)?;
fragment.set_limits(limits);
ctx.push(fragment);
Ok(())
@@ -157,9 +157,9 @@ pub fn layout_limits(
/// Get the size to stretch the base to.
fn stretch_size(styles: StyleChain, elem: &Packed<AttachElem>) -> Option<Rel<Abs>> {
// Extract from an EquationElem.
- let mut base = elem.base();
+ let mut base = &elem.base;
while let Some(equation) = base.to_packed::<EquationElem>() {
- base = equation.body();
+ base = &equation.body;
}
base.to_packed::<StretchElem>().map(|stretch| stretch.size(styles))
diff --git a/crates/typst-layout/src/math/cancel.rs b/crates/typst-layout/src/math/cancel.rs
index 716832fb..9826397f 100644
--- a/crates/typst-layout/src/math/cancel.rs
+++ b/crates/typst-layout/src/math/cancel.rs
@@ -16,7 +16,7 @@ pub fn layout_cancel(
ctx: &mut MathContext,
styles: StyleChain,
) -> SourceResult<()> {
- let body = ctx.layout_into_fragment(elem.body(), styles)?;
+ let body = ctx.layout_into_fragment(&elem.body, styles)?;
// Preserve properties of body.
let body_class = body.class();
diff --git a/crates/typst-layout/src/math/frac.rs b/crates/typst-layout/src/math/frac.rs
index fdc3be17..63463d76 100644
--- a/crates/typst-layout/src/math/frac.rs
+++ b/crates/typst-layout/src/math/frac.rs
@@ -23,8 +23,8 @@ pub fn layout_frac(
layout_frac_like(
ctx,
styles,
- elem.num(),
- std::slice::from_ref(elem.denom()),
+ &elem.num,
+ std::slice::from_ref(&elem.denom),
false,
elem.span(),
)
@@ -37,7 +37,7 @@ pub fn layout_binom(
ctx: &mut MathContext,
styles: StyleChain,
) -> SourceResult<()> {
- layout_frac_like(ctx, styles, elem.upper(), elem.lower(), true, elem.span())
+ layout_frac_like(ctx, styles, &elem.upper, &elem.lower, true, elem.span())
}
/// Layout a fraction or binomial.
diff --git a/crates/typst-layout/src/math/lr.rs b/crates/typst-layout/src/math/lr.rs
index 2f4556fe..19176ee8 100644
--- a/crates/typst-layout/src/math/lr.rs
+++ b/crates/typst-layout/src/math/lr.rs
@@ -13,17 +13,16 @@ pub fn layout_lr(
ctx: &mut MathContext,
styles: StyleChain,
) -> SourceResult<()> {
- let mut body = elem.body();
-
// Extract from an EquationElem.
+ let mut body = &elem.body;
if let Some(equation) = body.to_packed::<EquationElem>() {
- body = equation.body();
+ body = &equation.body;
}
// Extract implicit LrElem.
if let Some(lr) = body.to_packed::<LrElem>() {
if lr.size(styles).is_one() {
- body = lr.body();
+ body = &lr.body;
}
}
@@ -100,7 +99,7 @@ pub fn layout_mid(
ctx: &mut MathContext,
styles: StyleChain,
) -> SourceResult<()> {
- let mut fragments = ctx.layout_into_fragments(elem.body(), styles)?;
+ let mut fragments = ctx.layout_into_fragments(&elem.body, styles)?;
for fragment in &mut fragments {
match fragment {
diff --git a/crates/typst-layout/src/math/mat.rs b/crates/typst-layout/src/math/mat.rs
index d28bb037..bf492902 100644
--- a/crates/typst-layout/src/math/mat.rs
+++ b/crates/typst-layout/src/math/mat.rs
@@ -27,7 +27,7 @@ pub fn layout_vec(
let frame = layout_vec_body(
ctx,
styles,
- elem.children(),
+ &elem.children,
elem.align(styles),
elem.gap(styles),
LeftRightAlternator::Right,
@@ -44,7 +44,7 @@ pub fn layout_mat(
styles: StyleChain,
) -> SourceResult<()> {
let augment = elem.augment(styles);
- let rows = elem.rows();
+ let rows = &elem.rows;
if let Some(aug) = &augment {
for &offset in &aug.hline.0 {
@@ -58,7 +58,7 @@ pub fn layout_mat(
}
}
- let ncols = elem.rows().first().map_or(0, |row| row.len());
+ let ncols = rows.first().map_or(0, |row| row.len());
for &offset in &aug.vline.0 {
if offset == 0 || offset.unsigned_abs() >= ncols {
@@ -97,7 +97,7 @@ pub fn layout_cases(
let frame = layout_vec_body(
ctx,
styles,
- elem.children(),
+ &elem.children,
FixedAlignment::Start,
elem.gap(styles),
LeftRightAlternator::None,
diff --git a/crates/typst-layout/src/math/mod.rs b/crates/typst-layout/src/math/mod.rs
index 62ecd172..06dc6653 100644
--- a/crates/typst-layout/src/math/mod.rs
+++ b/crates/typst-layout/src/math/mod.rs
@@ -632,7 +632,7 @@ fn layout_h(
ctx: &mut MathContext,
styles: StyleChain,
) -> SourceResult<()> {
- if let Spacing::Rel(rel) = elem.amount() {
+ if let Spacing::Rel(rel) = elem.amount {
if rel.rel.is_zero() {
ctx.push(MathFragment::Spacing(rel.abs.resolve(styles), elem.weak(styles)));
}
@@ -647,11 +647,10 @@ fn layout_class(
ctx: &mut MathContext,
styles: StyleChain,
) -> SourceResult<()> {
- let class = *elem.class();
- let style = EquationElem::set_class(Some(class)).wrap();
- let mut fragment = ctx.layout_into_fragment(elem.body(), styles.chain(&style))?;
- fragment.set_class(class);
- fragment.set_limits(Limits::for_class(class));
+ let style = EquationElem::set_class(Some(elem.class)).wrap();
+ let mut fragment = ctx.layout_into_fragment(&elem.body, styles.chain(&style))?;
+ fragment.set_class(elem.class);
+ fragment.set_limits(Limits::for_class(elem.class));
ctx.push(fragment);
Ok(())
}
@@ -663,7 +662,7 @@ fn layout_op(
ctx: &mut MathContext,
styles: StyleChain,
) -> SourceResult<()> {
- let fragment = ctx.layout_into_fragment(elem.text(), styles)?;
+ let fragment = ctx.layout_into_fragment(&elem.text, styles)?;
let italics = fragment.italics_correction();
let accent_attach = fragment.accent_attach();
let text_like = fragment.is_text_like();
diff --git a/crates/typst-layout/src/math/root.rs b/crates/typst-layout/src/math/root.rs
index 4e5d844f..a6b5c03d 100644
--- a/crates/typst-layout/src/math/root.rs
+++ b/crates/typst-layout/src/math/root.rs
@@ -18,7 +18,6 @@ pub fn layout_root(
styles: StyleChain,
) -> SourceResult<()> {
let index = elem.index(styles);
- let radicand = elem.radicand();
let span = elem.span();
let gap = scaled!(
@@ -36,7 +35,7 @@ pub fn layout_root(
let radicand = {
let cramped = style_cramped();
let styles = styles.chain(&cramped);
- let run = ctx.layout_into_run(radicand, styles)?;
+ let run = ctx.layout_into_run(&elem.radicand, styles)?;
let multiline = run.is_multiline();
let mut radicand = run.into_fragment(styles).into_frame();
if multiline {
diff --git a/crates/typst-layout/src/math/stretch.rs b/crates/typst-layout/src/math/stretch.rs
index 4bc5a926..6379bdb2 100644
--- a/crates/typst-layout/src/math/stretch.rs
+++ b/crates/typst-layout/src/math/stretch.rs
@@ -21,7 +21,7 @@ pub fn layout_stretch(
ctx: &mut MathContext,
styles: StyleChain,
) -> SourceResult<()> {
- let mut fragment = ctx.layout_into_fragment(elem.body(), styles)?;
+ let mut fragment = ctx.layout_into_fragment(&elem.body, styles)?;
stretch_fragment(
ctx,
styles,
diff --git a/crates/typst-layout/src/math/text.rs b/crates/typst-layout/src/math/text.rs
index eb30373d..7e849c46 100644
--- a/crates/typst-layout/src/math/text.rs
+++ b/crates/typst-layout/src/math/text.rs
@@ -20,7 +20,7 @@ pub fn layout_text(
ctx: &mut MathContext,
styles: StyleChain,
) -> SourceResult<()> {
- let text = elem.text();
+ let text = &elem.text;
let span = elem.span();
let mut chars = text.chars();
let math_size = EquationElem::size_in(styles);
diff --git a/crates/typst-layout/src/math/underover.rs b/crates/typst-layout/src/math/underover.rs
index e5599638..7b3617c3 100644
--- a/crates/typst-layout/src/math/underover.rs
+++ b/crates/typst-layout/src/math/underover.rs
@@ -32,7 +32,7 @@ pub fn layout_underline(
ctx: &mut MathContext,
styles: StyleChain,
) -> SourceResult<()> {
- layout_underoverline(ctx, styles, elem.body(), elem.span(), Position::Under)
+ layout_underoverline(ctx, styles, &elem.body, elem.span(), Position::Under)
}
/// Lays out an [`OverlineElem`].
@@ -42,7 +42,7 @@ pub fn layout_overline(
ctx: &mut MathContext,
styles: StyleChain,
) -> SourceResult<()> {
- layout_underoverline(ctx, styles, elem.body(), elem.span(), Position::Over)
+ layout_underoverline(ctx, styles, &elem.body, elem.span(), Position::Over)
}
/// Lays out an [`UnderbraceElem`].
@@ -55,7 +55,7 @@ pub fn layout_underbrace(
layout_underoverspreader(
ctx,
styles,
- elem.body(),
+ &elem.body,
&elem.annotation(styles),
'⏟',
BRACE_GAP,
@@ -74,7 +74,7 @@ pub fn layout_overbrace(
layout_underoverspreader(
ctx,
styles,
- elem.body(),
+ &elem.body,
&elem.annotation(styles),
'⏞',
BRACE_GAP,
@@ -93,7 +93,7 @@ pub fn layout_underbracket(
layout_underoverspreader(
ctx,
styles,
- elem.body(),
+ &elem.body,
&elem.annotation(styles),
'⎵',
BRACKET_GAP,
@@ -112,7 +112,7 @@ pub fn layout_overbracket(
layout_underoverspreader(
ctx,
styles,
- elem.body(),
+ &elem.body,
&elem.annotation(styles),
'⎴',
BRACKET_GAP,
@@ -131,7 +131,7 @@ pub fn layout_underparen(
layout_underoverspreader(
ctx,
styles,
- elem.body(),
+ &elem.body,
&elem.annotation(styles),
'⏝',
PAREN_GAP,
@@ -150,7 +150,7 @@ pub fn layout_overparen(
layout_underoverspreader(
ctx,
styles,
- elem.body(),
+ &elem.body,
&elem.annotation(styles),
'⏜',
PAREN_GAP,
@@ -169,7 +169,7 @@ pub fn layout_undershell(
layout_underoverspreader(
ctx,
styles,
- elem.body(),
+ &elem.body,
&elem.annotation(styles),
'⏡',
SHELL_GAP,
@@ -188,7 +188,7 @@ pub fn layout_overshell(
layout_underoverspreader(
ctx,
styles,
- elem.body(),
+ &elem.body,
&elem.annotation(styles),
'⏠',
SHELL_GAP,