style/font_metrics.rs
1/* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4
5//! Access to font metrics from the style system.
6
7#![deny(missing_docs)]
8
9use crate::values::computed::Length;
10
11/// Represents the font metrics that style needs from a font to compute the
12/// value of certain CSS units like `ex`.
13#[derive(Clone, Debug, PartialEq)]
14pub struct FontMetrics {
15 /// The x-height of the font.
16 pub x_height: Option<Length>,
17 /// The zero advance. This is usually writing mode dependent
18 pub zero_advance_measure: Option<Length>,
19 /// The cap-height of the font.
20 pub cap_height: Option<Length>,
21 /// The ideographic-width of the font.
22 pub ic_width: Option<Length>,
23 /// The ascent of the font (a value is always available for this).
24 pub ascent: Length,
25 /// Script scale down factor for math-depth 1.
26 /// https://w3c.github.io/mathml-core/#dfn-scriptpercentscaledown
27 pub script_percent_scale_down: Option<f32>,
28 /// Script scale down factor for math-depth 2.
29 /// https://w3c.github.io/mathml-core/#dfn-scriptscriptpercentscaledown
30 pub script_script_percent_scale_down: Option<f32>,
31}
32
33impl Default for FontMetrics {
34 fn default() -> Self {
35 FontMetrics {
36 x_height: None,
37 zero_advance_measure: None,
38 cap_height: None,
39 ic_width: None,
40 ascent: Length::new(0.0),
41 script_percent_scale_down: None,
42 script_script_percent_scale_down: None,
43 }
44 }
45}
46
47/// Type of font metrics to retrieve.
48#[derive(Clone, Debug, PartialEq)]
49pub enum FontMetricsOrientation {
50 /// Get metrics for horizontal or vertical according to the Context's
51 /// writing mode, using horizontal metrics for vertical/mixed
52 MatchContextPreferHorizontal,
53 /// Get metrics for horizontal or vertical according to the Context's
54 /// writing mode, using vertical metrics for vertical/mixed
55 MatchContextPreferVertical,
56 /// Force getting horizontal metrics.
57 Horizontal,
58}