pub struct Dim { /* private fields */ }Expand description
TeX-style dimension: width, height, depth, italic correction, mu.
One unit is one em at the current math style unless a method says otherwise.
§Examples
use latex_rust::Dim;
let half = Dim::ratio(1, 2);
assert!(half.eq_dim(&(&Dim::one() / &Dim::from_i64(2))));
assert!(!Dim::zero().eq_dim(&Dim::one()));Implementations§
Source§impl Dim
impl Dim
Sourcepub fn from_font_units(units: i64, units_per_em: u16) -> Self
pub fn from_font_units(units: i64, units_per_em: u16) -> Self
Convert integer font units to em: units / units_per_em.
Sourcepub fn clamp_nonneg(&self) -> Self
pub fn clamp_nonneg(&self) -> Self
max(self, 0).
Sourcepub fn as_ratio(&self) -> Option<(i128, i128)>
pub fn as_ratio(&self) -> Option<(i128, i128)>
The exact rational value in em, as (numerator, denominator), or
None if this dimension is NaN.
The denominator is positive and the fraction is in lowest terms. This is
the only accessor that does not round: Self::to_dec_string formats a
decimal expansion and Self::to_ieee32_bits rounds to binary32. An
external renderer that wants to convert at its own pixel boundary,
rather than take the crate’s rounding, should start here.
§Examples
use latex_rust::Dim;
assert_eq!(Dim::ratio(2, 6).as_ratio(), Some((1, 3)));
assert_eq!(Dim::ratio(1, -2).as_ratio(), Some((-1, 2)));
assert_eq!(Dim::zero().as_ratio(), Some((0, 1)));
assert_eq!(Dim::ratio(1, 0).as_ratio(), None);Sourcepub fn to_dec_string(&self) -> String
pub fn to_dec_string(&self) -> String
Decimal string (exact terminating expansion, or scientific).
Sourcepub fn to_svg_string(&self) -> String
pub fn to_svg_string(&self) -> String
Compact decimal for SVG attributes.
Sourcepub fn from_ieee32_bits(bits: u32) -> Self
pub fn from_ieee32_bits(bits: u32) -> Self
Layout dimension from an IEEE-754 binary32 bit pattern (outline boundary).
Sourcepub fn to_ieee32_bits(&self) -> u32
pub fn to_ieee32_bits(&self) -> u32
Round to IEEE-754 binary32 bits for PNG / raster emission only.
Sourcepub fn floor_to_u32(&self) -> Result<u32, Error>
pub fn floor_to_u32(&self) -> Result<u32, Error>
Largest u32 that is not greater than self. Negative and NaN fail.
Sourcepub fn ceil_to_u32(&self) -> Result<u32, Error>
pub fn ceil_to_u32(&self) -> Result<u32, Error>
Smallest u32 that is not less than self.