Struct tetra::graphics::text::Font [−][src]
pub struct Font { /* fields omitted */ }
Expand description
A font with an associated size, cached on the GPU.
Performance
Creating a Font
is a relatively expensive operation. If you can, store them in your State
struct rather than recreating them each frame.
Cloning a Font
is a very cheap operation, as the underlying data is shared between the
original instance and the clone via reference-counting.
This does mean, however, that updating a Font
(for example, changing its filter mode) will also
update any other clones of that Font
.
Examples
The text
example demonstrates how to load a font and then draw some text.
Implementations
impl Font
[src]
impl Font
[src]pub fn vector<P>(ctx: &mut Context, path: P, size: f32) -> Result<Font> where
P: AsRef<Path>,
[src]
pub fn vector<P>(ctx: &mut Context, path: P, size: f32) -> Result<Font> where
P: AsRef<Path>,
[src]Creates a Font
from a vector font file, with the given size.
TrueType and OpenType fonts are supported.
If you want to load multiple sizes of the same font, you can use a
VectorFontBuilder
to avoid loading/parsing the file multiple times.
Errors
TetraError::FailedToLoadAsset
will be returned if the file could not be loaded.TetraError::InvalidFont
will be returned if the font data was invalid.TetraError::PlatformError
will be returned if the GPU cache for the font could not be created.
pub fn from_vector_file_data(
ctx: &mut Context,
data: &'static [u8],
size: f32
) -> Result<Font>
[src]
pub fn from_vector_file_data(
ctx: &mut Context,
data: &'static [u8],
size: f32
) -> Result<Font>
[src]Creates a Font
from a slice of binary data.
TrueType and OpenType fonts are supported.
This is useful in combination with include_bytes
, as it
allows you to include your font data directly in the binary.
If you want to load multiple sizes of the same font, you can use a
VectorFontBuilder
to avoid parsing the data multiple times.
Errors
TetraError::InvalidFont
will be returned if the font data was invalid.TetraError::PlatformError
will be returned if the GPU cache for the font could not be created.
pub fn bmfont<P>(ctx: &mut Context, path: P) -> Result<Font> where
P: AsRef<Path>,
[src]
pub fn bmfont<P>(ctx: &mut Context, path: P) -> Result<Font> where
P: AsRef<Path>,
[src]Creates a Font
from an AngelCode BMFont file.
By default, Tetra will search for the font’s images relative to the font itself.
If you need more control over the search path, or want to override the paths
entirely, this can be done via BmFontBuilder
.
Currently, only the text format is supported. Support for the binary file format may be added in the future.
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.
Errors
TetraError::FailedToLoadAsset
will be returned if the font or the associated images could not be loaded.TetraError::InvalidFont
will be returned if the font data was invalid.TetraError::PlatformError
will be returned if the GPU cache for the font could not be created.
pub fn filter_mode(&self) -> FilterMode
[src]
pub fn filter_mode(&self) -> FilterMode
[src]Returns the filter mode of the font.
pub fn set_filter_mode(&mut self, ctx: &mut Context, filter_mode: FilterMode)
[src]
pub fn set_filter_mode(&mut self, ctx: &mut Context, filter_mode: FilterMode)
[src]Sets the filter mode of the font.
Note that changing the filter mode of a font will affect all Text
objects
that use that font, including existing ones. This is due to the fact that
each font has a shared texture atlas.
Trait Implementations
Auto Trait Implementations
impl !RefUnwindSafe for Font
impl !Send for Font
impl !Sync for Font
impl Unpin for Font
impl !UnwindSafe for Font
Blanket Implementations
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]pub fn borrow_mut(&mut self) -> &mut T
[src]
pub fn borrow_mut(&mut self) -> &mut T
[src]Mutably borrows from an owned value. Read more
impl<T> ToOwned for T where
T: Clone,
[src]
impl<T> ToOwned for T where
T: Clone,
[src]type Owned = T
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
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]
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