summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/typst-library/src/layout/mod.rs1
-rw-r--r--crates/typst-library/src/math/ctx.rs6
-rw-r--r--crates/typst-library/src/math/mod.rs14
-rw-r--r--tests/ref/bugs/block-width-box.pngbin0 -> 1683 bytes
-rw-r--r--tests/typ/bugs/block-width-box.typ6
5 files changed, 21 insertions, 6 deletions
diff --git a/crates/typst-library/src/layout/mod.rs b/crates/typst-library/src/layout/mod.rs
index ace5cd6e..d9e8ec9a 100644
--- a/crates/typst-library/src/layout/mod.rs
+++ b/crates/typst-library/src/layout/mod.rs
@@ -266,6 +266,7 @@ fn realize_block<'a>(
// These elements implement `Layout` but still require a flow for
// proper layout.
if content.can::<dyn Layout>()
+ && !content.is::<BoxElem>()
&& !content.is::<LineElem>()
&& !content.is::<RectElem>()
&& !content.is::<SquareElem>()
diff --git a/crates/typst-library/src/math/ctx.rs b/crates/typst-library/src/math/ctx.rs
index b9aef711..c992c0eb 100644
--- a/crates/typst-library/src/math/ctx.rs
+++ b/crates/typst-library/src/math/ctx.rs
@@ -149,6 +149,12 @@ impl<'a, 'b, 'v> MathContext<'a, 'b, 'v> {
Ok(self.layout_fragment(elem)?.into_frame())
}
+ pub fn layout_box(&mut self, boxed: &BoxElem) -> SourceResult<Frame> {
+ Ok(boxed
+ .layout(self.vt, self.outer.chain(&self.local), self.regions)?
+ .into_frame())
+ }
+
pub fn layout_content(&mut self, content: &Content) -> SourceResult<Frame> {
Ok(content
.layout(self.vt, self.outer.chain(&self.local), self.regions)?
diff --git a/crates/typst-library/src/math/mod.rs b/crates/typst-library/src/math/mod.rs
index 578064ba..3ae3f23a 100644
--- a/crates/typst-library/src/math/mod.rs
+++ b/crates/typst-library/src/math/mod.rs
@@ -457,18 +457,20 @@ impl LayoutMath for Content {
return Ok(());
}
+ if let Some(boxed) = self.to::<BoxElem>() {
+ let frame = ctx.layout_box(boxed)?;
+ ctx.push(FrameFragment::new(ctx, frame).with_spaced(true));
+ return Ok(());
+ }
+
if let Some(elem) = self.with::<dyn LayoutMath>() {
return elem.layout_math(ctx);
}
let mut frame = ctx.layout_content(self)?;
if !frame.has_baseline() {
- if self.is::<BoxElem>() {
- frame.set_baseline(frame.height());
- } else {
- let axis = scaled!(ctx, axis_height);
- frame.set_baseline(frame.height() / 2.0 + axis);
- }
+ 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/bugs/block-width-box.png b/tests/ref/bugs/block-width-box.png
new file mode 100644
index 00000000..9cb27a5d
--- /dev/null
+++ b/tests/ref/bugs/block-width-box.png
Binary files differ
diff --git a/tests/typ/bugs/block-width-box.typ b/tests/typ/bugs/block-width-box.typ
new file mode 100644
index 00000000..a039bc66
--- /dev/null
+++ b/tests/typ/bugs/block-width-box.typ
@@ -0,0 +1,6 @@
+// Test box in 100% width block.
+
+---
+#block(width: 100%, fill: red, box("a box"))
+
+#block(width: 100%, fill: red, [#box("a box") #box()])