From 97b2f18870af1379bb5e0e041e943aced7d6df18 Mon Sep 17 00:00:00 2001 From: Nathan Vegdahl Date: Wed, 21 Jan 2015 20:21:34 -0800 Subject: [PATCH] Source Code Pro is now embedded in the executable as the default font. --- src/{font.rs => font/mod.rs} | 18 ++++++++++++++++++ .../font}/source_code_pro/LICENSE.txt | 0 .../source_code_pro/SourceCodePro-Bold.ttf | Bin .../source_code_pro/SourceCodePro-Regular.ttf | Bin .../SourceCodePro-Semibold.ttf | Bin src/gui/mod.rs | 4 ++-- 6 files changed, 20 insertions(+), 2 deletions(-) rename src/{font.rs => font/mod.rs} (87%) rename {fonts => src/font}/source_code_pro/LICENSE.txt (100%) rename {fonts => src/font}/source_code_pro/SourceCodePro-Bold.ttf (100%) rename {fonts => src/font}/source_code_pro/SourceCodePro-Regular.ttf (100%) rename {fonts => src/font}/source_code_pro/SourceCodePro-Semibold.ttf (100%) diff --git a/src/font.rs b/src/font/mod.rs similarity index 87% rename from src/font.rs rename to src/font/mod.rs index 7fefee2..10fad96 100644 --- a/src/font.rs +++ b/src/font/mod.rs @@ -12,6 +12,8 @@ use sdl2::rect::Rect; use string_utils::{is_line_ending}; +const SOURCE_CODE_PRO: &'static [u8] = include_bytes!("source_code_pro/SourceCodePro-Regular.ttf"); + struct CachedGlyph { texture: Option, height: i32, @@ -28,7 +30,23 @@ pub struct Font { glyph_cache: HashMap, } + 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 { let lib = freetype::Library::init().unwrap(); let mut face = lib.new_face(path.as_str().unwrap(), 0).unwrap(); diff --git a/fonts/source_code_pro/LICENSE.txt b/src/font/source_code_pro/LICENSE.txt similarity index 100% rename from fonts/source_code_pro/LICENSE.txt rename to src/font/source_code_pro/LICENSE.txt diff --git a/fonts/source_code_pro/SourceCodePro-Bold.ttf b/src/font/source_code_pro/SourceCodePro-Bold.ttf similarity index 100% rename from fonts/source_code_pro/SourceCodePro-Bold.ttf rename to src/font/source_code_pro/SourceCodePro-Bold.ttf diff --git a/fonts/source_code_pro/SourceCodePro-Regular.ttf b/src/font/source_code_pro/SourceCodePro-Regular.ttf similarity index 100% rename from fonts/source_code_pro/SourceCodePro-Regular.ttf rename to src/font/source_code_pro/SourceCodePro-Regular.ttf diff --git a/fonts/source_code_pro/SourceCodePro-Semibold.ttf b/src/font/source_code_pro/SourceCodePro-Semibold.ttf similarity index 100% rename from fonts/source_code_pro/SourceCodePro-Semibold.ttf rename to src/font/source_code_pro/SourceCodePro-Semibold.ttf diff --git a/src/gui/mod.rs b/src/gui/mod.rs index 7b4a709..ab56a41 100644 --- a/src/gui/mod.rs +++ b/src/gui/mod.rs @@ -18,7 +18,7 @@ pub struct GUI { impl 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 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 { - 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 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();