mirror of
https://github.com/servo/servo.git
synced 2025-08-09 07:25:35 +01:00
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).
This commit is contained in:
parent
a7c796aaf1
commit
91c7ca11b3
4 changed files with 33 additions and 6 deletions
|
@ -1,5 +1,6 @@
|
||||||
use azure::azure_hl::DrawTarget;
|
use azure::azure_hl::DrawTarget;
|
||||||
use gfx::geometry::*;
|
use au = gfx::geometry;
|
||||||
|
use au::Au;
|
||||||
use geom::rect::Rect;
|
use geom::rect::Rect;
|
||||||
use image::base::Image;
|
use image::base::Image;
|
||||||
use render_context::RenderContext;
|
use render_context::RenderContext;
|
||||||
|
@ -53,6 +54,10 @@ impl DisplayItem {
|
||||||
Image(_, ref img) => ctx.draw_image(self.d().bounds, clone_arc(img)),
|
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),
|
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 {
|
static pure fn new_SolidColor(bounds: &Rect<Au>, r: u8, g: u8, b: u8) -> DisplayItem {
|
||||||
|
@ -81,14 +86,16 @@ trait DisplayListMethods {
|
||||||
|
|
||||||
impl DisplayList : DisplayListMethods {
|
impl DisplayList : DisplayListMethods {
|
||||||
fn append_item(item: ~DisplayItem) {
|
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);
|
self.push(move item);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn draw_into_context(ctx: &RenderContext) {
|
fn draw_into_context(ctx: &RenderContext) {
|
||||||
debug!("beginning display list");
|
debug!("beginning display list");
|
||||||
for self.each |item| {
|
for self.each |item| {
|
||||||
debug!("drawing %?", *item);
|
// FIXME(Issue #150): crashes
|
||||||
|
//debug!("drawing %?", *item);
|
||||||
item.draw_into_context(ctx);
|
item.draw_into_context(ctx);
|
||||||
}
|
}
|
||||||
debug!("ending display list");
|
debug!("ending display list");
|
||||||
|
|
|
@ -70,6 +70,10 @@ pub pure fn to_px(au: Au) -> int {
|
||||||
(*au / 60) as 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
|
// assumes 72 points per inch, and 96 px per inch
|
||||||
pub pure fn from_pt(f: float) -> Au {
|
pub pure fn from_pt(f: float) -> Au {
|
||||||
from_px((f / 72f * 96f) as int)
|
from_px((f / 72f * 96f) as int)
|
||||||
|
|
|
@ -38,14 +38,20 @@ impl RenderContext {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn draw_border(&self, bounds: &Rect<Au>, width: Au, r: u8, g: u8, b: u8) {
|
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,
|
let color = Color(r.to_float() as AzFloat,
|
||||||
g.to_float() as AzFloat,
|
g.to_float() as AzFloat,
|
||||||
b.to_float() as AzFloat,
|
b.to_float() as AzFloat,
|
||||||
1f as AzFloat);
|
1f as AzFloat);
|
||||||
let pattern = ColorPattern(color);
|
let pattern = ColorPattern(color);
|
||||||
let stroke_fields = 2; // CAP_SQUARE
|
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);
|
let draw_opts = DrawOptions(1 as AzFloat, 0 as uint16_t);
|
||||||
|
|
||||||
self.canvas.draw_target.stroke_rect(&rect, &pattern, &stroke_opts, &draw_opts);
|
self.canvas.draw_target.stroke_rect(&rect, &pattern, &stroke_opts, &draw_opts);
|
||||||
|
@ -162,6 +168,7 @@ impl u8 : to_float {
|
||||||
|
|
||||||
trait ToAzureRect {
|
trait ToAzureRect {
|
||||||
fn to_azure_rect() -> Rect<AzFloat>;
|
fn to_azure_rect() -> Rect<AzFloat>;
|
||||||
|
fn to_azure_snapped_rect() -> Rect<AzFloat>;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Rect<Au> : ToAzureRect {
|
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),
|
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))
|
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")]
|
#[cfg(target_os = "linux")]
|
||||||
|
|
|
@ -420,7 +420,11 @@ impl RenderBox : RenderBoxMethods {
|
||||||
TextBox(_,d) => {
|
TextBox(_,d) => {
|
||||||
list.append_item(~DisplayItem::new_Text(&abs_box_bounds,
|
list.append_item(~DisplayItem::new_Text(&abs_box_bounds,
|
||||||
~d.run.serialize(builder.ctx.font_cache),
|
~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
|
// TODO: items for background, border, outline
|
||||||
GenericBox(_) => {
|
GenericBox(_) => {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue