pub struct Font {
pub name: String,
pub line_height: u32,
pub size: u32,
/* private fields */
}Expand description
The Font is used to load fonts that can be used in the TextBuffer
The Font can be loaded from an .sfl or .fnt file and then used in the TextBuffer, in example:
use glerminal::{TerminalBuilder, Font, FontFormat};
let mut terminal = TerminalBuilder::new()
.with_title("Hello glerminal::font::Font!")
.with_dimensions((1280, 720))
.with_font(Font::load(&FontFormat::SFL, "fonts/source_code_pro.sfl"))
.with_headless(true)
.build();Alternatively you can use load_raw to load the font straight with include_str! and include_bytes!, example:
use glerminal::{TerminalBuilder, Font, FontFormat};
static SCP_SFL: &'static str = include_str!("../fonts/source_code_pro.sfl");
static SCP_PNG: &'static [u8] = include_bytes!("../fonts/source_code_pro.png");
let mut terminal = TerminalBuilder::new()
.with_title("Hello glerminal::font::Font!")
.with_dimensions((1280, 720))
.with_font(Font::load_raw(&FontFormat::SFL, SCP_SFL, SCP_PNG))
.with_headless(true)
.build();Fields§
§name: StringThe name of the font
line_height: u32Line height of the font
size: u32Size of the font (width)
Implementations§
Source§impl Font
impl Font
Sourcepub fn load<T: Into<PathBuf>>(format: &FontFormat, fnt_path: T) -> Font
pub fn load<T: Into<PathBuf>>(format: &FontFormat, fnt_path: T) -> Font
Loads the font fron the given font file, for example:
use glerminal::{Font, FontFormat};
let font = Font::load(&FontFormat::SFL, "fonts/source_code_pro.sfl");Sourcepub fn load_raw<T: Into<String>, R: Read>(
format: &FontFormat,
content: T,
image_read: R,
) -> Font
pub fn load_raw<T: Into<String>, R: Read>( format: &FontFormat, content: T, image_read: R, ) -> Font
Loads the font from the given string (font file contents) and Read (image read)
use glerminal::{Font, FontFormat};
use std::fs::File;
let font = Font::load_raw(&FontFormat::SFL, include_str!("../fonts/source_code_pro.sfl"), File::open("fonts/source_code_pro.png").unwrap());Sourcepub fn get_character(&self, character: u16) -> Result<CharacterData, String>
pub fn get_character(&self, character: u16) -> Result<CharacterData, String>
Gets the CharacterData from the Font with the given char, if the charcter exists, otherwise returns an error as a String. Example:
use glerminal::{Font, FontFormat};
let a_char_data = Font::load(&FontFormat::SFL, "fonts/source_code_pro.sfl").get_character('a' as u16);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
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Convert
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Convert
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.