aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorBrian J. Burg <burg@cs.washington.edu>2012-10-24 13:52:14 -0700
committerBrian J. Burg <burg@cs.washington.edu>2012-10-24 15:34:04 -0700
commit91c7ca11b3b07178a6022a62af6958543fb0a9ab (patch)
treea9ca98db7298b86564d1ad0e2665fc267b7f85d8 /src
parenta7c796aaf1982810751c5126cdae3373604dfc5f (diff)
downloadservo-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')
-rw-r--r--src/servo/gfx/display_list.rs13
-rw-r--r--src/servo/gfx/geometry.rs4
-rw-r--r--src/servo/gfx/render_context.rs16
-rw-r--r--src/servo/layout/box.rs6
4 files changed, 33 insertions, 6 deletions
diff --git a/src/servo/gfx/display_list.rs b/src/servo/gfx/display_list.rs
index 62d10be73b6..3e1b9361708 100644
--- a/src/servo/gfx/display_list.rs
+++ b/src/servo/gfx/display_list.rs
@@ -1,5 +1,6 @@
use azure::azure_hl::DrawTarget;
-use gfx::geometry::*;
+use au = gfx::geometry;
+use au::Au;
use geom::rect::Rect;
use image::base::Image;
use render_context::RenderContext;
@@ -53,6 +54,10 @@ impl DisplayItem {
Image(_, ref img) => ctx.draw_image(self.d().bounds, clone_arc(img)),
Border(_, width, r, g, b) => ctx.draw_border(&self.d().bounds, width, r, g, b),
}
+
+ debug!("%?", {
+ ctx.draw_border(&self.d().bounds, au::from_px(1), 150, 150, 150);
+ () });
}
static pure fn new_SolidColor(bounds: &Rect<Au>, r: u8, g: u8, b: u8) -> DisplayItem {
@@ -81,14 +86,16 @@ trait DisplayListMethods {
impl DisplayList : DisplayListMethods {
fn append_item(item: ~DisplayItem) {
- debug!("Adding display item %u: %?", self.len(), item);
+ // FIXME(Issue #150): crashes
+ //debug!("Adding display item %u: %?", self.len(), item);
self.push(move item);
}
fn draw_into_context(ctx: &RenderContext) {
debug!("beginning display list");
for self.each |item| {
- debug!("drawing %?", *item);
+ // FIXME(Issue #150): crashes
+ //debug!("drawing %?", *item);
item.draw_into_context(ctx);
}
debug!("ending display list");
diff --git a/src/servo/gfx/geometry.rs b/src/servo/gfx/geometry.rs
index b3f1c9c46db..904a4b9c4fb 100644
--- a/src/servo/gfx/geometry.rs
+++ b/src/servo/gfx/geometry.rs
@@ -70,6 +70,10 @@ pub pure fn to_px(au: Au) -> int {
(*au / 60) as int
}
+pub pure fn to_frac_px(au: Au) -> float {
+ (*au as float) / 60f
+}
+
// assumes 72 points per inch, and 96 px per inch
pub pure fn from_pt(f: float) -> Au {
from_px((f / 72f * 96f) as int)
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")]
diff --git a/src/servo/layout/box.rs b/src/servo/layout/box.rs
index 61e5fdaf826..91ce6555483 100644
--- a/src/servo/layout/box.rs
+++ b/src/servo/layout/box.rs
@@ -420,7 +420,11 @@ impl RenderBox : RenderBoxMethods {
TextBox(_,d) => {
list.append_item(~DisplayItem::new_Text(&abs_box_bounds,
~d.run.serialize(builder.ctx.font_cache),
- d.range))
+ d.range));
+ // debug frames for text box bounds
+ debug!("%?", {
+ list.append_item(~DisplayItem::new_Border(&abs_box_bounds, au::from_px(1), 0, 0, 200))
+ ; ()});
},
// TODO: items for background, border, outline
GenericBox(_) => {