diff options
| author | Malo <57839069+MDLC01@users.noreply.github.com> | 2025-07-02 09:00:45 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-07-02 08:00:45 +0000 |
| commit | 09c831d3b32935fe162f198e3512e1e7cd6647db (patch) | |
| tree | a80a3e60381c2ac162034c45661d4070443563a7 /crates/typst-library/src/layout | |
| parent | 30ddc4a7ca38ea41d9184cec6eee732307c80b33 (diff) | |
Use "subs" and "sups" font features for typographic scripts (#5777)
Diffstat (limited to 'crates/typst-library/src/layout')
| -rw-r--r-- | crates/typst-library/src/layout/em.rs | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/crates/typst-library/src/layout/em.rs b/crates/typst-library/src/layout/em.rs index e2d8b120..746e1769 100644 --- a/crates/typst-library/src/layout/em.rs +++ b/crates/typst-library/src/layout/em.rs @@ -6,7 +6,7 @@ use ecow::EcoString; use typst_utils::{Numeric, Scalar}; use crate::foundations::{cast, repr, Repr, Resolve, StyleChain, Value}; -use crate::layout::Abs; +use crate::layout::{Abs, Length}; use crate::text::TextElem; /// A length that is relative to the font size. @@ -26,18 +26,18 @@ impl Em { Self(Scalar::ONE) } - /// Create a font-relative length. + /// Creates a font-relative length. pub const fn new(em: f64) -> Self { Self(Scalar::new(em)) } - /// Create an em length from font units at the given units per em. + /// Creates an em length from font units at the given units per em. pub fn from_units(units: impl Into<f64>, units_per_em: f64) -> Self { Self(Scalar::new(units.into() / units_per_em)) } - /// Create an em length from a length at the given font size. - pub fn from_length(length: Abs, font_size: Abs) -> Self { + /// Creates an em length from an absolute length at the given font size. + pub fn from_abs(length: Abs, font_size: Abs) -> Self { let result = length / font_size; if result.is_finite() { Self(Scalar::new(result)) @@ -46,6 +46,11 @@ impl Em { } } + /// Creates an em length from a length at the given font size. + pub fn from_length(length: Length, font_size: Abs) -> Em { + length.em + Self::from_abs(length.abs, font_size) + } + /// The number of em units. pub const fn get(self) -> f64 { (self.0).get() @@ -56,7 +61,7 @@ impl Em { Self::new(self.get().abs()) } - /// Convert to an absolute length at the given font size. + /// Converts to an absolute length at the given font size. pub fn at(self, font_size: Abs) -> Abs { let resolved = font_size * self.get(); if resolved.is_finite() { |
