stylo: Store font metrics provider in thread local style context

This commit is contained in:
Manish Goregaokar 2017-04-04 11:11:27 -07:00 committed by Manish Goregaokar
parent 2ea8d61fbf
commit e402c72d0e
19 changed files with 158 additions and 35 deletions

View file

@ -8,6 +8,7 @@
use Atom;
use app_units::Au;
use context::SharedStyleContext;
use euclid::Size2D;
use std::fmt;
@ -31,8 +32,36 @@ pub enum FontMetricsQueryResult {
NotAvailable,
}
// TODO: 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
#[derive(Debug)]
#[cfg(feature = "servo")]
/// Dummy metrics provider for Servo. Knows nothing about fonts and does not provide
/// any metrics.
pub struct ServoMetricsProvider;
#[cfg(feature = "servo")]
impl FontMetricsProvider for ServoMetricsProvider {
fn create_from(_: &SharedStyleContext) -> Self {
ServoMetricsProvider
}
}
#[cfg(feature = "gecko")]
/// Construct a font metrics provider for the current product
pub fn get_metrics_provider_for_product() -> ::gecko::wrapper::GeckoFontMetricsProvider {
::gecko::wrapper::GeckoFontMetricsProvider::new()
}
#[cfg(feature = "servo")]
/// Construct a font metrics provider for the current product
pub fn get_metrics_provider_for_product() -> ServoMetricsProvider {
ServoMetricsProvider
}
/// A trait used to represent something capable of providing us font metrics.
pub trait FontMetricsProvider: Send + Sync + fmt::Debug {
pub trait FontMetricsProvider: Send + fmt::Debug {
/// Obtain the metrics for given font family.
///
/// TODO: We could make this take the full list, I guess, and save a few
@ -41,4 +70,13 @@ pub trait FontMetricsProvider: Send + Sync + fmt::Debug {
fn query(&self, _font_name: &Atom) -> FontMetricsQueryResult {
FontMetricsQueryResult::NotAvailable
}
/// Get default size of a given language and generic family
fn get_size(&self, _font_name: &Atom, _font_family: u8) -> Au {
unimplemented!()
}
/// Construct from a shared style context
fn create_from(context: &SharedStyleContext) -> Self where Self: Sized;
}