mirror of
https://github.com/servo/servo.git
synced 2025-08-07 14:35:33 +01:00
Derive ToCss for font-face sources
This commit is contained in:
parent
3ee6598abb
commit
3217d1404e
3 changed files with 11 additions and 30 deletions
|
@ -24,33 +24,16 @@ use style_traits::{ToCss, OneOrMoreCommaSeparated, ParseError, StyleParseError};
|
|||
use values::specified::url::SpecifiedUrl;
|
||||
|
||||
/// A source for a font-face rule.
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
#[cfg_attr(feature = "servo", derive(Deserialize, Serialize))]
|
||||
#[derive(Clone, Debug, Eq, PartialEq, ToCss)]
|
||||
pub enum Source {
|
||||
/// A `url()` source.
|
||||
Url(UrlSource),
|
||||
/// A `local()` source.
|
||||
#[css(function)]
|
||||
Local(FamilyName),
|
||||
}
|
||||
|
||||
impl ToCss for Source {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result
|
||||
where W: fmt::Write,
|
||||
{
|
||||
match *self {
|
||||
Source::Url(ref url) => {
|
||||
try!(dest.write_str("url(\""));
|
||||
try!(url.to_css(dest));
|
||||
},
|
||||
Source::Local(ref family) => {
|
||||
try!(dest.write_str("local(\""));
|
||||
try!(family.to_css(dest));
|
||||
},
|
||||
}
|
||||
dest.write_str("\")")
|
||||
}
|
||||
}
|
||||
|
||||
impl OneOrMoreCommaSeparated for Source {}
|
||||
|
||||
/// A `UrlSource` represents a font-face source that has been specified with a
|
||||
|
@ -70,7 +53,7 @@ impl ToCss for UrlSource {
|
|||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result
|
||||
where W: fmt::Write,
|
||||
{
|
||||
dest.write_str(self.url.as_str())
|
||||
self.url.to_css(dest)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue