mirror of
https://github.com/servo/servo.git
synced 2025-07-01 12:33:40 +01:00
Bump app_units; use from_f64_au
This commit is contained in:
parent
812cac78f0
commit
489bbb849a
3 changed files with 27 additions and 33 deletions
26
Cargo.lock
generated
26
Cargo.lock
generated
|
@ -57,7 +57,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
|
||||
[[package]]
|
||||
name = "app_units"
|
||||
version = "0.5.3"
|
||||
version = "0.5.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"heapsize 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
@ -1091,7 +1091,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
name = "gfx"
|
||||
version = "0.0.1"
|
||||
dependencies = [
|
||||
"app_units 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"app_units 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"byteorder 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"core-foundation 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
@ -1504,7 +1504,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
name = "layout"
|
||||
version = "0.0.1"
|
||||
dependencies = [
|
||||
"app_units 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"app_units 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"atomic_refcell 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"bitflags 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"canvas_traits 0.0.1",
|
||||
|
@ -1554,7 +1554,7 @@ dependencies = [
|
|||
name = "layout_thread"
|
||||
version = "0.0.1"
|
||||
dependencies = [
|
||||
"app_units 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"app_units 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"atomic_refcell 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"euclid 0.15.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"fnv 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
@ -2528,7 +2528,7 @@ name = "script"
|
|||
version = "0.0.1"
|
||||
dependencies = [
|
||||
"angle 0.5.0 (git+https://github.com/servo/angle?branch=servo)",
|
||||
"app_units 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"app_units 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"audio-video-metadata 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"base64 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
@ -2607,7 +2607,7 @@ dependencies = [
|
|||
name = "script_layout_interface"
|
||||
version = "0.0.1"
|
||||
dependencies = [
|
||||
"app_units 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"app_units 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"atomic_refcell 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"canvas_traits 0.0.1",
|
||||
"cssparser 0.20.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
@ -2916,7 +2916,7 @@ dependencies = [
|
|||
name = "servo_geometry"
|
||||
version = "0.0.1"
|
||||
dependencies = [
|
||||
"app_units 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"app_units 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"euclid 0.15.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"heapsize 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
@ -3072,7 +3072,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
name = "style"
|
||||
version = "0.0.1"
|
||||
dependencies = [
|
||||
"app_units 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"app_units 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"arraydeque 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"arrayvec 0.3.23 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"atomic_refcell 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
@ -3136,7 +3136,7 @@ dependencies = [
|
|||
name = "style_tests"
|
||||
version = "0.0.1"
|
||||
dependencies = [
|
||||
"app_units 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"app_units 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"byteorder 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"cssparser 0.20.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"euclid 0.15.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
@ -3158,7 +3158,7 @@ dependencies = [
|
|||
name = "style_traits"
|
||||
version = "0.0.1"
|
||||
dependencies = [
|
||||
"app_units 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"app_units 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"cssparser 0.20.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"euclid 0.15.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
@ -3550,7 +3550,7 @@ name = "webrender"
|
|||
version = "0.50.0"
|
||||
source = "git+https://github.com/servo/webrender#e7c60ad67ca9c0732be18c3df25b686f12d652ca"
|
||||
dependencies = [
|
||||
"app_units 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"app_units 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"bincode 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"bit-set 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"bitflags 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
@ -3578,7 +3578,7 @@ name = "webrender_api"
|
|||
version = "0.50.0"
|
||||
source = "git+https://github.com/servo/webrender#e7c60ad67ca9c0732be18c3df25b686f12d652ca"
|
||||
dependencies = [
|
||||
"app_units 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"app_units 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"bincode 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"byteorder 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"core-foundation 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
@ -3716,7 +3716,7 @@ dependencies = [
|
|||
"checksum angle 0.5.0 (git+https://github.com/servo/angle?branch=servo)" = "<none>"
|
||||
"checksum ansi_term 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "23ac7c30002a5accbf7e8987d0632fa6de155b7c3d39d0067317a391e00a2ef6"
|
||||
"checksum antidote 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "34fde25430d87a9388dadbe6e34d7f72a462c8b43ac8d309b42b0a8505d7e2a5"
|
||||
"checksum app_units 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "7ff4f3fe57393a150b39b026b6f6f4b9a6c4f49b52d0a4e2d61d08d926358438"
|
||||
"checksum app_units 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)" = "7eb1573f29213263e6016754100e0ae875049d3692dfe6764834c2d7957ca94c"
|
||||
"checksum arraydeque 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "96e774cadb24c2245225280c6799793f9802b918a58a79615e9490607489a717"
|
||||
"checksum arrayvec 0.3.23 (registry+https://github.com/rust-lang/crates.io-index)" = "699e63a93b79d717e8c3b5eb1b28b7780d0d6d9e59a72eb769291c83b0c8dc67"
|
||||
"checksum aster 0.41.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4ccfdf7355d9db158df68f976ed030ab0f6578af811f5a7bb6dcf221ec24e0e0"
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue