mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
style: Cleanup generic font-family handling.
To be more similar between Rust and C++. This introduces GenericFontFamily and exposes that plus FontFamilyNameSyntax to C++, using that where appropriate instead of plain uint8_t as we were doing. As a follow-up, as discussed on IRC with Jonathan, we can remove the -moz-fixed family, and turn it just into an alias of Monospace. The only non-trivial change is the MatchType changes, but they're ok I think. The code already assumed at most one CSS generic, and the struct still takes 8 bits. I've verified that the relevant tests are passing (though try is closed). Differential Revision: https://phabricator.services.mozilla.com/D24272
This commit is contained in:
parent
c49a88ec84
commit
2184e3f2e5
7 changed files with 124 additions and 250 deletions
|
@ -69,6 +69,7 @@ use crate::selector_parser::{AttrValue, HorizontalDirection, Lang};
|
|||
use crate::shared_lock::Locked;
|
||||
use crate::string_cache::{Atom, Namespace, WeakAtom, WeakNamespace};
|
||||
use crate::stylist::CascadeData;
|
||||
use crate::values::computed::font::GenericFontFamily;
|
||||
use crate::values::specified::length::FontBaseSize;
|
||||
use crate::CaseSensitivityExt;
|
||||
use app_units::Au;
|
||||
|
@ -1041,7 +1042,7 @@ impl FontMetricsProvider for GeckoFontMetricsProvider {
|
|||
GeckoFontMetricsProvider::new()
|
||||
}
|
||||
|
||||
fn get_size(&self, font_name: &Atom, font_family: u8) -> Au {
|
||||
fn get_size(&self, font_name: &Atom, font_family: GenericFontFamily) -> Au {
|
||||
let mut cache = self.font_size_cache.borrow_mut();
|
||||
if let Some(sizes) = cache.iter().find(|el| el.0 == *font_name) {
|
||||
return sizes.1.size_for_generic(font_family);
|
||||
|
@ -1100,16 +1101,17 @@ impl FontMetricsProvider for GeckoFontMetricsProvider {
|
|||
}
|
||||
|
||||
impl structs::FontSizePrefs {
|
||||
fn size_for_generic(&self, font_family: u8) -> Au {
|
||||
fn size_for_generic(&self, font_family: GenericFontFamily) -> Au {
|
||||
Au(match font_family {
|
||||
structs::kPresContext_DefaultVariableFont_ID => self.mDefaultVariableSize,
|
||||
structs::kPresContext_DefaultFixedFont_ID => self.mDefaultFixedSize,
|
||||
structs::kGenericFont_serif => self.mDefaultSerifSize,
|
||||
structs::kGenericFont_sans_serif => self.mDefaultSansSerifSize,
|
||||
structs::kGenericFont_monospace => self.mDefaultMonospaceSize,
|
||||
structs::kGenericFont_cursive => self.mDefaultCursiveSize,
|
||||
structs::kGenericFont_fantasy => self.mDefaultFantasySize,
|
||||
_ => unreachable!("Unknown generic ID"),
|
||||
GenericFontFamily::None => self.mDefaultVariableSize,
|
||||
GenericFontFamily::Serif => self.mDefaultSerifSize,
|
||||
GenericFontFamily::SansSerif => self.mDefaultSansSerifSize,
|
||||
GenericFontFamily::Monospace => self.mDefaultMonospaceSize,
|
||||
GenericFontFamily::Cursive => self.mDefaultCursiveSize,
|
||||
GenericFontFamily::Fantasy => self.mDefaultFantasySize,
|
||||
GenericFontFamily::MozEmoji => {
|
||||
unreachable!("Should never get here, since this doesn't (yet) appear on font family")
|
||||
},
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue