summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLU Jialin <luxxxlucy@gmail.com>2023-09-25 19:13:16 +0800
committerGitHub <noreply@github.com>2023-09-25 13:13:16 +0200
commit04b4536772362e15de5ee3e88d05dbb066f85f37 (patch)
tree7048777fd3608315e577fca57d50b19f44e7a895
parent50b031843410505a45da6f2792d9b87e3d5845a1 (diff)
Fixing the baseline in math content (#2220)
-rw-r--r--crates/typst-library/src/math/fragment.rs4
-rw-r--r--tests/ref/bugs/math-shift.pngbin0 -> 2260 bytes
-rw-r--r--tests/typ/bugs/math-shift.typ5
3 files changed, 8 insertions, 1 deletions
diff --git a/crates/typst-library/src/math/fragment.rs b/crates/typst-library/src/math/fragment.rs
index 4e174349..5ac1f2dd 100644
--- a/crates/typst-library/src/math/fragment.rs
+++ b/crates/typst-library/src/math/fragment.rs
@@ -187,6 +187,7 @@ pub struct GlyphFragment {
pub font: Font,
pub lang: Lang,
pub fill: Paint,
+ pub shift: Abs,
pub width: Abs,
pub ascent: Abs,
pub descent: Abs,
@@ -225,6 +226,7 @@ impl GlyphFragment {
font: ctx.font.clone(),
lang: TextElem::lang_in(ctx.styles()),
fill: TextElem::fill_in(ctx.styles()),
+ shift: TextElem::baseline_in(ctx.styles()),
style: ctx.style,
font_size: ctx.size,
width: Abs::zero(),
@@ -309,7 +311,7 @@ impl GlyphFragment {
let size = Size::new(self.width, self.ascent + self.descent);
let mut frame = Frame::new(size);
frame.set_baseline(self.ascent);
- frame.push(Point::with_y(self.ascent), FrameItem::Text(item));
+ frame.push(Point::with_y(self.ascent + self.shift), FrameItem::Text(item));
frame.meta_iter(self.meta);
frame
}
diff --git a/tests/ref/bugs/math-shift.png b/tests/ref/bugs/math-shift.png
new file mode 100644
index 00000000..4d4b5f5e
--- /dev/null
+++ b/tests/ref/bugs/math-shift.png
Binary files differ
diff --git a/tests/typ/bugs/math-shift.typ b/tests/typ/bugs/math-shift.typ
new file mode 100644
index 00000000..4a833e31
--- /dev/null
+++ b/tests/typ/bugs/math-shift.typ
@@ -0,0 +1,5 @@
+// https://github.com/typst/typst/issues/2214
+// The math content should also be affected by the TextElem baseline.
+
+hello #text(baseline: -5pt)[123 #sym.WW\orld]\
+hello #text(baseline: -5pt)[$123 WW#text[or]$ld]\