ladybird/Userland/Libraries/LibWeb/SVG/SVGViewport.h
MacDue 74b655d035 LibWeb: Update SVG <circle> element to use geometry properties
With this the `<circle>` element now correctly parses percentage sizes,
and resolves them relative to the viewport.

The rest of the geometry elements are still left TODO.
2024-03-04 10:50:32 +01:00

30 lines
774 B
C++

/*
* Copyright (c) 2024, MacDue <macdue@dueutil.tech>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/Math.h>
#include <LibWeb/SVG/AttributeParser.h>
#include <LibWeb/SVG/ViewBox.h>
namespace Web::SVG {
class SVGViewport {
public:
virtual Optional<ViewBox> view_box() const = 0;
virtual Optional<PreserveAspectRatio> preserve_aspect_ratio() const = 0;
virtual ~SVGViewport() = default;
};
inline CSSPixels normalized_diagonal_length(CSSPixelSize viewport_size)
{
if (viewport_size.width() == viewport_size.height())
return viewport_size.width();
return sqrt((viewport_size.width() * viewport_size.width()) + (viewport_size.height() * viewport_size.height())) / CSSPixels::nearest_value_for(AK::Sqrt2<float>);
}
}