mirror of
https://github.com/RGBCube/serenity
synced 2025-05-22 18:45:08 +00:00
LibWeb: Update SVG get_path()
API to take a viewport size
This will allow resolving paths that use sizes that are relative to the viewport. This necessarily removes the on element caching, which has been redundant for a while as computed paths are stored on the paintable.
This commit is contained in:
parent
1fbf1073ab
commit
b9afea40e6
16 changed files with 55 additions and 126 deletions
|
@ -32,30 +32,21 @@ void SVGRectElement::attribute_changed(FlyString const& name, Optional<String> c
|
|||
|
||||
if (name == SVG::AttributeNames::x) {
|
||||
m_x = AttributeParser::parse_coordinate(value.value_or(String {}));
|
||||
m_path.clear();
|
||||
} else if (name == SVG::AttributeNames::y) {
|
||||
m_y = AttributeParser::parse_coordinate(value.value_or(String {}));
|
||||
m_path.clear();
|
||||
} else if (name == SVG::AttributeNames::width) {
|
||||
m_width = AttributeParser::parse_positive_length(value.value_or(String {}));
|
||||
m_path.clear();
|
||||
} else if (name == SVG::AttributeNames::height) {
|
||||
m_height = AttributeParser::parse_positive_length(value.value_or(String {}));
|
||||
m_path.clear();
|
||||
} else if (name == SVG::AttributeNames::rx) {
|
||||
m_radius_x = AttributeParser::parse_length(value.value_or(String {}));
|
||||
m_path.clear();
|
||||
} else if (name == SVG::AttributeNames::ry) {
|
||||
m_radius_y = AttributeParser::parse_length(value.value_or(String {}));
|
||||
m_path.clear();
|
||||
}
|
||||
}
|
||||
|
||||
Gfx::Path& SVGRectElement::get_path()
|
||||
Gfx::Path SVGRectElement::get_path(CSSPixelSize)
|
||||
{
|
||||
if (m_path.has_value())
|
||||
return m_path.value();
|
||||
|
||||
float width = m_width.value_or(0);
|
||||
float height = m_height.value_or(0);
|
||||
float x = m_x.value_or(0);
|
||||
|
@ -63,10 +54,8 @@ Gfx::Path& SVGRectElement::get_path()
|
|||
|
||||
Gfx::Path path;
|
||||
// If width or height is zero, rendering is disabled.
|
||||
if (width == 0 && height == 0) {
|
||||
m_path = move(path);
|
||||
return m_path.value();
|
||||
}
|
||||
if (width == 0 || height == 0)
|
||||
return path;
|
||||
|
||||
auto corner_radii = calculate_used_corner_radius_values();
|
||||
float rx = corner_radii.width();
|
||||
|
@ -116,8 +105,7 @@ Gfx::Path& SVGRectElement::get_path()
|
|||
if (rx > 0 && ry > 0)
|
||||
path.elliptical_arc_to({ x + rx, y }, corner_radii, x_axis_rotation, large_arc_flag, sweep_flag);
|
||||
|
||||
m_path = move(path);
|
||||
return m_path.value();
|
||||
return path;
|
||||
}
|
||||
|
||||
Gfx::FloatSize SVGRectElement::calculate_used_corner_radius_values() const
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue