Finished partial BDF output
This commit is contained in:
32
src/main.rs
32
src/main.rs
@@ -3,7 +3,7 @@ use std::fmt::Display;
|
|||||||
mod bit_reader;
|
mod bit_reader;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let font_file = include_bytes!("u8g2_font_logisoso24_tr.u8g2font");
|
let font_file = include_bytes!("u8g2_font_8x13_tr.u8g2font");
|
||||||
|
|
||||||
let header_bytes = &font_file[0..23];
|
let header_bytes = &font_file[0..23];
|
||||||
let mut data_bytes = &font_file[23..];
|
let mut data_bytes = &font_file[23..];
|
||||||
@@ -120,6 +120,8 @@ fn main() {
|
|||||||
for i in glyphs.iter() {
|
for i in glyphs.iter() {
|
||||||
bdf_file.push_str(&format!("STARTCHAR {}\n", i.unicode as char));
|
bdf_file.push_str(&format!("STARTCHAR {}\n", i.unicode as char));
|
||||||
bdf_file.push_str(&format!("ENCODING {}\n", i.unicode));
|
bdf_file.push_str(&format!("ENCODING {}\n", i.unicode));
|
||||||
|
bdf_file.push_str(&format!("BBX {} {} {} {}\n", i.glyph_width, i.glyph_height, i.glyph_x, i.glyph_y));
|
||||||
|
bdf_file.push_str("BITMAP\n");
|
||||||
|
|
||||||
let mut decoded_bits = Vec::new();
|
let mut decoded_bits = Vec::new();
|
||||||
|
|
||||||
@@ -143,17 +145,37 @@ fn main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut bdf_bitmap: Vec<Vec<u8>> = Vec::new();
|
let mut decoded_bits_iter = decoded_bits.iter();
|
||||||
|
|
||||||
while !decoded_bits.is_empty() {
|
for _ in 0..i.glyph_height {
|
||||||
for j in decoded_bits.iter().by_ref().take(i.glyph_width as usize) {
|
let bitmap_row = decoded_bits_iter.by_ref().take(i.glyph_width as usize).cloned().collect::<Vec<_>>();
|
||||||
|
let (chunks, remainder) = bitmap_row.as_chunks::<8>();
|
||||||
|
let mut bitmap_row_bytes = Vec::new();
|
||||||
|
|
||||||
|
for k in chunks {
|
||||||
|
bitmap_row_bytes.push(k.iter().fold(0_u8, |v, b| (v << 1) + (*b as u8)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if remainder.len() != 0 {
|
||||||
|
let bits = remainder.len();
|
||||||
|
let mut last_byte = remainder.iter().fold(0_u8, |v, b| (v << 1) + (*b as u8));
|
||||||
|
last_byte = last_byte << 8-bits;
|
||||||
|
bitmap_row_bytes.push(last_byte);
|
||||||
|
}
|
||||||
|
let mut bitmap_hex = String::new();
|
||||||
|
|
||||||
|
for byte in bitmap_row_bytes {
|
||||||
|
bitmap_hex.push_str(&format!("{:X}", byte));
|
||||||
|
}
|
||||||
|
bitmap_hex.push('\n');
|
||||||
|
bdf_file.push_str(&bitmap_hex);
|
||||||
}
|
}
|
||||||
|
bdf_file.push_str("ENDCHAR\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
bdf_file.push_str("ENDFONT");
|
bdf_file.push_str("ENDFONT");
|
||||||
|
|
||||||
|
println!("{bdf_file}");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
|||||||
Reference in New Issue
Block a user