diff --git a/servo/components/style/font_face.rs b/servo/components/style/font_face.rs index 757e30bbd698..9aeb12b92e4a 100644 --- a/servo/components/style/font_face.rs +++ b/servo/components/style/font_face.rs @@ -28,7 +28,6 @@ use cssparser::{AtRuleParser, DeclarationListParser, DeclarationParser, Parser}; use cssparser::{CowRcStr, SourceLocation}; use selectors::parser::SelectorParseErrorKind; use std::fmt::{self, Write}; -use style_traits::values::SequenceWriter; use style_traits::{Comma, CssWriter, OneOrMoreSeparated, ParseError}; use style_traits::{StyleParseErrorKind, ToCss}; @@ -72,8 +71,8 @@ pub enum FontFaceSourceListComponent { pub struct UrlSource { /// The specified url. pub url: SpecifiedUrl, - /// The format hints specified with the `format()` function. - pub format_hints: Vec, + /// The format hint specified with the `format()` function, if present. + pub format_hint: Option, } impl ToCss for UrlSource { @@ -82,14 +81,9 @@ impl ToCss for UrlSource { W: fmt::Write, { self.url.to_css(dest)?; - if !self.format_hints.is_empty() { + if let Some(hint) = &self.format_hint { dest.write_str(" format(")?; - { - let mut writer = SequenceWriter::new(dest, ", "); - for hint in self.format_hints.iter() { - writer.item(hint)?; - } - } + dest.write_str(&hint)?; dest.write_char(')')?; } Ok(()) @@ -334,14 +328,11 @@ impl<'a> FontFace<'a> { .rev() .filter(|source| { if let Source::Url(ref url_source) = **source { - let hints = &url_source.format_hints; // We support only opentype fonts and truetype is an alias for // that format. Sources without format hints need to be // downloaded in case we support them. - hints.is_empty() || - hints.iter().any(|hint| { - hint == "truetype" || hint == "opentype" || hint == "woff" - }) + url_source.format_hint.as_ref().map_or(true, + |hint| hint == "truetype" || hint == "opentype" || hint == "woff") } else { true } @@ -393,20 +384,20 @@ impl Parse for Source { let url = SpecifiedUrl::parse(context, input)?; // Parsing optional format() - let format_hints = if input + let format_hint = if input .try_parse(|input| input.expect_function_matching("format")) .is_ok() { input.parse_nested_block(|input| { - input.parse_comma_separated(|input| Ok(input.expect_string()?.as_ref().to_owned())) + Ok(Some(input.expect_string()?.as_ref().to_owned())) })? } else { - vec![] + None }; Ok(Source::Url(UrlSource { url: url, - format_hints: format_hints, + format_hint: format_hint, })) } } diff --git a/servo/ports/geckolib/glue.rs b/servo/ports/geckolib/glue.rs index c74d021166e4..ad439d317e23 100644 --- a/servo/ports/geckolib/glue.rs +++ b/servo/ports/geckolib/glue.rs @@ -3253,8 +3253,7 @@ pub unsafe extern "C" fn Servo_FontFaceRule_GetSources( }; let len = sources.iter().fold(0, |acc, src| { acc + match *src { - // Each format hint takes one position in the array of mSrc. - Source::Url(ref url) => url.format_hints.len() + 1, + Source::Url(ref url) => if url.format_hint.is_some() { 2 } else { 1 }, Source::Local(_) => 1, } }); @@ -3272,7 +3271,7 @@ pub unsafe extern "C" fn Servo_FontFaceRule_GetSources( match *source { Source::Url(ref url) => { set_next(FontFaceSourceListComponent::Url(&url.url)); - for hint in url.format_hints.iter() { + if let Some(hint) = &url.format_hint { set_next(FontFaceSourceListComponent::FormatHint { length: hint.len(), utf8_bytes: hint.as_ptr(), diff --git a/testing/web-platform/meta/css/css-fonts/parsing/font-face-src-format.html.ini b/testing/web-platform/meta/css/css-fonts/parsing/font-face-src-format.html.ini index 12c96fbd2716..82d337fc011c 100644 --- a/testing/web-platform/meta/css/css-fonts/parsing/font-face-src-format.html.ini +++ b/testing/web-platform/meta/css/css-fonts/parsing/font-face-src-format.html.ini @@ -1,7 +1,4 @@ [font-face-src-format.html] - [Check that src: url("foo.ttf") format("opentype", "truetype") is invalid] - expected: FAIL - [Check that src: url("foo.ttf") format(collection) is valid] expected: FAIL