|
@ -1,3 +1,5 @@ |
|
|
|
|
|
//! Strategies for rect-packing a glyph atlas.
|
|
|
|
|
|
|
|
|
mod skyline;
|
|
|
mod skyline;
|
|
|
|
|
|
|
|
|
use ::texture::{Buffer2d, ResizeableBuffer2d};
|
|
|
use ::texture::{Buffer2d, ResizeableBuffer2d};
|
|
@ -5,23 +7,40 @@ use ::geometry::Rect; |
|
|
|
|
|
|
|
|
pub use self::skyline::SkylinePacker;
|
|
|
pub use self::skyline::SkylinePacker;
|
|
|
|
|
|
|
|
|
|
|
|
/// A trait describing a generic atlas packer.
|
|
|
pub trait Packer {
|
|
|
pub trait Packer {
|
|
|
|
|
|
/// The type of the bitmap used to store the packed glyph bitmaps.
|
|
|
type Buffer: Buffer2d;
|
|
|
type Buffer: Buffer2d;
|
|
|
|
|
|
|
|
|
|
|
|
/// Create a new Packer, given a buffer to pack into.
|
|
|
fn new(b: Self::Buffer) -> Self;
|
|
|
fn new(b: Self::Buffer) -> Self;
|
|
|
|
|
|
|
|
|
|
|
|
/// Pack a glyph bitmap into the atlas, returning the location it was packed to.
|
|
|
fn pack<O>(&mut self, buf: &O) -> Option<Rect<usize>>
|
|
|
fn pack<O>(&mut self, buf: &O) -> Option<Rect<usize>>
|
|
|
where O: Buffer2d<Pixel=<Self::Buffer as Buffer2d>::Pixel>; // buffer with same pixel type as this atlas
|
|
|
where O: Buffer2d<Pixel=<Self::Buffer as Buffer2d>::Pixel>; // buffer with same pixel type as this atlas
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// Set the size of the margin enforced between glyphs in the atlas.
|
|
|
fn set_margin(&mut self, margin: usize);
|
|
|
fn set_margin(&mut self, margin: usize);
|
|
|
|
|
|
/// Return a reference to the buffer we're packing glyphs into.
|
|
|
fn buf(&self) -> &Self::Buffer;
|
|
|
fn buf(&self) -> &Self::Buffer;
|
|
|
|
|
|
/// Return a mutable reference to the buffer we're packing glyphs into.
|
|
|
fn buf_mut(&mut self) -> &mut Self::Buffer;
|
|
|
fn buf_mut(&mut self) -> &mut Self::Buffer;
|
|
|
|
|
|
/// Convert this packer into the glyph-packed buffer.
|
|
|
fn into_buf(self) -> Self::Buffer; // TODO: consider actually implementing Into?
|
|
|
fn into_buf(self) -> Self::Buffer; // TODO: consider actually implementing Into?
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// Return the dimensions of this atlas.
|
|
|
fn dimensions(&self) -> (usize, usize);
|
|
|
fn dimensions(&self) -> (usize, usize);
|
|
|
|
|
|
/// Resize this atlas.
|
|
|
fn set_dimensions(&mut self, w: usize, h: usize);
|
|
|
fn set_dimensions(&mut self, w: usize, h: usize);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// A trait describing an atlas packer which can expand its buffer if necessary.
|
|
|
pub trait GrowingPacker: Packer {
|
|
|
pub trait GrowingPacker: Packer {
|
|
|
|
|
|
/// Pack a glyph bitmap into the atlas, resizing the atlas if necessary.
|
|
|
|
|
|
/// Returns the location it was packed to.
|
|
|
|
|
|
///
|
|
|
/// `resize_fn` should describe a strategy for growing the atlas buffer based on the current size.
|
|
|
/// `resize_fn` should describe a strategy for growing the atlas buffer based on the current size.
|
|
|
fn pack_resize<F, O>(&mut self, buf: &O, resize_fn: F) -> Rect<usize>
|
|
|
fn pack_resize<F, O>(&mut self, buf: &O, resize_fn: F) -> Rect<usize>
|
|
|
where O: Buffer2d<Pixel=<<Self as Packer>::Buffer as Buffer2d>::Pixel>,
|
|
|
where O: Buffer2d<Pixel=<<Self as Packer>::Buffer as Buffer2d>::Pixel>,
|
|
|