From 363836a28e4c8877b7c5203ed4ce595a59731802 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Tue, 23 May 2023 15:30:28 +0200 Subject: [PATCH] Fix layout panic in rounded rectangle Fixes #1216 both by hardening the rounded rectangle against negative size and by ensuring that the negative size doesn't occur in the first place for this case. --- library/src/layout/flow.rs | 5 +++++ src/geom/rounded.rs | 2 +- tests/ref/bugs/clamp-panic.png | Bin 0 -> 274 bytes tests/typ/bugs/clamp-panic.typ | 3 +++ 4 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 tests/ref/bugs/clamp-panic.png create mode 100644 tests/typ/bugs/clamp-panic.typ diff --git a/library/src/layout/flow.rs b/library/src/layout/flow.rs index a21f81424..5e01f51d0 100644 --- a/library/src/layout/flow.rs +++ b/library/src/layout/flow.rs @@ -243,6 +243,11 @@ impl<'a> FlowLayouter<'a> { block: &Content, styles: StyleChain, ) -> SourceResult<()> { + // Skip directly if regino is already full. + if self.regions.is_full() { + self.finish_region()?; + } + // Placed elements that are out of flow produce placed items which // aren't aligned later. if let Some(placed) = block.to::() { diff --git a/src/geom/rounded.rs b/src/geom/rounded.rs index f445dfcb8..24b524485 100644 --- a/src/geom/rounded.rs +++ b/src/geom/rounded.rs @@ -52,7 +52,7 @@ fn stroke_segments( let mut connection = Connection::default(); let mut path = Path::new(); let mut always_continuous = true; - let max_radius = size.x.min(size.y) / 2.0; + let max_radius = size.x.min(size.y).max(Abs::zero()) / 2.0; for side in [Side::Top, Side::Right, Side::Bottom, Side::Left] { let continuous = stroke.get_ref(side) == stroke.get_ref(side.next_cw()); diff --git a/tests/ref/bugs/clamp-panic.png b/tests/ref/bugs/clamp-panic.png new file mode 100644 index 0000000000000000000000000000000000000000..c0c4912e367790ebadce605f97eecad23858e95a GIT binary patch literal 274 zcmeAS@N?(olHy`uVBq!ia0y~yU}OQZ^H`XHq_JJWMj#~-;1lBd9|)d5{XeDe|CHYU zsWJakqW?RZ0VO+Td~XF(TRmMILn>~)y?Kz6$xwjx!U9>1iZbg6{b?IiE5yq$H@&U) zJ+Sx<|ED_Ee#J8?Ge7k$R{(+@FO7vD8V&r>KlomoiHYgZ_qAs-S6Zjf{UuqrqA|w$ z&?JR5x(_3iXG$MZb*?aLsc!p_#o^ty!K_7!i|Npe7I(J|y;ojZ+}z9|igHU@Ixv&xe8TXJGJj^>bP0l+XkKjQ?jZ literal 0 HcmV?d00001 diff --git a/tests/typ/bugs/clamp-panic.typ b/tests/typ/bugs/clamp-panic.typ new file mode 100644 index 000000000..5f167c76b --- /dev/null +++ b/tests/typ/bugs/clamp-panic.typ @@ -0,0 +1,3 @@ +#set page(height: 20pt, margin: 0pt) +#v(22pt) +#block(fill: red, width: 100%, height: 10pt, radius: 4pt)