diff options
| author | Max <max@mkor.je> | 2025-06-04 10:14:24 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-06-04 10:14:24 +0000 |
| commit | aee99408e1cb6e825992a43399597f5d1a937230 (patch) | |
| tree | 9220c4d669b5039169c87f704313cc6ba3a51819 | |
| parent | 1de2095f67c9719a973868618c3548dd6083f534 (diff) | |
Apply short fall consistently in math when stretching (#6377)
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 Binary files differindex ffd3e806..9bac6c3d 100644 --- a/tests/ref/gradient-math-conic.png +++ b/tests/ref/gradient-math-conic.png diff --git a/tests/ref/gradient-math-dir.png b/tests/ref/gradient-math-dir.png Binary files differindex 8d33f51f..c2f5bcef 100644 --- a/tests/ref/gradient-math-dir.png +++ b/tests/ref/gradient-math-dir.png diff --git a/tests/ref/gradient-math-mat.png b/tests/ref/gradient-math-mat.png Binary files differindex ecf95303..d003d6d0 100644 --- a/tests/ref/gradient-math-mat.png +++ b/tests/ref/gradient-math-mat.png diff --git a/tests/ref/gradient-math-misc.png b/tests/ref/gradient-math-misc.png Binary files differindex 13f5c27b..41948138 100644 --- a/tests/ref/gradient-math-misc.png +++ b/tests/ref/gradient-math-misc.png diff --git a/tests/ref/gradient-math-radial.png b/tests/ref/gradient-math-radial.png Binary files differindex 8d0047bb..97fb17e6 100644 --- a/tests/ref/gradient-math-radial.png +++ b/tests/ref/gradient-math-radial.png diff --git a/tests/ref/issue-1617-mat-align.png b/tests/ref/issue-1617-mat-align.png Binary files differindex bd4ea16f..73d8ae82 100644 --- a/tests/ref/issue-1617-mat-align.png +++ b/tests/ref/issue-1617-mat-align.png diff --git a/tests/ref/issue-3774-math-call-empty-2d-args.png b/tests/ref/issue-3774-math-call-empty-2d-args.png Binary files differindex 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 diff --git a/tests/ref/math-accent-bottom-high-base.png b/tests/ref/math-accent-bottom-high-base.png Binary files differindex 23b14467..4893575c 100644 --- a/tests/ref/math-accent-bottom-high-base.png +++ b/tests/ref/math-accent-bottom-high-base.png diff --git a/tests/ref/math-accent-bottom-wide-base.png b/tests/ref/math-accent-bottom-wide-base.png Binary files differindex 0475b485..fb4a1169 100644 --- a/tests/ref/math-accent-bottom-wide-base.png +++ b/tests/ref/math-accent-bottom-wide-base.png diff --git a/tests/ref/math-accent-wide-base.png b/tests/ref/math-accent-wide-base.png Binary files differindex af716bf4..793ab30b 100644 --- a/tests/ref/math-accent-wide-base.png +++ b/tests/ref/math-accent-wide-base.png diff --git a/tests/ref/math-cases-gap.png b/tests/ref/math-cases-gap.png Binary files differindex 746572fa..6bd8e205 100644 --- a/tests/ref/math-cases-gap.png +++ b/tests/ref/math-cases-gap.png diff --git a/tests/ref/math-cases-linebreaks.png b/tests/ref/math-cases-linebreaks.png Binary files differindex eb4971c4..65b4e402 100644 --- a/tests/ref/math-cases-linebreaks.png +++ b/tests/ref/math-cases-linebreaks.png diff --git a/tests/ref/math-cases.png b/tests/ref/math-cases.png Binary files differindex ed0423de..34567837 100644 --- a/tests/ref/math-cases.png +++ b/tests/ref/math-cases.png diff --git a/tests/ref/math-mat-align-explicit-alternating.png b/tests/ref/math-mat-align-explicit-alternating.png Binary files differindex 1ebcc7b6..52a51378 100644 --- a/tests/ref/math-mat-align-explicit-alternating.png +++ b/tests/ref/math-mat-align-explicit-alternating.png diff --git a/tests/ref/math-mat-align-explicit-left.png b/tests/ref/math-mat-align-explicit-left.png Binary files differindex cb981924..09c5cb3d 100644 --- a/tests/ref/math-mat-align-explicit-left.png +++ b/tests/ref/math-mat-align-explicit-left.png diff --git a/tests/ref/math-mat-align-explicit-mixed.png b/tests/ref/math-mat-align-explicit-mixed.png Binary files differindex 88ccd6de..f2b38b3e 100644 --- a/tests/ref/math-mat-align-explicit-mixed.png +++ b/tests/ref/math-mat-align-explicit-mixed.png diff --git a/tests/ref/math-mat-align-explicit-right.png b/tests/ref/math-mat-align-explicit-right.png Binary files differindex b537e657..5db5378f 100644 --- a/tests/ref/math-mat-align-explicit-right.png +++ b/tests/ref/math-mat-align-explicit-right.png diff --git a/tests/ref/math-mat-align-implicit.png b/tests/ref/math-mat-align-implicit.png Binary files differindex b184d914..cd683315 100644 --- a/tests/ref/math-mat-align-implicit.png +++ b/tests/ref/math-mat-align-implicit.png diff --git a/tests/ref/math-mat-align-signed-numbers.png b/tests/ref/math-mat-align-signed-numbers.png Binary files differindex c9274379..4463e2fb 100644 --- a/tests/ref/math-mat-align-signed-numbers.png +++ b/tests/ref/math-mat-align-signed-numbers.png diff --git a/tests/ref/math-mat-align.png b/tests/ref/math-mat-align.png Binary files differindex 66513dd5..eaa3233d 100644 --- a/tests/ref/math-mat-align.png +++ b/tests/ref/math-mat-align.png diff --git a/tests/ref/math-mat-augment-set.png b/tests/ref/math-mat-augment-set.png Binary files differindex c5881b13..1a667615 100644 --- a/tests/ref/math-mat-augment-set.png +++ b/tests/ref/math-mat-augment-set.png diff --git a/tests/ref/math-mat-augment.png b/tests/ref/math-mat-augment.png Binary files differindex 0e2a42a2..306c4b19 100644 --- a/tests/ref/math-mat-augment.png +++ b/tests/ref/math-mat-augment.png diff --git a/tests/ref/math-mat-baseline.png b/tests/ref/math-mat-baseline.png Binary files differindex d2f26621..01928f72 100644 --- a/tests/ref/math-mat-baseline.png +++ b/tests/ref/math-mat-baseline.png diff --git a/tests/ref/math-mat-gap.png b/tests/ref/math-mat-gap.png Binary files differindex e4f87b59..90525ff2 100644 --- a/tests/ref/math-mat-gap.png +++ b/tests/ref/math-mat-gap.png diff --git a/tests/ref/math-mat-gaps.png b/tests/ref/math-mat-gaps.png Binary files differindex 40535877..95cd6cf1 100644 --- a/tests/ref/math-mat-gaps.png +++ b/tests/ref/math-mat-gaps.png diff --git a/tests/ref/math-mat-linebreaks.png b/tests/ref/math-mat-linebreaks.png Binary files differindex 52ff0a8b..6666749d 100644 --- a/tests/ref/math-mat-linebreaks.png +++ b/tests/ref/math-mat-linebreaks.png diff --git a/tests/ref/math-mat-sparse.png b/tests/ref/math-mat-sparse.png Binary files differindex e9f0d948..c255fe3e 100644 --- a/tests/ref/math-mat-sparse.png +++ b/tests/ref/math-mat-sparse.png diff --git a/tests/ref/math-mat-spread.png b/tests/ref/math-mat-spread.png Binary files differindex dc8b2bf7..b8f539cc 100644 --- a/tests/ref/math-mat-spread.png +++ b/tests/ref/math-mat-spread.png diff --git a/tests/ref/math-shorthands.png b/tests/ref/math-shorthands.png Binary files differindex 65b35aca..19bdb6be 100644 --- a/tests/ref/math-shorthands.png +++ b/tests/ref/math-shorthands.png diff --git a/tests/ref/math-vec-align-explicit-alternating.png b/tests/ref/math-vec-align-explicit-alternating.png Binary files differindex 1ebcc7b6..52a51378 100644 --- a/tests/ref/math-vec-align-explicit-alternating.png +++ b/tests/ref/math-vec-align-explicit-alternating.png diff --git a/tests/ref/math-vec-align.png b/tests/ref/math-vec-align.png Binary files differindex 680d0936..07d58df7 100644 --- a/tests/ref/math-vec-align.png +++ b/tests/ref/math-vec-align.png diff --git a/tests/ref/math-vec-gap.png b/tests/ref/math-vec-gap.png Binary files differindex e48b3e90..ccfb2171 100644 --- a/tests/ref/math-vec-gap.png +++ b/tests/ref/math-vec-gap.png diff --git a/tests/ref/math-vec-linebreaks.png b/tests/ref/math-vec-linebreaks.png Binary files differindex 52ff0a8b..6666749d 100644 --- a/tests/ref/math-vec-linebreaks.png +++ b/tests/ref/math-vec-linebreaks.png diff --git a/tests/ref/math-vec-wide.png b/tests/ref/math-vec-wide.png Binary files differindex 9dc887a8..000e3cf2 100644 --- a/tests/ref/math-vec-wide.png +++ b/tests/ref/math-vec-wide.png |
