1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 21:37:35 +00:00

LibWeb: Add initial implementation of CRC2D.clip()

This allows clipping your drawing by any path you like! To do this
all painting has been wrapped around a new draw_clipped() helper
method, which handles the clipping before/after painting.

Note: This clipping is currently missing support for intersecting
clip paths.
This commit is contained in:
MacDue 2023-04-06 20:57:59 +01:00 committed by Linus Groh
parent 92d9b6edb8
commit 20e9213cc4
5 changed files with 126 additions and 102 deletions

View file

@ -24,7 +24,8 @@ public:
virtual void stroke() = 0;
virtual void stroke(Path2D const& path) = 0;
virtual void clip() = 0;
virtual void clip(DeprecatedString const& fill_rule) = 0;
virtual void clip(Path2D& path, DeprecatedString const& fill_rule) = 0;
protected:
CanvasDrawPath() = default;

View file

@ -13,10 +13,10 @@ interface mixin CanvasDrawPath {
undefined stroke();
undefined stroke(Path2D path);
// FIXME: Replace this with these two definitions:
// undefined clip(optional CanvasFillRule fillRule = "nonzero");
// undefined clip(Path2D path, optional CanvasFillRule fillRule = "nonzero");
undefined clip();
// FIXME: `DOMString` should be `CanvasFillRule`
undefined clip(optional DOMString fillRule = "nonzero");
// FIXME: `DOMString` should be `CanvasFillRule`
undefined clip(Path2D path, optional DOMString fillRule = "nonzero");
// FIXME: boolean isPointInPath(unrestricted double x, unrestricted double y, optional CanvasFillRule fillRule = "nonzero");
// FIXME: boolean isPointInPath(Path2D path, unrestricted double x, unrestricted double y, optional CanvasFillRule fillRule = "nonzero");

View file

@ -13,6 +13,7 @@
#include <LibGfx/Color.h>
#include <LibGfx/PaintStyle.h>
#include <LibWeb/Bindings/CanvasRenderingContext2DPrototype.h>
#include <LibWeb/HTML/Canvas/CanvasPathClipper.h>
#include <LibWeb/HTML/CanvasGradient.h>
#include <LibWeb/HTML/CanvasPattern.h>
@ -77,6 +78,7 @@ public:
float line_width { 1 };
bool image_smoothing_enabled { true };
Bindings::ImageSmoothingQuality image_smoothing_quality { Bindings::ImageSmoothingQuality::Low };
Optional<CanvasClip> clip;
};
DrawingState& drawing_state() { return m_drawing_state; }
DrawingState const& drawing_state() const { return m_drawing_state; }