mirror of
https://github.com/servo/servo.git
synced 2025-08-06 06:00:15 +01:00
style: Simplify font_size::SpecifiedValue::as_font_ratio.
Signed-off-by: Emilio Cobos Álvarez <emilio@crisal.io>
This commit is contained in:
parent
465e6f14fe
commit
e30ed4ef44
1 changed files with 22 additions and 15 deletions
|
@ -768,23 +768,31 @@ ${helpers.single_keyword_system("font-variant-caps",
|
||||||
}, 1.)
|
}, 1.)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// If this value is specified as a ratio of the parent font (em units or percent)
|
/// If this value is specified as a ratio of the parent font (em units
|
||||||
/// return the ratio
|
/// or percent) return the ratio
|
||||||
pub fn as_font_ratio(&self) -> Option<f32> {
|
pub fn as_font_ratio(&self) -> Option<f32> {
|
||||||
if let SpecifiedValue::Length(ref lop) = *self {
|
match *self {
|
||||||
if let LengthOrPercentage::Percentage(pc) = *lop {
|
SpecifiedValue::Length(ref lop) => {
|
||||||
return Some(pc.0)
|
match *lop {
|
||||||
} else if let LengthOrPercentage::Length(ref nocalc) = *lop {
|
LengthOrPercentage::Percentage(pc) => {
|
||||||
if let NoCalcLength::FontRelative(FontRelativeLength::Em(em)) = *nocalc {
|
Some(pc.0)
|
||||||
return Some(em)
|
}
|
||||||
|
LengthOrPercentage::Length(ref nocalc) => {
|
||||||
|
match *nocalc {
|
||||||
|
NoCalcLength::FontRelative(FontRelativeLength::Em(em)) => {
|
||||||
|
Some(em)
|
||||||
|
}
|
||||||
|
_ => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// FIXME(emilio): This looks super fishy!
|
||||||
|
LengthOrPercentage::Calc(..) => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if let SpecifiedValue::Larger = *self {
|
SpecifiedValue::Larger => Some(LARGER_FONT_SIZE_RATIO),
|
||||||
return Some(LARGER_FONT_SIZE_RATIO)
|
SpecifiedValue::Smaller => Some(1. / LARGER_FONT_SIZE_RATIO),
|
||||||
} else if let SpecifiedValue::Smaller = *self {
|
_ => None,
|
||||||
return Some(1. / LARGER_FONT_SIZE_RATIO)
|
|
||||||
}
|
}
|
||||||
None
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Compute it against a given base font size
|
/// Compute it against a given base font size
|
||||||
|
@ -902,8 +910,7 @@ ${helpers.single_keyword_system("font-variant-caps",
|
||||||
specified_value: &SpecifiedValue,
|
specified_value: &SpecifiedValue,
|
||||||
mut computed: Au,
|
mut computed: Au,
|
||||||
parent: &Font) {
|
parent: &Font) {
|
||||||
if let SpecifiedValue::Keyword(kw, fraction)
|
if let SpecifiedValue::Keyword(kw, fraction) = *specified_value {
|
||||||
= *specified_value {
|
|
||||||
context.mutate_style().font_size_keyword = Some((kw, fraction));
|
context.mutate_style().font_size_keyword = Some((kw, fraction));
|
||||||
} else if let Some(ratio) = specified_value.as_font_ratio() {
|
} else if let Some(ratio) = specified_value.as_font_ratio() {
|
||||||
// In case a font-size-relative value was applied to a keyword
|
// In case a font-size-relative value was applied to a keyword
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue