Skip to main content

Length

Struct Length 

Source
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

Source

pub const ZERO: Length

A length of zero.

Source

pub const UNITS_PER_POINT: i64 = 25_400

Half-EMUs in one point.

Source

pub const UNITS_PER_TWIP: i64 = 1_270

Half-EMUs in one twip, which is 1/20 of a point.

Source

pub const UNITS_PER_HALF_POINT: i64 = 12_700

Half-EMUs in one half-point, the unit of font sizes.

Source

pub const UNITS_PER_EIGHTH_POINT: i64 = 3_175

Half-EMUs in one eighth of a point, the unit of border widths.

Source

pub const UNITS_PER_EMU: i64 = 2

Half-EMUs in one EMU, the DrawingML unit, which is 1/12,700 of a point.

Source

pub const UNITS_PER_DOT: i64 = 6_096

Half-EMUs in one dot of Word’s device grid, which is 1/300 inch.

Source

pub const UNITS_PER_INCH: i64

Half-EMUs in one inch.

Source

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.

Source

pub const fn from_units(units: i64) -> Length

Makes a length from a count of half-EMUs.

Source

pub const fn units(self) -> i64

Returns the length as a count of half-EMUs.

Source

pub fn points_f64(self) -> f64

This length in typographic points (1/72 inch) as f64, for output edges such as PDF and browser geometry.

Source

pub const fn from_points(points: i64) -> Option<Length>

Makes a length from whole points.

Source

pub const fn from_twips(twips: i64) -> Option<Length>

Makes a length from twips.

Source

pub const fn from_half_points(half_points: i64) -> Option<Length>

Makes a length from half-points.

Source

pub const fn from_eighth_points(eighth_points: i64) -> Option<Length>

Makes a length from eighths of a point.

Source

pub const fn from_emus(emus: i64) -> Option<Length>

Makes a length from EMUs.

Source

pub const fn checked_add(self, other: Length) -> Option<Length>

Adds two lengths, or returns None when the sum does not fit.

Source

pub const fn checked_sub(self, other: Length) -> Option<Length>

Subtracts a length, or returns None when the difference does not fit.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub const fn div_round(self, divisor: i64) -> Length

This length divided by divisor to the nearest half-EMU, as div_round rounds: the named form of the rounded division that the layout’s bare half-EMU code did with div_round. A divisor of 0 gives 0, as div_round does.

Source

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 Add for Length

Source§

type Output = Length

The resulting type after applying the + operator.
Source§

fn add(self, other: Length) -> Length

Performs the + operation. Read more
Source§

impl AddAssign for Length

Source§

fn add_assign(&mut self, other: Length)

Performs the += operation. Read more
Source§

impl Clone for Length

Source§

fn clone(&self) -> Length

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Length

Source§

impl Debug for Length

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Default for Length

Source§

fn default() -> Length

Returns the “default value” for a type. Read more
Source§

impl Eq for Length

Source§

impl Hash for Length

Source§

fn hash<__H>(&self, state: &mut __H)
where __H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Mul<i64> for Length

A length times a factor that the code knows, or that a reader bounded at the border.

Source§

type Output = Length

The resulting type after applying the * operator.
Source§

fn mul(self, factor: i64) -> Length

Performs the * operation. Read more
Source§

impl Neg for Length

Source§

type Output = Length

The resulting type after applying the - operator.
Source§

fn neg(self) -> Length

Performs the unary - operation. Read more
Source§

impl Ord for Length

Source§

fn cmp(&self, other: &Length) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

fn clamp_to<R>(self, range: R) -> Self
where Self: Sized, R: ClampBounds<Self>,

🔬This is a nightly-only experimental API. (clamp_to)
Restrict a value to a certain range. Read more
Source§

impl PartialEq for Length

Source§

fn eq(&self, other: &Length) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl PartialOrd for Length

Source§

fn partial_cmp(&self, other: &Length) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl StructuralPartialEq for Length

Source§

impl Sub for Length

Source§

type Output = Length

The resulting type after applying the - operator.
Source§

fn sub(self, other: Length) -> Length

Performs the - operation. Read more
Source§

impl SubAssign for Length

Source§

fn sub_assign(&mut self, other: Length)

Performs the -= operation. Read more
Source§

impl Sum for Length

Source§

fn sum<I>(lengths: I) -> Length
where I: Iterator<Item = Length>,

Takes an iterator and generates Self from the elements by “summing up” the items.

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Comparable<K> for Q
where Q: Ord + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn compare(&self, key: &K) -> Ordering

Compare self to key and return their ordering.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> Finish for T

Source§

fn finish(self)

Does nothing but move self, equivalent to drop.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<U, T> ToOwnedObj<U> for T
where U: FromObjRef<T>,

Source§

fn to_owned_obj(&self, data: FontData<'_>) -> U

Convert this type into T, using the provided data to resolve any offsets.
Source§

impl<U, T> ToOwnedTable<U> for T
where U: FromTableRef<T>,

Source§

fn to_owned_table(&self) -> U

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.