Skip to content

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

@RazrFalcon

Description

@RazrFalcon
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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions