🐛 Fix drop shadows viewport clipping

This commit is contained in:
Elena Torro 2025-03-17 16:55:17 +01:00
parent fa0da3a695
commit 731c21f082
6 changed files with 174 additions and 63 deletions

View file

@ -1,14 +1,14 @@
use skia_safe::{self as skia, RRect};
use skia_safe::{self as skia, Paint, RRect};
use super::{RenderState, SurfaceId};
use crate::math::Rect as MathRect;
use crate::shapes::{Fill, Frame, ImageFill, Rect, Shape, Type};
fn draw_image_fill_in_container(
fn draw_image_fill(
render_state: &mut RenderState,
shape: &Shape,
fill: &Fill,
image_fill: &ImageFill,
paint: &Paint,
) {
let image = render_state.images.get(&image_fill.id());
if image.is_none() {
@ -19,7 +19,6 @@ fn draw_image_fill_in_container(
let canvas = render_state.surfaces.canvas(SurfaceId::Fills);
let container = &shape.selrect;
let path_transform = shape.to_path_transform();
let paint = fill.to_paint(container);
let width = size.0 as f32;
let height = size.1 as f32;
@ -110,39 +109,29 @@ fn draw_image_fill_in_container(
* This SHOULD be the only public function in this module.
*/
pub fn render(render_state: &mut RenderState, shape: &Shape, fill: &Fill) {
let canvas = render_state.surfaces.canvas(SurfaceId::Fills);
let selrect = shape.selrect;
let path_transform = shape.to_path_transform();
let paint = &fill.to_paint(&shape.selrect);
match (fill, &shape.shape_type) {
(Fill::Image(image_fill), _) => {
draw_image_fill_in_container(render_state, shape, fill, image_fill);
draw_image_fill(render_state, shape, image_fill, paint);
}
(_, Type::Rect(_) | Type::Frame(_)) => {
if let Some(corners) = shape.shape_type.corners() {
let rrect = RRect::new_rect_radii(selrect, &corners);
canvas.draw_rrect(rrect, &fill.to_paint(&selrect));
} else {
canvas.draw_rect(selrect, &fill.to_paint(&selrect));
}
render_state
.surfaces
.draw_rect_to(SurfaceId::Fills, shape, paint);
}
(_, Type::Circle) => {
canvas.draw_oval(selrect, &fill.to_paint(&selrect));
render_state
.surfaces
.draw_circle_to(SurfaceId::Fills, shape, paint);
}
(_, Type::Path(_)) | (_, Type::Bool(_)) => {
if let Some(path) = &shape.shape_type.path() {
let svg_attrs = &shape.svg_attrs;
let mut skia_path = &mut path.to_skia_path();
if let Some(path_transform) = path_transform {
skia_path = skia_path.transform(&path_transform);
if let Some("evenodd") = svg_attrs.get("fill-rule").map(String::as_str) {
skia_path.set_fill_type(skia::PathFillType::EvenOdd);
}
canvas.draw_path(&skia_path, &fill.to_paint(&selrect));
}
}
render_state
.surfaces
.draw_path_to(SurfaceId::Fills, shape, paint);
}
(_, _) => {
unreachable!("This shape should not have fills")
}
(_, _) => unreachable!("This shape should not have fills"),
}
}