diff options
Diffstat (limited to 'build.rs')
-rw-r--r-- | build.rs | 53 |
1 files changed, 10 insertions, 43 deletions
@@ -19,33 +19,6 @@ fn exec(font_path: &str, characters: Vec<char>, font_name: &str) -> io::Result<( Ok(()) } -fn set_bit_at_position_to_true(i: u8, p: u8) -> u8 { - match p { - 0 => i | 0b1000_0000, - 1 => i | 0b0100_0000, - 2 => i | 0b0010_0000, - 3 => i | 0b0001_0000, - 4 => i | 0b0000_1000, - 5 => i | 0b0000_0100, - 6 => i | 0b0000_0010, - 7 => i | 0b0000_0001, - 8_u8..=u8::MAX => todo!(), - } -} -fn get_bit_at_position(i: u8, p: u8) -> bool { - match p { - 0 => (i & 0b1000_0000) == 0b1000_0000, - 1 => (i & 0b0100_0000) == 0b0100_0000, - 2 => (i & 0b0010_0000) == 0b0010_0000, - 3 => (i & 0b0001_0000) == 0b0001_0000, - 4 => (i & 0b0000_1000) == 0b0000_1000, - 5 => (i & 0b0000_0100) == 0b0000_0100, - 6 => (i & 0b0000_0010) == 0b0000_0010, - 7 => (i & 0b0000_0001) == 0b0000_0001, - 8_u8..=u8::MAX => todo!(), - } -} - fn render_character(font: &Font, scale: Scale, character: char) -> Vec<u8> { let glyph = font.glyph(character).scaled(scale); let bounding_box = glyph.exact_bounding_box().unwrap(); @@ -76,11 +49,8 @@ fn render_character(font: &Font, scale: Scale, character: char) -> Vec<u8> { .positioned(Point { x: 0.0, y: 0.0 }) .draw(|gx: u32, gy: u32, v| { let bit = (v * 255.0) as u8; - // image.push(bit); - let v = format!("{:x?}", bit); - let v = if v.len() == 1 { format!("0{}", v) } else { v }; - for char in v.chars() { - image[(2 + gy * width + gx) as usize] = char as u8; + if gx < width { + define_item(&mut image,(2 + (gy * width) + gx) as usize, bit); } }); image @@ -88,24 +58,21 @@ fn render_character(font: &Font, scale: Scale, character: char) -> Vec<u8> { fn img_to_hex(image: Vec<u8>) -> Vec<u8> { let mut image2: Vec<u8> = Vec::new(); let width = (image[0] as u16) | (image[1] as u16 >> 8); - for char in format!("Width: {width}\n").chars() { - image2.push(char as u8); - } - + let mut i: i32 = -3; for bit in image { i += 1; if i >= 0 { - if i as u16 == width * 2 { + if i as u16 == width { i = 0; image2.push('\n' as u8); } - // let v = format!("{:x?}", bit); - // let v = if v.len() == 1 { format!("0{}", v) } else { v }; - // for char in v.chars() { - // image2.push(char as u8); - // } - image2.push(bit); + let v = format!("{:x?}", bit); + let v = if v.len() == 1 { format!("0{}", v) } else { v }; + for char in v.chars() { + image2.push(char as u8); + } + // image2.push(if bit < 80 {' ' as u8} else if bit < 150 {'-' as u8} else {'#' as u8}) } } image2 |