pub struct Font { /* private fields */ }Expand description
Holds a font for rendering. See also:
Font::draw.
Implementations§
Source§impl Font
impl Font
Sourcepub fn with_ttf(ctx: &mut Context, ttf_data: Vec<u8>) -> Result<Font, Error>
pub fn with_ttf(ctx: &mut Context, ttf_data: Vec<u8>) -> Result<Font, Error>
Creates a new font renderer using the given .ttf file as a font.
The font is rasterized with
rusttype.
Sourcepub fn with_font8x8(ctx: &mut Context, smoothed: bool) -> Font
pub fn with_font8x8(ctx: &mut Context, smoothed: bool) -> Font
Creates a new font renderer using the
font8x8 font.
If smoothed is true, glyphs which are bigger than 8
physical pixels will be linearly interpolated when stretching
(smooth but blurry). If false, nearest-neighbor
interpolation is used (crisp but pixelated).
Sourcepub fn draw<'a, S: Into<String>>(
&self,
ctx: &'a mut GraphicsContext<'_>,
text: S,
x: f32,
y: f32,
font_size: f32,
) -> Text<'a>
pub fn draw<'a, S: Into<String>>( &self, ctx: &'a mut GraphicsContext<'_>, text: S, x: f32, y: f32, font_size: f32, ) -> Text<'a>
Creates a Text struct, which you can render after specifying your parameters by modifying it.
§Usage
// Initialize the font once somewhere, usually before the game loop:
let font = fae::Font::with_font8x8(&mut ctx, true);
// Then in rendering code, call draw:
let mut ctx = ctx.start_frame(width, height, dpi_factor);
font.draw(&mut ctx, "Hello, World!", 10.0, 10.0, 12.0)
.color((0.8, 0.5, 0.1, 1.0))
.finish();Sourcepub fn is_glyph_cache_full(&self, ctx: &GraphicsContext<'_>) -> bool
pub fn is_glyph_cache_full(&self, ctx: &GraphicsContext<'_>) -> bool
Returns true if this font failed to draw a glyph last
frame because the glyph cache was full. Generally, this
should become false on the next frame because the glyph
cache is resized at the start of the frame, as
needed. Resizing is limited by GL_MAX_TEXTURE_SIZE
however, so low-end systems might reach a limit if you’re
drawing lots of very large text using many symbols.
§What to do if the glyph cache is full
Consider using alternative means of rendering large text, or increase your application’s GPU capability requirements.
Sourcepub fn spritesheet(&self) -> &Spritesheet
pub fn spritesheet(&self) -> &Spritesheet
Returns the underlying draw call of this font. Can be used to render the glyph cache texture, which is useful for debugging rasterization, glyph rendering, or other glyph-cache-related problems.