Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hairline stroking at half-pixel offset + LineCap::Square produces artifacts #44

Open
RazrFalcon opened this issue Feb 7, 2022 · 0 comments
Labels
bug Something isn't working

Comments

@RazrFalcon
Copy link
Collaborator

use tiny_skia::*;

fn main() {
    let mut paint = Paint::default();
    paint.set_color_rgba8(255, 0, 0, 255);
    paint.anti_alias = true;

    let path = {
        let mut pb = PathBuilder::new();
        pb.move_to(2.5, 1.5);
        pb.line_to(5.5, 1.5);
        pb.line_to(5.5, 5.5);
        pb.line_to(2.5, 5.5);
        pb.close();
        pb.finish().unwrap()
    };

    let mut stroke = Stroke::default();
    stroke.width = 1.0;
    stroke.line_cap = LineCap::Square;

    let mut pixmap = Pixmap::new(7, 7).unwrap();
    pixmap.stroke_path(&path, &paint, &stroke, Transform::identity(), None);
    pixmap.save_png("image.png").unwrap();
}

produces (8x upscale, actual/expected):

image
image2

This issue can be "fixed" by not using LineCap::Square, by using larger stroke width (which would simply disable hairline stroking) and by closing the path manually, without relying on ClosePath/Z.

The Skia itself produces similar results, but not quite the same. Not sure if this is actually a Skia bug or an intentional behaviour.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant