mirror of
https://github.com/servo/servo.git
synced 2025-08-06 22:15:33 +01:00
Simplify our setup for font metric queries from style
This is a backport of https://phabricator.services.mozilla.com/D157589, by Emilio Cobos Álvarez, plus some additions so that Servo compiles, and some parts from https://phabricator.services.mozilla.com/D144455. Should have no change in behavior.
This commit is contained in:
parent
feaa66b597
commit
ab2ba273e3
21 changed files with 172 additions and 322 deletions
|
@ -6,9 +6,7 @@
|
|||
|
||||
#![deny(missing_docs)]
|
||||
|
||||
use crate::context::SharedStyleContext;
|
||||
use crate::values::computed::Length;
|
||||
use crate::Atom;
|
||||
|
||||
/// Represents the font metrics that style needs from a font to compute the
|
||||
/// value of certain CSS units like `ex`.
|
||||
|
@ -47,64 +45,3 @@ pub enum FontMetricsOrientation {
|
|||
/// Force getting horizontal metrics.
|
||||
Horizontal,
|
||||
}
|
||||
|
||||
/// A trait used to represent something capable of providing us font metrics.
|
||||
pub trait FontMetricsProvider {
|
||||
/// Obtain the metrics for given font family.
|
||||
fn query(
|
||||
&self,
|
||||
_context: &crate::values::computed::Context,
|
||||
_base_size: crate::values::specified::length::FontBaseSize,
|
||||
_orientation: FontMetricsOrientation,
|
||||
) -> FontMetrics {
|
||||
Default::default()
|
||||
}
|
||||
|
||||
/// Get default size of a given language and generic family.
|
||||
fn get_size(
|
||||
&self,
|
||||
font_name: &Atom,
|
||||
font_family: crate::values::computed::font::GenericFontFamily,
|
||||
) -> Length;
|
||||
|
||||
/// Construct from a shared style context
|
||||
fn create_from(context: &SharedStyleContext) -> Self
|
||||
where
|
||||
Self: Sized;
|
||||
}
|
||||
|
||||
// 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
|
||||
}
|
||||
|
||||
fn get_size(&self, _: &Atom, _: crate::values::computed::font::GenericFontFamily) -> Length {
|
||||
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() -> crate::gecko::wrapper::GeckoFontMetricsProvider {
|
||||
crate::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
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue