pub struct Font { /* private fields */ }Expand description
A single font loaded from a file.
Implementations§
Source§impl Font
impl Font
Sourcepub fn render_char(&self, chr: char, scale: f32) -> Option<(CharInfo, Bitmap)>
pub fn render_char(&self, chr: char, scale: f32) -> Option<(CharInfo, Bitmap)>
Renders a character from this font at a given scale into a pair of (CharInfo, Bitmap).
If the character isn’t handled by the font, None is returned.
Examples found in repository?
examples/basic_char.rs (line 7)
4fn main() {
5 let bytes = include_bytes!("Gudea-Regular.ttf");
6 let font = load_font_from_bytes(bytes.to_vec());
7 let (_, bitmap) = font.render_char('A', 40.0).unwrap();
8 for line in bitmap.lines() {
9 for &pixel in line {
10 if pixel == 0 {
11 print!(" ");
12 } else {
13 print!("#");
14 }
15 }
16 println!("");
17 }
18}Sourcepub fn make_atlas<I: Iterator<Item = char>>(
&self,
i: I,
scale: f32,
margin: u32,
width: usize,
height: usize,
) -> (Atlas, Bitmap, f32)
pub fn make_atlas<I: Iterator<Item = char>>( &self, i: I, scale: f32, margin: u32, width: usize, height: usize, ) -> (Atlas, Bitmap, f32)
Creates an atlas for a set of characters rendered at a given scale.
margin is the distance between characters in pixels.
width and height denote the starting size of the bitmap.
The resulting bitmap may be larger than width x height in order to fit all of the characters.
Examples found in repository?
examples/basic_atlas.rs (line 8)
4fn main() {
5 let bytes = include_bytes!("Gudea-Regular.ttf");
6 let font = load_font_from_bytes(bytes.to_vec());
7 let chars = font_atlas::ASCII.iter().cloned().chain(font_atlas::ASCII.iter().cloned());
8 let (_, bitmap, _) = font.make_atlas(chars, 20.0, 1, 128, 128);
9 for line in bitmap.lines() {
10 print!("{:03} ", line.len());
11 for &pixel in line {
12 if pixel == 0 {
13 print!(" ");
14 } else {
15 print!("#");
16 }
17 }
18 println!("");
19 }
20}Trait Implementations§
Auto Trait Implementations§
impl Freeze for Font
impl RefUnwindSafe for Font
impl Send for Font
impl Sync for Font
impl Unpin for Font
impl UnwindSafe for Font
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more