mirror of
https://github.com/typst/typst
synced 2025-05-14 04:56:26 +08:00
Gradient Part 5b: Fix gradients in math (#2604)
This commit is contained in:
parent
4d5255d9cb
commit
241a6d9e5a
@ -108,7 +108,7 @@ impl LayoutMath for CancelElem {
|
|||||||
let length = self.length(styles).resolve(styles);
|
let length = self.length(styles).resolve(styles);
|
||||||
|
|
||||||
let stroke = self.stroke(styles).unwrap_or(FixedStroke {
|
let stroke = self.stroke(styles).unwrap_or(FixedStroke {
|
||||||
paint: TextElem::fill_in(styles),
|
paint: TextElem::fill_in(styles).as_decoration(),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -143,7 +143,7 @@ fn layout(
|
|||||||
line_pos,
|
line_pos,
|
||||||
FrameItem::Shape(
|
FrameItem::Shape(
|
||||||
Geometry::Line(Point::with_x(line_width)).stroked(FixedStroke {
|
Geometry::Line(Point::with_x(line_width)).stroked(FixedStroke {
|
||||||
paint: TextElem::fill_in(ctx.styles()),
|
paint: TextElem::fill_in(ctx.styles()).as_decoration(),
|
||||||
thickness,
|
thickness,
|
||||||
..FixedStroke::default()
|
..FixedStroke::default()
|
||||||
}),
|
}),
|
||||||
|
@ -225,7 +225,7 @@ impl GlyphFragment {
|
|||||||
c,
|
c,
|
||||||
font: ctx.font.clone(),
|
font: ctx.font.clone(),
|
||||||
lang: TextElem::lang_in(ctx.styles()),
|
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()),
|
shift: TextElem::baseline_in(ctx.styles()),
|
||||||
style: ctx.style,
|
style: ctx.style,
|
||||||
font_size: ctx.size,
|
font_size: ctx.size,
|
||||||
|
@ -397,7 +397,7 @@ fn layout_mat_body(
|
|||||||
let default_stroke_thickness = DEFAULT_STROKE_THICKNESS.scaled(ctx);
|
let default_stroke_thickness = DEFAULT_STROKE_THICKNESS.scaled(ctx);
|
||||||
let default_stroke = FixedStroke {
|
let default_stroke = FixedStroke {
|
||||||
thickness: default_stroke_thickness,
|
thickness: default_stroke_thickness,
|
||||||
paint: TextElem::fill_in(ctx.styles()),
|
paint: TextElem::fill_in(ctx.styles()).as_decoration(),
|
||||||
line_cap: LineCap::Square,
|
line_cap: LineCap::Square,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
|
@ -122,7 +122,7 @@ fn layout(
|
|||||||
line_pos,
|
line_pos,
|
||||||
FrameItem::Shape(
|
FrameItem::Shape(
|
||||||
Geometry::Line(Point::with_x(radicand.width())).stroked(FixedStroke {
|
Geometry::Line(Point::with_x(radicand.width())).stroked(FixedStroke {
|
||||||
paint: TextElem::fill_in(ctx.styles()),
|
paint: TextElem::fill_in(ctx.styles()).as_decoration(),
|
||||||
thickness,
|
thickness,
|
||||||
..FixedStroke::default()
|
..FixedStroke::default()
|
||||||
}),
|
}),
|
||||||
|
@ -96,7 +96,7 @@ fn layout_underoverline(
|
|||||||
line_pos,
|
line_pos,
|
||||||
FrameItem::Shape(
|
FrameItem::Shape(
|
||||||
Geometry::Line(Point::with_x(width)).stroked(FixedStroke {
|
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,
|
thickness: bar_height,
|
||||||
..FixedStroke::default()
|
..FixedStroke::default()
|
||||||
}),
|
}),
|
||||||
|
BIN
tests/ref/visualize/gradient-math.png
Normal file
BIN
tests/ref/visualize/gradient-math.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 29 KiB |
68
tests/typ/visualize/gradient-math.typ
Normal file
68
tests/typ/visualize/gradient-math.typ
Normal file
@ -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,
|
||||||
|
) $
|
Loading…
x
Reference in New Issue
Block a user