Hairline stroking at half-pixel offset + `LineCap::Square` produces artifacts
RazrFalcon opened this issue · comments
Yevhenii Reizner commented
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):
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.