mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 10:48:11 +00:00

Previously, all SVG <text> elements were zero-sized boxes, that were only actually positioned and sized during painting. This led to a number of problems, the most visible of which being that text could not be scaled based on the viewBox. Which this patch, <text> elements get a correctly sized layout box, that can be hit-tested and respects the SVG viewBox. To share code with SVGGeometryElement's the PathData (from the prior commit) has been split into a computed path and computed transforms. The computed path is specific to geometry elements, but the computed transforms are shared between all SVG graphics elements.
39 lines
976 B
C++
39 lines
976 B
C++
/*
|
|
* Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <LibWeb/Layout/SVGGeometryBox.h>
|
|
#include <LibWeb/Painting/SVGGraphicsPaintable.h>
|
|
|
|
namespace Web::Painting {
|
|
|
|
class SVGGeometryPaintable final : public SVGGraphicsPaintable {
|
|
JS_CELL(SVGGeometryPaintable, SVGGraphicsPaintable);
|
|
|
|
public:
|
|
static JS::NonnullGCPtr<SVGGeometryPaintable> create(Layout::SVGGeometryBox const&);
|
|
|
|
virtual Optional<HitTestResult> hit_test(CSSPixelPoint, HitTestType) const override;
|
|
|
|
virtual void paint(PaintContext&, PaintPhase) const override;
|
|
|
|
Layout::SVGGeometryBox const& layout_box() const;
|
|
|
|
void set_computed_path(Gfx::Path path)
|
|
{
|
|
m_computed_path = move(path);
|
|
}
|
|
|
|
Optional<Gfx::Path> const& computed_path() const { return m_computed_path; }
|
|
|
|
protected:
|
|
SVGGeometryPaintable(Layout::SVGGeometryBox const&);
|
|
|
|
Optional<Gfx::Path> m_computed_path = {};
|
|
};
|
|
|
|
}
|