summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSébastien d'Herbais de Thun <sebastien.d.herbais@gmail.com>2023-11-07 12:09:51 +0100
committerGitHub <noreply@github.com>2023-11-07 12:09:51 +0100
commit241a6d9e5aa36c41e1f3be8a75a769e2ce98f7fb (patch)
tree3c497c82ad1d19dee5b37515dea50c2868043eff
parent4d5255d9cbfb3cb7fd48feee54138fcad4f5b552 (diff)
Gradient Part 5b: Fix gradients in math (#2604)
-rw-r--r--crates/typst-library/src/math/cancel.rs2
-rw-r--r--crates/typst-library/src/math/frac.rs2
-rw-r--r--crates/typst-library/src/math/fragment.rs2
-rw-r--r--crates/typst-library/src/math/matrix.rs2
-rw-r--r--crates/typst-library/src/math/root.rs2
-rw-r--r--crates/typst-library/src/math/underover.rs2
-rw-r--r--tests/ref/visualize/gradient-math.pngbin0 -> 29775 bytes
-rw-r--r--tests/typ/visualize/gradient-math.typ68
8 files changed, 74 insertions, 6 deletions
diff --git a/crates/typst-library/src/math/cancel.rs b/crates/typst-library/src/math/cancel.rs
index 16e4067a..455750f7 100644
--- a/crates/typst-library/src/math/cancel.rs
+++ b/crates/typst-library/src/math/cancel.rs
@@ -108,7 +108,7 @@ impl LayoutMath for CancelElem {
let length = self.length(styles).resolve(styles);
let stroke = self.stroke(styles).unwrap_or(FixedStroke {
- paint: TextElem::fill_in(styles),
+ paint: TextElem::fill_in(styles).as_decoration(),
..Default::default()
});
diff --git a/crates/typst-library/src/math/frac.rs b/crates/typst-library/src/math/frac.rs
index bd8d86bf..c3014178 100644
--- a/crates/typst-library/src/math/frac.rs
+++ b/crates/typst-library/src/math/frac.rs
@@ -143,7 +143,7 @@ fn layout(
line_pos,
FrameItem::Shape(
Geometry::Line(Point::with_x(line_width)).stroked(FixedStroke {
- paint: TextElem::fill_in(ctx.styles()),
+ paint: TextElem::fill_in(ctx.styles()).as_decoration(),
thickness,
..FixedStroke::default()
}),
diff --git a/crates/typst-library/src/math/fragment.rs b/crates/typst-library/src/math/fragment.rs
index a40ed2bf..76ee2512 100644
--- a/crates/typst-library/src/math/fragment.rs
+++ b/crates/typst-library/src/math/fragment.rs
@@ -225,7 +225,7 @@ impl GlyphFragment {
c,
font: ctx.font.clone(),
lang: TextElem::lang_in(ctx.styles()),
- fill: TextElem::fill_in(ctx.styles()),
+ fill: TextElem::fill_in(ctx.styles()).as_decoration(),
shift: TextElem::baseline_in(ctx.styles()),
style: ctx.style,
font_size: ctx.size,
diff --git a/crates/typst-library/src/math/matrix.rs b/crates/typst-library/src/math/matrix.rs
index b54da5d6..4142d235 100644
--- a/crates/typst-library/src/math/matrix.rs
+++ b/crates/typst-library/src/math/matrix.rs
@@ -397,7 +397,7 @@ fn layout_mat_body(
let default_stroke_thickness = DEFAULT_STROKE_THICKNESS.scaled(ctx);
let default_stroke = FixedStroke {
thickness: default_stroke_thickness,
- paint: TextElem::fill_in(ctx.styles()),
+ paint: TextElem::fill_in(ctx.styles()).as_decoration(),
line_cap: LineCap::Square,
..Default::default()
};
diff --git a/crates/typst-library/src/math/root.rs b/crates/typst-library/src/math/root.rs
index 13c5c147..ba918ea9 100644
--- a/crates/typst-library/src/math/root.rs
+++ b/crates/typst-library/src/math/root.rs
@@ -122,7 +122,7 @@ fn layout(
line_pos,
FrameItem::Shape(
Geometry::Line(Point::with_x(radicand.width())).stroked(FixedStroke {
- paint: TextElem::fill_in(ctx.styles()),
+ paint: TextElem::fill_in(ctx.styles()).as_decoration(),
thickness,
..FixedStroke::default()
}),
diff --git a/crates/typst-library/src/math/underover.rs b/crates/typst-library/src/math/underover.rs
index aeb83061..6fc76830 100644
--- a/crates/typst-library/src/math/underover.rs
+++ b/crates/typst-library/src/math/underover.rs
@@ -96,7 +96,7 @@ fn layout_underoverline(
line_pos,
FrameItem::Shape(
Geometry::Line(Point::with_x(width)).stroked(FixedStroke {
- paint: TextElem::fill_in(ctx.styles()),
+ paint: TextElem::fill_in(ctx.styles()).as_decoration(),
thickness: bar_height,
..FixedStroke::default()
}),
diff --git a/tests/ref/visualize/gradient-math.png b/tests/ref/visualize/gradient-math.png
new file mode 100644
index 00000000..13185bec
--- /dev/null
+++ b/tests/ref/visualize/gradient-math.png
Binary files differ
diff --git a/tests/typ/visualize/gradient-math.typ b/tests/typ/visualize/gradient-math.typ
new file mode 100644
index 00000000..2030ecbb
--- /dev/null
+++ b/tests/typ/visualize/gradient-math.typ
@@ -0,0 +1,68 @@
+// Test that gradients are applied correctly on equations.
+
+---
+// Test on cancel
+#show math.equation: set text(fill: gradient.linear(..color.map.rainbow))
+#show math.equation: box
+
+$ a dot cancel(5) = cancel(25) 5 x + cancel(5) 1 $
+
+---
+// Test on frac
+#show math.equation: set text(fill: gradient.linear(..color.map.rainbow))
+#show math.equation: box
+
+$ nabla dot bold(E) = frac(rho, epsilon_0) $
+
+---
+// Test on root
+#show math.equation: set text(fill: gradient.linear(..color.map.rainbow))
+#show math.equation: box
+
+$ x_"1,2" = frac(-b +- sqrt(b^2 - 4 a c), 2 a) $
+
+---
+// Test on matrix
+#show math.equation: set text(fill: gradient.linear(..color.map.rainbow))
+#show math.equation: box
+
+$ A = mat(
+ 1, 2, 3;
+ 4, 5, 6;
+ 7, 8, 9
+) $
+
+---
+// Test on underover
+#show math.equation: set text(fill: gradient.linear(..color.map.rainbow))
+#show math.equation: box
+
+$ underline(X^2) $
+$ overline("hello, world!") $
+
+---
+// Test a different direction
+#show math.equation: set text(fill: gradient.linear(..color.map.rainbow, dir: ttb))
+#show math.equation: box
+
+$ A = mat(
+ 1, 2, 3;
+ 4, 5, 6;
+ 7, 8, 9
+) $
+
+$ x_"1,2" = frac(-b +- sqrt(b^2 - 4 a c), 2 a) $
+
+---
+// Test miscelaneous
+
+#show math.equation: set text(fill: gradient.linear(..color.map.rainbow))
+#show math.equation: box
+
+$ hat(x) = bar x bar = vec(x, y, z) = tilde(x) = dot(x) $
+$ x prime = vec(1, 2, delim: "[") $
+$ sum_(i in NN) 1 + i $
+$ attach(
+ Pi, t: alpha, b: beta,
+ tl: 1, tr: 2+3, bl: 4+5, br: 6,
+) $