use ab_glyph::OutlinedGlyph;
use grid::Grid;
pub struct Metrics {
pub height: usize,
pub width: usize,
}
pub struct Bitmap {
metrics: Metrics,
bitmap: Grid<u8>,
}
impl Bitmap {
pub fn new(curves: &OutlinedGlyph) -> Self {
let bound = curves.px_bounds();
let metrics = Metrics {
height: bound.height() as usize,
width: bound.width() as usize,
};
let mut bitmap = Grid::new(metrics.height, metrics.width);
curves.draw(|x, y, c| {
let value = (c * 255.0).round() as u8;
bitmap[(y as usize, x as usize)] = value
});
Self { metrics, bitmap }
}
pub fn metrics(&self) -> &Metrics {
&self.metrics
}
pub fn pixel(&self, row: usize, col: usize) -> u8 {
self.bitmap[(row, col)]
}
}