From eabb8d4f2918ff3f8f992f369c7a6779a6461e8b Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Mon, 22 Sep 2014 17:00:00 +0100 Subject: [PATCH] Add support for font-size relative size keywords. Fix #3423 --- components/style/properties/mod.rs.mako | 27 ++++++++++++++----------- tests/ref/font_size.html | 2 ++ tests/ref/font_size_ref.html | 2 ++ 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/components/style/properties/mod.rs.mako b/components/style/properties/mod.rs.mako index a38c7568ca0..5f457dfcd49 100644 --- a/components/style/properties/mod.rs.mako +++ b/components/style/properties/mod.rs.mako @@ -908,8 +908,7 @@ pub mod longhands { // We already computed this element's font size; no need to compute it again. return context.font_size } - /// | | - /// TODO: support + /// | | | pub fn from_component_value(input: &ComponentValue, _base_url: &Url) -> Result { match specified::LengthOrPercentage::parse_non_negative(input) { @@ -917,17 +916,21 @@ pub mod longhands { Ok(specified::LP_Percentage(value)) => return Ok(specified::Em(value)), Err(()) => (), } - let au = match try!(get_ident_lower(input)).as_slice() { - "xx-small" => Au::from_px(MEDIUM_PX) * 3 / 5, - "x-small" => Au::from_px(MEDIUM_PX) * 3 / 4, - "small" => Au::from_px(MEDIUM_PX) * 8 / 9, - "medium" => Au::from_px(MEDIUM_PX), - "large" => Au::from_px(MEDIUM_PX) * 6 / 5, - "x-large" => Au::from_px(MEDIUM_PX) * 3 / 2, - "xx-large" => Au::from_px(MEDIUM_PX) * 2, + match try!(get_ident_lower(input)).as_slice() { + "xx-small" => Ok(specified::Au_(Au::from_px(MEDIUM_PX) * 3 / 5)), + "x-small" => Ok(specified::Au_(Au::from_px(MEDIUM_PX) * 3 / 4)), + "small" => Ok(specified::Au_(Au::from_px(MEDIUM_PX) * 8 / 9)), + "medium" => Ok(specified::Au_(Au::from_px(MEDIUM_PX))), + "large" => Ok(specified::Au_(Au::from_px(MEDIUM_PX) * 6 / 5)), + "x-large" => Ok(specified::Au_(Au::from_px(MEDIUM_PX) * 3 / 2)), + "xx-large" => Ok(specified::Au_(Au::from_px(MEDIUM_PX) * 2)), + + // https://github.com/servo/servo/issues/3423#issuecomment-56321664 + "smaller" => Ok(specified::Em(0.85)), + "larger" => Ok(specified::Em(1.2)), + _ => return Err(()) - }; - Ok(specified::Au_(au)) + } } diff --git a/tests/ref/font_size.html b/tests/ref/font_size.html index 868a6f4b3d3..6d534378724 100644 --- a/tests/ref/font_size.html +++ b/tests/ref/font_size.html @@ -4,6 +4,8 @@

24pt is 32px.

2em is 40px.

200% is 40px. +

smaller is 17px. +

larger is 24px.

xx-small is 9.6px.

x-small is 12px.

small is 14.2222…px. diff --git a/tests/ref/font_size_ref.html b/tests/ref/font_size_ref.html index d85c120b822..0c5d50fb8b7 100644 --- a/tests/ref/font_size_ref.html +++ b/tests/ref/font_size_ref.html @@ -4,6 +4,8 @@

24pt is 32px.

2em is 40px.

200% is 40px. +

smaller is 17px. +

larger is 24px.

xx-small is 9.6px.

x-small is 12px.

small is 14.2222…px.