mirror of
https://github.com/servo/servo.git
synced 2025-08-05 05:30:08 +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;
|
use values::specified::url::SpecifiedUrl;
|
||||||
|
|
||||||
/// A source for a font-face rule.
|
/// A source for a font-face rule.
|
||||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
|
||||||
#[cfg_attr(feature = "servo", derive(Deserialize, Serialize))]
|
#[cfg_attr(feature = "servo", derive(Deserialize, Serialize))]
|
||||||
|
#[derive(Clone, Debug, Eq, PartialEq, ToCss)]
|
||||||
pub enum Source {
|
pub enum Source {
|
||||||
/// A `url()` source.
|
/// A `url()` source.
|
||||||
Url(UrlSource),
|
Url(UrlSource),
|
||||||
/// A `local()` source.
|
/// A `local()` source.
|
||||||
|
#[css(function)]
|
||||||
Local(FamilyName),
|
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 {}
|
impl OneOrMoreCommaSeparated for Source {}
|
||||||
|
|
||||||
/// 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
|
||||||
|
@ -70,7 +53,7 @@ impl ToCss for UrlSource {
|
||||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result
|
fn to_css<W>(&self, dest: &mut W) -> fmt::Result
|
||||||
where W: fmt::Write,
|
where W: fmt::Write,
|
||||||
{
|
{
|
||||||
dest.write_str(self.url.as_str())
|
self.url.to_css(dest)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,12 +4,11 @@
|
||||||
|
|
||||||
//! Common handling for the specified value CSS url() values.
|
//! Common handling for the specified value CSS url() values.
|
||||||
|
|
||||||
use cssparser::CssStringWriter;
|
|
||||||
use gecko_bindings::structs::{ServoBundledURI, URLExtraData};
|
use gecko_bindings::structs::{ServoBundledURI, URLExtraData};
|
||||||
use gecko_bindings::structs::root::mozilla::css::ImageValue;
|
use gecko_bindings::structs::root::mozilla::css::ImageValue;
|
||||||
use gecko_bindings::sugar::refptr::RefPtr;
|
use gecko_bindings::sugar::refptr::RefPtr;
|
||||||
use parser::ParserContext;
|
use parser::ParserContext;
|
||||||
use std::fmt::{self, Write};
|
use std::fmt;
|
||||||
use style_traits::{ToCss, ParseError};
|
use style_traits::{ToCss, ParseError};
|
||||||
use stylearc::Arc;
|
use stylearc::Arc;
|
||||||
|
|
||||||
|
@ -100,8 +99,8 @@ impl SpecifiedUrl {
|
||||||
|
|
||||||
impl ToCss for SpecifiedUrl {
|
impl ToCss for SpecifiedUrl {
|
||||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||||
try!(dest.write_str("url(\""));
|
dest.write_str("url(")?;
|
||||||
try!(CssStringWriter::new(dest).write_str(&*self.serialization));
|
self.serialization.to_css(dest)?;
|
||||||
dest.write_str("\")")
|
dest.write_str(")")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,10 +4,9 @@
|
||||||
|
|
||||||
//! Common handling for the specified value CSS url() values.
|
//! Common handling for the specified value CSS url() values.
|
||||||
|
|
||||||
use cssparser::CssStringWriter;
|
|
||||||
use parser::ParserContext;
|
use parser::ParserContext;
|
||||||
use servo_url::ServoUrl;
|
use servo_url::ServoUrl;
|
||||||
use std::fmt::{self, Write};
|
use std::fmt;
|
||||||
// Note: We use std::sync::Arc rather than stylearc::Arc here because the
|
// Note: We use std::sync::Arc rather than stylearc::Arc here because the
|
||||||
// nonzero optimization is important in keeping the size of SpecifiedUrl below
|
// nonzero optimization is important in keeping the size of SpecifiedUrl below
|
||||||
// the threshold.
|
// the threshold.
|
||||||
|
@ -111,7 +110,6 @@ impl PartialEq for SpecifiedUrl {
|
||||||
|
|
||||||
impl ToCss for SpecifiedUrl {
|
impl ToCss for SpecifiedUrl {
|
||||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||||
try!(dest.write_str("url(\""));
|
|
||||||
let string = match self.original {
|
let string = match self.original {
|
||||||
Some(ref original) => &**original,
|
Some(ref original) => &**original,
|
||||||
None => match self.resolved {
|
None => match self.resolved {
|
||||||
|
@ -123,7 +121,8 @@ impl ToCss for SpecifiedUrl {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
try!(CssStringWriter::new(dest).write_str(string));
|
dest.write_str("url(")?;
|
||||||
dest.write_str("\")")
|
string.to_css(dest)?;
|
||||||
|
dest.write_str(")")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue