mirror of
https://github.com/servo/servo.git
synced 2025-08-05 13:40:08 +01:00
style: Use first generic rather than only generic to determine fallback font family
This seems like more sensible behavior. We have another use of only_generic(), but that affects font sizing and other browsers agree with us there: <div style="font-family: monospace">Should be 13px</div> <div style="font-family: something, monospace">Should be 16px</div> So not touching that one. Differential Revision: https://phabricator.services.mozilla.com/D130732
This commit is contained in:
parent
88b82f569b
commit
a9baf5fe3d
2 changed files with 15 additions and 7 deletions
|
@ -890,7 +890,6 @@ impl<'a, 'b: 'a> Cascade<'a, 'b> {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let use_document_fonts = static_prefs::pref!("browser.display.use_document_fonts") != 0;
|
|
||||||
let builder = &mut self.context.builder;
|
let builder = &mut self.context.builder;
|
||||||
let (default_font_type, prioritize_user_fonts) = {
|
let (default_font_type, prioritize_user_fonts) = {
|
||||||
let font = builder.get_font().gecko();
|
let font = builder.get_font().gecko();
|
||||||
|
@ -905,22 +904,23 @@ impl<'a, 'b: 'a> Cascade<'a, 'b> {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let generic = font.mFont.family.families.single_generic().unwrap_or(GenericFontFamily::None);
|
|
||||||
let default_font_type = unsafe {
|
let default_font_type = unsafe {
|
||||||
bindings::Gecko_nsStyleFont_ComputeDefaultFontType(
|
bindings::Gecko_nsStyleFont_ComputeFallbackFontTypeForLanguage(
|
||||||
builder.device.document(),
|
builder.device.document(),
|
||||||
generic,
|
|
||||||
font.mLanguage.mRawPtr,
|
font.mLanguage.mRawPtr,
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let use_document_fonts = static_prefs::pref!("browser.display.use_document_fonts") != 0;
|
||||||
|
|
||||||
// We prioritize user fonts over document fonts if the pref is set,
|
// We prioritize user fonts over document fonts if the pref is set,
|
||||||
// and we don't have a generic family already (or we're using
|
// and we don't have a generic family already (or we're using
|
||||||
// cursive or fantasy, since they're ignored, see bug 789788), and
|
// cursive or fantasy, since they're ignored, see bug 789788), and
|
||||||
// we have a generic family to actually replace it with.
|
// we have a generic family to actually replace it with.
|
||||||
let prioritize_user_fonts = !use_document_fonts &&
|
let prioritize_user_fonts =
|
||||||
|
!use_document_fonts &&
|
||||||
default_font_type != GenericFontFamily::None &&
|
default_font_type != GenericFontFamily::None &&
|
||||||
!generic.valid_for_user_font_prioritization();
|
font.mFont.family.families.needs_user_font_prioritization();
|
||||||
|
|
||||||
if !prioritize_user_fonts && default_font_type == font.mFont.family.families.fallback {
|
if !prioritize_user_fonts && default_font_type == font.mFont.family.families.fallback {
|
||||||
// Nothing to do.
|
// Nothing to do.
|
||||||
|
|
|
@ -627,12 +627,20 @@ impl FontFamilyList {
|
||||||
self.list = crate::ArcSlice::from_iter(new_list.into_iter());
|
self.list = crate::ArcSlice::from_iter(new_list.into_iter());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns whether we need to prioritize user fonts.
|
||||||
|
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,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
/// Return the generic ID if it is a single generic font
|
/// Return the generic ID if it is a single generic font
|
||||||
pub fn single_generic(&self) -> Option<GenericFontFamily> {
|
pub fn single_generic(&self) -> Option<GenericFontFamily> {
|
||||||
let mut iter = self.iter();
|
let mut iter = self.iter();
|
||||||
if let Some(SingleFontFamily::Generic(f)) = iter.next() {
|
if let Some(SingleFontFamily::Generic(f)) = iter.next() {
|
||||||
if iter.next().is_none() {
|
if iter.next().is_none() {
|
||||||
return Some(f.clone());
|
return Some(*f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
None
|
None
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue