SVGTextPositioningElement.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. JS::ThrowCompletionOr<void> SVGTextPositioningElement::initialize(JS::Realm& realm)
  22. {
  23. MUST_OR_THROW_OOM(Base::initialize(realm));
  24. set_prototype(&Bindings::ensure_web_prototype<Bindings::SVGTextPositioningElementPrototype>(realm, "SVGTextPositioningElement"));
  25. return {};
  26. }
  27. void SVGTextPositioningElement::attribute_changed(DeprecatedFlyString const& name, DeprecatedString const& value)
  28. {
  29. SVGGraphicsElement::attribute_changed(name, value);
  30. if (name == SVG::AttributeNames::x) {
  31. m_x = AttributeParser::parse_coordinate(value).value_or(m_x);
  32. } else if (name == SVG::AttributeNames::y) {
  33. m_y = AttributeParser::parse_coordinate(value).value_or(m_y);
  34. } else if (name == SVG::AttributeNames::dx) {
  35. m_dx = AttributeParser::parse_coordinate(value).value_or(m_dx);
  36. } else if (name == SVG::AttributeNames::dy) {
  37. m_dy = AttributeParser::parse_coordinate(value).value_or(m_dy);
  38. }
  39. }
  40. Gfx::FloatPoint SVGTextPositioningElement::get_offset() const
  41. {
  42. return { m_x + m_dx, m_y + m_dy };
  43. }
  44. }