LibWeb: Implement CanvasDrawPath::isPointInPath()

This commit is contained in:
mierenhoop 2024-09-18 10:52:33 +02:00 committed by Sam Atkins
parent 18bc5972f4
commit 259e798a26
Notes: github-actions[bot] 2024-09-18 20:22:53 +00:00
4 changed files with 25 additions and 2 deletions

View file

@ -27,6 +27,9 @@ public:
virtual void clip(StringView fill_rule) = 0;
virtual void clip(Path2D& path, StringView fill_rule) = 0;
virtual bool is_point_in_path(double x, double y, StringView fill_rule) = 0;
virtual bool is_point_in_path(Path2D const& path, double x, double y, StringView fill_rule) = 0;
protected:
CanvasDrawPath() = default;
};

View file

@ -18,8 +18,10 @@ interface mixin CanvasDrawPath {
// 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");
// FIXME: `DOMString` should be `CanvasFillRule`
boolean isPointInPath(unrestricted double x, unrestricted double y, optional DOMString fillRule = "nonzero");
// FIXME: `DOMString` should be `CanvasFillRule`
boolean isPointInPath(Path2D path, unrestricted double x, unrestricted double y, optional DOMString fillRule = "nonzero");
[FIXME] boolean isPointInStroke(unrestricted double x, unrestricted double y);
[FIXME] boolean isPointInStroke(Path2D path, unrestricted double x, unrestricted double y);
};

View file

@ -542,6 +542,21 @@ void CanvasRenderingContext2D::clip(Path2D& path, StringView fill_rule)
clip_internal(path.path(), parse_fill_rule(fill_rule));
}
static bool is_point_in_path_internal(Gfx::Path path, double x, double y, StringView fill_rule)
{
return path.contains(Gfx::FloatPoint(x, y), parse_fill_rule(fill_rule));
}
bool CanvasRenderingContext2D::is_point_in_path(double x, double y, StringView fill_rule)
{
return is_point_in_path_internal(path(), x, y, fill_rule);
}
bool CanvasRenderingContext2D::is_point_in_path(Path2D const& path, double x, double y, StringView fill_rule)
{
return is_point_in_path_internal(path.path(), x, y, fill_rule);
}
// https://html.spec.whatwg.org/multipage/canvas.html#check-the-usability-of-the-image-argument
WebIDL::ExceptionOr<CanvasImageSourceUsability> check_usability_of_image(CanvasImageSource const& image)
{

View file

@ -87,6 +87,9 @@ public:
virtual void clip(StringView fill_rule) override;
virtual void clip(Path2D& path, StringView fill_rule) override;
virtual bool is_point_in_path(double x, double y, StringView fill_rule) override;
virtual bool is_point_in_path(Path2D const& path, double x, double y, StringView fill_rule) override;
virtual bool image_smoothing_enabled() const override;
virtual void set_image_smoothing_enabled(bool) override;
virtual Bindings::ImageSmoothingQuality image_smoothing_quality() const override;