mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00:00
This is a "simplified" implementation of 'ic', similar to what Safari Preview currently supports: it only considers the advance of U+6C34 if found in the first available font, and otherwise falls back to the default of 1em. (The spec allows for this "in cases where it is impossible or impractical to determine the ideographic advance measure".) Differential Revision: https://phabricator.services.mozilla.com/D132818
50 lines
1.7 KiB
Rust
50 lines
1.7 KiB
Rust
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
|
|
|
//! Access to font metrics from the style system.
|
|
|
|
#![deny(missing_docs)]
|
|
|
|
use crate::values::computed::Length;
|
|
|
|
/// Represents the font metrics that style needs from a font to compute the
|
|
/// value of certain CSS units like `ex`.
|
|
#[derive(Clone, Debug, PartialEq)]
|
|
pub struct FontMetrics {
|
|
/// The x-height of the font.
|
|
pub x_height: Option<Length>,
|
|
/// The zero advance. This is usually writing mode dependent
|
|
pub zero_advance_measure: Option<Length>,
|
|
/// The cap-height of the font.
|
|
pub cap_height: Option<Length>,
|
|
/// The ideographic-width of the font.
|
|
pub ic_width: Option<Length>,
|
|
/// The ascent of the font (a value is always available for this).
|
|
pub ascent: Length,
|
|
}
|
|
|
|
impl Default for FontMetrics {
|
|
fn default() -> Self {
|
|
FontMetrics {
|
|
x_height: None,
|
|
zero_advance_measure: None,
|
|
cap_height: None,
|
|
ic_width: None,
|
|
ascent: Length::new(0.0),
|
|
}
|
|
}
|
|
}
|
|
|
|
/// Type of font metrics to retrieve.
|
|
#[derive(Clone, Debug, PartialEq)]
|
|
pub enum FontMetricsOrientation {
|
|
/// Get metrics for horizontal or vertical according to the Context's
|
|
/// writing mode, using horizontal metrics for vertical/mixed
|
|
MatchContextPreferHorizontal,
|
|
/// Get metrics for horizontal or vertical according to the Context's
|
|
/// writing mode, using vertical metrics for vertical/mixed
|
|
MatchContextPreferVertical,
|
|
/// Force getting horizontal metrics.
|
|
Horizontal,
|
|
}
|