diff options
author | Brian J. Burg <burg@cs.washington.edu> | 2012-10-24 13:52:14 -0700 |
---|---|---|
committer | Brian J. Burg <burg@cs.washington.edu> | 2012-10-24 15:34:04 -0700 |
commit | 91c7ca11b3b07178a6022a62af6958543fb0a9ab (patch) | |
tree | a9ca98db7298b86564d1ad0e2665fc267b7f85d8 /src/servo/gfx/render_context.rs | |
parent | a7c796aaf1982810751c5126cdae3373604dfc5f (diff) | |
download | servo-91c7ca11b3b07178a6022a62af6958543fb0a9ab.tar.gz servo-91c7ca11b3b07178a6022a62af6958543fb0a9ab.zip |
Snap borders with odd pixel width to pixel boundaries.
Add debug bounding boxes for text boxes (RUST_LOG=servo::layout::box)
and all boxes (RUST_LOG=servo::gfx::display_list).
Diffstat (limited to 'src/servo/gfx/render_context.rs')
-rw-r--r-- | src/servo/gfx/render_context.rs | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/src/servo/gfx/render_context.rs b/src/servo/gfx/render_context.rs index fcdc42481d5..590e5448cc8 100644 --- a/src/servo/gfx/render_context.rs +++ b/src/servo/gfx/render_context.rs @@ -38,14 +38,20 @@ impl RenderContext { } pub fn draw_border(&self, bounds: &Rect<Au>, width: Au, r: u8, g: u8, b: u8) { - let rect = bounds.to_azure_rect(); let color = Color(r.to_float() as AzFloat, g.to_float() as AzFloat, b.to_float() as AzFloat, 1f as AzFloat); let pattern = ColorPattern(color); let stroke_fields = 2; // CAP_SQUARE - let stroke_opts = StrokeOptions(au::to_px(width) as AzFloat, 10 as AzFloat, stroke_fields); + let width_px = au::to_px(width); + let rect = if width_px % 2 == 0 { + bounds.to_azure_rect() + } else { + bounds.to_azure_snapped_rect() + }; + + let stroke_opts = StrokeOptions(width_px as AzFloat, 10 as AzFloat, stroke_fields); let draw_opts = DrawOptions(1 as AzFloat, 0 as uint16_t); self.canvas.draw_target.stroke_rect(&rect, &pattern, &stroke_opts, &draw_opts); @@ -162,6 +168,7 @@ impl u8 : to_float { trait ToAzureRect { fn to_azure_rect() -> Rect<AzFloat>; + fn to_azure_snapped_rect() -> Rect<AzFloat>; } impl Rect<Au> : ToAzureRect { @@ -169,6 +176,11 @@ impl Rect<Au> : ToAzureRect { Rect(Point2D(au::to_px(self.origin.x) as AzFloat, au::to_px(self.origin.y) as AzFloat), Size2D(au::to_px(self.size.width) as AzFloat, au::to_px(self.size.height) as AzFloat)) } + + fn to_azure_snapped_rect() -> Rect<AzFloat> { + Rect(Point2D(au::to_px(self.origin.x) as AzFloat + 0.5f as AzFloat, au::to_px(self.origin.y) as AzFloat + 0.5f as AzFloat), + Size2D(au::to_px(self.size.width) as AzFloat, au::to_px(self.size.height) as AzFloat)) + } } #[cfg(target_os = "linux")] |