SVGTextPositioningElement.cpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /*
  2. * Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
  3. * Copyright (c) 2023, Aliaksandr Kalenik <kalenik.aliaksandr@gmail.com>
  4. *
  5. * SPDX-License-Identifier: BSD-2-Clause
  6. */
  7. #include <AK/Utf16View.h>
  8. #include <LibJS/Runtime/Completion.h>
  9. #include <LibJS/Runtime/Utf16String.h>
  10. #include <LibWeb/CSS/Parser/Parser.h>
  11. #include <LibWeb/DOM/Document.h>
  12. #include <LibWeb/SVG/AttributeNames.h>
  13. #include <LibWeb/SVG/AttributeParser.h>
  14. #include <LibWeb/SVG/SVGGeometryElement.h>
  15. #include <LibWeb/SVG/SVGTextPositioningElement.h>
  16. namespace Web::SVG {
  17. SVGTextPositioningElement::SVGTextPositioningElement(DOM::Document& document, DOM::QualifiedName qualified_name)
  18. : SVGTextContentElement(document, move(qualified_name))
  19. {
  20. }
  21. void SVGTextPositioningElement::initialize(JS::Realm& realm)
  22. {
  23. Base::initialize(realm);
  24. WEB_SET_PROTOTYPE_FOR_INTERFACE(SVGTextPositioningElement);
  25. }
  26. void SVGTextPositioningElement::attribute_changed(FlyString const& name, Optional<String> const& value)
  27. {
  28. SVGGraphicsElement::attribute_changed(name, value);
  29. if (name == SVG::AttributeNames::x) {
  30. m_x = AttributeParser::parse_coordinate(value.value_or(String {})).value_or(m_x);
  31. } else if (name == SVG::AttributeNames::y) {
  32. m_y = AttributeParser::parse_coordinate(value.value_or(String {})).value_or(m_y);
  33. } else if (name == SVG::AttributeNames::dx) {
  34. m_dx = AttributeParser::parse_coordinate(value.value_or(String {})).value_or(m_dx);
  35. } else if (name == SVG::AttributeNames::dy) {
  36. m_dy = AttributeParser::parse_coordinate(value.value_or(String {})).value_or(m_dy);
  37. }
  38. }
  39. Gfx::FloatPoint SVGTextPositioningElement::get_offset() const
  40. {
  41. return { m_x + m_dx, m_y + m_dy };
  42. }
  43. }