mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-10 11:36:22 +00:00
LibWeb: Initial support for dashed lines in Canvas
Implement setLineDash() and getLineDash() in CanvasPathDrawingStyles, which write/read from the CanvasState object. This doesn't implement the actual drawing of a dashed line, but at least sites using the Chart.js library no longer fail with an exception. Unfortunately the Painter classes don't support dashed/dotted lines based on segments yet.
This commit is contained in:
parent
c4c91f02b3
commit
e9001da8d6
Notes:
sideshowbarker
2024-07-17 09:49:48 +09:00
Author: https://github.com/simonkrauter 🔰
Commit: e9001da8d6
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/275
3 changed files with 26 additions and 2 deletions
|
@ -31,6 +31,29 @@ public:
|
||||||
return my_drawing_state().line_width;
|
return my_drawing_state().line_width;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-setlinedash
|
||||||
|
void set_line_dash(Vector<double> segments)
|
||||||
|
{
|
||||||
|
// 1. If any value in segments is not finite (e.g. an Infinity or a NaN value), or if any value is negative (less than zero), then return (without throwing an exception; user agents could show a message on a developer console, though, as that would be helpful for debugging).
|
||||||
|
for (auto const& segment : segments) {
|
||||||
|
if (!isfinite(segment) || segment < 0)
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. If the number of elements in segments is odd, then let segments be the concatenation of two copies of segments.
|
||||||
|
if (segments.size() % 2 == 1)
|
||||||
|
segments.extend(segments);
|
||||||
|
|
||||||
|
// 3. Let the object's dash list be segments.
|
||||||
|
my_drawing_state().dash_list = segments;
|
||||||
|
}
|
||||||
|
|
||||||
|
// https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-getlinedash
|
||||||
|
Vector<double> get_line_dash()
|
||||||
|
{
|
||||||
|
return my_drawing_state().dash_list;
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
CanvasPathDrawingStyles() = default;
|
CanvasPathDrawingStyles() = default;
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,7 @@ interface mixin CanvasPathDrawingStyles {
|
||||||
[FIXME] attribute CanvasLineJoin lineJoin;
|
[FIXME] attribute CanvasLineJoin lineJoin;
|
||||||
[FIXME] attribute unrestricted double miterLimit;
|
[FIXME] attribute unrestricted double miterLimit;
|
||||||
|
|
||||||
[FIXME] undefined setLineDash(sequence<unrestricted double> segments);
|
undefined setLineDash(sequence<unrestricted double> segments);
|
||||||
[FIXME] sequence<unrestricted double> getLineDash();
|
sequence<unrestricted double> getLineDash();
|
||||||
[FIXME] attribute unrestricted double lineDashOffset;
|
[FIXME] attribute unrestricted double lineDashOffset;
|
||||||
};
|
};
|
||||||
|
|
|
@ -77,6 +77,7 @@ public:
|
||||||
FillOrStrokeStyle fill_style { Gfx::Color::Black };
|
FillOrStrokeStyle fill_style { Gfx::Color::Black };
|
||||||
FillOrStrokeStyle stroke_style { Gfx::Color::Black };
|
FillOrStrokeStyle stroke_style { Gfx::Color::Black };
|
||||||
float line_width { 1 };
|
float line_width { 1 };
|
||||||
|
Vector<double> dash_list;
|
||||||
bool image_smoothing_enabled { true };
|
bool image_smoothing_enabled { true };
|
||||||
Bindings::ImageSmoothingQuality image_smoothing_quality { Bindings::ImageSmoothingQuality::Low };
|
Bindings::ImageSmoothingQuality image_smoothing_quality { Bindings::ImageSmoothingQuality::Low };
|
||||||
float global_alpha = { 1 };
|
float global_alpha = { 1 };
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue