auto merge of #774 : metajack/servo/au-rounding, r=pcwalton

This fixes too narrow boxes due to flooring computations.

r? @pcwalton
This commit is contained in:
bors-servo 2013-08-23 17:15:30 -07:00
commit 7492deae6d
5 changed files with 16 additions and 13 deletions

View file

@ -399,8 +399,8 @@ impl Font {
let azglyph = struct__AzGlyph { let azglyph = struct__AzGlyph {
mIndex: glyph.index() as uint32_t, mIndex: glyph.index() as uint32_t,
mPosition: struct__AzPoint { mPosition: struct__AzPoint {
x: (origin.x + glyph_offset.x).to_px() as AzFloat, x: (origin.x + glyph_offset.x).to_nearest_px() as AzFloat,
y: (origin.y + glyph_offset.y).to_px() as AzFloat y: (origin.y + glyph_offset.y).to_nearest_px() as AzFloat
} }
}; };
origin = Point2D(origin.x + glyph_advance, origin.y); origin = Point2D(origin.x + glyph_advance, origin.y);

View file

@ -82,15 +82,15 @@ pub fn box<T:Clone + Ord + Add<T,T> + Sub<T,T>>(x: T, y: T, w: T, h: T) -> Rect<
impl Au { impl Au {
pub fn scale_by(self, factor: float) -> Au { pub fn scale_by(self, factor: float) -> Au {
Au(((*self as float) * factor) as i32) Au(((*self as float) * factor).round() as i32)
} }
pub fn from_px(px: int) -> Au { pub fn from_px(px: int) -> Au {
NumCast::from(px * 60) NumCast::from(px * 60)
} }
pub fn to_px(&self) -> int { pub fn to_nearest_px(&self) -> int {
(**self / 60) as int ((**self as float) / 60f).round() as int
} }
pub fn to_snapped(&self) -> Au { pub fn to_snapped(&self) -> Au {

View file

@ -124,8 +124,10 @@ trait ToAzureRect {
impl ToAzureRect for Rect<Au> { impl ToAzureRect for Rect<Au> {
fn to_azure_rect(&self) -> Rect<AzFloat> { fn to_azure_rect(&self) -> Rect<AzFloat> {
Rect(Point2D(self.origin.x.to_px() as AzFloat, self.origin.y.to_px() as AzFloat), Rect(Point2D(self.origin.x.to_nearest_px() as AzFloat,
Size2D(self.size.width.to_px() as AzFloat, self.size.height.to_px() as AzFloat)) self.origin.y.to_nearest_px() as AzFloat),
Size2D(self.size.width.to_nearest_px() as AzFloat,
self.size.height.to_nearest_px() as AzFloat))
} }
} }
@ -135,9 +137,9 @@ trait ToSideOffsetsPx {
impl ToSideOffsetsPx for SideOffsets2D<Au> { impl ToSideOffsetsPx for SideOffsets2D<Au> {
fn to_float_px(&self) -> SideOffsets2D<AzFloat> { fn to_float_px(&self) -> SideOffsets2D<AzFloat> {
SideOffsets2D::new(self.top.to_px() as AzFloat, SideOffsets2D::new(self.top.to_nearest_px() as AzFloat,
self.right.to_px() as AzFloat, self.right.to_nearest_px() as AzFloat,
self.bottom.to_px() as AzFloat, self.bottom.to_nearest_px() as AzFloat,
self.left.to_px() as AzFloat) self.left.to_nearest_px() as AzFloat)
} }
} }

View file

@ -348,7 +348,8 @@ impl LayoutTask {
let render_layer = RenderLayer { let render_layer = RenderLayer {
display_list: display_list.clone(), display_list: display_list.clone(),
size: Size2D(root_size.width.to_px() as uint, root_size.height.to_px() as uint) size: Size2D(root_size.width.to_nearest_px() as uint,
root_size.height.to_nearest_px() as uint)
}; };
self.display_list = Some(display_list.clone()); self.display_list = Some(display_list.clone());

View file

@ -223,7 +223,7 @@ extern fn HTMLImageElement_getWidth(cx: *JSContext, _argc: c_uint, vp: *mut JSVa
let (port, chan) = comm::stream(); let (port, chan) = comm::stream();
// TODO(tkuehn): currently this just queries top-level page's layout. Need to handle subframes. // TODO(tkuehn): currently this just queries top-level page's layout. Need to handle subframes.
match (*page).query_layout(ContentBoxQuery(node, chan), port) { match (*page).query_layout(ContentBoxQuery(node, chan), port) {
Ok(ContentBoxResponse(rect)) => rect.size.width.to_px(), Ok(ContentBoxResponse(rect)) => rect.size.width.to_nearest_px(),
Err(()) => 0 Err(()) => 0
} }
// TODO: if nothing is being rendered(?), return zero dimensions // TODO: if nothing is being rendered(?), return zero dimensions