mirror of
https://github.com/servo/servo.git
synced 2025-08-12 17:05:33 +01:00
style: Update font-stretch to css-fonts-4.
These won't "just work", pending changes from bug 1436048 to use a floating point representation for those. Bug: 1454883 Reviewed-by: xidorn MozReview-Commit-ID: Bi5iTdFreMA
This commit is contained in:
parent
91be6c31c3
commit
f7636e6662
11 changed files with 267 additions and 124 deletions
|
@ -19,7 +19,6 @@ use num_traits::Zero;
|
|||
use properties::{CSSWideKeyword, PropertyDeclaration};
|
||||
use properties::longhands;
|
||||
use properties::longhands::font_weight::computed_value::T as FontWeight;
|
||||
use properties::longhands::font_stretch::computed_value::T as FontStretch;
|
||||
use properties::longhands::visibility::computed_value::T as Visibility;
|
||||
use properties::PropertyId;
|
||||
use properties::{LonghandId, ShorthandId};
|
||||
|
@ -880,61 +879,6 @@ impl ToAnimatedZero for FontWeight {
|
|||
}
|
||||
}
|
||||
|
||||
/// <https://drafts.csswg.org/css-fonts/#font-stretch-prop>
|
||||
impl Animate for FontStretch {
|
||||
#[inline]
|
||||
fn animate(&self, other: &Self, procedure: Procedure) -> Result<Self, ()> {
|
||||
let from = f64::from(*self);
|
||||
let to = f64::from(*other);
|
||||
let normal = f64::from(FontStretch::Normal);
|
||||
let (this_weight, other_weight) = procedure.weights();
|
||||
let result = (from - normal) * this_weight + (to - normal) * other_weight + normal;
|
||||
Ok(result.into())
|
||||
}
|
||||
}
|
||||
|
||||
impl ComputeSquaredDistance for FontStretch {
|
||||
#[inline]
|
||||
fn compute_squared_distance(&self, other: &Self) -> Result<SquaredDistance, ()> {
|
||||
f64::from(*self).compute_squared_distance(&(*other).into())
|
||||
}
|
||||
}
|
||||
|
||||
impl ToAnimatedZero for FontStretch {
|
||||
#[inline]
|
||||
fn to_animated_zero(&self) -> Result<Self, ()> { Err(()) }
|
||||
}
|
||||
|
||||
/// 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 {
|
||||
UltraCondensed => 1.0,
|
||||
ExtraCondensed => 2.0,
|
||||
Condensed => 3.0,
|
||||
SemiCondensed => 4.0,
|
||||
Normal => 5.0,
|
||||
SemiExpanded => 6.0,
|
||||
Expanded => 7.0,
|
||||
ExtraExpanded => 8.0,
|
||||
UltraExpanded => 9.0,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Into<FontStretch> for f64 {
|
||||
fn into(self) -> FontStretch {
|
||||
use properties::longhands::font_stretch::computed_value::T::*;
|
||||
let index = (self + 0.5).floor().min(9.0).max(1.0);
|
||||
static FONT_STRETCH_ENUM_MAP: [FontStretch; 9] =
|
||||
[ UltraCondensed, ExtraCondensed, Condensed, SemiCondensed, Normal,
|
||||
SemiExpanded, Expanded, ExtraExpanded, UltraExpanded ];
|
||||
FONT_STRETCH_ENUM_MAP[(index - 1.0) as usize]
|
||||
}
|
||||
}
|
||||
|
||||
/// <https://drafts.csswg.org/css-fonts-4/#font-variation-settings-def>
|
||||
impl Animate for FontVariationSettings {
|
||||
#[inline]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue