From 3b6dc09e474a02d3724e8aa8a0c52653c59862f8 Mon Sep 17 00:00:00 2001 From: Matt Brubeck Date: Mon, 10 Aug 2015 22:43:14 -0700 Subject: [PATCH] Snap rectangles to nearest pixels consistently. Snapping the top-left and bottom-right corners separately can cause a rectangle to change size when offset by a subpixel amount. Instead, this patch snaps the top-left corner, then rounds the size to a whole pixel amount, so any rectangle of a given size will always have the same snapped size. Fixes #7152. --- components/gfx/paint_context.rs | 19 +++++++------------ tests/ref/basic.list | 1 + .../text_decoration_underline_subpx_a.html | 16 ++++++++++++++++ .../text_decoration_underline_subpx_ref.html | 15 +++++++++++++++ .../html4/position-relative-035.htm.ini | 3 ++- 5 files changed, 41 insertions(+), 13 deletions(-) create mode 100644 tests/ref/text_decoration_underline_subpx_a.html create mode 100644 tests/ref/text_decoration_underline_subpx_ref.html diff --git a/components/gfx/paint_context.rs b/components/gfx/paint_context.rs index 6fbdece15ec..9f6df9287f0 100644 --- a/components/gfx/paint_context.rs +++ b/components/gfx/paint_context.rs @@ -1171,16 +1171,10 @@ pub trait ToAzureRect { impl ToAzureRect for Rect { fn to_nearest_azure_rect(&self) -> Rect { - 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 { - 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) -> 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() } } diff --git a/tests/ref/basic.list b/tests/ref/basic.list index ffaf75fa5ed..c851b309ec7 100644 --- a/tests/ref/basic.list +++ b/tests/ref/basic.list @@ -314,6 +314,7 @@ flaky_cpu == linebreak_simple_a.html linebreak_simple_b.html == text_decoration_cached.html text_decoration_cached_ref.html # text_decoration_propagation_a.html text_decoration_propagation_b.html != text_decoration_smoke_a.html text_decoration_smoke_ref.html +!= text_decoration_underline_subpx_a.html text_decoration_underline_subpx_ref.html == text_indent_a.html text_indent_ref.html == text_justify_none_a.html text_justify_none_ref.html != text_overflow_a.html text_overflow_ref.html diff --git a/tests/ref/text_decoration_underline_subpx_a.html b/tests/ref/text_decoration_underline_subpx_a.html new file mode 100644 index 00000000000..36dea4951ba --- /dev/null +++ b/tests/ref/text_decoration_underline_subpx_a.html @@ -0,0 +1,16 @@ + + + + + Underline test + + + +

Hello

+ + diff --git a/tests/ref/text_decoration_underline_subpx_ref.html b/tests/ref/text_decoration_underline_subpx_ref.html new file mode 100644 index 00000000000..8e23c14ed42 --- /dev/null +++ b/tests/ref/text_decoration_underline_subpx_ref.html @@ -0,0 +1,15 @@ + + + + + Underline test + + + +

Hello

+ + diff --git a/tests/wpt/metadata-css/css21_dev/html4/position-relative-035.htm.ini b/tests/wpt/metadata-css/css21_dev/html4/position-relative-035.htm.ini index 9cb4b4c28f7..8f7aa9b2111 100644 --- a/tests/wpt/metadata-css/css21_dev/html4/position-relative-035.htm.ini +++ b/tests/wpt/metadata-css/css21_dev/html4/position-relative-035.htm.ini @@ -1,3 +1,4 @@ [position-relative-035.htm] type: reftest - expected: FAIL + expected: + if os == "mac": FAIL