diff options
| author | Sébastien d'Herbais de Thun <sebastien.d.herbais@gmail.com> | 2023-10-10 11:51:22 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-10-10 11:51:22 +0200 |
| commit | 9bca0bce73cffe44dc85fa5f45d1736b473f9823 (patch) | |
| tree | d8b9ddff8d999a57ad873ee03184817cdfdaaccb /crates/typst-library/src | |
| parent | a8af6b449ac8ad607595649efde08e2d2b46d668 (diff) | |
Fix clipping when a box/block has a `radius` (#2338)
Diffstat (limited to 'crates/typst-library/src')
| -rw-r--r-- | crates/typst-library/src/layout/container.rs | 26 | ||||
| -rw-r--r-- | crates/typst-library/src/visualize/image.rs | 4 |
2 files changed, 18 insertions, 12 deletions
diff --git a/crates/typst-library/src/layout/container.rs b/crates/typst-library/src/layout/container.rs index 28a56103..36b62864 100644 --- a/crates/typst-library/src/layout/container.rs +++ b/crates/typst-library/src/layout/container.rs @@ -146,15 +146,18 @@ impl Layout for BoxElem { frame.set_baseline(frame.baseline() - shift); } - // Clip the contents - if self.clip(styles) { - frame.clip(); - } - // Prepare fill and stroke. let fill = self.fill(styles); let stroke = self.stroke(styles).map(|s| s.map(Stroke::unwrap_or_default)); + // Clip the contents + if self.clip(styles) { + let outset = self.outset(styles).relative_to(frame.size()); + let size = frame.size() + outset.sum_by_axis(); + let radius = self.radius(styles); + frame.clip(path_rect(size, radius, &stroke)); + } + // Add fill and/or stroke. if fill.is_some() || stroke.iter().any(Option::is_some) { let outset = self.outset(styles); @@ -408,17 +411,20 @@ impl Layout for BlockElem { frames }; + // Prepare fill and stroke. + let fill = self.fill(styles); + let stroke = self.stroke(styles).map(|s| s.map(Stroke::unwrap_or_default)); + // Clip the contents if self.clip(styles) { for frame in frames.iter_mut() { - frame.clip(); + let outset = self.outset(styles).relative_to(frame.size()); + let size = frame.size() + outset.sum_by_axis(); + let radius = self.radius(styles); + frame.clip(path_rect(size, radius, &stroke)); } } - // Prepare fill and stroke. - let fill = self.fill(styles); - let stroke = self.stroke(styles).map(|s| s.map(Stroke::unwrap_or_default)); - // Add fill and/or stroke. if fill.is_some() || stroke.iter().any(Option::is_some) { let mut skip = false; diff --git a/crates/typst-library/src/visualize/image.rs b/crates/typst-library/src/visualize/image.rs index b0c9d8ea..05a9c352 100644 --- a/crates/typst-library/src/visualize/image.rs +++ b/crates/typst-library/src/visualize/image.rs @@ -1,7 +1,7 @@ use std::ffi::OsStr; use std::path::Path; -use typst::geom::Smart; +use typst::geom::{self, Smart}; use typst::image::{Image, ImageFormat, RasterFormat, VectorFormat}; use typst::util::option_eq; @@ -212,7 +212,7 @@ impl Layout for ImageElem { // Create a clipping group if only part of the image should be visible. if fit == ImageFit::Cover && !target.fits(fitted) { - frame.clip(); + frame.clip(geom::Path::rect(frame.size())); } // Apply metadata. |
