summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--library/src/layout/container.rs15
-rw-r--r--tests/ref/text/baseline.pngbin6168 -> 29069 bytes
-rw-r--r--tests/typ/text/baseline.typ5
3 files changed, 17 insertions, 3 deletions
diff --git a/library/src/layout/container.rs b/library/src/layout/container.rs
index 7d733a87..09cfac8d 100644
--- a/library/src/layout/container.rs
+++ b/library/src/layout/container.rs
@@ -47,6 +47,8 @@ pub struct BoxNode {
pub width: Smart<Rel<Length>>,
/// The box's height.
pub height: Smart<Rel<Length>>,
+ /// The box's baseline shift.
+ pub baseline: Rel<Length>,
}
#[node]
@@ -55,7 +57,8 @@ impl BoxNode {
let body = args.eat::<Content>()?.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<Value> {
@@ -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 f011c8c4..c28b454a 100644
--- a/tests/ref/text/baseline.png
+++ b/tests/ref/text/baseline.png
Binary files differ
diff --git a/tests/typ/text/baseline.typ b/tests/typ/text/baseline.typ
index 57963195..c19e3c63 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!