diff options
| -rw-r--r-- | build.rs | 4 | ||||
| -rw-r--r-- | patterns/font.hexpat | 34 | ||||
| -rw-r--r-- | src/main.rs | 10 | 
3 files changed, 41 insertions, 7 deletions
| @@ -112,7 +112,7 @@ fn exec(font: FontMetadata) -> io::Result<()> {  fn save_bits_to_file(font: &FontMetadata, char: u8, bits: &[u8]) -> io::Result<()> {    fs::create_dir_all(format!("assets/computed-fonts/{}/", font.name))?; -  let filename = format!("assets/computed-fonts/{}/{}.bin", font.name, char); +  let filename = format!("assets/computed-fonts/{}/{}.charbmp", font.name, char);    let mut file = File::create(&filename)?;    file.write_all(bits)?;    let filename = format!("assets/computed-fonts/{}/{}.txt", font.name, char); @@ -158,7 +158,7 @@ impl BakedFont for {name}Struct {{    );    for char in font.unique_chars() {      contents = format!( -      "{contents}      {} => include_bytes!(\"../../assets/computed-fonts/{}/{}.bin\"), +      "{contents}      {} => include_bytes!(\"../../assets/computed-fonts/{}/{}.charbmp\"),  ",        char as u8, font.name, char as u8      ); diff --git a/patterns/font.hexpat b/patterns/font.hexpat new file mode 100644 index 0000000..4a6a8c4 --- /dev/null +++ b/patterns/font.hexpat @@ -0,0 +1,34 @@ +#pragma author memdmp +#pragma description Character Bitmap (.charbmp) file format, version 1 + +#pragma endian little +#pragma pattern_limit 4294967295 + +import std.sys; +import type.magic; + +struct PixelRow<auto width> { +  u8 columns[width - 1] [[name("Row"), inline]]; +}; +struct ImageData<auto width> { +  PixelRow<width> rows[while(!std::mem::eof())] [[name("Rows"), inline]]; +}; +struct Offset { +  /** The X Offset of the character */ +  s32 x [[name("X"), comment("The X offset of the character's pixel data"), color("ff99ff")]]; +  /** The Y Offset of the character */ +  s32 y [[name("Y"), comment("The Y offset of the character's pixel data"), color("ffff99")]]; +}; + +struct CharBmp { +  /** The width of each line of the drawn character */ +  u8 width [[name("Width"), comment("Indicates the width of the character's drawn data, in pixels"), color("ff44aa")]]; +  /** The width of each line of the drawn character */ +  Offset offset [[name("Offset"), comment("Indicates the offset of the character's drawn data, in pixels"), color("cc99bb")]]; +  /** The horizontal offset that the origin of the next glyph should be from the origin of this glyph. */ +  float advance_width  [[name("Offset"), comment("Indicates the offset of the character's drawn data, in pixels"), color("99aaff")]]; +  /** Table of contents entries */ +  ImageData<width> imageData[width] [[name("Content")]]; +}; + +CharBmp charbmp @ 0x00 [[name("CharBmp")]]; diff --git a/src/main.rs b/src/main.rs index 0f51f4e..3d9c225 100644 --- a/src/main.rs +++ b/src/main.rs @@ -30,8 +30,8 @@ pub fn main() {    let mut i = 0;    'running: loop {      i = (i + 1) % 255; - -    canvas.set_draw_color(Color::RGB(255, 255, 255)); +     +    canvas.set_draw_color(Color::RGB(12, 12, 12));      canvas.clear();      let mut offset: f32 = 0.0; @@ -43,13 +43,13 @@ pub fn main() {              .to_texture(&texture_creator, Color::RGB(i, 64, 255 - i))              .unwrap(),            None, -          char.to_rect(offset as i32, 0), +          char.to_rect(offset as i32 + 16, 16),          )          .unwrap();        offset += char.advance_width;      }      offset = 0.0; -    for c in "All hail Blahaj".chars() { +    for c in "Cum 2 Cosin25 :3".chars() {        let char = FONT_GALMURI.get_char(c);        canvas          .copy( @@ -57,7 +57,7 @@ pub fn main() {              .to_texture(&texture_creator, Color::RGB(i, 64, 255 - i))              .unwrap(),            None, -          char.to_rect(offset as i32, 40), +          char.to_rect(offset as i32 + 18, 16+36),          )          .unwrap();        offset += char.advance_width; |