mirror of
https://github.com/servo/servo.git
synced 2025-08-12 08:55:32 +01:00
style: Only parse font-stretch keywords in the font shorthand.
Bug: 1454883 Reviewed-by: xidorn MozReview-Commit-ID: 4BqnOSz83w4
This commit is contained in:
parent
36cef8ec68
commit
b1fbb28b8a
2 changed files with 57 additions and 5 deletions
|
@ -418,6 +418,41 @@ impl FontStretchKeyword {
|
|||
UltraExpanded => 2.,
|
||||
})
|
||||
}
|
||||
|
||||
/// Does the opposite operation to `compute`, in order to serialize keywords
|
||||
/// if possible.
|
||||
pub fn from_percentage(percentage: f32) -> Option<Self> {
|
||||
use self::FontStretchKeyword::*;
|
||||
// NOTE(emilio): Can't use `match` because of rust-lang/rust#41620.
|
||||
if percentage == 0.5 {
|
||||
return Some(UltraCondensed);
|
||||
}
|
||||
if percentage == 0.625 {
|
||||
return Some(ExtraCondensed);
|
||||
}
|
||||
if percentage == 0.75 {
|
||||
return Some(Condensed);
|
||||
}
|
||||
if percentage == 0.875 {
|
||||
return Some(SemiCondensed);
|
||||
}
|
||||
if percentage == 1. {
|
||||
return Some(Normal);
|
||||
}
|
||||
if percentage == 1.125 {
|
||||
return Some(SemiExpanded);
|
||||
}
|
||||
if percentage == 1.25 {
|
||||
return Some(Expanded);
|
||||
}
|
||||
if percentage == 1.5 {
|
||||
return Some(ExtraExpanded);
|
||||
}
|
||||
if percentage == 2. {
|
||||
return Some(UltraExpanded);
|
||||
}
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
impl FontStretch {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue