mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 23:37:36 +00:00
LibWeb: Use viewbox attribute in SVG symbol element
Previously when a viewBox was passed to a SVG symbol element it would not be taken into account when drawing the SVG.
This commit is contained in:
parent
9f73fc87a8
commit
e61fdd1dc6
9 changed files with 67 additions and 4 deletions
|
@ -159,7 +159,7 @@ void SVGFormattingContext::run(Box const& box, LayoutMode layout_mode, Available
|
|||
auto path_transform = dom_node.get_transform();
|
||||
|
||||
double viewbox_scale = 1;
|
||||
auto maybe_view_box = svg_svg_element.view_box();
|
||||
auto maybe_view_box = dom_node.view_box();
|
||||
if (maybe_view_box.has_value()) {
|
||||
// FIXME: This should allow just one of width or height to be specified.
|
||||
// E.g. We should be able to layout <svg width="100%"> where height is unspecified/auto.
|
||||
|
|
|
@ -33,7 +33,7 @@ Optional<Gfx::AffineTransform> SVGGeometryBox::layout_transform() const
|
|||
double scaling = 1;
|
||||
auto origin = viewbox_origin().to_type<double>().to_type<float>();
|
||||
Gfx::FloatPoint paint_offset = {};
|
||||
if (svg_box && svg_box->view_box().has_value()) {
|
||||
if (svg_box && geometry_element.view_box().has_value()) {
|
||||
// Note: SVGFormattingContext has already done the scaling based on the viewbox,
|
||||
// we now have to derive what it was from the original bounding box size.
|
||||
// FIXME: It would be nice if we could store the transform from layout somewhere, so we don't have to solve for it here.
|
||||
|
|
|
@ -76,7 +76,7 @@ void SVGGeometryPaintable::paint(PaintContext& context, PaintPhase phase) const
|
|||
auto offset = context.floored_device_point(svg_element_rect.location()).to_type<int>().to_type<float>();
|
||||
painter.translate(offset);
|
||||
|
||||
auto maybe_view_box = svg_element->view_box();
|
||||
auto maybe_view_box = geometry_element.view_box();
|
||||
|
||||
auto transform = layout_box().layout_transform();
|
||||
if (!transform.has_value())
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
#include <LibWeb/SVG/SVGGradientElement.h>
|
||||
#include <LibWeb/SVG/SVGGraphicsElement.h>
|
||||
#include <LibWeb/SVG/SVGSVGElement.h>
|
||||
#include <LibWeb/SVG/SVGSymbolElement.h>
|
||||
|
||||
namespace Web::SVG {
|
||||
|
||||
|
@ -230,4 +231,19 @@ Optional<float> SVGGraphicsElement::stroke_width() const
|
|||
return width.to_px(*layout_node(), scaled_viewport_size).to_double();
|
||||
}
|
||||
|
||||
Optional<ViewBox> SVGGraphicsElement::view_box() const
|
||||
{
|
||||
if (auto* svg_svg_element = shadow_including_first_ancestor_of_type<SVGSVGElement>()) {
|
||||
if (svg_svg_element->view_box().has_value())
|
||||
return svg_svg_element->view_box();
|
||||
}
|
||||
|
||||
if (auto* svg_symbol_element = shadow_including_first_ancestor_of_type<SVGSymbolElement>()) {
|
||||
if (svg_symbol_element->view_box().has_value())
|
||||
return svg_symbol_element->view_box();
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
#include <LibWeb/SVG/SVGElement.h>
|
||||
#include <LibWeb/SVG/SVGGradientElement.h>
|
||||
#include <LibWeb/SVG/TagNames.h>
|
||||
#include <LibWeb/SVG/ViewBox.h>
|
||||
|
||||
namespace Web::SVG {
|
||||
|
||||
|
@ -45,6 +46,8 @@ public:
|
|||
Optional<Gfx::PaintStyle const&> fill_paint_style(SVGPaintContext const&) const;
|
||||
Optional<Gfx::PaintStyle const&> stroke_paint_style(SVGPaintContext const&) const;
|
||||
|
||||
Optional<ViewBox> view_box() const;
|
||||
|
||||
protected:
|
||||
SVGGraphicsElement(DOM::Document&, DOM::QualifiedName);
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#include <LibWeb/CSS/StyleValues/IdentifierStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/OverflowStyleValue.h>
|
||||
#include <LibWeb/DOM/ShadowRoot.h>
|
||||
#include <LibWeb/SVG/AttributeNames.h>
|
||||
#include <LibWeb/SVG/SVGSymbolElement.h>
|
||||
#include <LibWeb/SVG/SVGUseElement.h>
|
||||
|
||||
|
@ -44,8 +45,12 @@ void SVGSymbolElement::apply_presentational_hints(CSS::StyleProperties& style) c
|
|||
// and this declaration must have importance over any other CSS rule or presentation attribute.
|
||||
style.set_property(CSS::PropertyID::Display, CSS::DisplayStyleValue::create(CSS::Display::from_short(CSS::Display::Short::None)).release_value_but_fixme_should_propagate_errors());
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Parse viewBox and apply it in SVGGraphicsElement/SVGGraphicsPaintable
|
||||
void SVGSymbolElement::attribute_changed(DeprecatedFlyString const& name, DeprecatedString const& value)
|
||||
{
|
||||
if (name.equals_ignoring_ascii_case(SVG::AttributeNames::viewBox))
|
||||
m_view_box = try_parse_view_box(value);
|
||||
}
|
||||
|
||||
bool SVGSymbolElement::is_direct_child_of_use_shadow_tree() const
|
||||
|
|
|
@ -18,12 +18,18 @@ public:
|
|||
|
||||
void apply_presentational_hints(CSS::StyleProperties& style) const override;
|
||||
|
||||
Optional<ViewBox> view_box() const { return m_view_box; }
|
||||
|
||||
private:
|
||||
SVGSymbolElement(DOM::Document&, DOM::QualifiedName);
|
||||
|
||||
virtual JS::ThrowCompletionOr<void> initialize(JS::Realm&) override;
|
||||
|
||||
bool is_direct_child_of_use_shadow_tree() const;
|
||||
|
||||
virtual void attribute_changed(DeprecatedFlyString const& name, DeprecatedString const& value) override;
|
||||
|
||||
Optional<ViewBox> m_view_box;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue