mirror of
https://github.com/servo/servo.git
synced 2025-08-09 23:45:35 +01:00
Make font-stretch animatable.
This commit is contained in:
parent
0b3fd8de76
commit
c71abc0c28
4 changed files with 78 additions and 9 deletions
|
@ -17,6 +17,7 @@ use properties::{CSSWideKeyword, PropertyDeclaration};
|
|||
use properties::longhands;
|
||||
use properties::longhands::background_size::computed_value::T as BackgroundSizeList;
|
||||
use properties::longhands::font_weight::computed_value::T as FontWeight;
|
||||
use properties::longhands::font_stretch::computed_value::T as FontStretch;
|
||||
use properties::longhands::line_height::computed_value::T as LineHeight;
|
||||
use properties::longhands::text_shadow::computed_value::T as TextShadowList;
|
||||
use properties::longhands::text_shadow::computed_value::TextShadow;
|
||||
|
@ -1360,6 +1361,54 @@ impl Animatable for FontWeight {
|
|||
}
|
||||
}
|
||||
|
||||
/// https://drafts.csswg.org/css-fonts/#font-stretch-prop
|
||||
impl Animatable for FontStretch {
|
||||
#[inline]
|
||||
fn add_weighted(&self, other: &Self, self_portion: f64, other_portion: f64) -> Result<Self, ()> {
|
||||
let from = f64::from(*self);
|
||||
let to = f64::from(*other);
|
||||
let interpolated_mapped_index = ((from * self_portion + to * other_portion) + 0.5).floor();
|
||||
Ok(interpolated_mapped_index.into())
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn compute_distance(&self, other: &Self) -> Result<f64, ()> {
|
||||
let from = f64::from(*self);
|
||||
let to = f64::from(*other);
|
||||
from.compute_distance(&to)
|
||||
}
|
||||
}
|
||||
|
||||
/// We should treat font stretch as real number in order to interpolate this property.
|
||||
/// https://drafts.csswg.org/css-fonts-3/#font-stretch-animation
|
||||
impl From<FontStretch> for f64 {
|
||||
fn from(stretch: FontStretch) -> f64 {
|
||||
use self::FontStretch::*;
|
||||
match stretch {
|
||||
ultra_condensed => 1.0,
|
||||
extra_condensed => 2.0,
|
||||
condensed => 3.0,
|
||||
semi_condensed => 4.0,
|
||||
normal => 5.0,
|
||||
semi_expanded => 6.0,
|
||||
expanded => 7.0,
|
||||
extra_expanded => 8.0,
|
||||
ultra_expanded => 9.0,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Into<FontStretch> for f64 {
|
||||
fn into(self) -> FontStretch {
|
||||
use properties::longhands::font_stretch::computed_value::T::*;
|
||||
debug_assert!(self >= 1.0 && self <= 9.0);
|
||||
static FONT_STRETCH_ENUM_MAP: [FontStretch; 9] =
|
||||
[ ultra_condensed, extra_condensed, condensed, semi_condensed, normal,
|
||||
semi_expanded, expanded, extra_expanded, ultra_expanded ];
|
||||
FONT_STRETCH_ENUM_MAP[(self - 1.0) as usize]
|
||||
}
|
||||
}
|
||||
|
||||
/// https://drafts.csswg.org/css-transitions/#animtype-simple-list
|
||||
impl<H: Animatable, V: Animatable> Animatable for generic_position::Position<H, V> {
|
||||
#[inline]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue