RazrFalcon / tiny-skia

A tiny Skia subset ported to Rust
BSD 3-Clause "New" or "Revised" License
1.05k stars 67 forks source link

ClipMask clears the pixmap #42

Closed snakedye closed 2 years ago

snakedye commented 2 years ago

Examples:

test

https://user-images.githubusercontent.com/49378990/150547430-da5299b3-8d13-4887-b56a-91ce9ff79206.mp4

How to reproduce:

fn main() {
    let mut pixmap = Pixmap::new(300, 300).unwrap();
    let mut clip = ClipMask::new();
    clip.set_path(
        300,
        300,
        &PathBuilder::from_rect(Rect::from_xywh(100., 0., 150., 300.).unwrap()),
        FillRule::EvenOdd,
        false
    );

    let background = Rect::from_xywh(0., 0., 300., 300.).unwrap();
    let rectangle = Rect::from_xywh(0., 100., 200., 100.).unwrap();

    pixmap.fill_path(
        &PathBuilder::from_rect(background),
        &Paint {
            shader: Shader::SolidColor(Color::WHITE),
            blend_mode: BlendMode::SourceOver,
            anti_alias: true,
            force_hq_pipeline: false,
        },
        FillRule::EvenOdd,
        Transform::identity(),
        None
    );

    pixmap.fill_path(
        &PathBuilder::from_rect(rectangle),
        &Paint {
            shader: Shader::SolidColor(Color::BLACK),
            blend_mode: BlendMode::SourceOver,
            anti_alias: true,
            force_hq_pipeline: false,
        },
        FillRule::EvenOdd,
        Transform::identity(),
        Some(&clip)
    );

    pixmap.save_png("/home/snakedye/test.png");
}
snakedye commented 2 years ago

I'm using tiny-skia = "0.6.2"

RazrFalcon commented 2 years ago

What result do you expect?

snakedye commented 2 years ago

Things outside the clipping path to not be rendered

RazrFalcon commented 2 years ago

Hmm... I guess I see the issue.

snakedye commented 2 years ago

Is it how skia does it?

RazrFalcon commented 2 years ago

No, I think it's a bug.

snakedye commented 2 years ago

If I want to patch this is there a place I should look into in particular. I have no experience in this domain but the bug doesn't seem major