summaryrefslogtreecommitdiff
path: root/src/bitmap.rs
diff options
context:
space:
mode:
authorJakob L. Kreuze <jakob@memeware.net>2018-06-21 11:03:00 -0400
committerJakob L. Kreuze <jakob@memeware.net>2018-06-21 11:03:00 -0400
commit8a28b09ae021f7002a1614fae3e94a0684707c09 (patch)
tree7812b829907ac58bcd1616538e46d6fb20628e5a /src/bitmap.rs
parent33b18a0d3c60ca08355503e356af351cb0373918 (diff)
refactor: Moved 'load_font' into 'bitmap.rs'
Diffstat (limited to 'src/bitmap.rs')
-rw-r--r--src/bitmap.rs43
1 files changed, 42 insertions, 1 deletions
diff --git a/src/bitmap.rs b/src/bitmap.rs
index d9ec391..120f9d1 100644
--- a/src/bitmap.rs
+++ b/src/bitmap.rs
@@ -186,7 +186,7 @@ impl BitmapManager {
if len < 16 {
bail!("ART does not contain a valid header.");
}
-
+
let mut data = Cursor::new(data);
let mut bitmaps = Vec::new();
@@ -334,6 +334,47 @@ impl BitmapManager {
}
}
+// FIXME: This documentation is bare and undescriptive.
+/// Loads a font blob into a Bitmap.
+pub fn load_font(font: &[u8]) -> Bitmap {
+ // TODO: There is no error checking, as I plan to dynamically generate a
+ // number of glyphs and appropriate dimensions from the size of 'data'.
+
+ // FIXME: Width and height constants are arbitrary and should ideally be
+ // dynamically calculated for a set of glyphs with arbitrary length.
+ let width = 128;
+ let height = 256;
+
+ let mut data = vec![0; height * width];
+
+ // FIXME: Again, this MAX_GLYPH, which isn't even referred to by a static
+ // constant, should be dynamically calculated.
+ for glyph in 0..256 {
+ let x_off = (glyph % 32) * 8;
+ let y_off = (glyph / 32) * 8;
+
+ for i in 0..8 {
+ for j in 0..8 {
+ let byte = font[(glyph * 8 + i) as usize];
+ let bit = 2 << (7 - j);
+
+ if byte & bit != 0 {
+ // The font files don't convey any color information, just
+ // the pixel that's set, so we default to a plain white.
+ let pixel = 0xffffffff;
+
+ let x = x_off + i;
+ let y = y_off + j;
+
+ data[x * width + y] = pixel;
+ }
+ }
+ }
+ }
+
+ Bitmap { width: width as u16, height: height as u16, data }
+}
+
#[cfg(test)]
mod tests {
use super::*;