mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-12-07 21:59:54 +00:00
Previously, we only supported very basic numbers and a single level of
text positioning support in the `x`, `y`, `dx` and `dy` attributes in
`<text>` and `<tspan>` SVG elements.
This improves our support for them in the following ways:
* Any `length-percentage` or `number` type value is accepted;
* Nested `<text>` and `<tspan>` use the 'current text position'
concept to determine where the next text run should go;
* We expose the attributes' values through the API.
Though we still do not support:
* Applying the `rotate` attribute;
* Applying transformations on a per-character basis.
* Proper horizontal and vertical glyph advancing (we just use the path
bounding box for now).
48 lines
1.6 KiB
C++
48 lines
1.6 KiB
C++
/*
|
|
* Copyright (c) 2021, Andreas Kling <andreas@ladybird.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <LibWeb/Forward.h>
|
|
#include <LibWeb/Layout/FormattingContext.h>
|
|
#include <LibWeb/Layout/SVGImageBox.h>
|
|
#include <LibWeb/Layout/SVGSVGBox.h>
|
|
#include <LibWeb/Layout/SVGTextBox.h>
|
|
#include <LibWeb/Layout/SVGTextPathBox.h>
|
|
|
|
namespace Web::Layout {
|
|
|
|
class SVGFormattingContext final : public FormattingContext {
|
|
public:
|
|
explicit SVGFormattingContext(LayoutState&, LayoutMode, Box const&, FormattingContext* parent, Gfx::AffineTransform parent_viewbox_transform = {});
|
|
~SVGFormattingContext();
|
|
|
|
virtual void run(AvailableSpace const&) override;
|
|
virtual CSSPixels automatic_content_width() const override;
|
|
virtual CSSPixels automatic_content_height() const override;
|
|
|
|
private:
|
|
void layout_svg_element(Box const&);
|
|
void layout_nested_viewport(Box const&);
|
|
void layout_container_element(SVGBox const&);
|
|
void layout_graphics_element(SVGGraphicsBox const&);
|
|
void layout_path_like_element(SVGGraphicsBox const&);
|
|
void layout_mask_or_clip(SVGBox const&);
|
|
void layout_image_element(SVGImageBox const& image_box);
|
|
|
|
[[nodiscard]] Gfx::Path compute_path_for_text(SVGTextBox const&) const;
|
|
[[nodiscard]] Gfx::Path compute_path_for_text_path(SVGTextPathBox const&) const;
|
|
|
|
Gfx::AffineTransform m_parent_viewbox_transform {};
|
|
|
|
Optional<AvailableSpace> m_available_space {};
|
|
Gfx::AffineTransform m_current_viewbox_transform {};
|
|
CSSPixelSize m_viewport_size {};
|
|
CSSPixelPoint m_svg_offset {};
|
|
Gfx::FloatPoint m_current_text_position {};
|
|
};
|
|
|
|
}
|