mirror of
https://github.com/penpot/penpot.git
synced 2025-12-11 22:14:05 +01:00
🐛 Fix apply shadow and blur bounds
This commit is contained in:
@@ -812,41 +812,23 @@ impl Shape {
|
|||||||
result
|
result
|
||||||
}
|
}
|
||||||
|
|
||||||
fn apply_shadow_bounds(&self, mut rect: math::Rect, scale: f32) -> math::Rect {
|
fn apply_shadow_bounds(&self, mut rect: math::Rect) -> math::Rect {
|
||||||
for shadow in self.shadows_visible() {
|
for shadow in self.shadows_visible() {
|
||||||
if !shadow.hidden() {
|
if !shadow.hidden() {
|
||||||
let (x, y) = shadow.offset;
|
if let Some(filter) = shadow.get_drop_shadow_filter() {
|
||||||
let mut shadow_rect = rect;
|
let shadow_bounds = filter.compute_fast_bounds(rect);
|
||||||
|
rect.join(shadow_bounds);
|
||||||
shadow_rect.left += x;
|
}
|
||||||
shadow_rect.right += x;
|
|
||||||
shadow_rect.top += y;
|
|
||||||
shadow_rect.bottom += y;
|
|
||||||
|
|
||||||
let safe_margin = 2.0 / scale.max(0.1);
|
|
||||||
let total_expansion = shadow.blur + shadow.spread + safe_margin;
|
|
||||||
shadow_rect.left -= total_expansion;
|
|
||||||
shadow_rect.top -= total_expansion;
|
|
||||||
shadow_rect.right += total_expansion;
|
|
||||||
shadow_rect.bottom += total_expansion;
|
|
||||||
|
|
||||||
rect.join(shadow_rect);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
rect
|
rect
|
||||||
}
|
}
|
||||||
|
|
||||||
fn apply_blur_bounds(&self, mut rect: math::Rect, scale: f32) -> math::Rect {
|
fn apply_blur_bounds(&self, mut rect: math::Rect) -> math::Rect {
|
||||||
let blur = self.blur.as_ref();
|
let image_filter = self.image_filter(1.);
|
||||||
if let Some(blur) = blur {
|
if let Some(image_filter) = image_filter {
|
||||||
if !blur.hidden {
|
let blur_bounds = image_filter.compute_fast_bounds(rect);
|
||||||
let safe_margin = 1.0 / scale.max(0.1);
|
rect.join(blur_bounds);
|
||||||
let scaled_blur = blur.value + safe_margin;
|
|
||||||
rect.left -= scaled_blur;
|
|
||||||
rect.top -= scaled_blur;
|
|
||||||
rect.right += scaled_blur;
|
|
||||||
rect.bottom += scaled_blur;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
rect
|
rect
|
||||||
}
|
}
|
||||||
@@ -875,12 +857,7 @@ impl Shape {
|
|||||||
rect
|
rect
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn apply_children_blur(
|
pub fn apply_children_blur(&self, mut rect: math::Rect, tree: ShapesPoolRef) -> math::Rect {
|
||||||
&self,
|
|
||||||
mut rect: math::Rect,
|
|
||||||
tree: ShapesPoolRef,
|
|
||||||
scale: f32,
|
|
||||||
) -> math::Rect {
|
|
||||||
let mut children_blur = 0.0;
|
let mut children_blur = 0.0;
|
||||||
let mut current_parent_id = self.parent_id;
|
let mut current_parent_id = self.parent_id;
|
||||||
|
|
||||||
@@ -907,16 +884,11 @@ impl Shape {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let safe_margin = 1.0 / scale.max(0.1);
|
let blur = skia::image_filters::blur((children_blur, children_blur), None, None, None);
|
||||||
let blur = children_blur + safe_margin;
|
if let Some(image_filter) = blur {
|
||||||
|
let blur_bounds = image_filter.compute_fast_bounds(rect);
|
||||||
if blur > 0.0 {
|
rect.join(blur_bounds);
|
||||||
rect.left -= blur;
|
|
||||||
rect.top -= blur;
|
|
||||||
rect.right += blur;
|
|
||||||
rect.bottom += blur;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
rect
|
rect
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -957,10 +929,10 @@ impl Shape {
|
|||||||
};
|
};
|
||||||
|
|
||||||
rect = self.apply_stroke_bounds(rect, max_stroke);
|
rect = self.apply_stroke_bounds(rect, max_stroke);
|
||||||
rect = self.apply_shadow_bounds(rect, scale);
|
rect = self.apply_shadow_bounds(rect);
|
||||||
rect = self.apply_blur_bounds(rect, scale);
|
rect = self.apply_blur_bounds(rect);
|
||||||
rect = self.apply_children_bounds(rect, shapes_pool, scale);
|
rect = self.apply_children_bounds(rect, shapes_pool, scale);
|
||||||
rect = self.apply_children_blur(rect, shapes_pool, scale);
|
rect = self.apply_children_blur(rect, shapes_pool);
|
||||||
|
|
||||||
rect
|
rect
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user