SVGPolylineElement.cpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /*
  2. * Copyright (c) 2022, Sam Atkins <atkinssj@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibWeb/Bindings/Intrinsics.h>
  7. #include <LibWeb/Bindings/SVGPolylineElementPrototype.h>
  8. #include <LibWeb/SVG/AttributeNames.h>
  9. #include <LibWeb/SVG/AttributeParser.h>
  10. #include <LibWeb/SVG/SVGPolylineElement.h>
  11. namespace Web::SVG {
  12. JS_DEFINE_ALLOCATOR(SVGPolylineElement);
  13. SVGPolylineElement::SVGPolylineElement(DOM::Document& document, DOM::QualifiedName qualified_name)
  14. : SVGGeometryElement(document, qualified_name)
  15. {
  16. }
  17. void SVGPolylineElement::initialize(JS::Realm& realm)
  18. {
  19. Base::initialize(realm);
  20. WEB_SET_PROTOTYPE_FOR_INTERFACE(SVGPolylineElement);
  21. }
  22. void SVGPolylineElement::attribute_changed(FlyString const& name, Optional<String> const& old_value, Optional<String> const& value)
  23. {
  24. SVGGeometryElement::attribute_changed(name, old_value, value);
  25. if (name == SVG::AttributeNames::points)
  26. m_points = AttributeParser::parse_points(value.value_or(String {}));
  27. }
  28. Gfx::DeprecatedPath SVGPolylineElement::get_path(CSSPixelSize)
  29. {
  30. Gfx::DeprecatedPath path;
  31. if (m_points.is_empty())
  32. return path;
  33. // 1. perform an absolute moveto operation to the first coordinate pair in the list of points
  34. path.move_to(m_points.first());
  35. // 2. for each subsequent coordinate pair, perform an absolute lineto operation to that coordinate pair.
  36. for (size_t point_index = 1; point_index < m_points.size(); ++point_index)
  37. path.line_to(m_points[point_index]);
  38. return path;
  39. }
  40. }