Struct tetra::graphics::text::BmFontBuilder[][src]

pub struct BmFontBuilder { /* fields omitted */ }
Expand description

A builder for fonts stored in the AngelCode BMFont format.

Currently, only the text format is supported. Support for the binary file format may be added in the future.

Font::bmfont provides a simpler API for loading vector fonts, if you don’t need all of the functionality of this struct.

Exporting from BMFont

For best results, follow these guidelines when exporting from BMFont:

Font Settings

  • For the sizing to match the TTF version of the same font, tick ‘match char height’.

Export Options

  • Unless you are using a custom shader, choose the ‘white text with alpha’ preset.
  • Export using the ‘text’ font descriptor format.
  • Make sure the corresponding Tetra feature flag is enabled for your texture’s file format.

Performance

Creating or cloning a BmFontBuilder can be expensive, depending on how many images you load into it.

The data is not internally reference-counted (unlike some other Tetra structs like VectorFontBuilder), as you’ll generally only use a BmFontBuilder once. This allows the builder’s buffers to be re-used by the created Font.

Implementations

impl BmFontBuilder[src]

pub fn new<P>(path: P) -> Result<BmFontBuilder> where
    P: AsRef<Path>, 
[src]

Loads a BMFont from the given file.

By default, the image directory will be set to the same directory as the font itself.

Errors

pub fn from_file_data<D>(data: D) -> BmFontBuilder where
    D: Into<String>, 
[src]

Loads a BMFont from a string.

As a BMFont only contains relative paths, you will need to specify an image directory and/or page data in order for the font to successfully build.

pub fn with_image_dir<P>(self, path: P) -> BmFontBuilder where
    P: Into<PathBuf>, 
[src]

Sets the directory to search for the font’s image files.

This will automatically be set if the builder was created via new, but can be overridden.

If all of the font’s pages are manually loaded via the other builder methods, this path will be ignored.

pub fn with_page<P>(self, id: u32, path: P) -> Result<BmFontBuilder> where
    P: AsRef<Path>, 
[src]

Loads an image for the specified page of the font.

This will override the path specified in the font itself.

Errors

pub fn with_page_file_data(self, id: u32, data: &[u8]) -> Result<BmFontBuilder>[src]

Sets the image for the specified page of the font, using data encoded in one of Tetra’s supported image file formats.

The format of the data will be determined based on the ‘magic bytes’ at the beginning of the data. Note that TGA files do not have recognizable magic bytes, so this function will not recognize them.

This will override the path specified in the font itself.

Errors

pub fn with_page_image_data(self, id: u32, data: ImageData) -> BmFontBuilder[src]

Sets the image for the specified page of the font, using decoded image data.

This will override the path specified in the font itself.

pub fn with_page_rgba8<D>(
    self,
    id: u32,
    width: i32,
    height: i32,
    data: D
) -> Result<BmFontBuilder> where
    D: Into<Vec<u8>>, 
[src]

Sets the image for the specified page of the font, using RGBA8 data.

This will override the path specified in the font itself.

Errors

pub fn with_page_rgba<D>(
    self,
    id: u32,
    width: i32,
    height: i32,
    data: D
) -> Result<BmFontBuilder> where
    D: Into<Vec<u8>>, 
[src]

👎 Deprecated since 0.6.4:

renamed to with_page_rgba8 for consistency

pub fn build(self, ctx: &mut Context) -> Result<Font>[src]

Builds the font.

Any pages that have not had their images manually set will be loaded from the path specified by with_image_dir.

Errors

Trait Implementations

impl Clone for BmFontBuilder[src]

fn clone(&self) -> BmFontBuilder[src]

Returns a copy of the value. Read more

fn clone_from(&mut self, source: &Self)1.0.0[src]

Performs copy-assignment from source. Read more

impl Debug for BmFontBuilder[src]

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

Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

impl<T> From<T> for T[src]

pub fn from(t: T) -> T[src]

Performs the conversion.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

pub fn into(self) -> U[src]

Performs the conversion.

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

pub fn to_owned(&self) -> T[src]

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

pub fn clone_into(&self, target: &mut T)[src]

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

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

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

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

Performs the conversion.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

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

Performs the conversion.