mirror of
https://github.com/servo/servo.git
synced 2025-08-03 20:50:07 +01:00
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:
commit
7492deae6d
5 changed files with 16 additions and 13 deletions
|
@ -399,8 +399,8 @@ impl Font {
|
|||
let azglyph = struct__AzGlyph {
|
||||
mIndex: glyph.index() as uint32_t,
|
||||
mPosition: struct__AzPoint {
|
||||
x: (origin.x + glyph_offset.x).to_px() as AzFloat,
|
||||
y: (origin.y + glyph_offset.y).to_px() as AzFloat
|
||||
x: (origin.x + glyph_offset.x).to_nearest_px() as AzFloat,
|
||||
y: (origin.y + glyph_offset.y).to_nearest_px() as AzFloat
|
||||
}
|
||||
};
|
||||
origin = Point2D(origin.x + glyph_advance, origin.y);
|
||||
|
|
|
@ -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 {
|
||||
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 {
|
||||
NumCast::from(px * 60)
|
||||
}
|
||||
|
||||
pub fn to_px(&self) -> int {
|
||||
(**self / 60) as int
|
||||
pub fn to_nearest_px(&self) -> int {
|
||||
((**self as float) / 60f).round() as int
|
||||
}
|
||||
|
||||
pub fn to_snapped(&self) -> Au {
|
||||
|
|
|
@ -124,8 +124,10 @@ trait ToAzureRect {
|
|||
|
||||
impl ToAzureRect for Rect<Au> {
|
||||
fn to_azure_rect(&self) -> Rect<AzFloat> {
|
||||
Rect(Point2D(self.origin.x.to_px() as AzFloat, self.origin.y.to_px() as AzFloat),
|
||||
Size2D(self.size.width.to_px() as AzFloat, self.size.height.to_px() as AzFloat))
|
||||
Rect(Point2D(self.origin.x.to_nearest_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> {
|
||||
fn to_float_px(&self) -> SideOffsets2D<AzFloat> {
|
||||
SideOffsets2D::new(self.top.to_px() as AzFloat,
|
||||
self.right.to_px() as AzFloat,
|
||||
self.bottom.to_px() as AzFloat,
|
||||
self.left.to_px() as AzFloat)
|
||||
SideOffsets2D::new(self.top.to_nearest_px() as AzFloat,
|
||||
self.right.to_nearest_px() as AzFloat,
|
||||
self.bottom.to_nearest_px() as AzFloat,
|
||||
self.left.to_nearest_px() as AzFloat)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -348,7 +348,8 @@ impl LayoutTask {
|
|||
|
||||
let render_layer = RenderLayer {
|
||||
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());
|
||||
|
|
|
@ -223,7 +223,7 @@ extern fn HTMLImageElement_getWidth(cx: *JSContext, _argc: c_uint, vp: *mut JSVa
|
|||
let (port, chan) = comm::stream();
|
||||
// TODO(tkuehn): currently this just queries top-level page's layout. Need to handle subframes.
|
||||
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
|
||||
}
|
||||
// TODO: if nothing is being rendered(?), return zero dimensions
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue