1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 00:37:45 +00:00

LibWeb: Make CSSPixels and Length use 64-bit (double) floating point

This fixes a plethora of rounding problems on many websites.
In the future, we may want to replace this with fixed-point arithmetic
(bug #18566) for performance (and consistency with other engines),
but in the meantime this makes the web look a bit better. :^)

There's a lot more things that could be converted to doubles, which
would reduce the amount of casting necessary in this patch.
We can do that incrementally, however.
This commit is contained in:
Andreas Kling 2023-05-24 10:50:57 +02:00
parent 30262d7023
commit 655d9d1462
80 changed files with 298 additions and 299 deletions

View file

@ -148,16 +148,16 @@ void paint_background(PaintContext& context, Layout::NodeWithStyleAndBoxModelMet
CSSPixelRect image_rect;
switch (layer.size_type) {
case CSS::BackgroundSize::Contain: {
float max_width_ratio = (background_positioning_area.width() / natural_image_width).value();
float max_height_ratio = (background_positioning_area.height() / natural_image_height).value();
float ratio = min(max_width_ratio, max_height_ratio);
double max_width_ratio = (background_positioning_area.width() / natural_image_width).value();
double max_height_ratio = (background_positioning_area.height() / natural_image_height).value();
double ratio = min(max_width_ratio, max_height_ratio);
image_rect.set_size(natural_image_width * ratio, natural_image_height * ratio);
break;
}
case CSS::BackgroundSize::Cover: {
float max_width_ratio = (background_positioning_area.width() / natural_image_width).value();
float max_height_ratio = (background_positioning_area.height() / natural_image_height).value();
float ratio = max(max_width_ratio, max_height_ratio);
double max_width_ratio = (background_positioning_area.width() / natural_image_width).value();
double max_height_ratio = (background_positioning_area.height() / natural_image_height).value();
double ratio = max(max_width_ratio, max_height_ratio);
image_rect.set_size(natural_image_width * ratio, natural_image_height * ratio);
break;
}
@ -253,7 +253,7 @@ void paint_background(PaintContext& context, Layout::NodeWithStyleAndBoxModelMet
repeat_x = false;
} else {
auto space = fmod(background_positioning_area.width(), image_rect.width());
x_step = image_rect.width() + (space / (float)(whole_images - 1));
x_step = image_rect.width() + (space / static_cast<double>(whole_images - 1));
repeat_x = true;
}
break;
@ -284,7 +284,7 @@ void paint_background(PaintContext& context, Layout::NodeWithStyleAndBoxModelMet
repeat_y = false;
} else {
auto space = fmod(background_positioning_area.height(), image_rect.height());
y_step = image_rect.height() + ((float)space / (float)(whole_images - 1));
y_step = image_rect.height() + (static_cast<double>(space) / static_cast<double>(whole_images - 1));
repeat_y = true;
}
break;