Enum ggez::graphics::Font
[−]
[src]
pub enum Font { TTFFont { font: Font<'static>, points: u32, scale: Scale, }, BitmapFont { bytes: Vec<u8>, width: usize, height: usize, glyphs: BTreeMap<char, usize>, glyph_width: usize, }, }
A font that defines the shape of characters drawn on the screen. Can be created from a .ttf file or from an image (bitmap fonts).
Variants
TTFFont
Fields of TTFFont
font: Font<'static> | |
points: u32 | |
scale: Scale |
BitmapFont
Fields of BitmapFont
bytes: Vec<u8> | |
width: usize | |
height: usize | |
glyphs: BTreeMap<char, usize> | |
glyph_width: usize |
Methods
impl Font
[src]
fn new<P>(context: &mut Context, path: P, points: u32) -> GameResult<Font> where
P: AsRef<Path> + Debug,
P: AsRef<Path> + Debug,
Load a new TTF font from the given file.
fn from_bytes(
name: &str,
bytes: &[u8],
points: u32,
dpi: (f32, f32)
) -> GameResult<Font>
name: &str,
bytes: &[u8],
points: u32,
dpi: (f32, f32)
) -> GameResult<Font>
Loads a new TTF font from data copied out of the given buffer.
fn new_bitmap<P: AsRef<Path>>(
context: &mut Context,
path: P,
glyphs: &str
) -> GameResult<Font>
context: &mut Context,
path: P,
glyphs: &str
) -> GameResult<Font>
Loads an Image
and uses it to create a new bitmap font
The Image
is a 1D list of glyphs, which maybe isn't
super ideal but should be fine.
The glyphs
string is the characters in the image from left to right.
fn default_font() -> GameResult<Self>
Returns a baked-in default font: currently DejaVuSerif.ttf
Note it does create a new Font
object with every call.
fn get_height(&self) -> usize
Get the height of the Font in pixels.
The height of the font includes any spacing, it will be the total height a line needs.
fn get_width(&self, text: &str) -> usize
Returns the width a line of text needs, in pixels. Does not handle line-breaks.
fn get_wrap(&self, text: &str, wrap_limit: usize) -> (usize, Vec<String>)
Breaks the given text into lines that will not exceed wrap_limit
pixels
in length. It accounts for newlines correctly but does not
try to break words or handle hypenated words; it just breaks
at whitespace. (It also doesn't preserve whitespace.)
Returns a tuple of maximum line width and a Vec
of wrapped String
s.