From bce7b24cfb86ba1b8a253d999e5bcc9d330cba6b Mon Sep 17 00:00:00 2001 From: Aliaksandr Kalenik Date: Mon, 1 Jul 2024 17:27:22 +0200 Subject: [PATCH] LibWeb: Fix painting of paths with storke-width=0 in Skia painter From SkPaint.h: "Sets the thickness of the pen used by the paint to outline the shape. A stroke-width of zero is treated as "hairline" width. Hairlines are always exactly one pixel wide in device space (their thickness does not change as the canvas is scaled)." While we expect stroke-width=0 to simply not be painted. --- .../LibWeb/Painting/DisplayListPlayerSkia.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/Userland/Libraries/LibWeb/Painting/DisplayListPlayerSkia.cpp b/Userland/Libraries/LibWeb/Painting/DisplayListPlayerSkia.cpp index 628363eced1..8035032dcb4 100644 --- a/Userland/Libraries/LibWeb/Painting/DisplayListPlayerSkia.cpp +++ b/Userland/Libraries/LibWeb/Painting/DisplayListPlayerSkia.cpp @@ -698,6 +698,10 @@ CommandResult DisplayListPlayerSkia::fill_path_using_paint_style(FillPathUsingPa CommandResult DisplayListPlayerSkia::stroke_path_using_color(StrokePathUsingColor const& command) { + // Skia treats zero thickness as a special case and will draw a hairline, while we want to draw nothing. + if (!command.thickness) + return CommandResult::Continue; + auto& canvas = surface().canvas(); SkPaint paint; paint.setAntiAlias(true); @@ -712,6 +716,10 @@ CommandResult DisplayListPlayerSkia::stroke_path_using_color(StrokePathUsingColo CommandResult DisplayListPlayerSkia::stroke_path_using_paint_style(StrokePathUsingPaintStyle const& command) { + // Skia treats zero thickness as a special case and will draw a hairline, while we want to draw nothing. + if (!command.thickness) + return CommandResult::Continue; + auto path = to_skia_path(command.path); path.offset(command.aa_translation.x(), command.aa_translation.y()); auto paint = paint_style_to_skia_paint(*command.paint_style, command.bounding_rect().to_type()); @@ -725,6 +733,10 @@ CommandResult DisplayListPlayerSkia::stroke_path_using_paint_style(StrokePathUsi CommandResult DisplayListPlayerSkia::draw_ellipse(DrawEllipse const& command) { + // Skia treats zero thickness as a special case and will draw a hairline, while we want to draw nothing. + if (!command.thickness) + return CommandResult::Continue; + auto const& rect = command.rect; auto& canvas = surface().canvas(); SkPaint paint; @@ -749,6 +761,10 @@ CommandResult DisplayListPlayerSkia::fill_ellipse(FillEllipse const& command) CommandResult DisplayListPlayerSkia::draw_line(DrawLine const& command) { + // Skia treats zero thickness as a special case and will draw a hairline, while we want to draw nothing. + if (!command.thickness) + return CommandResult::Continue; + auto from = SkPoint::Make(command.from.x(), command.from.y()); auto to = SkPoint::Make(command.to.x(), command.to.y()); auto& canvas = surface().canvas();