1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 07:58:11 +00:00

LibWeb: Add an initial implementation of SVG text-anchor

This only handles very simple <text> elements, but this is enough (with
the font-size changes) to improve the badges on the GitHub README a fair
bit.
This commit is contained in:
MacDue 2023-07-19 19:12:00 +01:00 committed by Andreas Kling
parent 4cdb4de049
commit 30277f385c
10 changed files with 77 additions and 0 deletions

View file

@ -8,6 +8,7 @@
#include <AK/Utf16View.h>
#include <LibJS/Runtime/Completion.h>
#include <LibJS/Runtime/Utf16String.h>
#include <LibWeb/CSS/Parser/Parser.h>
#include <LibWeb/DOM/Document.h>
#include <LibWeb/Layout/SVGTextBox.h>
#include <LibWeb/SVG/AttributeNames.h>
@ -30,6 +31,22 @@ JS::ThrowCompletionOr<void> SVGTextContentElement::initialize(JS::Realm& realm)
return {};
}
Optional<TextAnchor> SVGTextContentElement::text_anchor() const
{
if (!layout_node())
return {};
switch (layout_node()->computed_values().text_anchor()) {
case CSS::TextAnchor::Start:
return TextAnchor::Start;
case CSS::TextAnchor::Middle:
return TextAnchor::Middle;
case CSS::TextAnchor::End:
return TextAnchor::End;
default:
VERIFY_NOT_REACHED();
}
}
void SVGTextContentElement::attribute_changed(DeprecatedFlyString const& name, DeprecatedString const& value)
{
SVGGraphicsElement::attribute_changed(name, value);