pub struct FontCollection<'a>(/* private fields */);
Expand description

A collection of fonts read straight from a font file’s data. The data in the collection is not validated. This structure may or may not own the font data.

Lifetime

The lifetime reflects the font data lifetime. FontCollection<'static> covers most cases ie both dynamically loaded owned data and for referenced compile time font data.

Implementations§

source§

impl<'a> FontCollection<'a>

source

pub fn from_bytes<B: Into<SharedBytes<'a>>>( bytes: B ) -> Result<FontCollection<'a>, Error>

Constructs a font collection from an array of bytes, typically loaded from a font file, which may be a single font or a TrueType Collection holding a number of fonts. This array may be owned (e.g. Vec<u8>), or borrowed (&[u8]). As long as From<T> is implemented for Bytes for some type T, T can be used as input.

This returns an error if bytes does not seem to be font data in a format we recognize.

source

pub fn into_font(self) -> Result<Font<'a>, Error>

If this FontCollection holds a single font, or a TrueType Collection containing only one font, return that as a Font. The FontCollection is consumed.

If this FontCollection holds multiple fonts, return a CollectionContainsMultipleFonts error.

If an error occurs, the FontCollection is lost, since this function takes ownership of it, and the error values don’t give it back. If that is a problem, use the font_at or into_fonts methods instead, which borrow the FontCollection rather than taking ownership of it.

source

pub fn font_at(&self, i: usize) -> Result<Font<'a>, Error>

Gets the font at index i in the font collection, if it exists and is valid. The produced font borrows the font data that is either borrowed or owned by this font collection.

source

pub fn into_fonts(self) -> IntoFontsIter<'a>

Converts self into an Iterator yielding each Font that exists within the collection.

Trait Implementations§

source§

impl<'a> Clone for FontCollection<'a>

source§

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

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more
source§

impl<'a> Debug for FontCollection<'a>

source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> RefUnwindSafe for FontCollection<'a>

§

impl<'a> Send for FontCollection<'a>

§

impl<'a> Sync for FontCollection<'a>

§

impl<'a> Unpin for FontCollection<'a>

§

impl<'a> UnwindSafe for FontCollection<'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> 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,

§

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>,

§

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>,

§

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.