mirror of
https://github.com/typst/typst
synced 2025-05-15 17:45:27 +08:00
Expose units_per_em and raw face id
This commit is contained in:
parent
3e03667c37
commit
33733fd1ef
13
src/env/mod.rs
vendored
13
src/env/mod.rs
vendored
@ -190,6 +190,19 @@ pub struct FaceId(u32);
|
|||||||
impl FaceId {
|
impl FaceId {
|
||||||
/// A blank initialization value.
|
/// A blank initialization value.
|
||||||
pub const MAX: Self = Self(u32::MAX);
|
pub const MAX: Self = Self(u32::MAX);
|
||||||
|
|
||||||
|
/// Create a face id from the raw underlying value.
|
||||||
|
///
|
||||||
|
/// This should only be called with values returned by
|
||||||
|
/// [`into_raw`](Self::into_raw).
|
||||||
|
pub fn from_raw(v: u32) -> Self {
|
||||||
|
Self(v)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Convert into the raw underlying value.
|
||||||
|
pub fn into_raw(self) -> u32 {
|
||||||
|
self.0
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A unique identifier for a loaded resource.
|
/// A unique identifier for a loaded resource.
|
||||||
|
15
src/font.rs
15
src/font.rs
@ -69,6 +69,16 @@ impl Face {
|
|||||||
&self.ttf
|
&self.ttf
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get the number of units per em.
|
||||||
|
pub fn units_per_em(&self) -> f64 {
|
||||||
|
self.units_per_em
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Convert from font units to an em length.
|
||||||
|
pub fn to_em(&self, units: impl Into<f64>) -> Em {
|
||||||
|
Em::from_units(units, self.units_per_em)
|
||||||
|
}
|
||||||
|
|
||||||
/// Look up a vertical metric.
|
/// Look up a vertical metric.
|
||||||
pub fn vertical_metric(&self, metric: VerticalFontMetric) -> Em {
|
pub fn vertical_metric(&self, metric: VerticalFontMetric) -> Em {
|
||||||
match metric {
|
match metric {
|
||||||
@ -79,11 +89,6 @@ impl Face {
|
|||||||
VerticalFontMetric::Descender => self.descender,
|
VerticalFontMetric::Descender => self.descender,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Convert from font units to an em length.
|
|
||||||
pub fn to_em(&self, units: impl Into<f64>) -> Em {
|
|
||||||
Em::from_units(units, self.units_per_em)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Identifies a vertical metric of a font.
|
/// Identifies a vertical metric of a font.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user