mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 02:27:35 +00:00
LibWeb: Use CSSPixelFraction
to represent aspect ratios
This allows us to retain perfect precision for aspect ratios derived from either the intrinsic sizes of replaced elements, or the `aspect-ratio` CSS property.
This commit is contained in:
parent
4fb209d25f
commit
34c5043cbe
22 changed files with 57 additions and 55 deletions
|
@ -140,16 +140,16 @@ Optional<CSSPixels> SVGDecodedImageData::intrinsic_height() const
|
|||
return {};
|
||||
}
|
||||
|
||||
Optional<float> SVGDecodedImageData::intrinsic_aspect_ratio() const
|
||||
Optional<CSSPixelFraction> SVGDecodedImageData::intrinsic_aspect_ratio() const
|
||||
{
|
||||
// https://www.w3.org/TR/SVG2/coords.html#SizingSVGInCSS
|
||||
auto width = intrinsic_width();
|
||||
auto height = intrinsic_height();
|
||||
if (width.has_value() && height.has_value())
|
||||
return width->to_float() / height->to_float();
|
||||
return *width / *height;
|
||||
|
||||
if (auto const& viewbox = m_root_element->view_box(); viewbox.has_value())
|
||||
return viewbox->width / viewbox->height;
|
||||
return CSSPixels::nearest_value_for(viewbox->width) / CSSPixels::nearest_value_for(viewbox->height);
|
||||
|
||||
return {};
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue