Auto merge of #7766 - glennw:au-tidy, r=pcwalton

A few clean ups for Au type



<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/7766)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2015-09-28 11:35:04 -06:00
commit 007c22737d
3 changed files with 25 additions and 51 deletions

View file

@ -34,7 +34,7 @@ use std::{f32, mem, ptr};
use style::computed_values::{border_style, filter, image_rendering, mix_blend_mode};
use text::TextRun;
use text::glyph::CharIndex;
use util::geometry::{self, Au, MAX_RECT, ZERO_RECT};
use util::geometry::{self, Au, MAX_RECT, ZERO_POINT, ZERO_RECT};
use util::opts;
use util::range::Range;
@ -1344,7 +1344,7 @@ impl<'a> PaintContext<'a> {
self.draw_target.set_transform(&draw_target_transform.mul(&Matrix2D::new(0., -1.,
1., 0.,
x, y)));
Point2D::zero()
ZERO_POINT
}
SidewaysRight => {
let x = text.baseline_origin.x.to_f32_px();
@ -1352,7 +1352,7 @@ impl<'a> PaintContext<'a> {
self.draw_target.set_transform(&draw_target_transform.mul(&Matrix2D::new(0., 1.,
-1., 0.,
x, y)));
Point2D::zero()
ZERO_POINT
}
};

View file

@ -25,12 +25,26 @@ use std::ptr;
use std::sync::Arc;
use style::computed_values::{font_stretch, font_weight};
use text::glyph::GlyphId;
use util::geometry::{Au, px_to_pt};
use util::geometry::Au;
pub struct FontTable {
data: CFData,
}
// assumes 72 points per inch, and 96 px per inch
fn px_to_pt(px: f64) -> f64 {
px / 96. * 72.
}
// assumes 72 points per inch, and 96 px per inch
fn pt_to_px(pt: f64) -> f64 {
pt / 72. * 96.
}
fn au_from_pt(pt: f64) -> Au {
Au::from_f64_px(pt_to_px(pt))
}
impl FontTable {
pub fn wrap(data: CFData) -> FontTable {
FontTable { data: data }
@ -161,27 +175,27 @@ impl FontHandleMethods for FontHandle {
let scale = px_to_pt(self.ctfont.pt_size() as f64) / (ascent + descent);
let line_gap = (ascent + descent + leading + 0.5).floor();
let max_advance_width = Au::from_pt(bounding_rect.size.width as f64);
let max_advance_width = au_from_pt(bounding_rect.size.width as f64);
let average_advance = self.glyph_index('0')
.and_then(|idx| self.glyph_h_advance(idx))
.map(|advance| Au::from_f64_px(advance))
.unwrap_or(max_advance_width);
let metrics = FontMetrics {
underline_size: Au::from_pt(self.ctfont.underline_thickness() as f64),
underline_size: au_from_pt(self.ctfont.underline_thickness() as f64),
// TODO(Issue #201): underline metrics are not reliable. Have to pull out of font table
// directly.
//
// see also: https://bugs.webkit.org/show_bug.cgi?id=16768
// see also: https://bugreports.qt-project.org/browse/QTBUG-13364
underline_offset: Au::from_pt(self.ctfont.underline_position() as f64),
underline_offset: au_from_pt(self.ctfont.underline_position() as f64),
strikeout_size: Au(0), // FIXME(Issue #942)
strikeout_offset: Au(0), // FIXME(Issue #942)
leading: Au::from_pt(leading),
x_height: Au::from_pt(self.ctfont.x_height() as f64),
leading: au_from_pt(leading),
x_height: au_from_pt(self.ctfont.x_height() as f64),
em_size: em_size,
ascent: Au::from_pt(ascent * scale),
descent: Au::from_pt(descent * scale),
ascent: au_from_pt(ascent * scale),
descent: au_from_pt(descent * scale),
max_advance: max_advance_width,
average_advance: average_advance,
line_gap: Au::from_f64_px(line_gap),

View file

@ -3,7 +3,6 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use cssparser::ToCss;
use euclid::length::Length;
use euclid::num::Zero;
use euclid::point::Point2D;
use euclid::rect::Rect;
@ -205,29 +204,12 @@ impl Au {
Au((px * AU_PER_PX) as i32)
}
#[inline]
pub fn from_page_px(px: Length<PagePx, f32>) -> Au {
Au((px.get() * (AU_PER_PX as f32)) as i32)
}
/// Rounds this app unit down to the pixel towards zero and returns it.
#[inline]
pub fn to_px(self) -> i32 {
self.0 / AU_PER_PX
}
/// Rounds this app unit down to the previous (left or top) pixel and returns it.
#[inline]
pub fn to_prev_px(self) -> i32 {
((self.0 as f64) / (AU_PER_PX as f64)).floor() as i32
}
/// Rounds this app unit up to the next (right or bottom) pixel and returns it.
#[inline]
pub fn to_next_px(self) -> i32 {
((self.0 as f64) / (AU_PER_PX as f64)).ceil() as i32
}
#[inline]
pub fn to_nearest_px(self) -> i32 {
((self.0 as f64) / (AU_PER_PX as f64)).round() as i32
@ -248,39 +230,17 @@ impl Au {
(self.0 as f64) / (AU_PER_PX as f64)
}
#[inline]
pub fn to_snapped(self) -> Au {
let res = self.0 % AU_PER_PX;
return if res >= 30i32 { return Au(self.0 - res + AU_PER_PX) }
else { return Au(self.0 - res) };
}
#[inline]
pub fn from_f32_px(px: f32) -> Au {
Au((px * (AU_PER_PX as f32)) as i32)
}
#[inline]
pub fn from_pt(pt: f64) -> Au {
Au::from_f64_px(pt_to_px(pt))
}
#[inline]
pub fn from_f64_px(px: f64) -> Au {
Au((px * (AU_PER_PX as f64)) as i32)
}
}
// assumes 72 points per inch, and 96 px per inch
pub fn pt_to_px(pt: f64) -> f64 {
pt / 72. * 96.
}
// assumes 72 points per inch, and 96 px per inch
pub fn px_to_pt(px: f64) -> f64 {
px / 96. * 72.
}
/// Returns true if the rect contains the given point. Points on the top or left sides of the rect
/// are considered inside the rectangle, while points on the right or bottom sides of the rect are
/// not considered inside the rectangle.