Skip to content

Commit

Permalink
Serialize unquoted font-family without quote
Browse files Browse the repository at this point in the history
  • Loading branch information
canova committed Mar 30, 2017
1 parent 54e2b7b commit 9991c49
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 24 deletions.
4 changes: 2 additions & 2 deletions components/gfx/font_cache_thread.rs
Expand Up @@ -269,7 +269,7 @@ impl FontCache {
});
}
Source::Local(ref font) => {
let font_face_name = LowercaseString::new(&font.0);
let font_face_name = LowercaseString::new(&font.name);
let templates = &mut self.web_families.get_mut(&family_name).unwrap();
let mut found = false;
for_each_variation(&font_face_name, |path| {
Expand Down Expand Up @@ -464,7 +464,7 @@ impl FontCacheThread {
}

pub fn add_web_font(&self, family: FamilyName, sources: EffectiveSources, sender: IpcSender<()>) {
self.chan.send(Command::AddWebFont(LowercaseString::new(&family.0), sources, sender)).unwrap();
self.chan.send(Command::AddWebFont(LowercaseString::new(&family.name), sources, sender)).unwrap();
}

pub fn exit(&self) {
Expand Down
10 changes: 8 additions & 2 deletions components/style/font_face.rs
Expand Up @@ -282,7 +282,10 @@ macro_rules! font_face_descriptors {
font_face_descriptors! {
mandatory descriptors = [
/// The name of this font face
"font-family" family: FamilyName = FamilyName(atom!("")),
"font-family" family: FamilyName = FamilyName {
name: atom!(""),
quoted: true,
},

/// The alternative sources for this font face.
"src" sources: Vec<Source> = Vec::new(),
Expand All @@ -308,7 +311,10 @@ font_face_descriptors! {
font_face_descriptors! {
mandatory descriptors = [
/// The name of this font face
"font-family" family: FamilyName = FamilyName(atom!("")),
"font-family" family: FamilyName = FamilyName {
name: atom!(""),
quoted: true,
},

/// The alternative sources for this font face.
"src" sources: Vec<Source> = Vec::new(),
Expand Down
6 changes: 3 additions & 3 deletions components/style/gecko/rules.rs
Expand Up @@ -17,7 +17,7 @@ pub type FontFaceRule = RefPtr<nsCSSFontFaceRule>;
fn set_font_face_descriptors(descriptors: &mut CSSFontFaceDescriptors,
data: FontFaceData) {
// font-family
descriptors.mFamily.set_string_from_atom(&data.family.0);
descriptors.mFamily.set_string_from_atom(&data.family.name);

macro_rules! map_enum {
($target:ident = ($data:ident: $prop:ident) {
Expand Down Expand Up @@ -74,8 +74,8 @@ fn set_font_face_descriptors(descriptors: &mut CSSFontFaceDescriptors,
next!().set_font_format(&hint);
}
}
Source::Local(ref name) => {
next!().set_local_font(&name.0);
Source::Local(ref family) => {
next!().set_local_font(&family.name);
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion components/style/gecko_bindings/bindings.rs
Expand Up @@ -660,7 +660,8 @@ extern "C" {
}
extern "C" {
pub fn Gecko_FontFamilyList_AppendNamed(aList: *mut FontFamilyList,
aName: *mut nsIAtom);
aName: *mut nsIAtom,
aQuoted: bool);
}
extern "C" {
pub fn Gecko_FontFamilyList_AppendGeneric(list: *mut FontFamilyList,
Expand Down
4 changes: 2 additions & 2 deletions components/style/properties/gecko.mako.rs
Expand Up @@ -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) =
Expand Down
37 changes: 28 additions & 9 deletions components/style/properties/longhand/font.mako.rs
Expand Up @@ -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;
Expand All @@ -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,
}
}
Expand Down Expand Up @@ -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());

Expand Down Expand Up @@ -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)
}
}
}

Expand Down
10 changes: 8 additions & 2 deletions tests/unit/gfx/font_cache_thread.rs
Expand Up @@ -12,8 +12,14 @@ fn test_local_web_font() {
let (inp_chan, _) = ipc::channel().unwrap();
let (out_chan, out_receiver) = ipc::channel().unwrap();
let font_cache_thread = FontCacheThread::new(inp_chan, None);
let family_name = FamilyName(From::from("test family"));
let variant_name = FamilyName(From::from("test font face"));
let family_name = FamilyName {
name: From::from("test family"),
quoted: true,
};
let variant_name = FamilyName {
name: From::from("test font face"),
quoted: true,
};
let font_face_rule = FontFaceData {
family: family_name.clone(),
sources: vec![Source::Local(variant_name)],
Expand Down
3 changes: 0 additions & 3 deletions tests/wpt/metadata/cssom/serialize-values.html.ini
Expand Up @@ -16,9 +16,6 @@
[content: attr(foo_bar)]
expected: FAIL

[font-family: Arial]
expected: FAIL

[list-style-type: decimal-leading-zero]
expected: FAIL

Expand Down

0 comments on commit 9991c49

Please sign in to comment.