mirror of
https://github.com/SerenityOS/serenity
synced 2026-05-01 03:47:48 +02:00
To rebaseline image test expecatations, I ran:
out/gn/Ladybird.app/Contents/MacOS/headless-browser \
--resources $PWD/out/gn/Ladybird.app/Contents/Resources \
--dump-failed-ref-tests \
--run-tests $PWD/Tests/LibWeb \
--filter 'canvas-*'
I then copied over the new baselines with
D=Tests/LibWeb/Ref/reference/images
cp test-dumps/canvas-implict-moves-and-lines.png \
$D/canvas-implict-moves-and-lines-ref.png
(Note: No `-ref` suffix on first path, yes suffix on second path.)
We currently don't track if a path is open or closed, and paint
butt linecaps at the end of closed paths too. We did that with
round linecaps as well, but there that wasn't visible. This makes
closed paths look a bit weird now; we'll have to fix this in a
follow-up. In a way, this just exposes another not-yet-implemented
feature.
55 lines
1.7 KiB
C++
55 lines
1.7 KiB
C++
/*
|
|
* Copyright (c) 2022, Sam Atkins <atkinssj@serenityos.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <LibWeb/HTML/Canvas/CanvasState.h>
|
|
|
|
namespace Web::HTML {
|
|
|
|
// https://html.spec.whatwg.org/multipage/canvas.html#canvaspathdrawingstyles
|
|
template<typename IncludingClass>
|
|
class CanvasPathDrawingStyles {
|
|
public:
|
|
~CanvasPathDrawingStyles() = default;
|
|
|
|
// https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-linewidth
|
|
void set_line_width(float line_width)
|
|
{
|
|
// On setting, zero, negative, infinite, and NaN values must be ignored, leaving the value unchanged;
|
|
if (line_width <= 0 || !isfinite(line_width))
|
|
return;
|
|
// other values must change the current value to the new value.
|
|
my_drawing_state().line_width = line_width;
|
|
}
|
|
float line_width() const
|
|
{
|
|
// On getting, it must return the current value.
|
|
return my_drawing_state().line_width;
|
|
}
|
|
|
|
// https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-linecap
|
|
void set_line_cap(Bindings::CanvasLineCap line_cap)
|
|
{
|
|
// On setting, the current value must be changed to the new value.
|
|
my_drawing_state().line_cap = line_cap;
|
|
}
|
|
Bindings::CanvasLineCap line_cap() const
|
|
{
|
|
// On getting, it must return the current value.
|
|
return my_drawing_state().line_cap;
|
|
}
|
|
|
|
protected:
|
|
CanvasPathDrawingStyles() = default;
|
|
|
|
private:
|
|
CanvasState::DrawingState& my_drawing_state() { return reinterpret_cast<IncludingClass&>(*this).drawing_state(); }
|
|
CanvasState::DrawingState const& my_drawing_state() const { return reinterpret_cast<IncludingClass const&>(*this).drawing_state(); }
|
|
};
|
|
|
|
}
|