diff --git a/library/src/layout/container.rs b/library/src/layout/container.rs index 7d733a876..09cfac8db 100644 --- a/library/src/layout/container.rs +++ b/library/src/layout/container.rs @@ -47,6 +47,8 @@ pub struct BoxNode { pub width: Smart>, /// The box's height. pub height: Smart>, + /// The box's baseline shift. + pub baseline: Rel, } #[node] @@ -55,7 +57,8 @@ impl BoxNode { let body = args.eat::()?.unwrap_or_default(); let width = args.named("width")?.unwrap_or_default(); let height = args.named("height")?.unwrap_or_default(); - Ok(Self { body, width, height }.pack()) + let baseline = args.named("baseline")?.unwrap_or_default(); + Ok(Self { body, width, height, baseline }.pack()) } fn field(&self, name: &str) -> Option { @@ -86,7 +89,15 @@ impl Layout for BoxNode { let is_auto = sizing.as_ref().map(Smart::is_auto); let expand = regions.expand | !is_auto; let pod = Regions::one(size, expand); - self.body.layout(vt, styles, pod) + let mut frame = self.body.layout(vt, styles, pod)?.into_frame(); + + // Apply baseline shift. + let shift = self.baseline.resolve(styles).relative_to(frame.height()); + if !shift.is_zero() { + frame.set_baseline(frame.baseline() - shift); + } + + Ok(Fragment::frame(frame)) } } diff --git a/tests/ref/text/baseline.png b/tests/ref/text/baseline.png index f011c8c41..c28b454a4 100644 Binary files a/tests/ref/text/baseline.png and b/tests/ref/text/baseline.png differ diff --git a/tests/typ/text/baseline.typ b/tests/typ/text/baseline.typ index 57963195d..c19e3c636 100644 --- a/tests/typ/text/baseline.typ +++ b/tests/typ/text/baseline.typ @@ -1,4 +1,4 @@ -// Test text baseline. +// Test baseline handling. --- Hi #text(1.5em)[You], #text(0.75em)[how are you?] @@ -7,3 +7,6 @@ Our cockatoo was one of the #text(baseline: -0.2em)[#box(circle(radius: 2pt)) first] #text(baseline: 0.2em)[birds #box(circle(radius: 2pt))] that ever learned to mimic a human voice. + +--- +Hey #box(baseline: 40%, image("/tiger.jpg", width: 1.5cm)) there!