mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 19:57:35 +00:00
LibWeb: Add CSSPixels::nearest_value_for(FloatingPoint)
This is intended to annotate conversions from unknown floating-point values to CSSPixels, and make it more obvious the fp value will be rounded to the nearest fixed-point value.
This commit is contained in:
parent
360c0eb509
commit
71baa8c31a
28 changed files with 120 additions and 112 deletions
|
@ -300,11 +300,11 @@ static CSSPixels snap_a_length_as_a_border_width(double device_pixels_per_css_pi
|
|||
|
||||
// 3. If len is greater than zero, but less than 1 device pixel, round len up to 1 device pixel.
|
||||
if (device_pixels > 0 && device_pixels < 1)
|
||||
return CSSPixels(1 / device_pixels_per_css_pixel);
|
||||
return CSSPixels::nearest_value_for(1 / device_pixels_per_css_pixel);
|
||||
|
||||
// 4. If len is greater than 1 device pixel, round it down to the nearest integer number of device pixels.
|
||||
if (device_pixels > 1)
|
||||
return CSSPixels(floor(device_pixels) / device_pixels_per_css_pixel);
|
||||
return CSSPixels::nearest_value_for(floor(device_pixels) / device_pixels_per_css_pixel);
|
||||
|
||||
return length;
|
||||
}
|
||||
|
@ -742,7 +742,7 @@ void NodeWithStyle::apply_style(const CSS::StyleProperties& computed_style)
|
|||
// FIXME: Converting to pixels isn't really correct - values should be in "user units"
|
||||
// https://svgwg.org/svg2-draft/coords.html#TermUserUnits
|
||||
if (stroke_width->is_number())
|
||||
computed_values.set_stroke_width(CSS::Length::make_px(CSSPixels(stroke_width->as_number().number())));
|
||||
computed_values.set_stroke_width(CSS::Length::make_px(CSSPixels::nearest_value_for(stroke_width->as_number().number())));
|
||||
else if (stroke_width->is_length())
|
||||
computed_values.set_stroke_width(stroke_width->as_length().length());
|
||||
else if (stroke_width->is_percentage())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue