1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 01:07:36 +00:00

LibWeb: Implement Path2D class

This commit is contained in:
Sam Atkins 2022-08-11 16:50:23 +01:00 committed by Andreas Kling
parent a37ab7b9f8
commit 2ec52bbbd5
9 changed files with 92 additions and 0 deletions

View file

@ -17,6 +17,7 @@
#include <LibWeb/HTML/HTMLCanvasElement.h>
#include <LibWeb/HTML/HTMLImageElement.h>
#include <LibWeb/HTML/ImageData.h>
#include <LibWeb/HTML/Path2D.h>
#include <LibWeb/HTML/TextMetrics.h>
#include <LibWeb/HTML/Window.h>
#include <LibWeb/Layout/TextNode.h>

View file

@ -0,0 +1,35 @@
/*
* Copyright (c) 2022, Sam Atkins <atkinssj@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibWeb/HTML/Path2D.h>
namespace Web::HTML {
// https://html.spec.whatwg.org/multipage/canvas.html#dom-path2d
Path2D::Path2D(Optional<Variant<NonnullRefPtr<Path2D>, String>> const& path)
{
// 1. Let output be a new Path2D object.
// 2. If path is not given, then return output.
if (!path.has_value())
return;
// 3. If path is a Path2D object, then add all subpaths of path to output and return output.
// (In other words, it returns a copy of the argument.)
if (path->has<NonnullRefPtr<Path2D>>()) {
this->path() = path->get<NonnullRefPtr<Path2D>>()->path();
return;
}
dbgln("TODO: Implement constructing Path2D object with an SVG path string");
// FIXME: 4. Let svgPath be the result of parsing and interpreting path according to SVG 2's rules for path data. [SVG]
// FIXME: 5. Let (x, y) be the last point in svgPath.
// FIXME: 6. Add all the subpaths, if any, from svgPath to output.
// FIXME: 7. Create a new subpath in output with (x, y) as the only point in the subpath.
// FIXME: 8. Return output.
}
}

View file

@ -0,0 +1,36 @@
/*
* Copyright (c) 2022, Sam Atkins <atkinssj@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/RefCounted.h>
#include <LibGfx/Path.h>
#include <LibWeb/Bindings/Wrappable.h>
#include <LibWeb/HTML/Canvas/CanvasPath.h>
namespace Web::HTML {
// https://html.spec.whatwg.org/multipage/canvas.html#path2d
class Path2D
: public RefCounted<Path2D>
, public Bindings::Wrappable
, public CanvasPath {
AK_MAKE_NONCOPYABLE(Path2D);
AK_MAKE_NONMOVABLE(Path2D);
public:
using WrapperType = Bindings::Path2DWrapper;
static NonnullRefPtr<Path2D> create_with_global_object(Bindings::WindowObject&, Optional<Variant<NonnullRefPtr<Path2D>, String>> const& path) { return adopt_ref(*new Path2D(path)); }
static NonnullRefPtr<Path2D> create(Optional<Variant<NonnullRefPtr<Path2D>, String>> const& path) { return adopt_ref(*new Path2D(path)); }
~Path2D() = default;
private:
Path2D(Optional<Variant<NonnullRefPtr<Path2D>, String>> const&);
};
}

View file

@ -0,0 +1,11 @@
#import <HTML/Canvas/CanvasPath.idl>
// https://html.spec.whatwg.org/multipage/canvas.html#path2d
[Exposed=(Window,Worker)]
interface Path2D {
constructor(optional (Path2D or DOMString) path);
// FIXME: undefined addPath(Path2D path, optional DOMMatrix2DInit transform = {});
};
Path2D includes CanvasPath;