Skip to content

Commit bb0c05d

Browse files
author
bors-servo
authored
Auto merge of servo#17732 - emilio:font-size-as-ratio, r=nox
style: Simplify font_size::SpecifiedValue::as_font_ratio. <!-- 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/17732) <!-- Reviewable:end -->
2 parents a240054 + e30ed4e commit bb0c05d

File tree

1 file changed

+22
-15
lines changed

1 file changed

+22
-15
lines changed

components/style/properties/longhand/font.mako.rs

+22-15
Original file line numberDiff line numberDiff line change
@@ -768,23 +768,31 @@ ${helpers.single_keyword_system("font-variant-caps",
768768
}, 1.)
769769
}
770770

771-
/// If this value is specified as a ratio of the parent font (em units or percent)
772-
/// return the ratio
771+
/// If this value is specified as a ratio of the parent font (em units
772+
/// or percent) return the ratio
773773
pub fn as_font_ratio(&self) -> Option<f32> {
774-
if let SpecifiedValue::Length(ref lop) = *self {
775-
if let LengthOrPercentage::Percentage(pc) = *lop {
776-
return Some(pc.0)
777-
} else if let LengthOrPercentage::Length(ref nocalc) = *lop {
778-
if let NoCalcLength::FontRelative(FontRelativeLength::Em(em)) = *nocalc {
779-
return Some(em)
774+
match *self {
775+
SpecifiedValue::Length(ref lop) => {
776+
match *lop {
777+
LengthOrPercentage::Percentage(pc) => {
778+
Some(pc.0)
779+
}
780+
LengthOrPercentage::Length(ref nocalc) => {
781+
match *nocalc {
782+
NoCalcLength::FontRelative(FontRelativeLength::Em(em)) => {
783+
Some(em)
784+
}
785+
_ => None,
786+
}
787+
}
788+
// FIXME(emilio): This looks super fishy!
789+
LengthOrPercentage::Calc(..) => None,
780790
}
781791
}
782-
} else if let SpecifiedValue::Larger = *self {
783-
return Some(LARGER_FONT_SIZE_RATIO)
784-
} else if let SpecifiedValue::Smaller = *self {
785-
return Some(1. / LARGER_FONT_SIZE_RATIO)
792+
SpecifiedValue::Larger => Some(LARGER_FONT_SIZE_RATIO),
793+
SpecifiedValue::Smaller => Some(1. / LARGER_FONT_SIZE_RATIO),
794+
_ => None,
786795
}
787-
None
788796
}
789797

790798
/// Compute it against a given base font size
@@ -902,8 +910,7 @@ ${helpers.single_keyword_system("font-variant-caps",
902910
specified_value: &SpecifiedValue,
903911
mut computed: Au,
904912
parent: &Font) {
905-
if let SpecifiedValue::Keyword(kw, fraction)
906-
= *specified_value {
913+
if let SpecifiedValue::Keyword(kw, fraction) = *specified_value {
907914
context.mutate_style().font_size_keyword = Some((kw, fraction));
908915
} else if let Some(ratio) = specified_value.as_font_ratio() {
909916
// In case a font-size-relative value was applied to a keyword

0 commit comments

Comments
 (0)