SVGPolylineElement.cpp 1.3 KB

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