Source Code Pro is now embedded in the executable as the default font.

This commit is contained in:
Nathan Vegdahl 2015-01-21 20:21:34 -08:00
parent b4e0a2e234
commit 97b2f18870
6 changed files with 20 additions and 2 deletions

View File

@ -12,6 +12,8 @@ use sdl2::rect::Rect;
use string_utils::{is_line_ending}; use string_utils::{is_line_ending};
const SOURCE_CODE_PRO: &'static [u8] = include_bytes!("source_code_pro/SourceCodePro-Regular.ttf");
struct CachedGlyph { struct CachedGlyph {
texture: Option<Texture>, texture: Option<Texture>,
height: i32, height: i32,
@ -28,7 +30,23 @@ pub struct Font {
glyph_cache: HashMap<char, CachedGlyph>, glyph_cache: HashMap<char, CachedGlyph>,
} }
impl Font { impl Font {
/// Creates a new font from the default font (Source Code Pro)
pub fn new_default(size: u32) -> Font {
let lib = freetype::Library::init().unwrap();
let mut face = lib.new_memory_face(SOURCE_CODE_PRO, 0).unwrap();
let _ = face.set_pixel_sizes(0, size);
Font {
ftl: lib,
face: face,
glyph_cache: HashMap::new(),
}
}
/// Creates a new font from the given font file
pub fn new_from_file(path: &Path, size: u32) -> Font { pub fn new_from_file(path: &Path, size: u32) -> Font {
let lib = freetype::Library::init().unwrap(); let lib = freetype::Library::init().unwrap();
let mut face = lib.new_face(path.as_str().unwrap(), 0).unwrap(); let mut face = lib.new_face(path.as_str().unwrap(), 0).unwrap();

View File

@ -18,7 +18,7 @@ pub struct GUI {
impl GUI { impl GUI {
pub fn new() -> GUI { pub fn new() -> GUI {
let font = Font::new_from_file(&Path::new("./fonts/source_code_pro/SourceCodePro-Regular.ttf"), 14); let font = Font::new_default(14);
// Get the window and renderer for sdl // Get the window and renderer for sdl
let window = sdl2::video::Window::new("Led Editor", sdl2::video::WindowPos::PosCentered, sdl2::video::WindowPos::PosCentered, 800, 600, sdl2::video::OPENGL | sdl2::video::RESIZABLE).unwrap(); let window = sdl2::video::Window::new("Led Editor", sdl2::video::WindowPos::PosCentered, sdl2::video::WindowPos::PosCentered, 800, 600, sdl2::video::OPENGL | sdl2::video::RESIZABLE).unwrap();
@ -38,7 +38,7 @@ impl GUI {
pub fn new_from_editor(ed: Editor) -> GUI { pub fn new_from_editor(ed: Editor) -> GUI {
let font = Font::new_from_file(&Path::new("./fonts/source_code_pro/SourceCodePro-Regular.ttf"), 14); let font = Font::new_default(14);
// Get the window and renderer for sdl // Get the window and renderer for sdl
let window = sdl2::video::Window::new("Led Editor", sdl2::video::WindowPos::PosCentered, sdl2::video::WindowPos::PosCentered, 800, 600, sdl2::video::OPENGL | sdl2::video::RESIZABLE).unwrap(); let window = sdl2::video::Window::new("Led Editor", sdl2::video::WindowPos::PosCentered, sdl2::video::WindowPos::PosCentered, 800, 600, sdl2::video::OPENGL | sdl2::video::RESIZABLE).unwrap();