From 02285e8b1fbdf284f2a1115c97f84fc7acb2122e Mon Sep 17 00:00:00 2001 From: Laurenz Date: Thu, 18 Apr 2024 11:33:36 +0200 Subject: [PATCH] Fix path in sized container (#3954) --- crates/typst/src/visualize/path.rs | 14 ++++++-------- tests/ref/issue-path-in-sized-container.png | Bin 0 -> 152 bytes tests/suite/visualize/path.typ | 13 +++++++++++++ 3 files changed, 19 insertions(+), 8 deletions(-) create mode 100644 tests/ref/issue-path-in-sized-container.png diff --git a/crates/typst/src/visualize/path.rs b/crates/typst/src/visualize/path.rs index 5ee9922f2..170a1386a 100644 --- a/crates/typst/src/visualize/path.rs +++ b/crates/typst/src/visualize/path.rs @@ -6,8 +6,7 @@ use crate::foundations::{ array, cast, elem, Array, Packed, Reflect, Resolve, Smart, StyleChain, }; use crate::layout::{ - Abs, Axes, Fragment, Frame, FrameItem, LayoutMultiple, Length, Point, Regions, Rel, - Size, + Abs, Axes, Frame, FrameItem, LayoutSingle, Length, Point, Regions, Rel, Size, }; use crate::visualize::{FixedStroke, Geometry, Paint, Shape, Stroke}; @@ -26,7 +25,7 @@ use PathVertex::{AllControlPoints, MirroredControlPoint, Vertex}; /// ((50%, 0pt), (40pt, 0pt)), /// ) /// ``` -#[elem(LayoutMultiple)] +#[elem(LayoutSingle)] pub struct PathElem { /// How to fill the path. /// @@ -70,14 +69,14 @@ pub struct PathElem { pub vertices: Vec, } -impl LayoutMultiple for Packed { +impl LayoutSingle for Packed { #[typst_macros::time(name = "path", span = self.span())] fn layout( &self, _: &mut Engine, styles: StyleChain, regions: Regions, - ) -> SourceResult { + ) -> SourceResult { let resolve = |axes: Axes>| { axes.resolve(styles) .zip_map(regions.base(), Rel::relative_to) @@ -89,7 +88,7 @@ impl LayoutMultiple for Packed { let mut size = Size::zero(); if points.is_empty() { - return Ok(Fragment::frame(Frame::soft(size))); + return Ok(Frame::soft(size)); } // Only create a path if there are more than zero points. @@ -148,8 +147,7 @@ impl LayoutMultiple for Packed { let mut frame = Frame::soft(size); let shape = Shape { geometry: Geometry::Path(path), stroke, fill }; frame.push(Point::zero(), FrameItem::Shape(shape, self.span())); - - Ok(Fragment::frame(frame)) + Ok(frame) } } diff --git a/tests/ref/issue-path-in-sized-container.png b/tests/ref/issue-path-in-sized-container.png new file mode 100644 index 0000000000000000000000000000000000000000..ebecc122b5e0ec111406fa91a7298599e37db9d4 GIT binary patch literal 152 zcmeAS@N?(olHy`uVBq!ia0vp^6+o=a!VDzWGGD$5q(lRJLR|m<|6hOmzk<2Ff|V!tzf&EMvh#Ft45_&F_Ou}{gMt8yqfU%nO+Sl@!qdOA7aU@k?NEH#-?%#A v)s7R6o4TI(0kKMCHxM^JQHVU3_CNQ86gMa9whabAlNdZ*{an^LB{Ts5>jN@a literal 0 HcmV?d00001 diff --git a/tests/suite/visualize/path.typ b/tests/suite/visualize/path.typ index 10955f148..bdd3dc726 100644 --- a/tests/suite/visualize/path.typ +++ b/tests/suite/visualize/path.typ @@ -50,3 +50,16 @@ --- path-bad-point-array --- // Error: 7-31 point array must contain exactly two entries #path(((0%, 0%), (0%, 0%, 0%))) + +--- issue-path-in-sized-container --- +// Paths used to implement `LayoutMultiple` rather than `LayoutSingle` without +// fulfilling the necessary contract of respecting region expansion. +#block( + fill: aqua, + width: 20pt, + height: 15pt, + path( + (0pt, 0pt), + (10pt, 10pt), + ), +)