mirror of
https://github.com/servo/servo.git
synced 2025-08-06 22:15:33 +01:00
Serialize unquoted font-family without quote
This commit is contained in:
parent
54e2b7b2d5
commit
9991c496b3
8 changed files with 53 additions and 24 deletions
|
@ -1257,8 +1257,8 @@ fn static_assert() {
|
|||
|
||||
for family in &v.0 {
|
||||
match *family {
|
||||
FontFamily::FamilyName(ref name) => {
|
||||
unsafe { Gecko_FontFamilyList_AppendNamed(list, name.0.as_ptr()); }
|
||||
FontFamily::FamilyName(ref f) => {
|
||||
unsafe { Gecko_FontFamilyList_AppendNamed(list, f.name.as_ptr(), f.quoted); }
|
||||
}
|
||||
FontFamily::Generic(ref name) => {
|
||||
let (family_type, generic) =
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
no_viewport_percentage!(SpecifiedValue);
|
||||
|
||||
pub mod computed_value {
|
||||
use cssparser::{CssStringWriter, Parser};
|
||||
use cssparser::{CssStringWriter, Parser, serialize_identifier};
|
||||
use std::fmt::{self, Write};
|
||||
use Atom;
|
||||
use style_traits::ToCss;
|
||||
|
@ -33,13 +33,16 @@
|
|||
|
||||
#[derive(Debug, PartialEq, Eq, Clone, Hash)]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf, Deserialize, Serialize))]
|
||||
pub struct FamilyName(pub Atom);
|
||||
pub struct FamilyName {
|
||||
pub name: Atom,
|
||||
pub quoted: bool,
|
||||
}
|
||||
|
||||
impl FontFamily {
|
||||
#[inline]
|
||||
pub fn atom(&self) -> &Atom {
|
||||
match *self {
|
||||
FontFamily::FamilyName(ref name) => &name.0,
|
||||
FontFamily::FamilyName(ref family_name) => &family_name.name,
|
||||
FontFamily::Generic(ref name) => name,
|
||||
}
|
||||
}
|
||||
|
@ -70,13 +73,22 @@
|
|||
"monospace" => return FontFamily::Generic(atom!("monospace")),
|
||||
_ => {}
|
||||
}
|
||||
FontFamily::FamilyName(FamilyName(input))
|
||||
|
||||
// We don't know if it's quoted or not. So we set it to
|
||||
// quoted by default.
|
||||
FontFamily::FamilyName(FamilyName {
|
||||
name: input,
|
||||
quoted: true,
|
||||
})
|
||||
}
|
||||
|
||||
/// Parse a font-family value
|
||||
pub fn parse(input: &mut Parser) -> Result<Self, ()> {
|
||||
if let Ok(value) = input.try(|input| input.expect_string()) {
|
||||
return Ok(FontFamily::FamilyName(FamilyName(Atom::from(&*value))))
|
||||
return Ok(FontFamily::FamilyName(FamilyName {
|
||||
name: Atom::from(&*value),
|
||||
quoted: true,
|
||||
}))
|
||||
}
|
||||
let first_ident = try!(input.expect_ident());
|
||||
|
||||
|
@ -120,15 +132,22 @@
|
|||
value.push_str(" ");
|
||||
value.push_str(&ident);
|
||||
}
|
||||
Ok(FontFamily::FamilyName(FamilyName(Atom::from(value))))
|
||||
Ok(FontFamily::FamilyName(FamilyName {
|
||||
name: Atom::from(value),
|
||||
quoted: false,
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
impl ToCss for FamilyName {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
dest.write_char('"')?;
|
||||
write!(CssStringWriter::new(dest), "{}", self.0)?;
|
||||
dest.write_char('"')
|
||||
if self.quoted {
|
||||
dest.write_char('"')?;
|
||||
write!(CssStringWriter::new(dest), "{}", self.name)?;
|
||||
dest.write_char('"')
|
||||
} else {
|
||||
serialize_identifier(&*self.name.to_string(), dest)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue