Skip to main content

Axes

Struct Axes 

Source
pub struct Axes<'a> {
    records: &'a [VariationAxisRecord],
}
Expand description

A collection of variation axes.

This is empty if the font is not variable.

Fields§

§records: &'a [VariationAxisRecord]

Implementations§

Source§

impl<'a> Axes<'a>

Source

pub(crate) fn new(font: &'a Font) -> Self

Source

pub fn len(&self) -> u32

The number of axes.

Source

pub fn is_empty(&self) -> bool

Returns true if the font has no axes.

Source

pub fn get(&self, index: u32) -> Option<Axis>

Returns the axis at index.

Source

pub fn get_by_tag(&self, tag: Tag) -> Option<Axis>

Returns the first axis with the given tag.

Source

pub fn filter<V>( &self, variations: V, ) -> impl Iterator<Item = Variation> + Clone

Returns the values in variations that apply to these axes.

The rules are the same as those used when building a font instance:

  • A variation for an axis the font does not have is dropped.
  • If an axis is given more than once, the last value is used.
  • Each value is clamped to the range of its axis.

The result is in the font’s axis order and contains only the axes that were given.

// For a font with one `wght` axis from 100 to 900:
let filtered: Vec<_> = font
    .axes()
    .filter([("wght", 400.0), ("opsz", 100.0), ("wght", 1200.0)])
    .collect();
assert_eq!(filtered, [Variation::new(Tag::new(b"wght"), 900.0)]);
Source

pub fn iter(&self) -> impl Iterator<Item = Axis> + 'a + Clone

Returns an iterator over the axes in font order.

Trait Implementations§

Source§

impl<'a> Clone for Axes<'a>

Source§

fn clone(&self) -> Axes<'a>

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<'a> Copy for Axes<'a>

Auto Trait Implementations§

§

impl<'a> Freeze for Axes<'a>

§

impl<'a> RefUnwindSafe for Axes<'a>

§

impl<'a> Send for Axes<'a>

§

impl<'a> Sync for Axes<'a>

§

impl<'a> Unpin for Axes<'a>

§

impl<'a> UnsafeUnpin for Axes<'a>

§

impl<'a> UnwindSafe for Axes<'a>

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<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<T> ErasedDestructor for T
where T: 'static,

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> 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<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.