Truly independent web browser
/*
* Copyright (c) 2022, Andreas Kling <[email protected]>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <LibWeb/Geometry/DOMPoint.h>
#include <LibWeb/Geometry/DOMRect.h>
#include <LibWeb/Layout/LayoutRustFFI.h>
#include <LibWeb/SVG/AttributeNames.h>
#include <LibWeb/SVG/AttributeParsing.h>
#include <LibWeb/SVG/SVGGraphicsElement.h>
#include <LibWeb/WebIDL/ExceptionOr.h>
#include <LibWebCommon/WebIDL/Types.h>
namespace Web::SVG {
// https://svgwg.org/svg2-draft/text.html#InterfaceSVGTextContentElement
class SVGTextContentElement : public SVGGraphicsElement {
WEB_WRAPPABLE(SVGTextContentElement, SVGGraphicsElement);
public:
static constexpr u16 LENGTHADJUST_UNKNOWN = 0;
static constexpr u16 LENGTHADJUST_SPACING = 1;
static constexpr u16 LENGTHADJUST_SPACINGANDGLYPHS = 2;
GC::Ref<SVGAnimatedEnumeration> length_adjust();
// What the textLength and lengthAdjust attributes ask of layout: The length to fit the text to, where the element
// gives a valid one, and whether the glyphs stretch along with the spacing between them.
struct ParsedTextLength {
Optional<SVGLengthValue> text_length;
bool adjusts_glyphs { false };
};
ParsedTextLength parsed_text_length() const;
// https://svgwg.org/svg2-draft/text.html#__svg__SVGTextContentElement__textLength
// The initial value of the ‘textLength’ content attribute is defined to equal the user-agent's calculated length
// for the element.
// FIXME: Use the calculated length of the element as the initial value, rather than 0.
REFLECT_ANIMATED_LENGTH_ATTRIBUTE_WITH_GETTER(textLength, text_length, Horizontal, SVGLengthValue::number(0));
WebIDL::ExceptionOr<WebIDL::Long> get_number_of_chars();
WebIDL::ExceptionOr<float> get_computed_text_length();
WebIDL::ExceptionOr<float> get_sub_string_length(WebIDL::UnsignedLong charnum, WebIDL::UnsignedLong nchars);
WebIDL::ExceptionOr<GC::Ref<Geometry::DOMPoint>> get_start_position_of_char(WebIDL::UnsignedLong charnum);
WebIDL::ExceptionOr<GC::Ref<Geometry::DOMPoint>> get_end_position_of_char(WebIDL::UnsignedLong charnum);
WebIDL::ExceptionOr<GC::Ref<Geometry::DOMRect>> get_extent_of_char(WebIDL::UnsignedLong charnum);
WebIDL::Long get_char_num_at_position(Bindings::DOMPointInit const&);
protected:
SVGTextContentElement(DOM::Document&, DOM::QualifiedName);
virtual void attribute_changed(Utf16FlyString const& name, Optional<Utf16String> const& old_value, Optional<Utf16String> const& value, Optional<Utf16FlyString> const& namespace_) override;
private:
virtual bool is_svg_text_content_element() const final { return true; }
Vector<Layout::RustFFI::FfiSvgTextCharacterCell> character_cells();
};
}
namespace Web::DOM {
template<>
inline bool Node::fast_is<SVG::SVGTextContentElement>() const { return is_svg_text_content_element(); }
}