LibWeb: Misc. SVG improvements
No functional changes: added spec comments, moved some code, removed an unused member.
This commit is contained in:
parent
3553861046
commit
66925a3d80
Notes:
github-actions[bot]
2024-10-28 21:54:26 +00:00
Author: https://github.com/gmta Commit: https://github.com/LadybirdBrowser/ladybird/commit/66925a3d80a Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/2026 Reviewed-by: https://github.com/kalenikaliaksandr ✅
4 changed files with 8 additions and 7 deletions
|
@ -83,13 +83,10 @@ void SVGPathPaintable::paint(PaintContext& context, PaintPhase phase) const
|
|||
return copy;
|
||||
};
|
||||
|
||||
// Note: This is assuming .x_scale() == .y_scale() (which it does currently).
|
||||
auto viewbox_scale = paint_transform.x_scale();
|
||||
|
||||
auto svg_viewport = [&] {
|
||||
if (maybe_view_box.has_value())
|
||||
return Gfx::FloatRect { maybe_view_box->min_x, maybe_view_box->min_y, maybe_view_box->width, maybe_view_box->height };
|
||||
return Gfx::FloatRect { { 0, 0 }, svg_element_rect.size().to_type<float>() };
|
||||
return Gfx::FloatRect { {}, svg_element_rect.size().to_type<float>() };
|
||||
}();
|
||||
|
||||
if (context.draw_svg_geometry_for_clip_path()) {
|
||||
|
@ -137,6 +134,7 @@ void SVGPathPaintable::paint(PaintContext& context, PaintPhase phase) const
|
|||
auto stroke_opacity = graphics_element.stroke_opacity().value_or(1);
|
||||
|
||||
// Note: This is assuming .x_scale() == .y_scale() (which it does currently).
|
||||
auto viewbox_scale = paint_transform.x_scale();
|
||||
float stroke_thickness = graphics_element.stroke_width().value_or(1) * viewbox_scale;
|
||||
|
||||
if (auto paint_style = graphics_element.stroke_paint_style(paint_context); paint_style.has_value()) {
|
||||
|
|
|
@ -93,7 +93,9 @@ private:
|
|||
SpreadMethod spread_method_impl(HashTable<SVGGradientElement const*>& seen_gradients) const;
|
||||
Optional<Gfx::AffineTransform> gradient_transform_impl(HashTable<SVGGradientElement const*>& seen_gradients) const;
|
||||
|
||||
// https://svgwg.org/svg2-draft/pservers.html#LinearGradientAttributes
|
||||
Optional<GradientUnits> m_gradient_units = {};
|
||||
|
||||
Optional<SpreadMethod> m_spread_method = {};
|
||||
Optional<Gfx::AffineTransform> m_gradient_transform = {};
|
||||
};
|
||||
|
|
|
@ -118,6 +118,7 @@ Optional<Painting::PaintStyle> SVGLinearGradientElement::to_gfx_paint_style(SVGP
|
|||
// FIXME: Resolve percentages properly
|
||||
Gfx::FloatPoint start_point {};
|
||||
Gfx::FloatPoint end_point {};
|
||||
|
||||
// https://svgwg.org/svg2-draft/pservers.html#LinearGradientElementGradientUnitsAttribute
|
||||
if (units == GradientUnits::ObjectBoundingBox) {
|
||||
// If gradientUnits="objectBoundingBox", the user coordinate system for attributes ‘x1’, ‘y1’, ‘x2’ and ‘y2’
|
||||
|
@ -134,11 +135,11 @@ Optional<Painting::PaintStyle> SVGLinearGradientElement::to_gfx_paint_style(SVGP
|
|||
// is referenced (i.e., the user coordinate system for the element referencing the gradient element via a
|
||||
// fill or stroke property) and then applying the transform specified by attribute ‘gradientTransform’.
|
||||
// Percentages represent values relative to the current SVG viewport.
|
||||
start_point = Gfx::FloatPoint {
|
||||
start_point = {
|
||||
start_x().resolve_relative_to(paint_context.viewport.width()),
|
||||
start_y().resolve_relative_to(paint_context.viewport.height()),
|
||||
};
|
||||
end_point = Gfx::FloatPoint {
|
||||
end_point = {
|
||||
end_x().resolve_relative_to(paint_context.viewport.width()),
|
||||
end_y().resolve_relative_to(paint_context.viewport.height()),
|
||||
};
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
|
||||
namespace Web::SVG {
|
||||
|
||||
// https://svgwg.org/svg2-draft/pservers.html#GradientStops
|
||||
class SVGStopElement final : public SVGElement {
|
||||
WEB_PLATFORM_OBJECT(SVGStopElement, SVGElement);
|
||||
JS_DECLARE_ALLOCATOR(SVGStopElement);
|
||||
|
@ -36,7 +37,6 @@ private:
|
|||
virtual void initialize(JS::Realm&) override;
|
||||
|
||||
Optional<NumberPercentage> m_offset;
|
||||
Optional<Gfx::Color> m_color;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue