aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--build.rs5
-rw-r--r--src/font.rs16
2 files changed, 18 insertions, 3 deletions
diff --git a/build.rs b/build.rs
index 3a4b452..7b7b410 100644
--- a/build.rs
+++ b/build.rs
@@ -2,6 +2,8 @@ use rusttype::{Font, Point, Scale};
use std::fs::{self, File};
use std::io::{self, Write};
+// TODO: Build a Rust Macro that does what this does but without a build.rs
+
#[derive(Clone)]
struct FontMetadata {
pub charset: &'static str,
@@ -103,9 +105,8 @@ fn generate_struct(font: &FontMetadata) -> io::Result<String> {
let name = font.name;
let mut contents = format!(
"pub struct {name} {{}}
-impl {name} {{}}
impl BakedFont for {name} {{
- fn get_char(c: char) -> &'static [u8] {{
+ fn get_char_bytes(c: char) -> &'static [u8] {{
match c as u8 {{
"
);
diff --git a/src/font.rs b/src/font.rs
index 546fabe..d4e8d88 100644
--- a/src/font.rs
+++ b/src/font.rs
@@ -15,8 +15,22 @@ fn insert_value(arr: &mut Vec<*const Glyph>, idx: usize, glyph: *const Glyph) {
arr[idx] = glyph;
}
+pub struct RenderableCharacter {
+ pub width: u16,
+ pub data: &'static [u8],
+}
+/**
+ A trait describing a generated font.
+ */
pub trait BakedFont {
- fn get_char(character: char) -> &'static [u8];
+ fn get_char_bytes(character: char) -> &'static [u8];
+ fn get_char(character: char) -> RenderableCharacter {
+ let bytes = Self::get_char_bytes(character);
+ RenderableCharacter {
+ width: (bytes[0] as u16) | (bytes[1] as u16 >> 8) ,
+ data: &bytes[2..]
+ }
+ }
}
pub struct Font<'a> {
pub texture: &'a [u8],