summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax <max@mkor.je>2025-06-04 10:14:24 +0000
committerGitHub <noreply@github.com>2025-06-04 10:14:24 +0000
commitaee99408e1cb6e825992a43399597f5d1a937230 (patch)
tree9220c4d669b5039169c87f704313cc6ba3a51819
parent1de2095f67c9719a973868618c3548dd6083f534 (diff)
Apply short fall consistently in math when stretching (#6377)
-rw-r--r--crates/typst-layout/src/math/accent.rs2
-rw-r--r--crates/typst-layout/src/math/frac.rs4
-rw-r--r--crates/typst-layout/src/math/fragment.rs12
-rw-r--r--crates/typst-layout/src/math/mat.rs4
-rw-r--r--crates/typst-layout/src/math/root.rs2
-rw-r--r--crates/typst-layout/src/math/stretch.rs11
-rw-r--r--crates/typst-layout/src/math/text.rs2
-rw-r--r--crates/typst-layout/src/math/underover.rs2
-rw-r--r--tests/ref/gradient-math-conic.pngbin1721 -> 1642 bytes
-rw-r--r--tests/ref/gradient-math-dir.pngbin2615 -> 2575 bytes
-rw-r--r--tests/ref/gradient-math-mat.pngbin1560 -> 1557 bytes
-rw-r--r--tests/ref/gradient-math-misc.pngbin2993 -> 3138 bytes
-rw-r--r--tests/ref/gradient-math-radial.pngbin1641 -> 1606 bytes
-rw-r--r--tests/ref/issue-1617-mat-align.pngbin3354 -> 3335 bytes
-rw-r--r--tests/ref/issue-3774-math-call-empty-2d-args.pngbin1315 -> 1334 bytes
-rw-r--r--tests/ref/math-accent-bottom-high-base.pngbin572 -> 567 bytes
-rw-r--r--tests/ref/math-accent-bottom-wide-base.pngbin359 -> 351 bytes
-rw-r--r--tests/ref/math-accent-wide-base.pngbin510 -> 506 bytes
-rw-r--r--tests/ref/math-cases-gap.pngbin340 -> 354 bytes
-rw-r--r--tests/ref/math-cases-linebreaks.pngbin506 -> 492 bytes
-rw-r--r--tests/ref/math-cases.pngbin1281 -> 1228 bytes
-rw-r--r--tests/ref/math-mat-align-explicit-alternating.pngbin1035 -> 927 bytes
-rw-r--r--tests/ref/math-mat-align-explicit-left.pngbin989 -> 903 bytes
-rw-r--r--tests/ref/math-mat-align-explicit-mixed.pngbin2523 -> 2454 bytes
-rw-r--r--tests/ref/math-mat-align-explicit-right.pngbin976 -> 875 bytes
-rw-r--r--tests/ref/math-mat-align-implicit.pngbin1046 -> 954 bytes
-rw-r--r--tests/ref/math-mat-align-signed-numbers.pngbin2036 -> 2024 bytes
-rw-r--r--tests/ref/math-mat-align.pngbin1564 -> 1531 bytes
-rw-r--r--tests/ref/math-mat-augment-set.pngbin1810 -> 1714 bytes
-rw-r--r--tests/ref/math-mat-augment.pngbin3631 -> 3563 bytes
-rw-r--r--tests/ref/math-mat-baseline.pngbin818 -> 816 bytes
-rw-r--r--tests/ref/math-mat-gap.pngbin496 -> 526 bytes
-rw-r--r--tests/ref/math-mat-gaps.pngbin1309 -> 1311 bytes
-rw-r--r--tests/ref/math-mat-linebreaks.pngbin651 -> 648 bytes
-rw-r--r--tests/ref/math-mat-sparse.pngbin882 -> 956 bytes
-rw-r--r--tests/ref/math-mat-spread.pngbin1814 -> 1796 bytes
-rw-r--r--tests/ref/math-shorthands.pngbin1231 -> 1173 bytes
-rw-r--r--tests/ref/math-vec-align-explicit-alternating.pngbin1035 -> 927 bytes
-rw-r--r--tests/ref/math-vec-align.pngbin1098 -> 1126 bytes
-rw-r--r--tests/ref/math-vec-gap.pngbin420 -> 436 bytes
-rw-r--r--tests/ref/math-vec-linebreaks.pngbin651 -> 648 bytes
-rw-r--r--tests/ref/math-vec-wide.pngbin620 -> 630 bytes
42 files changed, 15 insertions, 24 deletions
diff --git a/crates/typst-layout/src/math/accent.rs b/crates/typst-layout/src/math/accent.rs
index 53dfdf05..30160646 100644
--- a/crates/typst-layout/src/math/accent.rs
+++ b/crates/typst-layout/src/math/accent.rs
@@ -46,7 +46,7 @@ pub fn layout_accent(
// wide in many case.
let width = elem.size(styles).relative_to(base.width());
let short_fall = ACCENT_SHORT_FALL.at(glyph.font_size);
- let variant = glyph.stretch_horizontal(ctx, width, short_fall);
+ let variant = glyph.stretch_horizontal(ctx, width - short_fall);
let accent = variant.frame;
let accent_attach = variant.accent_attach.0;
diff --git a/crates/typst-layout/src/math/frac.rs b/crates/typst-layout/src/math/frac.rs
index 6d3caac4..2567349d 100644
--- a/crates/typst-layout/src/math/frac.rs
+++ b/crates/typst-layout/src/math/frac.rs
@@ -110,12 +110,12 @@ fn layout_frac_like(
if binom {
let mut left = GlyphFragment::new(ctx, styles, '(', span)
- .stretch_vertical(ctx, height, short_fall);
+ .stretch_vertical(ctx, height - short_fall);
left.center_on_axis(ctx);
ctx.push(left);
ctx.push(FrameFragment::new(styles, frame));
let mut right = GlyphFragment::new(ctx, styles, ')', span)
- .stretch_vertical(ctx, height, short_fall);
+ .stretch_vertical(ctx, height - short_fall);
right.center_on_axis(ctx);
ctx.push(right);
} else {
diff --git a/crates/typst-layout/src/math/fragment.rs b/crates/typst-layout/src/math/fragment.rs
index 85101c48..01fa6be4 100644
--- a/crates/typst-layout/src/math/fragment.rs
+++ b/crates/typst-layout/src/math/fragment.rs
@@ -435,13 +435,8 @@ impl GlyphFragment {
}
/// Try to stretch a glyph to a desired height.
- pub fn stretch_vertical(
- self,
- ctx: &mut MathContext,
- height: Abs,
- short_fall: Abs,
- ) -> VariantFragment {
- stretch_glyph(ctx, self, height, short_fall, Axis::Y)
+ pub fn stretch_vertical(self, ctx: &mut MathContext, height: Abs) -> VariantFragment {
+ stretch_glyph(ctx, self, height, Axis::Y)
}
/// Try to stretch a glyph to a desired width.
@@ -449,9 +444,8 @@ impl GlyphFragment {
self,
ctx: &mut MathContext,
width: Abs,
- short_fall: Abs,
) -> VariantFragment {
- stretch_glyph(ctx, self, width, short_fall, Axis::X)
+ stretch_glyph(ctx, self, width, Axis::X)
}
}
diff --git a/crates/typst-layout/src/math/mat.rs b/crates/typst-layout/src/math/mat.rs
index d678f865..e509cecc 100644
--- a/crates/typst-layout/src/math/mat.rs
+++ b/crates/typst-layout/src/math/mat.rs
@@ -314,7 +314,7 @@ fn layout_delimiters(
if let Some(left) = left {
let mut left = GlyphFragment::new(ctx, styles, left, span)
- .stretch_vertical(ctx, target, short_fall);
+ .stretch_vertical(ctx, target - short_fall);
left.align_on_axis(ctx, delimiter_alignment(left.c));
ctx.push(left);
}
@@ -323,7 +323,7 @@ fn layout_delimiters(
if let Some(right) = right {
let mut right = GlyphFragment::new(ctx, styles, right, span)
- .stretch_vertical(ctx, target, short_fall);
+ .stretch_vertical(ctx, target - short_fall);
right.align_on_axis(ctx, delimiter_alignment(right.c));
ctx.push(right);
}
diff --git a/crates/typst-layout/src/math/root.rs b/crates/typst-layout/src/math/root.rs
index c7f41488..32f52719 100644
--- a/crates/typst-layout/src/math/root.rs
+++ b/crates/typst-layout/src/math/root.rs
@@ -50,7 +50,7 @@ pub fn layout_root(
// Layout root symbol.
let target = radicand.height() + thickness + gap;
let sqrt = GlyphFragment::new(ctx, styles, '√', span)
- .stretch_vertical(ctx, target, Abs::zero())
+ .stretch_vertical(ctx, target)
.frame;
// Layout the index.
diff --git a/crates/typst-layout/src/math/stretch.rs b/crates/typst-layout/src/math/stretch.rs
index 6157d0c5..40f76da5 100644
--- a/crates/typst-layout/src/math/stretch.rs
+++ b/crates/typst-layout/src/math/stretch.rs
@@ -67,8 +67,7 @@ pub fn stretch_fragment(
let mut variant = stretch_glyph(
ctx,
glyph,
- stretch.relative_to(relative_to_size),
- short_fall,
+ stretch.relative_to(relative_to_size) - short_fall,
axis,
);
@@ -120,7 +119,6 @@ pub fn stretch_glyph(
ctx: &mut MathContext,
mut base: GlyphFragment,
target: Abs,
- short_fall: Abs,
axis: Axis,
) -> VariantFragment {
// If the base glyph is good enough, use it.
@@ -128,8 +126,7 @@ pub fn stretch_glyph(
Axis::X => base.width,
Axis::Y => base.height(),
};
- let short_target = target - short_fall;
- if short_target <= advance {
+ if target <= advance {
return base.into_variant();
}
@@ -153,13 +150,13 @@ pub fn stretch_glyph(
for variant in construction.variants {
best_id = variant.variant_glyph;
best_advance = base.font.to_em(variant.advance_measurement).at(base.font_size);
- if short_target <= best_advance {
+ if target <= best_advance {
break;
}
}
// This is either good or the best we've got.
- if short_target <= best_advance || construction.assembly.is_none() {
+ if target <= best_advance || construction.assembly.is_none() {
base.set_id(ctx, best_id);
return base.into_variant();
}
diff --git a/crates/typst-layout/src/math/text.rs b/crates/typst-layout/src/math/text.rs
index 7ecbcfba..e191ec17 100644
--- a/crates/typst-layout/src/math/text.rs
+++ b/crates/typst-layout/src/math/text.rs
@@ -159,7 +159,7 @@ fn layout_glyph(
let mut variant = if math_size == MathSize::Display {
let height = scaled!(ctx, styles, display_operator_min_height)
.max(SQRT_2 * glyph.height());
- glyph.stretch_vertical(ctx, height, Abs::zero())
+ glyph.stretch_vertical(ctx, height)
} else {
glyph.into_variant()
};
diff --git a/crates/typst-layout/src/math/underover.rs b/crates/typst-layout/src/math/underover.rs
index 5b6bd40e..a24113c8 100644
--- a/crates/typst-layout/src/math/underover.rs
+++ b/crates/typst-layout/src/math/underover.rs
@@ -286,7 +286,7 @@ fn layout_underoverspreader(
let body_class = body.class();
let body = body.into_fragment(styles);
let glyph = GlyphFragment::new(ctx, styles, c, span);
- let stretched = glyph.stretch_horizontal(ctx, body.width(), Abs::zero());
+ let stretched = glyph.stretch_horizontal(ctx, body.width());
let mut rows = vec![];
let baseline = match position {
diff --git a/tests/ref/gradient-math-conic.png b/tests/ref/gradient-math-conic.png
index ffd3e806..9bac6c3d 100644
--- a/tests/ref/gradient-math-conic.png
+++ b/tests/ref/gradient-math-conic.png
Binary files differ
diff --git a/tests/ref/gradient-math-dir.png b/tests/ref/gradient-math-dir.png
index 8d33f51f..c2f5bcef 100644
--- a/tests/ref/gradient-math-dir.png
+++ b/tests/ref/gradient-math-dir.png
Binary files differ
diff --git a/tests/ref/gradient-math-mat.png b/tests/ref/gradient-math-mat.png
index ecf95303..d003d6d0 100644
--- a/tests/ref/gradient-math-mat.png
+++ b/tests/ref/gradient-math-mat.png
Binary files differ
diff --git a/tests/ref/gradient-math-misc.png b/tests/ref/gradient-math-misc.png
index 13f5c27b..41948138 100644
--- a/tests/ref/gradient-math-misc.png
+++ b/tests/ref/gradient-math-misc.png
Binary files differ
diff --git a/tests/ref/gradient-math-radial.png b/tests/ref/gradient-math-radial.png
index 8d0047bb..97fb17e6 100644
--- a/tests/ref/gradient-math-radial.png
+++ b/tests/ref/gradient-math-radial.png
Binary files differ
diff --git a/tests/ref/issue-1617-mat-align.png b/tests/ref/issue-1617-mat-align.png
index bd4ea16f..73d8ae82 100644
--- a/tests/ref/issue-1617-mat-align.png
+++ b/tests/ref/issue-1617-mat-align.png
Binary files differ
diff --git a/tests/ref/issue-3774-math-call-empty-2d-args.png b/tests/ref/issue-3774-math-call-empty-2d-args.png
index c1bf52d0..52472d8d 100644
--- a/tests/ref/issue-3774-math-call-empty-2d-args.png
+++ b/tests/ref/issue-3774-math-call-empty-2d-args.png
Binary files differ
diff --git a/tests/ref/math-accent-bottom-high-base.png b/tests/ref/math-accent-bottom-high-base.png
index 23b14467..4893575c 100644
--- a/tests/ref/math-accent-bottom-high-base.png
+++ b/tests/ref/math-accent-bottom-high-base.png
Binary files differ
diff --git a/tests/ref/math-accent-bottom-wide-base.png b/tests/ref/math-accent-bottom-wide-base.png
index 0475b485..fb4a1169 100644
--- a/tests/ref/math-accent-bottom-wide-base.png
+++ b/tests/ref/math-accent-bottom-wide-base.png
Binary files differ
diff --git a/tests/ref/math-accent-wide-base.png b/tests/ref/math-accent-wide-base.png
index af716bf4..793ab30b 100644
--- a/tests/ref/math-accent-wide-base.png
+++ b/tests/ref/math-accent-wide-base.png
Binary files differ
diff --git a/tests/ref/math-cases-gap.png b/tests/ref/math-cases-gap.png
index 746572fa..6bd8e205 100644
--- a/tests/ref/math-cases-gap.png
+++ b/tests/ref/math-cases-gap.png
Binary files differ
diff --git a/tests/ref/math-cases-linebreaks.png b/tests/ref/math-cases-linebreaks.png
index eb4971c4..65b4e402 100644
--- a/tests/ref/math-cases-linebreaks.png
+++ b/tests/ref/math-cases-linebreaks.png
Binary files differ
diff --git a/tests/ref/math-cases.png b/tests/ref/math-cases.png
index ed0423de..34567837 100644
--- a/tests/ref/math-cases.png
+++ b/tests/ref/math-cases.png
Binary files differ
diff --git a/tests/ref/math-mat-align-explicit-alternating.png b/tests/ref/math-mat-align-explicit-alternating.png
index 1ebcc7b6..52a51378 100644
--- a/tests/ref/math-mat-align-explicit-alternating.png
+++ b/tests/ref/math-mat-align-explicit-alternating.png
Binary files differ
diff --git a/tests/ref/math-mat-align-explicit-left.png b/tests/ref/math-mat-align-explicit-left.png
index cb981924..09c5cb3d 100644
--- a/tests/ref/math-mat-align-explicit-left.png
+++ b/tests/ref/math-mat-align-explicit-left.png
Binary files differ
diff --git a/tests/ref/math-mat-align-explicit-mixed.png b/tests/ref/math-mat-align-explicit-mixed.png
index 88ccd6de..f2b38b3e 100644
--- a/tests/ref/math-mat-align-explicit-mixed.png
+++ b/tests/ref/math-mat-align-explicit-mixed.png
Binary files differ
diff --git a/tests/ref/math-mat-align-explicit-right.png b/tests/ref/math-mat-align-explicit-right.png
index b537e657..5db5378f 100644
--- a/tests/ref/math-mat-align-explicit-right.png
+++ b/tests/ref/math-mat-align-explicit-right.png
Binary files differ
diff --git a/tests/ref/math-mat-align-implicit.png b/tests/ref/math-mat-align-implicit.png
index b184d914..cd683315 100644
--- a/tests/ref/math-mat-align-implicit.png
+++ b/tests/ref/math-mat-align-implicit.png
Binary files differ
diff --git a/tests/ref/math-mat-align-signed-numbers.png b/tests/ref/math-mat-align-signed-numbers.png
index c9274379..4463e2fb 100644
--- a/tests/ref/math-mat-align-signed-numbers.png
+++ b/tests/ref/math-mat-align-signed-numbers.png
Binary files differ
diff --git a/tests/ref/math-mat-align.png b/tests/ref/math-mat-align.png
index 66513dd5..eaa3233d 100644
--- a/tests/ref/math-mat-align.png
+++ b/tests/ref/math-mat-align.png
Binary files differ
diff --git a/tests/ref/math-mat-augment-set.png b/tests/ref/math-mat-augment-set.png
index c5881b13..1a667615 100644
--- a/tests/ref/math-mat-augment-set.png
+++ b/tests/ref/math-mat-augment-set.png
Binary files differ
diff --git a/tests/ref/math-mat-augment.png b/tests/ref/math-mat-augment.png
index 0e2a42a2..306c4b19 100644
--- a/tests/ref/math-mat-augment.png
+++ b/tests/ref/math-mat-augment.png
Binary files differ
diff --git a/tests/ref/math-mat-baseline.png b/tests/ref/math-mat-baseline.png
index d2f26621..01928f72 100644
--- a/tests/ref/math-mat-baseline.png
+++ b/tests/ref/math-mat-baseline.png
Binary files differ
diff --git a/tests/ref/math-mat-gap.png b/tests/ref/math-mat-gap.png
index e4f87b59..90525ff2 100644
--- a/tests/ref/math-mat-gap.png
+++ b/tests/ref/math-mat-gap.png
Binary files differ
diff --git a/tests/ref/math-mat-gaps.png b/tests/ref/math-mat-gaps.png
index 40535877..95cd6cf1 100644
--- a/tests/ref/math-mat-gaps.png
+++ b/tests/ref/math-mat-gaps.png
Binary files differ
diff --git a/tests/ref/math-mat-linebreaks.png b/tests/ref/math-mat-linebreaks.png
index 52ff0a8b..6666749d 100644
--- a/tests/ref/math-mat-linebreaks.png
+++ b/tests/ref/math-mat-linebreaks.png
Binary files differ
diff --git a/tests/ref/math-mat-sparse.png b/tests/ref/math-mat-sparse.png
index e9f0d948..c255fe3e 100644
--- a/tests/ref/math-mat-sparse.png
+++ b/tests/ref/math-mat-sparse.png
Binary files differ
diff --git a/tests/ref/math-mat-spread.png b/tests/ref/math-mat-spread.png
index dc8b2bf7..b8f539cc 100644
--- a/tests/ref/math-mat-spread.png
+++ b/tests/ref/math-mat-spread.png
Binary files differ
diff --git a/tests/ref/math-shorthands.png b/tests/ref/math-shorthands.png
index 65b35aca..19bdb6be 100644
--- a/tests/ref/math-shorthands.png
+++ b/tests/ref/math-shorthands.png
Binary files differ
diff --git a/tests/ref/math-vec-align-explicit-alternating.png b/tests/ref/math-vec-align-explicit-alternating.png
index 1ebcc7b6..52a51378 100644
--- a/tests/ref/math-vec-align-explicit-alternating.png
+++ b/tests/ref/math-vec-align-explicit-alternating.png
Binary files differ
diff --git a/tests/ref/math-vec-align.png b/tests/ref/math-vec-align.png
index 680d0936..07d58df7 100644
--- a/tests/ref/math-vec-align.png
+++ b/tests/ref/math-vec-align.png
Binary files differ
diff --git a/tests/ref/math-vec-gap.png b/tests/ref/math-vec-gap.png
index e48b3e90..ccfb2171 100644
--- a/tests/ref/math-vec-gap.png
+++ b/tests/ref/math-vec-gap.png
Binary files differ
diff --git a/tests/ref/math-vec-linebreaks.png b/tests/ref/math-vec-linebreaks.png
index 52ff0a8b..6666749d 100644
--- a/tests/ref/math-vec-linebreaks.png
+++ b/tests/ref/math-vec-linebreaks.png
Binary files differ
diff --git a/tests/ref/math-vec-wide.png b/tests/ref/math-vec-wide.png
index 9dc887a8..000e3cf2 100644
--- a/tests/ref/math-vec-wide.png
+++ b/tests/ref/math-vec-wide.png
Binary files differ