diff options
fix: nyaa
Diffstat (limited to 'build.rs')
-rw-r--r-- | build.rs | 36 |
1 files changed, 30 insertions, 6 deletions
@@ -101,17 +101,39 @@ fn save_bits_to_file(font: &FontMetadata, char: u8, bits: &[u8]) -> io::Result<( file.write_all(&FontMetadata::img_to_hex(bits.to_vec()))?; Ok(()) } +fn to_upper_snake_with_first_upper_preceeded_by_underscore(str: String) -> String { + let mut str = str; + for char in "ABCDEFGHIJKLMNOPQRSTUVWXYZ".chars() { + str = str.replace(char,format!("_{char}").as_str()); + } + str.to_uppercase() +} fn generate_struct(font: &FontMetadata) -> io::Result<String> { let name = font.name; let mut contents = format!( - "pub struct {name} {{}} -impl BakedFont for {name} {{ - fn get_char_bytes(c: char) -> &'static [u8] {{ - match c as u8 {{ -" + "pub struct {name}Struct {{}} +impl BakedFont for {name}Struct {{ + fn has_char(&self, c: char) -> bool {{ + match c as u8 {{" ); for char in font.unique_chars() { contents = format!( + "{contents} + | {}", + char as u8, + ); + } + contents = format!( + "{contents} + => true, + _ => false + }} + }} + fn get_char_bytes(&self, c: char) -> &'static [u8] {{ + match c as u8 {{ +"); + for char in font.unique_chars() { + contents = format!( "{contents} {} => include_bytes!(\"../../assets/computed-fonts/{}/{}.bin\"), ", char as u8, font.name, char as u8 @@ -122,7 +144,9 @@ impl BakedFont for {name} {{ }} }} }} -" +pub const FONT{}: {name}Struct = {name}Struct{{ +}}; +", to_upper_snake_with_first_upper_preceeded_by_underscore(name.to_string()) ); Ok(contents) } |