stylo: Use font metrics provider as a cache for font size results

This commit is contained in:
Manish Goregaokar 2017-04-04 11:11:27 -07:00 committed by Manish Goregaokar
parent e402c72d0e
commit 2febe7ccde
8 changed files with 60 additions and 24 deletions

View file

@ -46,8 +46,16 @@ impl FontMetricsProvider for ServoMetricsProvider {
fn create_from(_: &SharedStyleContext) -> Self {
ServoMetricsProvider
}
fn get_size(&self, _font_name: &Atom, _font_family: u8) -> Au {
unreachable!("Dummy provider should never be used to compute font size")
}
}
// Servo's font metrics provider will probably not live in this crate, so this will
// have to be replaced with something else (perhaps a trait method on TElement)
// when we get there
#[cfg(feature = "gecko")]
/// Construct a font metrics provider for the current product
pub fn get_metrics_provider_for_product() -> ::gecko::wrapper::GeckoFontMetricsProvider {
@ -61,7 +69,7 @@ pub fn get_metrics_provider_for_product() -> ServoMetricsProvider {
}
/// A trait used to represent something capable of providing us font metrics.
pub trait FontMetricsProvider: Send + fmt::Debug {
pub trait FontMetricsProvider: fmt::Debug {
/// Obtain the metrics for given font family.
///
/// TODO: We could make this take the full list, I guess, and save a few
@ -72,9 +80,7 @@ pub trait FontMetricsProvider: Send + fmt::Debug {
}
/// Get default size of a given language and generic family
fn get_size(&self, _font_name: &Atom, _font_family: u8) -> Au {
unimplemented!()
}
fn get_size(&self, font_name: &Atom, font_family: u8) -> Au;
/// Construct from a shared style context
fn create_from(context: &SharedStyleContext) -> Self where Self: Sized;