1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 23:47:45 +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

@ -125,6 +125,12 @@ enum class FillRule {
Evenodd
};
enum class TextAnchor {
Start,
Middle,
End
};
class AttributeParser final {
public:
~AttributeParser() = default;

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);

View file

@ -6,6 +6,7 @@
#pragma once
#include <LibWeb/SVG/AttributeParser.h>
#include <LibWeb/SVG/SVGGraphicsElement.h>
#include <LibWeb/WebIDL/ExceptionOr.h>
@ -24,6 +25,8 @@ public:
Gfx::FloatPoint get_offset() const;
Optional<TextAnchor> text_anchor() const;
protected:
SVGTextContentElement(DOM::Document&, DOM::QualifiedName);