diff --git a/components/style/font_metrics.rs b/components/style/font_metrics.rs index 13a4e9e182b..259e5693942 100644 --- a/components/style/font_metrics.rs +++ b/components/style/font_metrics.rs @@ -18,6 +18,8 @@ pub struct FontMetrics { pub zero_advance_measure: Option, /// The cap-height of the font. pub cap_height: Option, + /// The ideographic-width of the font. + pub ic_width: Option, /// The ascent of the font (a value is always available for this). pub ascent: Length, } @@ -28,6 +30,7 @@ impl Default for FontMetrics { x_height: None, zero_advance_measure: None, cap_height: None, + ic_width: None, ascent: Length::new(0.0), } } diff --git a/components/style/values/generics/calc.rs b/components/style/values/generics/calc.rs index d2bc2a85523..d9044bbb818 100644 --- a/components/style/values/generics/calc.rs +++ b/components/style/values/generics/calc.rs @@ -47,6 +47,7 @@ pub enum SortKey { Deg, Em, Ex, + Ic, Px, Rem, Sec, diff --git a/components/style/values/specified/calc.rs b/components/style/values/specified/calc.rs index d6997934554..f5448591f21 100644 --- a/components/style/values/specified/calc.rs +++ b/components/style/values/specified/calc.rs @@ -185,6 +185,7 @@ impl generic::CalcNodeLeaf for Leaf { FontRelativeLength::Em(..) => SortKey::Em, FontRelativeLength::Ex(..) => SortKey::Ex, FontRelativeLength::Cap(..) => SortKey::Cap, + FontRelativeLength::Ic(..) => SortKey::Ic, FontRelativeLength::Rem(..) => SortKey::Rem, }, NoCalcLength::ViewportPercentage(ref vp) => match *vp { diff --git a/components/style/values/specified/length.rs b/components/style/values/specified/length.rs index 6105155d81d..600d65a531c 100644 --- a/components/style/values/specified/length.rs +++ b/components/style/values/specified/length.rs @@ -59,6 +59,9 @@ pub enum FontRelativeLength { /// A "cap" value: https://drafts.csswg.org/css-values/#cap #[css(dimension)] Cap(CSSFloat), + /// An "ic" value: https://drafts.csswg.org/css-values/#ic + #[css(dimension)] + Ic(CSSFloat), /// A "rem" value: https://drafts.csswg.org/css-values/#rem #[css(dimension)] Rem(CSSFloat), @@ -93,6 +96,7 @@ impl FontRelativeLength { FontRelativeLength::Ex(v) | FontRelativeLength::Ch(v) | FontRelativeLength::Cap(v) | + FontRelativeLength::Ic(v) | FontRelativeLength::Rem(v) => v == 0., } } @@ -103,6 +107,7 @@ impl FontRelativeLength { FontRelativeLength::Ex(v) | FontRelativeLength::Ch(v) | FontRelativeLength::Cap(v) | + FontRelativeLength::Ic(v) | FontRelativeLength::Rem(v) => v < 0., } } @@ -119,12 +124,13 @@ impl FontRelativeLength { (&Ex(one), &Ex(other)) => Ex(one + other), (&Ch(one), &Ch(other)) => Ch(one + other), (&Cap(one), &Cap(other)) => Cap(one + other), + (&Ic(one), &Ic(other)) => Ic(one + other), (&Rem(one), &Rem(other)) => Rem(one + other), // See https://github.com/rust-lang/rust/issues/68867. rustc isn't // able to figure it own on its own so we help. _ => unsafe { match *self { - Em(..) | Ex(..) | Ch(..) | Cap(..) | Rem(..) => {}, + Em(..) | Ex(..) | Ch(..) | Cap(..) | Ic(..) | Rem(..) => {}, } debug_unreachable!("Forgot to handle unit in try_sum()") }, @@ -237,6 +243,20 @@ impl FontRelativeLength { }); (reference_size, length) }, + FontRelativeLength::Ic(length) => { + let metrics = + query_font_metrics(context, base_size, FontMetricsOrientation::MatchContextPreferVertical); + let reference_size = metrics.ic_width.unwrap_or_else(|| { + // https://drafts.csswg.org/css-values/#ic + // + // In the cases where it is impossible or impractical to + // determine the ideographic advance measure, it must be + // assumed to be 1em. + // + reference_font_size + }); + (reference_size, length) + }, FontRelativeLength::Rem(length) => { // https://drafts.csswg.org/css-values/#rem: // @@ -549,6 +569,7 @@ impl NoCalcLength { "ex" => NoCalcLength::FontRelative(FontRelativeLength::Ex(value)), "ch" => NoCalcLength::FontRelative(FontRelativeLength::Ch(value)), "cap" => NoCalcLength::FontRelative(FontRelativeLength::Cap(value)), + "ic" => NoCalcLength::FontRelative(FontRelativeLength::Ic(value)), "rem" => NoCalcLength::FontRelative(FontRelativeLength::Rem(value)), // viewport percentages "vw" if !context.in_page_rule() => { @@ -709,12 +730,13 @@ impl PartialOrd for FontRelativeLength { (&Ex(ref one), &Ex(ref other)) => one.partial_cmp(other), (&Ch(ref one), &Ch(ref other)) => one.partial_cmp(other), (&Cap(ref one), &Cap(ref other)) => one.partial_cmp(other), + (&Ic(ref one), &Ic(ref other)) => one.partial_cmp(other), (&Rem(ref one), &Rem(ref other)) => one.partial_cmp(other), // See https://github.com/rust-lang/rust/issues/68867. rustc isn't // able to figure it own on its own so we help. _ => unsafe { match *self { - Em(..) | Ex(..) | Ch(..) | Cap(..) | Rem(..) => {}, + Em(..) | Ex(..) | Ch(..) | Cap(..) | Ic(..) | Rem(..) => {}, } debug_unreachable!("Forgot an arm in partial_cmp?") }, @@ -732,6 +754,7 @@ impl Mul for FontRelativeLength { FontRelativeLength::Ex(v) => FontRelativeLength::Ex(v * scalar), FontRelativeLength::Ch(v) => FontRelativeLength::Ch(v * scalar), FontRelativeLength::Cap(v) => FontRelativeLength::Cap(v * scalar), + FontRelativeLength::Ic(v) => FontRelativeLength::Ic(v * scalar), FontRelativeLength::Rem(v) => FontRelativeLength::Rem(v * scalar), } }