mirror of
https://github.com/servo/servo.git
synced 2025-08-04 13:10:20 +01:00
style: Accept keywords in addition to strings in the @font-face format() hint function
The CSS Fonts 4 spec requires this, and Safari (at least) has long supported it. Depends on D154277 Differential Revision: https://phabricator.services.mozilla.com/D154237
This commit is contained in:
parent
65e6e072ea
commit
31b2a54164
1 changed files with 33 additions and 4 deletions
|
@ -50,22 +50,46 @@ impl OneOrMoreSeparated for Source {
|
||||||
type S = Comma;
|
type S = Comma;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Keywords for the font-face src descriptor's format() function.
|
||||||
|
#[derive(Clone, Copy, Debug, Eq, Parse, PartialEq, ToCss, ToShmem)]
|
||||||
|
#[repr(u8)]
|
||||||
|
#[allow(missing_docs)]
|
||||||
|
pub enum FontFaceSourceFormatKeyword {
|
||||||
|
Collection,
|
||||||
|
EmbeddedOpentype,
|
||||||
|
Opentype,
|
||||||
|
Svg,
|
||||||
|
Truetype,
|
||||||
|
Woff,
|
||||||
|
Woff2,
|
||||||
|
}
|
||||||
|
|
||||||
/// A POD representation for Gecko. All pointers here are non-owned and as such
|
/// A POD representation for Gecko. All pointers here are non-owned and as such
|
||||||
/// can't outlive the rule they came from, but we can't enforce that via C++.
|
/// can't outlive the rule they came from, but we can't enforce that via C++.
|
||||||
///
|
///
|
||||||
/// All the strings are of course utf8.
|
/// All the strings are of course utf8.
|
||||||
#[cfg(feature = "gecko")]
|
#[cfg(feature = "gecko")]
|
||||||
|
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
||||||
#[repr(u8)]
|
#[repr(u8)]
|
||||||
#[allow(missing_docs)]
|
#[allow(missing_docs)]
|
||||||
pub enum FontFaceSourceListComponent {
|
pub enum FontFaceSourceListComponent {
|
||||||
Url(*const crate::gecko::url::CssUrl),
|
Url(*const crate::gecko::url::CssUrl),
|
||||||
Local(*mut crate::gecko_bindings::structs::nsAtom),
|
Local(*mut crate::gecko_bindings::structs::nsAtom),
|
||||||
FormatHint {
|
FormatHintKeyword(FontFaceSourceFormatKeyword),
|
||||||
|
FormatHintString {
|
||||||
length: usize,
|
length: usize,
|
||||||
utf8_bytes: *const u8,
|
utf8_bytes: *const u8,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Eq, PartialEq, ToCss, ToShmem)]
|
||||||
|
#[repr(u8)]
|
||||||
|
#[allow(missing_docs)]
|
||||||
|
pub enum FontFaceSourceFormat {
|
||||||
|
Keyword(FontFaceSourceFormatKeyword),
|
||||||
|
String(String),
|
||||||
|
}
|
||||||
|
|
||||||
/// A `UrlSource` represents a font-face source that has been specified with a
|
/// A `UrlSource` represents a font-face source that has been specified with a
|
||||||
/// `url()` function.
|
/// `url()` function.
|
||||||
///
|
///
|
||||||
|
@ -76,7 +100,7 @@ pub struct UrlSource {
|
||||||
/// The specified url.
|
/// The specified url.
|
||||||
pub url: SpecifiedUrl,
|
pub url: SpecifiedUrl,
|
||||||
/// The format hint specified with the `format()` function, if present.
|
/// The format hint specified with the `format()` function, if present.
|
||||||
pub format_hint: Option<String>,
|
pub format_hint: Option<FontFaceSourceFormat>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ToCss for UrlSource {
|
impl ToCss for UrlSource {
|
||||||
|
@ -87,7 +111,7 @@ impl ToCss for UrlSource {
|
||||||
self.url.to_css(dest)?;
|
self.url.to_css(dest)?;
|
||||||
if let Some(hint) = &self.format_hint {
|
if let Some(hint) = &self.format_hint {
|
||||||
dest.write_str(" format(")?;
|
dest.write_str(" format(")?;
|
||||||
dest.write_str(&hint)?;
|
hint.to_css(dest)?;
|
||||||
dest.write_char(')')?;
|
dest.write_char(')')?;
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -393,7 +417,12 @@ impl Parse for Source {
|
||||||
.is_ok()
|
.is_ok()
|
||||||
{
|
{
|
||||||
input.parse_nested_block(|input| {
|
input.parse_nested_block(|input| {
|
||||||
Ok(Some(input.expect_string()?.as_ref().to_owned()))
|
if let Ok(kw) = input.try_parse(FontFaceSourceFormatKeyword::parse) {
|
||||||
|
Ok(Some(FontFaceSourceFormat::Keyword(kw)))
|
||||||
|
} else {
|
||||||
|
let s = input.expect_string()?.as_ref().to_owned();
|
||||||
|
Ok(Some(FontFaceSourceFormat::String(s)))
|
||||||
|
}
|
||||||
})?
|
})?
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue