Serenity Operating System
at master 35 lines 1.1 kB view raw
1/* 2 * Copyright (c) 2022, Andreas Kling <kling@serenityos.org> 3 * 4 * SPDX-License-Identifier: BSD-2-Clause 5 */ 6 7#include <AK/Utf16View.h> 8#include <LibJS/Runtime/Completion.h> 9#include <LibJS/Runtime/Utf16String.h> 10#include <LibWeb/DOM/Document.h> 11#include <LibWeb/SVG/SVGTextContentElement.h> 12 13namespace Web::SVG { 14 15SVGTextContentElement::SVGTextContentElement(DOM::Document& document, DOM::QualifiedName qualified_name) 16 : SVGGraphicsElement(document, move(qualified_name)) 17{ 18} 19 20JS::ThrowCompletionOr<void> SVGTextContentElement::initialize(JS::Realm& realm) 21{ 22 MUST_OR_THROW_OOM(Base::initialize(realm)); 23 set_prototype(&Bindings::ensure_web_prototype<Bindings::SVGTextContentElementPrototype>(realm, "SVGTextContentElement")); 24 25 return {}; 26} 27 28// https://svgwg.org/svg2-draft/text.html#__svg__SVGTextContentElement__getNumberOfChars 29WebIDL::ExceptionOr<int> SVGTextContentElement::get_number_of_chars() const 30{ 31 auto chars = TRY_OR_THROW_OOM(vm(), utf8_to_utf16(child_text_content())); 32 return static_cast<int>(chars.size()); 33} 34 35}