mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-22 01:35:35 +00:00
servo: Merge #7161 - Snap rectangles to nearest pixels consistently (from mbrubeck:underline); r=pcwalton
Snapping the top-left and bottom-right corners separately can cause a rectangle to change size or even become empty when offset by a subpixel amount. Instead, this patch snaps the top-left corner, then snaps the size to a whole pixel amount, so any rectangle of a given original size will always have the same snapped size. Fixes #7152. r? @pcwalton or @glennw Source-Repo: https://github.com/servo/servo Source-Revision: 9c528c6382ee4355f42824a7caad217c4eb8a3b0
This commit is contained in:
parent
aa30a38864
commit
6ad3db2453
@ -1171,16 +1171,10 @@ pub trait ToAzureRect {
|
||||
|
||||
impl ToAzureRect for Rect<Au> {
|
||||
fn to_nearest_azure_rect(&self) -> Rect<AzFloat> {
|
||||
let top_left = self.origin.to_nearest_azure_point();
|
||||
let bottom_right = self.bottom_right().to_nearest_azure_point();
|
||||
Rect::new(top_left,
|
||||
Size2D::new((bottom_right.x - top_left.x) as AzFloat,
|
||||
(bottom_right.y - top_left.y) as AzFloat))
|
||||
|
||||
Rect::new(self.origin.to_nearest_azure_point(), self.size.to_nearest_azure_size())
|
||||
}
|
||||
fn to_azure_rect(&self) -> Rect<AzFloat> {
|
||||
Rect::new(self.origin.to_azure_point(), Size2D::new(self.size.width.to_f32_px(),
|
||||
self.size.height.to_f32_px()))
|
||||
Rect::new(self.origin.to_azure_point(), self.size.to_azure_size())
|
||||
}
|
||||
}
|
||||
|
||||
@ -1382,11 +1376,12 @@ impl DrawTargetExtensions for DrawTarget {
|
||||
}
|
||||
|
||||
fn create_rectangular_path(&self, rect: &Rect<Au>) -> Path {
|
||||
let rect = rect.to_nearest_azure_rect();
|
||||
let path_builder = self.create_path_builder();
|
||||
path_builder.move_to(rect.origin.to_nearest_azure_point());
|
||||
path_builder.line_to(Point2D::new(rect.max_x(), rect.origin.y).to_nearest_azure_point());
|
||||
path_builder.line_to(Point2D::new(rect.max_x(), rect.max_y()).to_nearest_azure_point());
|
||||
path_builder.line_to(Point2D::new(rect.origin.x, rect.max_y()).to_nearest_azure_point());
|
||||
path_builder.move_to(rect.origin);
|
||||
path_builder.line_to(Point2D::new(rect.max_x(), rect.origin.y));
|
||||
path_builder.line_to(Point2D::new(rect.max_x(), rect.max_y()));
|
||||
path_builder.line_to(Point2D::new(rect.origin.x, rect.max_y()));
|
||||
path_builder.finish()
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user