Path2D.cpp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /*
  2. * Copyright (c) 2022, Sam Atkins <atkinssj@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibWeb/HTML/Path2D.h>
  7. #include <LibWeb/HTML/Window.h>
  8. namespace Web::HTML {
  9. JS::NonnullGCPtr<Path2D> Path2D::create_with_global_object(HTML::Window& window, Optional<Variant<JS::Handle<Path2D>, String>> const& path)
  10. {
  11. return *window.heap().allocate<Path2D>(window.realm(), window, path);
  12. }
  13. // https://html.spec.whatwg.org/multipage/canvas.html#dom-path2d
  14. Path2D::Path2D(HTML::Window& window, Optional<Variant<JS::Handle<Path2D>, String>> const& path)
  15. : PlatformObject(window.realm())
  16. {
  17. set_prototype(&window.cached_web_prototype("Path2D"));
  18. // 1. Let output be a new Path2D object.
  19. // 2. If path is not given, then return output.
  20. if (!path.has_value())
  21. return;
  22. // 3. If path is a Path2D object, then add all subpaths of path to output and return output.
  23. // (In other words, it returns a copy of the argument.)
  24. if (path->has<JS::Handle<Path2D>>()) {
  25. this->path() = path->get<JS::Handle<Path2D>>()->path();
  26. return;
  27. }
  28. dbgln("TODO: Implement constructing Path2D object with an SVG path string");
  29. // FIXME: 4. Let svgPath be the result of parsing and interpreting path according to SVG 2's rules for path data. [SVG]
  30. // FIXME: 5. Let (x, y) be the last point in svgPath.
  31. // FIXME: 6. Add all the subpaths, if any, from svgPath to output.
  32. // FIXME: 7. Create a new subpath in output with (x, y) as the only point in the subpath.
  33. // FIXME: 8. Return output.
  34. }
  35. Path2D::~Path2D() = default;
  36. }