Browse Source

textium: fix a few issues in rasterization

* don't underflow bbox {x,y}
* actually specify a pack resize strategy when packing
* fix the type signature of make_atlas
* bring packer::{Packer, GrowingPacker} traits into scope
master
Erin 8 years ago
parent
commit
1c833836f8
1 changed files with 5 additions and 5 deletions
  1. +5
    -5
      textium/src/rasterizer.rs

+ 5
- 5
textium/src/rasterizer.rs View File

@ -5,7 +5,7 @@ use std::collections::HashMap;
use ::{FontAtlas, GlyphMetadata};
use ::geometry::Rect;
use ::texture::{Buffer2d, Bitmap};
use ::packer::SkylinePacker;
use ::packer::{Packer, GrowingPacker, SkylinePacker};
pub struct Font<'a> {
font: rusttype::Font<'a>
@ -27,7 +27,7 @@ impl<'a> Font<'a> {
/// `width` and `height` are the starting size of the bitmap.
///
/// The packer may enlarge the bitmap beyond its initial dimensions in order to fit all glyphs.
pub fn make_atlas<I>(&self, chrs: I, scale: f32, margin: u32, width: usize, height: usize)
pub fn make_atlas<I>(&self, chrs: I, scale: f32, margin: usize, width: usize, height: usize)
-> (FontAtlas, Bitmap<u8>, f32)
where I: Iterator<Item=char>
{
@ -36,7 +36,7 @@ impl<'a> Font<'a> {
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);
let r = packer.pack_resize(&rendered, |(w, h)| (w*2, h*2));
info.bounding_box = r;
atlas.glyph_data.insert(chr, info);
} else if chr == ' ' {
@ -83,8 +83,8 @@ impl<'a> Font<'a> {
let data = GlyphMetadata {
scale: scale,
bounding_box: Rect {
x: bbox.min.x as usize,
y: bbox.min.y as usize,
x: 0_usize,
y: 0_usize,
w: bbox.width() as usize,
h: bbox.height() as usize,
},


Loading…
Cancel
Save