mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +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
|
@ -269,7 +269,7 @@ impl FontCache {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
Source::Local(ref font) => {
|
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 templates = &mut self.web_families.get_mut(&family_name).unwrap();
|
||||||
let mut found = false;
|
let mut found = false;
|
||||||
for_each_variation(&font_face_name, |path| {
|
for_each_variation(&font_face_name, |path| {
|
||||||
|
@ -464,7 +464,7 @@ impl FontCacheThread {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_web_font(&self, family: FamilyName, sources: EffectiveSources, sender: IpcSender<()>) {
|
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) {
|
pub fn exit(&self) {
|
||||||
|
|
|
@ -282,7 +282,10 @@ macro_rules! font_face_descriptors {
|
||||||
font_face_descriptors! {
|
font_face_descriptors! {
|
||||||
mandatory descriptors = [
|
mandatory descriptors = [
|
||||||
/// The name of this font face
|
/// 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.
|
/// The alternative sources for this font face.
|
||||||
"src" sources: Vec<Source> = Vec::new(),
|
"src" sources: Vec<Source> = Vec::new(),
|
||||||
|
@ -308,7 +311,10 @@ font_face_descriptors! {
|
||||||
font_face_descriptors! {
|
font_face_descriptors! {
|
||||||
mandatory descriptors = [
|
mandatory descriptors = [
|
||||||
/// The name of this font face
|
/// 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.
|
/// The alternative sources for this font face.
|
||||||
"src" sources: Vec<Source> = Vec::new(),
|
"src" sources: Vec<Source> = Vec::new(),
|
||||||
|
|
|
@ -17,7 +17,7 @@ pub type FontFaceRule = RefPtr<nsCSSFontFaceRule>;
|
||||||
fn set_font_face_descriptors(descriptors: &mut CSSFontFaceDescriptors,
|
fn set_font_face_descriptors(descriptors: &mut CSSFontFaceDescriptors,
|
||||||
data: FontFaceData) {
|
data: FontFaceData) {
|
||||||
// font-family
|
// font-family
|
||||||
descriptors.mFamily.set_string_from_atom(&data.family.0);
|
descriptors.mFamily.set_string_from_atom(&data.family.name);
|
||||||
|
|
||||||
macro_rules! map_enum {
|
macro_rules! map_enum {
|
||||||
($target:ident = ($data:ident: $prop:ident) {
|
($target:ident = ($data:ident: $prop:ident) {
|
||||||
|
@ -74,8 +74,8 @@ fn set_font_face_descriptors(descriptors: &mut CSSFontFaceDescriptors,
|
||||||
next!().set_font_format(&hint);
|
next!().set_font_format(&hint);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Source::Local(ref name) => {
|
Source::Local(ref family) => {
|
||||||
next!().set_local_font(&name.0);
|
next!().set_local_font(&family.name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -660,7 +660,8 @@ extern "C" {
|
||||||
}
|
}
|
||||||
extern "C" {
|
extern "C" {
|
||||||
pub fn Gecko_FontFamilyList_AppendNamed(aList: *mut FontFamilyList,
|
pub fn Gecko_FontFamilyList_AppendNamed(aList: *mut FontFamilyList,
|
||||||
aName: *mut nsIAtom);
|
aName: *mut nsIAtom,
|
||||||
|
aQuoted: bool);
|
||||||
}
|
}
|
||||||
extern "C" {
|
extern "C" {
|
||||||
pub fn Gecko_FontFamilyList_AppendGeneric(list: *mut FontFamilyList,
|
pub fn Gecko_FontFamilyList_AppendGeneric(list: *mut FontFamilyList,
|
||||||
|
|
|
@ -1257,8 +1257,8 @@ fn static_assert() {
|
||||||
|
|
||||||
for family in &v.0 {
|
for family in &v.0 {
|
||||||
match *family {
|
match *family {
|
||||||
FontFamily::FamilyName(ref name) => {
|
FontFamily::FamilyName(ref f) => {
|
||||||
unsafe { Gecko_FontFamilyList_AppendNamed(list, name.0.as_ptr()); }
|
unsafe { Gecko_FontFamilyList_AppendNamed(list, f.name.as_ptr(), f.quoted); }
|
||||||
}
|
}
|
||||||
FontFamily::Generic(ref name) => {
|
FontFamily::Generic(ref name) => {
|
||||||
let (family_type, generic) =
|
let (family_type, generic) =
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
no_viewport_percentage!(SpecifiedValue);
|
no_viewport_percentage!(SpecifiedValue);
|
||||||
|
|
||||||
pub mod computed_value {
|
pub mod computed_value {
|
||||||
use cssparser::{CssStringWriter, Parser};
|
use cssparser::{CssStringWriter, Parser, serialize_identifier};
|
||||||
use std::fmt::{self, Write};
|
use std::fmt::{self, Write};
|
||||||
use Atom;
|
use Atom;
|
||||||
use style_traits::ToCss;
|
use style_traits::ToCss;
|
||||||
|
@ -33,13 +33,16 @@
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Eq, Clone, Hash)]
|
#[derive(Debug, PartialEq, Eq, Clone, Hash)]
|
||||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf, Deserialize, Serialize))]
|
#[cfg_attr(feature = "servo", derive(HeapSizeOf, Deserialize, Serialize))]
|
||||||
pub struct FamilyName(pub Atom);
|
pub struct FamilyName {
|
||||||
|
pub name: Atom,
|
||||||
|
pub quoted: bool,
|
||||||
|
}
|
||||||
|
|
||||||
impl FontFamily {
|
impl FontFamily {
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn atom(&self) -> &Atom {
|
pub fn atom(&self) -> &Atom {
|
||||||
match *self {
|
match *self {
|
||||||
FontFamily::FamilyName(ref name) => &name.0,
|
FontFamily::FamilyName(ref family_name) => &family_name.name,
|
||||||
FontFamily::Generic(ref name) => name,
|
FontFamily::Generic(ref name) => name,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -70,13 +73,22 @@
|
||||||
"monospace" => return FontFamily::Generic(atom!("monospace")),
|
"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
|
/// Parse a font-family value
|
||||||
pub fn parse(input: &mut Parser) -> Result<Self, ()> {
|
pub fn parse(input: &mut Parser) -> Result<Self, ()> {
|
||||||
if let Ok(value) = input.try(|input| input.expect_string()) {
|
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());
|
let first_ident = try!(input.expect_ident());
|
||||||
|
|
||||||
|
@ -120,15 +132,22 @@
|
||||||
value.push_str(" ");
|
value.push_str(" ");
|
||||||
value.push_str(&ident);
|
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 {
|
impl ToCss for FamilyName {
|
||||||
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 {
|
||||||
dest.write_char('"')?;
|
if self.quoted {
|
||||||
write!(CssStringWriter::new(dest), "{}", self.0)?;
|
dest.write_char('"')?;
|
||||||
dest.write_char('"')
|
write!(CssStringWriter::new(dest), "{}", self.name)?;
|
||||||
|
dest.write_char('"')
|
||||||
|
} else {
|
||||||
|
serialize_identifier(&*self.name.to_string(), dest)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,8 +12,14 @@ fn test_local_web_font() {
|
||||||
let (inp_chan, _) = ipc::channel().unwrap();
|
let (inp_chan, _) = ipc::channel().unwrap();
|
||||||
let (out_chan, out_receiver) = ipc::channel().unwrap();
|
let (out_chan, out_receiver) = ipc::channel().unwrap();
|
||||||
let font_cache_thread = FontCacheThread::new(inp_chan, None);
|
let font_cache_thread = FontCacheThread::new(inp_chan, None);
|
||||||
let family_name = FamilyName(From::from("test family"));
|
let family_name = FamilyName {
|
||||||
let variant_name = FamilyName(From::from("test font face"));
|
name: From::from("test family"),
|
||||||
|
quoted: true,
|
||||||
|
};
|
||||||
|
let variant_name = FamilyName {
|
||||||
|
name: From::from("test font face"),
|
||||||
|
quoted: true,
|
||||||
|
};
|
||||||
let font_face_rule = FontFaceData {
|
let font_face_rule = FontFaceData {
|
||||||
family: family_name.clone(),
|
family: family_name.clone(),
|
||||||
sources: vec![Source::Local(variant_name)],
|
sources: vec![Source::Local(variant_name)],
|
||||||
|
|
|
@ -16,9 +16,6 @@
|
||||||
[content: attr(foo_bar)]
|
[content: attr(foo_bar)]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
[font-family: Arial]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[list-style-type: decimal-leading-zero]
|
[list-style-type: decimal-leading-zero]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue