Skip to main content

ResourceFontLoader

Struct ResourceFontLoader 

Source
pub struct ResourceFontLoader<R> { /* private fields */ }
Expand description

Loads font files through a ResourceProvider, one key per file in load order.

Implementations§

Source§

impl<R> ResourceFontLoader<R>

Source

pub fn new(resources: R) -> Self

Creates a loader backed by the given resource provider.

Examples found in repository?
examples/bake_format.rs (line 24)
11fn main() -> ExitCode {
12    let mut args = std::env::args_os().skip(1);
13    let (Some(output), None) = (args.next().map(PathBuf::from), args.next()) else {
14        eprintln!("usage: bake_format <output.pkg>");
15        return ExitCode::FAILURE;
16    };
17    let texmf = match TexmfResources::discover() {
18        Ok(texmf) => texmf,
19        Err(error) => {
20            eprintln!("bake_format: {error}");
21            return ExitCode::FAILURE;
22        }
23    };
24    let fonts = ResourceFontLoader::new(&texmf);
25    let format = match FormatBuilder::new(PREAMBLE)
26        .kernel("latex.ltx")
27        .build(&texmf, &fonts)
28    {
29        Ok(format) => format,
30        Err(error) => {
31            eprintln!("bake_format: {error}");
32            return ExitCode::FAILURE;
33        }
34    };
35    if let Err(error) = std::fs::write(&output, &format) {
36        eprintln!("bake_format: cannot write {}: {error}", output.display());
37        return ExitCode::FAILURE;
38    }
39    eprintln!(
40        "bake_format: wrote {} bytes to {}",
41        format.len(),
42        output.display()
43    );
44    ExitCode::SUCCESS
45}
Source

pub fn resources(&self) -> &R

Returns a reference to the underlying resource provider.

Source

pub fn cached_font_count(&self) -> usize

Number of font files loaded so far.

Source

pub fn font(&self, key: FontKey) -> Option<FontData>

Returns the loaded font with the given key, so hosts can draw what the engine laid out.

Trait Implementations§

Source§

impl<R: Debug> Debug for ResourceFontLoader<R>

Source§

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

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

impl<R> FontLoader for ResourceFontLoader<R>

Source§

fn load(&self, spec: &FontSpec) -> Result<FontData, FontError>

Returns the face a spec names, with a key the host chooses to identify it in the IR.

Auto Trait Implementations§

§

impl<R> !Freeze for ResourceFontLoader<R>

§

impl<R> !RefUnwindSafe for ResourceFontLoader<R>

§

impl<R> !Sync for ResourceFontLoader<R>

§

impl<R> !UnwindSafe for ResourceFontLoader<R>

§

impl<R> Send for ResourceFontLoader<R>
where R: Send,

§

impl<R> Unpin for ResourceFontLoader<R>
where R: Unpin,

§

impl<R> UnsafeUnpin for ResourceFontLoader<R>
where R: UnsafeUnpin,

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