diff --git a/Libraries/LibGfx/Painter.h b/Libraries/LibGfx/Painter.h index 300b718ca9a..e4b30fbf64f 100644 --- a/Libraries/LibGfx/Painter.h +++ b/Libraries/LibGfx/Painter.h @@ -31,7 +31,7 @@ public: virtual void stroke_path(Gfx::Path const&, Gfx::Color, float thickness) = 0; virtual void stroke_path(Gfx::Path const&, Gfx::Color, float thickness, float blur_radius, Gfx::CompositingAndBlendingOperator compositing_and_blending_operator) = 0; virtual void stroke_path(Gfx::Path const&, Gfx::PaintStyle const&, ReadonlySpan, float thickness, float global_alpha, Gfx::CompositingAndBlendingOperator compositing_and_blending_operator) = 0; - virtual void stroke_path(Gfx::Path const&, Gfx::PaintStyle const&, ReadonlySpan, float thickness, float global_alpha, Gfx::CompositingAndBlendingOperator compositing_and_blending_operator, Gfx::Path::CapStyle const&, Gfx::Path::JoinStyle const&, float miter_limit) = 0; + virtual void stroke_path(Gfx::Path const&, Gfx::PaintStyle const&, ReadonlySpan, float thickness, float global_alpha, Gfx::CompositingAndBlendingOperator compositing_and_blending_operator, Gfx::Path::CapStyle const&, Gfx::Path::JoinStyle const&, float miter_limit, Vector const&, float dash_offset) = 0; virtual void fill_path(Gfx::Path const&, Gfx::Color, Gfx::WindingRule) = 0; virtual void fill_path(Gfx::Path const&, Gfx::Color, Gfx::WindingRule, float blur_radius, Gfx::CompositingAndBlendingOperator compositing_and_blending_operator) = 0; diff --git a/Libraries/LibGfx/PainterSkia.cpp b/Libraries/LibGfx/PainterSkia.cpp index 1edc4bf5b20..375595912be 100644 --- a/Libraries/LibGfx/PainterSkia.cpp +++ b/Libraries/LibGfx/PainterSkia.cpp @@ -20,7 +20,9 @@ #include #include #include +#include #include +#include #include namespace Gfx { @@ -225,7 +227,7 @@ void PainterSkia::stroke_path(Gfx::Path const& path, Gfx::PaintStyle const& pain }); } -void PainterSkia::stroke_path(Gfx::Path const& path, Gfx::PaintStyle const& paint_style, ReadonlySpan filters, float thickness, float global_alpha, Gfx::CompositingAndBlendingOperator compositing_and_blending_operator, Gfx::Path::CapStyle const& cap_style, Gfx::Path::JoinStyle const& join_style, float miter_limit) +void PainterSkia::stroke_path(Gfx::Path const& path, Gfx::PaintStyle const& paint_style, ReadonlySpan filters, float thickness, float global_alpha, Gfx::CompositingAndBlendingOperator compositing_and_blending_operator, Gfx::Path::CapStyle const& cap_style, Gfx::Path::JoinStyle const& join_style, float miter_limit, Vector const& dash_array, float dash_offset) { // Skia treats zero thickness as a special case and will draw a hairline, while we want to draw nothing. if (thickness <= 0) @@ -241,6 +243,7 @@ void PainterSkia::stroke_path(Gfx::Path const& path, Gfx::PaintStyle const& pain paint.setStrokeCap(to_skia_cap(cap_style)); paint.setStrokeJoin(to_skia_join(join_style)); paint.setStrokeMiter(miter_limit); + paint.setPathEffect(SkDashPathEffect::Make(dash_array.data(), dash_array.size(), dash_offset)); paint.setBlender(to_skia_blender(compositing_and_blending_operator)); impl().with_canvas([&](auto& canvas) { canvas.drawPath(sk_path, paint); diff --git a/Libraries/LibGfx/PainterSkia.h b/Libraries/LibGfx/PainterSkia.h index 0e6a0dc0e79..0f78388cce2 100644 --- a/Libraries/LibGfx/PainterSkia.h +++ b/Libraries/LibGfx/PainterSkia.h @@ -25,7 +25,7 @@ public: virtual void stroke_path(Gfx::Path const&, Gfx::Color, float thickness) override; virtual void stroke_path(Gfx::Path const&, Gfx::Color, float thickness, float blur_radius, Gfx::CompositingAndBlendingOperator compositing_and_blending_operator) override; virtual void stroke_path(Gfx::Path const&, Gfx::PaintStyle const&, ReadonlySpan, float thickness, float global_alpha, Gfx::CompositingAndBlendingOperator compositing_and_blending_operator) override; - virtual void stroke_path(Gfx::Path const&, Gfx::PaintStyle const&, ReadonlySpan, float thickness, float global_alpha, Gfx::CompositingAndBlendingOperator compositing_and_blending_operator, Gfx::Path::CapStyle const&, Gfx::Path::JoinStyle const&, float miter_limit) override; + virtual void stroke_path(Gfx::Path const&, Gfx::PaintStyle const&, ReadonlySpan, float thickness, float global_alpha, Gfx::CompositingAndBlendingOperator compositing_and_blending_operator, Gfx::Path::CapStyle const&, Gfx::Path::JoinStyle const&, float miter_limit, Vector const&, float dash_offset) override; virtual void fill_path(Gfx::Path const&, Gfx::Color, Gfx::WindingRule) override; virtual void fill_path(Gfx::Path const&, Gfx::Color, Gfx::WindingRule, float blur_radius, Gfx::CompositingAndBlendingOperator compositing_and_blending_operator) override; virtual void fill_path(Gfx::Path const&, Gfx::PaintStyle const&, ReadonlySpan, float global_alpha, Gfx::CompositingAndBlendingOperator compositing_and_blending_operator, Gfx::WindingRule) override; diff --git a/Libraries/LibWeb/HTML/CanvasRenderingContext2D.cpp b/Libraries/LibWeb/HTML/CanvasRenderingContext2D.cpp index 8c248e735e5..2604ad0c5bc 100644 --- a/Libraries/LibWeb/HTML/CanvasRenderingContext2D.cpp +++ b/Libraries/LibWeb/HTML/CanvasRenderingContext2D.cpp @@ -329,10 +329,16 @@ void CanvasRenderingContext2D::stroke_internal(Gfx::Path const& path) auto& state = drawing_state(); - // FIXME: Honor state's dash_list, and line_dash_offset. auto line_cap = to_gfx_cap(state.line_cap); auto line_join = to_gfx_join(state.line_join); - painter->stroke_path(path, state.stroke_style.to_gfx_paint_style(), state.filters, state.line_width, state.global_alpha, state.current_compositing_and_blending_operator, line_cap, line_join, state.miter_limit); + // FIXME: Need a Vector for rendering dash_array, but state.dash_list is Vector. + // Maybe possible to avoid creating copies? + auto dash_array = Vector {}; + dash_array.ensure_capacity(state.dash_list.size()); + for (auto const& dash : state.dash_list) { + dash_array.append(static_cast(dash)); + } + painter->stroke_path(path, state.stroke_style.to_gfx_paint_style(), state.filters, state.line_width, state.global_alpha, state.current_compositing_and_blending_operator, line_cap, line_join, state.miter_limit, dash_array, state.line_dash_offset); did_draw(path.bounding_box()); } diff --git a/Libraries/LibWeb/Painting/DisplayListPlayerSkia.cpp b/Libraries/LibWeb/Painting/DisplayListPlayerSkia.cpp index ffb74e93312..9a4f1541e65 100644 --- a/Libraries/LibWeb/Painting/DisplayListPlayerSkia.cpp +++ b/Libraries/LibWeb/Painting/DisplayListPlayerSkia.cpp @@ -663,7 +663,6 @@ void DisplayListPlayerSkia::stroke_path_using_color(StrokePathUsingColor const& if (!command.thickness) return; - // FIXME: Use .dash_array, .dash_offset. auto& canvas = surface().canvas(); SkPaint paint; paint.setAntiAlias(true); @@ -673,6 +672,7 @@ void DisplayListPlayerSkia::stroke_path_using_color(StrokePathUsingColor const& paint.setStrokeJoin(to_skia_join(command.join_style)); paint.setColor(to_skia_color(command.color)); paint.setStrokeMiter(command.miter_limit); + paint.setPathEffect(SkDashPathEffect::Make(command.dash_array.data(), command.dash_array.size(), command.dash_offset)); auto path = to_skia_path(command.path); path.offset(command.aa_translation.x(), command.aa_translation.y()); canvas.drawPath(path, paint); @@ -684,7 +684,6 @@ void DisplayListPlayerSkia::stroke_path_using_paint_style(StrokePathUsingPaintSt if (!command.thickness) return; - // FIXME: Use .dash_array, .dash_offset. 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()); @@ -695,6 +694,7 @@ void DisplayListPlayerSkia::stroke_path_using_paint_style(StrokePathUsingPaintSt paint.setStrokeCap(to_skia_cap(command.cap_style)); paint.setStrokeJoin(to_skia_join(command.join_style)); paint.setStrokeMiter(command.miter_limit); + paint.setPathEffect(SkDashPathEffect::Make(command.dash_array.data(), command.dash_array.size(), command.dash_offset)); surface().canvas().drawPath(path, paint); } diff --git a/Tests/LibWeb/Screenshot/images/canvas-stroke-styles-ref.png b/Tests/LibWeb/Screenshot/images/canvas-stroke-styles-ref.png index e12fc3bd393..2cd64fd3e36 100644 Binary files a/Tests/LibWeb/Screenshot/images/canvas-stroke-styles-ref.png and b/Tests/LibWeb/Screenshot/images/canvas-stroke-styles-ref.png differ diff --git a/Tests/LibWeb/Screenshot/images/svg-stroke-styles-ref.png b/Tests/LibWeb/Screenshot/images/svg-stroke-styles-ref.png index 52181966bbc..de9f879beb5 100644 Binary files a/Tests/LibWeb/Screenshot/images/svg-stroke-styles-ref.png and b/Tests/LibWeb/Screenshot/images/svg-stroke-styles-ref.png differ