diff options
| author | Eric Biedert <github@ericbiedert.de> | 2024-10-28 15:31:00 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-10-28 14:31:00 +0000 |
| commit | 45377f25ecbd33b56ec5fcd1335f20b13488a93d (patch) | |
| tree | 994bd469ffbadbafdba62f44143c1fbbcfb2b812 /crates/typst-layout | |
| parent | 6dd05cc17ab0a1d6ddbc11854d1a662d91da142f (diff) | |
Fix clipping with outset (#5295)
Co-authored-by: Laurenz <laurmaedje@gmail.com>
Diffstat (limited to 'crates/typst-layout')
| -rw-r--r-- | crates/typst-layout/src/flow/block.rs | 6 | ||||
| -rw-r--r-- | crates/typst-layout/src/inline/box.rs | 3 | ||||
| -rw-r--r-- | crates/typst-layout/src/shapes.rs | 5 |
3 files changed, 8 insertions, 6 deletions
diff --git a/crates/typst-layout/src/flow/block.rs b/crates/typst-layout/src/flow/block.rs index 1dd98812..48ca1fba 100644 --- a/crates/typst-layout/src/flow/block.rs +++ b/crates/typst-layout/src/flow/block.rs @@ -84,8 +84,7 @@ pub fn layout_single_block( // Clip the contents, if requested. if elem.clip(styles) { - let size = frame.size() + outset.relative_to(frame.size()).sum_by_axis(); - frame.clip(clip_rect(size, &radius, &stroke)); + frame.clip(clip_rect(frame.size(), &radius, &stroke, &outset)); } // Add fill and/or stroke. @@ -231,8 +230,7 @@ pub fn layout_multi_block( // Clip the contents, if requested. if clip { - let size = frame.size() + outset.relative_to(frame.size()).sum_by_axis(); - frame.clip(clip_rect(size, &radius, &stroke)); + frame.clip(clip_rect(frame.size(), &radius, &stroke, &outset)); } // Add fill and/or stroke. diff --git a/crates/typst-layout/src/inline/box.rs b/crates/typst-layout/src/inline/box.rs index 30572e4e..62054bea 100644 --- a/crates/typst-layout/src/inline/box.rs +++ b/crates/typst-layout/src/inline/box.rs @@ -61,8 +61,7 @@ pub fn layout_box( // Clip the contents, if requested. if elem.clip(styles) { - let size = frame.size() + outset.relative_to(frame.size()).sum_by_axis(); - frame.clip(clip_rect(size, &radius, &stroke)); + frame.clip(clip_rect(frame.size(), &radius, &stroke, &outset)); } // Add fill and/or stroke. diff --git a/crates/typst-layout/src/shapes.rs b/crates/typst-layout/src/shapes.rs index 31f8c42b..81be1219 100644 --- a/crates/typst-layout/src/shapes.rs +++ b/crates/typst-layout/src/shapes.rs @@ -412,7 +412,11 @@ pub fn clip_rect( size: Size, radius: &Corners<Rel<Abs>>, stroke: &Sides<Option<FixedStroke>>, + outset: &Sides<Rel<Abs>>, ) -> Path { + let outset = outset.relative_to(size); + let size = size + outset.sum_by_axis(); + let stroke_widths = stroke .as_ref() .map(|s| s.as_ref().map_or(Abs::zero(), |s| s.thickness / 2.0)); @@ -441,6 +445,7 @@ pub fn clip_rect( } } path.close_path(); + path.translate(Point::new(-outset.left, -outset.top)); path } |
