mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 04:37:34 +00:00
LibGfx: Implement Rect::to_rounded<U>()
This replaces the usage of `rounded_int_rect`, whose name did not accurately reflect the rounding operation happening. For example, the position of the rect was not rounded but floored, and the size was pulled through `roundf` before casting to `int` which could result in inadvertent flooring if the resulting floating point could not exactly represent the rounded value.
This commit is contained in:
parent
bec474d99b
commit
ab19b092ed
5 changed files with 16 additions and 9 deletions
|
@ -180,7 +180,7 @@ DOM::ExceptionOr<void> CanvasRenderingContext2D::draw_image(CanvasImageSource co
|
|||
if (!painter)
|
||||
return {};
|
||||
auto transformed_destination_rect = m_drawing_state.transform.map(destination_rect);
|
||||
painter->draw_scaled_bitmap(rounded_int_rect(transformed_destination_rect), *bitmap, source_rect, 1.0f, Gfx::Painter::ScalingMode::BilinearBlend);
|
||||
painter->draw_scaled_bitmap(transformed_destination_rect.to_rounded<int>(), *bitmap, source_rect, 1.0f, Gfx::Painter::ScalingMode::BilinearBlend);
|
||||
|
||||
// 7. If image is not origin-clean, then set the CanvasRenderingContext2D's origin-clean flag to false.
|
||||
if (image_is_not_origin_clean(image))
|
||||
|
|
|
@ -36,7 +36,7 @@ void CanvasPaintable::paint(PaintContext& context, PaintPhase phase) const
|
|||
return;
|
||||
|
||||
if (layout_box().dom_node().bitmap())
|
||||
context.painter().draw_scaled_bitmap(rounded_int_rect(absolute_rect()), *layout_box().dom_node().bitmap(), layout_box().dom_node().bitmap()->rect(), 1.0f, to_gfx_scaling_mode(computed_values().image_rendering()));
|
||||
context.painter().draw_scaled_bitmap(absolute_rect().to_rounded<int>(), *layout_box().dom_node().bitmap(), layout_box().dom_node().bitmap()->rect(), 1.0f, to_gfx_scaling_mode(computed_values().image_rendering()));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -47,7 +47,7 @@ void ImagePaintable::paint(PaintContext& context, PaintPhase phase) const
|
|||
alt = image_element.src();
|
||||
context.painter().draw_text(enclosing_int_rect(absolute_rect()), alt, Gfx::TextAlignment::Center, computed_values().color(), Gfx::TextElision::Right);
|
||||
} else if (auto bitmap = layout_box().image_loader().bitmap(layout_box().image_loader().current_frame_index())) {
|
||||
context.painter().draw_scaled_bitmap(rounded_int_rect(absolute_rect()), *bitmap, bitmap->rect(), 1.0f, to_gfx_scaling_mode(computed_values().image_rendering()));
|
||||
context.painter().draw_scaled_bitmap(absolute_rect().to_rounded<int>(), *bitmap, bitmap->rect(), 1.0f, to_gfx_scaling_mode(computed_values().image_rendering()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -270,7 +270,7 @@ void StackingContext::paint(PaintContext& context) const
|
|||
|
||||
auto transformed_destination_rect = affine_transform.map(source_rect).translated(transform_origin);
|
||||
source_rect.translate_by(transform_origin);
|
||||
context.painter().draw_scaled_bitmap(Gfx::rounded_int_rect(transformed_destination_rect), *bitmap, source_rect, opacity, Gfx::Painter::ScalingMode::BilinearBlend);
|
||||
context.painter().draw_scaled_bitmap(transformed_destination_rect.to_rounded<int>(), *bitmap, source_rect, opacity, Gfx::Painter::ScalingMode::BilinearBlend);
|
||||
} else {
|
||||
paint_internal(context);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue