1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#![deny(missing_docs)]
use Atom;
use app_units::Au;
use context::SharedStyleContext;
use logical_geometry::WritingMode;
use media_queries::Device;
use properties::style_structs::Font;
use std::fmt;
#[derive(Clone, Debug, PartialEq)]
pub struct FontMetrics {
pub x_height: Au,
pub zero_advance_measure: Au,
}
#[derive(Clone, Debug, PartialEq)]
pub enum FontMetricsQueryResult {
Available(FontMetrics),
NotAvailable,
}
pub trait FontMetricsProvider: fmt::Debug {
fn query(&self, _font: &Font, _font_size: Au, _wm: WritingMode,
_in_media_query: bool, _device: &Device) -> FontMetricsQueryResult {
FontMetricsQueryResult::NotAvailable
}
fn get_size(&self, font_name: &Atom, font_family: u8) -> Au;
fn create_from(context: &SharedStyleContext) -> Self where Self: Sized;
}
#[derive(Debug)]
#[cfg(feature = "servo")]
pub struct ServoMetricsProvider;
#[cfg(feature = "servo")]
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")
}
}
#[cfg(feature = "gecko")]
pub fn get_metrics_provider_for_product() -> ::gecko::wrapper::GeckoFontMetricsProvider {
::gecko::wrapper::GeckoFontMetricsProvider::new()
}
#[cfg(feature = "servo")]
pub fn get_metrics_provider_for_product() -> ServoMetricsProvider {
ServoMetricsProvider
}