Bump app_units; use from_f64_au

This commit is contained in:
Manish Goregaokar 2017-09-07 12:36:56 -07:00
parent 812cac78f0
commit 489bbb849a
3 changed files with 27 additions and 33 deletions

View file

@ -29,7 +29,7 @@ servo = ["serde", "heapsize", "heapsize_derive",
gecko_debug = ["nsstring_vendor/gecko_debug"]
[dependencies]
app_units = "0.5.3"
app_units = "0.5.5"
arrayvec = "0.3.20"
arraydeque = "0.2.3"
atomic_refcell = "0.1"

View file

@ -6,7 +6,7 @@
//!
//! [length]: https://drafts.csswg.org/css-values/#lengths
use app_units::{Au, MAX_AU, MIN_AU};
use app_units::Au;
use cssparser::{Parser, Token, BasicParseError};
use euclid::Size2D;
use font_metrics::FontMetricsQueryResult;
@ -236,16 +236,6 @@ impl CharacterWidth {
}
}
/// Helper to convert a floating point length to application units
fn to_au_round(length: CSSFloat, au_per_unit: CSSFloat) -> Au {
Au(
((length * au_per_unit) as f64)
.min(MAX_AU.0 as f64)
.max(MIN_AU.0 as f64)
.round() as i32
)
}
/// Represents an absolute length with its unit
#[derive(Clone, Copy, Debug, PartialEq)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
@ -292,16 +282,20 @@ impl ToComputedValue for AbsoluteLength {
}
}
fn au_from_f32_round(x: f32) -> Au {
Au::from_f64_au((x as f64).round())
}
impl From<AbsoluteLength> for Au {
fn from(length: AbsoluteLength) -> Au {
match length {
AbsoluteLength::Px(value) => to_au_round(value, AU_PER_PX),
AbsoluteLength::In(value) => to_au_round(value, AU_PER_IN),
AbsoluteLength::Cm(value) => to_au_round(value, AU_PER_CM),
AbsoluteLength::Mm(value) => to_au_round(value, AU_PER_MM),
AbsoluteLength::Q(value) => to_au_round(value, AU_PER_Q),
AbsoluteLength::Pt(value) => to_au_round(value, AU_PER_PT),
AbsoluteLength::Pc(value) => to_au_round(value, AU_PER_PC),
AbsoluteLength::Px(value) => au_from_f32_round((value * AU_PER_PX)),
AbsoluteLength::In(value) => au_from_f32_round((value * AU_PER_IN)),
AbsoluteLength::Cm(value) => au_from_f32_round((value * AU_PER_CM)),
AbsoluteLength::Mm(value) => au_from_f32_round((value * AU_PER_MM)),
AbsoluteLength::Q(value) => au_from_f32_round((value * AU_PER_Q)),
AbsoluteLength::Pt(value) => au_from_f32_round((value * AU_PER_PT)),
AbsoluteLength::Pc(value) => au_from_f32_round((value * AU_PER_PC)),
}
}
}
@ -360,7 +354,7 @@ impl PhysicalLength {
let inch = self.0 / MM_PER_INCH;
to_au_round(inch, physical_inch as f32)
au_from_f32_round(inch * physical_inch as f32)
}
}