From 51a21403ba2e8ced2aeb6a80996d9247f0b7ffd0 Mon Sep 17 00:00:00 2001 From: damaxwell Date: Thu, 20 Jul 2023 02:59:22 -0800 Subject: Improved #box baselines in math (#1755) * Improved #box baselines in math * add a test --- crates/typst-library/src/math/mod.rs | 10 +++++++--- tests/ref/math/content.png | Bin 7891 -> 10381 bytes tests/typ/math/content.typ | 14 ++++++++++++++ 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/crates/typst-library/src/math/mod.rs b/crates/typst-library/src/math/mod.rs index c29ad29b..1b5c27f8 100644 --- a/crates/typst-library/src/math/mod.rs +++ b/crates/typst-library/src/math/mod.rs @@ -43,7 +43,7 @@ use self::ctx::*; use self::fragment::*; use self::row::*; use self::spacing::*; -use crate::layout::{HElem, ParElem, Spacing}; +use crate::layout::{BoxElem, HElem, ParElem, Spacing}; use crate::meta::Supplement; use crate::meta::{ Count, Counter, CounterUpdate, LocalName, Numbering, Outlinable, Refable, @@ -480,8 +480,12 @@ impl LayoutMath for Content { let mut frame = ctx.layout_content(self)?; if !frame.has_baseline() { - let axis = scaled!(ctx, axis_height); - frame.set_baseline(frame.height() / 2.0 + axis); + if self.is::() { + frame.set_baseline(frame.height()); + } else { + let axis = scaled!(ctx, axis_height); + frame.set_baseline(frame.height() / 2.0 + axis); + } } ctx.push(FrameFragment::new(ctx, frame).with_spaced(true)); diff --git a/tests/ref/math/content.png b/tests/ref/math/content.png index a5f5f137..4fbd4670 100644 Binary files a/tests/ref/math/content.png and b/tests/ref/math/content.png differ diff --git a/tests/typ/math/content.typ b/tests/typ/math/content.typ index 5a51901a..49f39733 100644 --- a/tests/typ/math/content.typ +++ b/tests/typ/math/content.typ @@ -17,3 +17,17 @@ $ x := #table(columns: 2)[x][y]/mat(1, 2, 3) // Test font switch. #let here = text.with(font: "Noto Sans") $#here[f] := #here[Hi there]$. + +--- +// Test boxes without a baseline act as if the baseline is at the base +#{ + box(stroke: 0.2pt, $a #box(stroke: 0.2pt, $a$)$) + h(12pt) + box(stroke: 0.2pt, $a #box(stroke: 0.2pt, $g$)$) + h(12pt) + box(stroke: 0.2pt, $g #box(stroke: 0.2pt, $g$)$) +} + +--- +// Test boxes with a baseline are respected +#box(stroke: 0.2pt, $a #box(baseline:0.5em, stroke: 0.2pt, $a$)$) -- cgit v1.2.3