Auto merge of #7463 - nox:css-ch, r=SimonSapin

Implement the ch unit as 0.5em



<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/7463)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2015-08-31 02:19:55 -06:00
commit 1093f6bdcf

View file

@ -151,6 +151,7 @@ pub mod specified {
pub enum FontRelativeLength { pub enum FontRelativeLength {
Em(CSSFloat), Em(CSSFloat),
Ex(CSSFloat), Ex(CSSFloat),
Ch(CSSFloat),
Rem(CSSFloat) Rem(CSSFloat)
} }
@ -159,6 +160,7 @@ pub mod specified {
match self { match self {
&FontRelativeLength::Em(length) => write!(dest, "{}em", length), &FontRelativeLength::Em(length) => write!(dest, "{}em", length),
&FontRelativeLength::Ex(length) => write!(dest, "{}ex", length), &FontRelativeLength::Ex(length) => write!(dest, "{}ex", length),
&FontRelativeLength::Ch(length) => write!(dest, "{}ch", length),
&FontRelativeLength::Rem(length) => write!(dest, "{}rem", length) &FontRelativeLength::Rem(length) => write!(dest, "{}rem", length)
} }
} }
@ -172,9 +174,10 @@ pub mod specified {
{ {
match self { match self {
&FontRelativeLength::Em(length) => reference_font_size.scale_by(length), &FontRelativeLength::Em(length) => reference_font_size.scale_by(length),
&FontRelativeLength::Ex(length) => { &FontRelativeLength::Ex(length) | &FontRelativeLength::Ch(length) => {
let x_height = 0.5; // TODO: find that from the font // https://github.com/servo/servo/issues/7462
reference_font_size.scale_by(length * x_height) let em_factor = 0.5;
reference_font_size.scale_by(length * em_factor)
}, },
&FontRelativeLength::Rem(length) => root_font_size.scale_by(length) &FontRelativeLength::Rem(length) => root_font_size.scale_by(length)
} }
@ -284,6 +287,7 @@ pub mod specified {
match self { match self {
FontRelativeLength::Em(v) => FontRelativeLength::Em(v * scalar), FontRelativeLength::Em(v) => FontRelativeLength::Em(v * scalar),
FontRelativeLength::Ex(v) => FontRelativeLength::Ex(v * scalar), FontRelativeLength::Ex(v) => FontRelativeLength::Ex(v * scalar),
FontRelativeLength::Ch(v) => FontRelativeLength::Ch(v * scalar),
FontRelativeLength::Rem(v) => FontRelativeLength::Rem(v * scalar), FontRelativeLength::Rem(v) => FontRelativeLength::Rem(v * scalar),
} }
} }
@ -338,6 +342,7 @@ pub mod specified {
// font-relative // font-relative
"em" => Ok(Length::FontRelative(FontRelativeLength::Em(value))), "em" => Ok(Length::FontRelative(FontRelativeLength::Em(value))),
"ex" => Ok(Length::FontRelative(FontRelativeLength::Ex(value))), "ex" => Ok(Length::FontRelative(FontRelativeLength::Ex(value))),
"ch" => Ok(Length::FontRelative(FontRelativeLength::Ch(value))),
"rem" => Ok(Length::FontRelative(FontRelativeLength::Rem(value))), "rem" => Ok(Length::FontRelative(FontRelativeLength::Rem(value))),
// viewport percentages // viewport percentages
"vw" => Ok(Length::ViewportPercentage(ViewportPercentageLength::Vw(value))), "vw" => Ok(Length::ViewportPercentage(ViewportPercentageLength::Vw(value))),