mirror of
https://github.com/servo/servo.git
synced 2025-10-04 02:29:12 +01:00
style: Simplify language-dependent font fallback code
.fallback is always the default font for the lang group unless we're a system font (in which case it's "none"). The only reason we need that is because we need to react to language changes (which affect the initial font). Simplify the model a bit doing the language lookup in gfxTextRun (this should avoid allocating a few nsStyleFont structs too. Depends on D130732 Differential Revision: https://phabricator.services.mozilla.com/D131312
This commit is contained in:
parent
f911fb4f0f
commit
19aa8842c2
3 changed files with 57 additions and 55 deletions
|
@ -182,6 +182,9 @@ pub struct FontFamily {
|
|||
pub families: FontFamilyList,
|
||||
/// Whether this font-family came from a specified system-font.
|
||||
pub is_system_font: bool,
|
||||
/// Whether this is the initial font-family that might react to language
|
||||
/// changes.
|
||||
pub is_initial: bool,
|
||||
}
|
||||
|
||||
macro_rules! static_font_family {
|
||||
|
@ -193,10 +196,9 @@ macro_rules! static_font_family {
|
|||
list: crate::ArcSlice::from_iter_leaked(std::iter::once($family)),
|
||||
#[cfg(feature = "servo")]
|
||||
list: Box::new([$family]),
|
||||
#[cfg(feature = "gecko")]
|
||||
fallback: GenericFontFamily::None,
|
||||
},
|
||||
is_system_font: false,
|
||||
is_initial: false,
|
||||
};
|
||||
}
|
||||
};
|
||||
|
@ -234,9 +236,9 @@ impl FontFamily {
|
|||
syntax: FontFamilyNameSyntax::Identifiers,
|
||||
},
|
||||
))),
|
||||
fallback: GenericFontFamily::None,
|
||||
},
|
||||
is_system_font: true,
|
||||
is_initial: false,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -303,7 +305,7 @@ impl ToCss for FontFamily {
|
|||
Some(f) => f.to_css(dest)?,
|
||||
None => {
|
||||
#[cfg(feature = "gecko")]
|
||||
return self.families.fallback.to_css(dest);
|
||||
return return Ok(());
|
||||
#[cfg(feature = "servo")]
|
||||
unreachable!();
|
||||
},
|
||||
|
@ -562,8 +564,6 @@ impl SingleFontFamily {
|
|||
pub struct FontFamilyList {
|
||||
/// The actual list of font families specified.
|
||||
pub list: crate::ArcSlice<SingleFontFamily>,
|
||||
/// A fallback font type (none, serif, or sans-serif, generally).
|
||||
pub fallback: GenericFontFamily,
|
||||
}
|
||||
|
||||
/// A list of font families.
|
||||
|
@ -592,17 +592,6 @@ impl FontFamilyList {
|
|||
self.list.iter()
|
||||
}
|
||||
|
||||
/// Puts the fallback in the list if needed.
|
||||
#[cfg(feature = "gecko")]
|
||||
pub fn normalize(&mut self) {
|
||||
if self.fallback == GenericFontFamily::None {
|
||||
return;
|
||||
}
|
||||
let mut new_list = self.list.iter().cloned().collect::<Vec<_>>();
|
||||
new_list.push(SingleFontFamily::Generic(self.fallback));
|
||||
self.list = crate::ArcSlice::from_iter(new_list.into_iter());
|
||||
}
|
||||
|
||||
/// If there's a generic font family on the list which is suitable for user
|
||||
/// font prioritization, then move it to the front of the list. Otherwise,
|
||||
/// prepend the default generic.
|
||||
|
@ -629,7 +618,7 @@ impl FontFamilyList {
|
|||
|
||||
/// Returns whether we need to prioritize user fonts.
|
||||
#[cfg(feature = "gecko")]
|
||||
pub (crate) fn needs_user_font_prioritization(&self) -> bool {
|
||||
pub(crate) fn needs_user_font_prioritization(&self) -> bool {
|
||||
self.iter().next().map_or(true, |f| match f {
|
||||
SingleFontFamily::Generic(f) => !f.valid_for_user_font_prioritization(),
|
||||
_ => true,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue