pub struct Length(/* private fields */);Expand description
A length in half-EMUs, which is 1/25,400 of a point.
The constructors that scale a value from a file return None when the result lies beyond
Length::FILE_LIMIT, so untrusted input cannot overflow. The operators behave as the i64
arithmetic that they stand for; a factor that the file gives without a bound takes
Length::checked_mul.
Implementations§
Source§impl Length
impl Length
Sourcepub const UNITS_PER_POINT: i64 = 25_400
pub const UNITS_PER_POINT: i64 = 25_400
Half-EMUs in one point.
Sourcepub const UNITS_PER_TWIP: i64 = 1_270
pub const UNITS_PER_TWIP: i64 = 1_270
Half-EMUs in one twip, which is 1/20 of a point.
Sourcepub const UNITS_PER_HALF_POINT: i64 = 12_700
pub const UNITS_PER_HALF_POINT: i64 = 12_700
Half-EMUs in one half-point, the unit of font sizes.
Sourcepub const UNITS_PER_EIGHTH_POINT: i64 = 3_175
pub const UNITS_PER_EIGHTH_POINT: i64 = 3_175
Half-EMUs in one eighth of a point, the unit of border widths.
Sourcepub const UNITS_PER_EMU: i64 = 2
pub const UNITS_PER_EMU: i64 = 2
Half-EMUs in one EMU, the DrawingML unit, which is 1/12,700 of a point.
Sourcepub const UNITS_PER_DOT: i64 = 6_096
pub const UNITS_PER_DOT: i64 = 6_096
Half-EMUs in one dot of Word’s device grid, which is 1/300 inch.
Sourcepub const UNITS_PER_INCH: i64
pub const UNITS_PER_INCH: i64
Half-EMUs in one inch.
Sourcepub const FILE_LIMIT: i64
pub const FILE_LIMIT: i64
The largest distance from zero of a length that a constructor reads from a file: 2^46
half-EMUs, about 2.8 billion points. It lies above the largest DrawingML coordinate
(ST_Coordinate, 27,273,042,316,900 EMUs) and far above any page, and a sum of 131,071
lengths within it fits in an i64, so the layout adds them with the plain operators.
Sourcepub const fn from_units(units: i64) -> Length
pub const fn from_units(units: i64) -> Length
Makes a length from a count of half-EMUs.
Sourcepub const fn from_points(points: i64) -> Option<Length>
pub const fn from_points(points: i64) -> Option<Length>
Makes a length from whole points.
Sourcepub const fn from_twips(twips: i64) -> Option<Length>
pub const fn from_twips(twips: i64) -> Option<Length>
Makes a length from twips.
Sourcepub const fn from_half_points(half_points: i64) -> Option<Length>
pub const fn from_half_points(half_points: i64) -> Option<Length>
Makes a length from half-points.
Sourcepub const fn from_eighth_points(eighth_points: i64) -> Option<Length>
pub const fn from_eighth_points(eighth_points: i64) -> Option<Length>
Makes a length from eighths of a point.
Sourcepub const fn checked_add(self, other: Length) -> Option<Length>
pub const fn checked_add(self, other: Length) -> Option<Length>
Adds two lengths, or returns None when the sum does not fit.
Sourcepub const fn checked_sub(self, other: Length) -> Option<Length>
pub const fn checked_sub(self, other: Length) -> Option<Length>
Subtracts a length, or returns None when the difference does not fit.
Sourcepub const fn saturating_sub(self, other: Length) -> Length
pub const fn saturating_sub(self, other: Length) -> Length
Subtracts a length, and stays at the smallest or largest length when the difference does not fit, as a limit at the largest length does.
Sourcepub const fn checked_mul(self, factor: i64) -> Option<Length>
pub const fn checked_mul(self, factor: i64) -> Option<Length>
Multiplies by a factor that the file gives without a bound, such as a count, or returns
None when the product does not fit.
Sourcepub const fn div_toward_zero(self, divisor: i64) -> Length
pub const fn div_toward_zero(self, divisor: i64) -> Length
This length divided by divisor, rounded toward zero as integer division rounds: the
named form of the division that the layout’s bare half-EMU code did with /. A divisor
of 0 panics, as that division does.
Sourcepub const fn up_to_whole(self, units_per_step: i64) -> Length
pub const fn up_to_whole(self, units_per_step: i64) -> Length
This length rounded up to a whole number of steps of units_per_step half-EMUs, such as
Self::UNITS_PER_TWIP for whole twips: a negative length rounds up toward zero. A step
of 0 panics, as integer division by 0 does.
Sourcepub const fn down_to_whole(self, units_per_step: i64) -> Length
pub const fn down_to_whole(self, units_per_step: i64) -> Length
This length rounded down to a whole number of steps of units_per_step half-EMUs, such
as Self::UNITS_PER_TWIP for whole twips: a negative length rounds down away from
zero. A step of 0 panics, as integer division by 0 does.
Sourcepub const fn toward_zero_whole(self, units_per_step: i64) -> Length
pub const fn toward_zero_whole(self, units_per_step: i64) -> Length
This length rounded toward zero to a whole number of steps of units_per_step
half-EMUs, such as Self::UNITS_PER_TWIP for whole twips: a positive length rounds
down and a negative one up. A step of 0 panics, as integer division by 0 does.
Sourcepub const fn nearest_whole(self, units_per_step: i64) -> Length
pub const fn nearest_whole(self, units_per_step: i64) -> Length
This length rounded to the nearest whole number of steps of units_per_step half-EMUs,
such as Self::UNITS_PER_TWIP for whole twips, a half step up toward the larger value,
as div_round rounds. A step of 0 gives 0, as div_round does.
Sourcepub fn checked_div_round(self, divisor: i64) -> Option<Length>
pub fn checked_div_round(self, divisor: i64) -> Option<Length>
This length divided by divisor to the nearest half-EMU, as checked_div_round
rounds, for a length that a factor from a file scaled: None when the terms of the
division do not fit in an i64, or when the divisor is 0.
Trait Implementations§
Source§impl AddAssign for Length
impl AddAssign for Length
Source§fn add_assign(&mut self, other: Length)
fn add_assign(&mut self, other: Length)
+= operation. Read moreimpl Copy for Length
impl Eq for Length
Source§impl Mul<i64> for Length
A length times a factor that the code knows, or that a reader bounded at the border.
impl Mul<i64> for Length
A length times a factor that the code knows, or that a reader bounded at the border.
Source§impl Ord for Length
impl Ord for Length
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
1.21.0 (const: unstable) · Source§fn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialOrd for Length
impl PartialOrd for Length
impl StructuralPartialEq for Length
Auto Trait Implementations§
impl Forget for Length
impl Freeze for Length
impl Move for Length
impl RefUnwindSafe for Length
impl Send for Length
impl Sync for Length
impl Unpin for Length
impl UnsafeUnpin for Length
impl UnwindSafe for Length
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.impl<T> ErasedDestructor for Twhere
T: 'static,
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<U, T> ToOwnedObj<U> for Twhere
U: FromObjRef<T>,
impl<U, T> ToOwnedObj<U> for Twhere
U: FromObjRef<T>,
Source§fn to_owned_obj(&self, data: FontData<'_>) -> U
fn to_owned_obj(&self, data: FontData<'_>) -> U
T, using the provided data to resolve any offsets.