From c8da3176c678588238a3740b4974945803329469 Mon Sep 17 00:00:00 2001 From: Erin Date: Wed, 16 Aug 2017 16:30:01 -0500 Subject: [PATCH] textium: minor random cleanup --- textium/src/lib.rs | 6 ++---- textium/src/rasterizer.rs | 14 ++++++++------ 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/textium/src/lib.rs b/textium/src/lib.rs index ecb0461..090887b 100644 --- a/textium/src/lib.rs +++ b/textium/src/lib.rs @@ -15,9 +15,7 @@ pub mod geometry; pub mod rasterizer; pub mod packer; -use std::iter::Iterator; use std::collections::HashMap; -use glium::backend::Facade; use glium::texture::Texture2d; pub use error::Error; @@ -44,7 +42,7 @@ pub struct GlyphMetadata { /// Maps glyphs to their size, location, and rendering properties in a glyph atlas. pub struct FontAtlas { - pub glyph_data: HashMap + pub glyph_metadata: HashMap } /// A GPU-backed font texture, plus a [`FontAtlas`]. @@ -52,7 +50,7 @@ pub struct FontAtlas { /// [`FontAtlas`]: struct.FontAtlas.html pub struct FontTexture { /// The GPU texture of packed glyphs. - pub texture: Texture2d, + pub data: Texture2d, /// Atlas describing where glyphs are. pub atlas: FontAtlas, diff --git a/textium/src/rasterizer.rs b/textium/src/rasterizer.rs index 7e9d461..74ec295 100644 --- a/textium/src/rasterizer.rs +++ b/textium/src/rasterizer.rs @@ -4,14 +4,15 @@ use rusttype; use std::collections::HashMap; -use ::{FontAtlas, GlyphMetadata}; +use ::{FontTexture, FontAtlas, GlyphMetadata}; use ::geometry::Rect; use ::texture::{Buffer2d, Bitmap}; use ::packer::{Packer, GrowingPacker, SkylinePacker}; /// Wraps a rusttype font and provides atlas packing and rasterization functions. pub struct Font<'a> { - font: rusttype::Font<'a> + font: rusttype::Font<'a>, + texture: Option, } #[allow(dead_code)] @@ -19,7 +20,8 @@ impl<'a> Font<'a> { /// Construct a Textium font from a RustType one. pub fn new(rt_font: rusttype::Font<'a>) -> Font { Font { - font: rt_font + font: rt_font, + texture: None, } } @@ -34,14 +36,14 @@ impl<'a> Font<'a> { -> (FontAtlas, Bitmap, f32) where I: Iterator { - let mut atlas = FontAtlas {glyph_data: HashMap::new()}; + let mut atlas = FontAtlas {glyph_metadata: HashMap::new()}; let mut packer = SkylinePacker::new(Bitmap::new(width, height)); packer.set_margin(margin); for chr in chrs { if let Some((mut info, rendered)) = self.rasterize_char(chr, scale) { let r = packer.pack_resize(&rendered, |(w, h)| (w*2, h*2)); info.bounding_box = r; - atlas.glyph_data.insert(chr, info); + atlas.glyph_metadata.insert(chr, info); } else if chr == ' ' { // generate a blank pixel for the space texture // TODO: this is bad and should be fixed @@ -49,7 +51,7 @@ impl<'a> Font<'a> { let empty_bitmap = Bitmap::new(1, 1); let r = packer.pack_resize(&empty_bitmap, |(w, h)| (w*2, h*2)); info.bounding_box = r; - atlas.glyph_data.insert(chr, info); + atlas.glyph_metadata.insert(chr, info); } else { // TODO: use a Result instead of panic!ing panic!("Cannot render character {}", chr);