summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax <me@mkor.je>2024-10-01 07:59:31 +0000
committerGitHub <noreply@github.com>2024-10-01 07:59:31 +0000
commit75f646c9756634fe6bc7f94349f6496ed0fc5484 (patch)
tree160a97178f84778efddffb00e2ecb0caf6fe8bca
parent1a24b29d86dfe72e0d3c7f79475c187ed4df5e5a (diff)
Fix `math.stretch` not working vertically with attachments (#5069)
-rw-r--r--crates/typst/src/math/stretch.rs8
-rw-r--r--tests/ref/issue-4188-lr-corner-brackets.pngbin368 -> 364 bytes
-rw-r--r--tests/ref/math-stretch-horizontal-attach.png (renamed from tests/ref/math-stretch-attach.png)bin2245 -> 2245 bytes
-rw-r--r--tests/ref/math-stretch-vertical-attach.pngbin0 -> 493 bytes
-rw-r--r--tests/suite/math/stretch.typ11
5 files changed, 16 insertions, 3 deletions
diff --git a/crates/typst/src/math/stretch.rs b/crates/typst/src/math/stretch.rs
index d316fa9a..232252b9 100644
--- a/crates/typst/src/math/stretch.rs
+++ b/crates/typst/src/math/stretch.rs
@@ -73,9 +73,15 @@ pub(super) fn stretch_fragment(
_ => return,
};
- let Some(axis) = axis.or_else(|| stretch_axis(ctx, &glyph)) else {
+ // Return if we attempt to stretch along an axis which isn't stretchable,
+ // so that the original fragment isn't modified.
+ let Some(stretch_axis) = stretch_axis(ctx, &glyph) else {
return;
};
+ let axis = axis.unwrap_or(stretch_axis);
+ if axis != stretch_axis {
+ return;
+ }
let relative_to_size = relative_to.unwrap_or_else(|| fragment.size().get(axis));
diff --git a/tests/ref/issue-4188-lr-corner-brackets.png b/tests/ref/issue-4188-lr-corner-brackets.png
index 81e9ecdc..6e247908 100644
--- a/tests/ref/issue-4188-lr-corner-brackets.png
+++ b/tests/ref/issue-4188-lr-corner-brackets.png
Binary files differ
diff --git a/tests/ref/math-stretch-attach.png b/tests/ref/math-stretch-horizontal-attach.png
index 179281a5..179281a5 100644
--- a/tests/ref/math-stretch-attach.png
+++ b/tests/ref/math-stretch-horizontal-attach.png
Binary files differ
diff --git a/tests/ref/math-stretch-vertical-attach.png b/tests/ref/math-stretch-vertical-attach.png
new file mode 100644
index 00000000..213ab89b
--- /dev/null
+++ b/tests/ref/math-stretch-vertical-attach.png
Binary files differ
diff --git a/tests/suite/math/stretch.typ b/tests/suite/math/stretch.typ
index e6817ee5..60696746 100644
--- a/tests/suite/math/stretch.typ
+++ b/tests/suite/math/stretch.typ
@@ -13,8 +13,8 @@ $ H stretch(=)^"define" U + p V \
f : X stretch(arrow.hook, size: #150%)_"injective" Y \
V stretch(->, size: #(100% + 1.5em))^("surjection") ZZ $
---- math-stretch-attach ---
-// Test stretch interactions with attachments.
+--- math-stretch-horizontal-attach ---
+// Test horizontal stretch interactions with attachments.
#set page(width: auto)
$stretch(stretch(=, size: #4em))_A$
@@ -28,6 +28,13 @@ $ P = Q
U stretch(equiv)^(forall i)_"Chern-Weil" V
stretch(equiv, size: #(120% + 2mm))^(forall i)_"Chern-Weil" W $
+--- math-stretch-vertical-attach ---
+// Test vertical stretch interactions with attachments.
+$arrow.t$
+$stretch(arrow.t)^"map"$
+$stretch(arrow.t, size: #2em)^"map"$
+$stretch(arrow.t, size: #200%)^"map"$
+
--- math-stretch-horizontal ---
// Test stretching along horizontal axis.
#let ext(sym) = math.stretch(sym, size: 2em)