mirror of
https://github.com/servo/servo.git
synced 2025-08-07 06:25:32 +01:00
style: Use a SharedFontList object to store font-family values for Gecko.
This commit is contained in:
parent
c0f404999c
commit
4d9dd4b757
6 changed files with 242 additions and 89 deletions
|
@ -25,9 +25,6 @@ use gecko_bindings::bindings::Gecko_CopyFontFamilyFrom;
|
|||
use gecko_bindings::bindings::Gecko_CopyImageValueFrom;
|
||||
use gecko_bindings::bindings::Gecko_CopyListStyleImageFrom;
|
||||
use gecko_bindings::bindings::Gecko_EnsureImageLayersLength;
|
||||
use gecko_bindings::bindings::Gecko_FontFamilyList_AppendGeneric;
|
||||
use gecko_bindings::bindings::Gecko_FontFamilyList_AppendNamed;
|
||||
use gecko_bindings::bindings::Gecko_FontFamilyList_Clear;
|
||||
use gecko_bindings::bindings::Gecko_SetCursorArrayLength;
|
||||
use gecko_bindings::bindings::Gecko_SetCursorImageValue;
|
||||
use gecko_bindings::bindings::Gecko_StyleTransition_SetUnsupportedProperty;
|
||||
|
@ -2035,28 +2032,11 @@ fn static_assert() {
|
|||
}
|
||||
|
||||
pub fn set_font_family(&mut self, v: longhands::font_family::computed_value::T) {
|
||||
use properties::longhands::font_family::computed_value::{FontFamily, FamilyNameSyntax};
|
||||
|
||||
let list = &mut self.gecko.mFont.fontlist;
|
||||
unsafe { Gecko_FontFamilyList_Clear(list); }
|
||||
|
||||
self.gecko.mGenericID = structs::kGenericFont_NONE;
|
||||
|
||||
for family in &v.0 {
|
||||
match *family {
|
||||
FontFamily::FamilyName(ref f) => {
|
||||
let quoted = matches!(f.syntax, FamilyNameSyntax::Quoted);
|
||||
unsafe { Gecko_FontFamilyList_AppendNamed(list, f.name.as_ptr(), quoted); }
|
||||
}
|
||||
FontFamily::Generic(ref name) => {
|
||||
let (family_type, generic) = FontFamily::generic(name);
|
||||
if v.0.len() == 1 {
|
||||
self.gecko.mGenericID = generic;
|
||||
}
|
||||
unsafe { Gecko_FontFamilyList_AppendGeneric(list, family_type); }
|
||||
}
|
||||
}
|
||||
if let Some(generic) = v.0.single_generic() {
|
||||
self.gecko.mGenericID = generic;
|
||||
}
|
||||
self.gecko.mFont.fontlist.mFontlist.mBasePtr.set_move((v.0).0.clone());
|
||||
}
|
||||
|
||||
pub fn font_family_count(&self) -> usize {
|
||||
|
@ -2078,46 +2058,28 @@ fn static_assert() {
|
|||
}
|
||||
|
||||
pub fn clone_font_family(&self) -> longhands::font_family::computed_value::T {
|
||||
use cssparser::serialize_identifier;
|
||||
use properties::longhands::font_family::computed_value::{FontFamily, FamilyName, FamilyNameSyntax};
|
||||
use gecko_bindings::structs::FontFamilyType;
|
||||
use gecko_string_cache::Atom;
|
||||
use properties::longhands::font_family::computed_value;
|
||||
use properties::longhands::font_family::computed_value::FontFamily;
|
||||
use properties::longhands::font_family::computed_value::FontFamilyList;
|
||||
|
||||
if self.gecko.mFont.fontlist.mFontlist.is_empty() {
|
||||
let default = match self.gecko.mFont.fontlist.mDefaultFontType {
|
||||
FontFamilyType::eFamily_serif => FontFamily::Generic(atom!("serif")),
|
||||
FontFamilyType::eFamily_sans_serif => FontFamily::Generic(atom!("sans-serif")),
|
||||
let fontlist = &self.gecko.mFont.fontlist;
|
||||
let shared_fontlist = unsafe { fontlist.mFontlist.mBasePtr.to_safe() };
|
||||
|
||||
if shared_fontlist.mNames.is_empty() {
|
||||
let default = match fontlist.mDefaultFontType {
|
||||
FontFamilyType::eFamily_serif => {
|
||||
FontFamily::Generic(atom!("serif"))
|
||||
}
|
||||
FontFamilyType::eFamily_sans_serif => {
|
||||
FontFamily::Generic(atom!("sans-serif"))
|
||||
}
|
||||
_ => panic!("Default generic must be serif or sans-serif"),
|
||||
};
|
||||
return longhands::font_family::computed_value::T(vec![default]);
|
||||
computed_value::T(FontFamilyList::new(vec![default]))
|
||||
} else {
|
||||
computed_value::T(FontFamilyList(shared_fontlist))
|
||||
}
|
||||
|
||||
longhands::font_family::computed_value::T(
|
||||
self.gecko.mFont.fontlist.mFontlist.iter().map(|gecko_font_family_name| {
|
||||
match gecko_font_family_name.mType {
|
||||
FontFamilyType::eFamily_serif => FontFamily::Generic(atom!("serif")),
|
||||
FontFamilyType::eFamily_sans_serif => FontFamily::Generic(atom!("sans-serif")),
|
||||
FontFamilyType::eFamily_monospace => FontFamily::Generic(atom!("monospace")),
|
||||
FontFamilyType::eFamily_cursive => FontFamily::Generic(atom!("cursive")),
|
||||
FontFamilyType::eFamily_fantasy => FontFamily::Generic(atom!("fantasy")),
|
||||
FontFamilyType::eFamily_moz_fixed => FontFamily::Generic(Atom::from("-moz-fixed")),
|
||||
FontFamilyType::eFamily_named => {
|
||||
let name = Atom::from(&*gecko_font_family_name.mName);
|
||||
let mut serialization = String::new();
|
||||
serialize_identifier(&name.to_string(), &mut serialization).unwrap();
|
||||
FontFamily::FamilyName(FamilyName {
|
||||
name: name.clone(),
|
||||
syntax: FamilyNameSyntax::Identifiers(serialization),
|
||||
})
|
||||
},
|
||||
FontFamilyType::eFamily_named_quoted => FontFamily::FamilyName(FamilyName {
|
||||
name: (&*gecko_font_family_name.mName).into(),
|
||||
syntax: FamilyNameSyntax::Quoted,
|
||||
}),
|
||||
x => panic!("Found unexpected font FontFamilyType: {:?}", x),
|
||||
}
|
||||
}).collect()
|
||||
)
|
||||
}
|
||||
|
||||
pub fn unzoom_fonts(&mut self, device: &Device) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue