Browse Source

textium: minor random cleanup

master
Erin 8 years ago
parent
commit
c8da3176c6
2 changed files with 10 additions and 10 deletions
  1. +2
    -4
      textium/src/lib.rs
  2. +8
    -6
      textium/src/rasterizer.rs

+ 2
- 4
textium/src/lib.rs View File

@ -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<char, GlyphMetadata>
pub glyph_metadata: HashMap<char, GlyphMetadata>
}
/// 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,


+ 8
- 6
textium/src/rasterizer.rs View File

@ -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<FontTexture>,
}
#[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<u8>, f32)
where I: Iterator<Item=char>
{
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);


Loading…
Cancel
Save