mirror of
https://github.com/servo/servo.git
synced 2025-08-06 06:00:15 +01:00
Auto merge of #18413 - Manishearth:bump-au, r=jdm
Bump app_units; use from_f64_au <!-- Reviewable:start --> This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/18413) <!-- Reviewable:end -->
This commit is contained in:
commit
2b73735539
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)",
|
||||
|
@ -1098,7 +1098,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)",
|
||||
|
@ -1511,7 +1511,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",
|
||||
|
@ -1561,7 +1561,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)",
|
||||
|
@ -2535,7 +2535,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)",
|
||||
|
@ -2614,7 +2614,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)",
|
||||
|
@ -2923,7 +2923,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)",
|
||||
]
|
||||
|
@ -3079,7 +3079,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)",
|
||||
|
@ -3144,7 +3144,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)",
|
||||
|
@ -3166,7 +3166,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)",
|
||||
|
@ -3558,7 +3558,7 @@ name = "webrender"
|
|||
version = "0.50.0"
|
||||
source = "git+https://github.com/servo/webrender#01c38a21e6951dcc0241b1b65d6acb837d42ba22"
|
||||
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)",
|
||||
|
@ -3586,7 +3586,7 @@ name = "webrender_api"
|
|||
version = "0.50.0"
|
||||
source = "git+https://github.com/servo/webrender#01c38a21e6951dcc0241b1b65d6acb837d42ba22"
|
||||
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)",
|
||||
|
@ -3724,7 +3724,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))]
|
||||
|
@ -309,16 +299,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)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -395,7 +389,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