Fixed format issues to output minimum readable BDF
This commit is contained in:
77798
src/8x13.bdf
Normal file
77798
src/8x13.bdf
Normal file
File diff suppressed because it is too large
Load Diff
56
src/main.rs
56
src/main.rs
@@ -1,9 +1,9 @@
|
|||||||
use std::fmt::Display;
|
use std::{fmt::Display, io::Write};
|
||||||
|
|
||||||
mod bit_reader;
|
mod bit_reader;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let font_file = include_bytes!("u8g2_font_8x13_tr.u8g2font");
|
let font_file = include_bytes!("u8g2_font_logisoso24_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..];
|
||||||
@@ -20,10 +20,10 @@ fn main() {
|
|||||||
bits_glyph_delta: header_bytes[8],
|
bits_glyph_delta: header_bytes[8],
|
||||||
bound_box_width: header_bytes[9],
|
bound_box_width: header_bytes[9],
|
||||||
bound_box_height: header_bytes[10],
|
bound_box_height: header_bytes[10],
|
||||||
bound_box_x: header_bytes[11],
|
bound_box_x: header_bytes[11] as i8,
|
||||||
bound_box_y: header_bytes[12],
|
bound_box_y: header_bytes[12] as i8,
|
||||||
ascent_capital_a: header_bytes[13],
|
ascent_capital_a: header_bytes[13] as i8,
|
||||||
descent_lowercase_g: header_bytes[14],
|
descent_lowercase_g: header_bytes[14] as i8,
|
||||||
paren_ascent: header_bytes[15],
|
paren_ascent: header_bytes[15],
|
||||||
paren_descent: header_bytes[16],
|
paren_descent: header_bytes[16],
|
||||||
offset_of_capital_a: u16::from_be_bytes([header_bytes[17], header_bytes[18]]),
|
offset_of_capital_a: u16::from_be_bytes([header_bytes[17], header_bytes[18]]),
|
||||||
@@ -113,13 +113,40 @@ fn main() {
|
|||||||
let mut bdf_file = String::new();
|
let mut bdf_file = String::new();
|
||||||
|
|
||||||
bdf_file.push_str("STARTFONT 2.1\n");
|
bdf_file.push_str("STARTFONT 2.1\n");
|
||||||
bdf_file.push_str("u8g2_font_converted\n");
|
bdf_file.push_str("-u8g2_font_converted\n");
|
||||||
bdf_file.push_str("SIZE 24 72 72\n");
|
let font_pt = header.bound_box_height * (72/96);
|
||||||
|
bdf_file.push_str("SIZE 13 75 75\n");
|
||||||
|
bdf_file.push_str(
|
||||||
|
&format!(
|
||||||
|
"FONTBOUNDINGBOX {} {} {} {}\n",
|
||||||
|
header.bound_box_width,
|
||||||
|
header.bound_box_height,
|
||||||
|
header.bound_box_x,
|
||||||
|
header.bound_box_y
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
bdf_file.push_str(&format!("STARTPROPERTIES 3
|
||||||
|
CHARSET_ENCODING \"1\"
|
||||||
|
FONT_ASCENT {}
|
||||||
|
FONT_DESCENT {}
|
||||||
|
ENDPROPERTIES\n\n", header.bound_box_height.wrapping_add_signed(header.descent_lowercase_g), header.descent_lowercase_g.abs()));
|
||||||
|
|
||||||
bdf_file.push_str(&format!("CHARS {}\n", header.glyphs));
|
bdf_file.push_str(&format!("CHARS {}\n", header.glyphs));
|
||||||
|
|
||||||
for i in glyphs.iter() {
|
for i in glyphs.iter() {
|
||||||
|
if i.unicode == 32 {
|
||||||
|
bdf_file.push_str("STARTCHAR space\n");
|
||||||
|
} else {
|
||||||
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));
|
||||||
|
let swidth = "SWIDTH 568 0\n";
|
||||||
|
bdf_file.push_str(swidth);
|
||||||
|
|
||||||
|
let dwidth = i.glyph_d;
|
||||||
|
bdf_file.push_str(&format!("DWIDTH {} 0\n", dwidth));
|
||||||
|
|
||||||
bdf_file.push_str(&format!("BBX {} {} {} {}\n", i.glyph_width, i.glyph_height, i.glyph_x, i.glyph_y));
|
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");
|
bdf_file.push_str("BITMAP\n");
|
||||||
|
|
||||||
@@ -165,7 +192,7 @@ fn main() {
|
|||||||
let mut bitmap_hex = String::new();
|
let mut bitmap_hex = String::new();
|
||||||
|
|
||||||
for byte in bitmap_row_bytes {
|
for byte in bitmap_row_bytes {
|
||||||
bitmap_hex.push_str(&format!("{:X}", byte));
|
bitmap_hex.push_str(&format!("{:02X}", byte));
|
||||||
}
|
}
|
||||||
bitmap_hex.push('\n');
|
bitmap_hex.push('\n');
|
||||||
bdf_file.push_str(&bitmap_hex);
|
bdf_file.push_str(&bitmap_hex);
|
||||||
@@ -175,7 +202,8 @@ fn main() {
|
|||||||
|
|
||||||
bdf_file.push_str("ENDFONT");
|
bdf_file.push_str("ENDFONT");
|
||||||
|
|
||||||
println!("{bdf_file}");
|
let mut f = std::fs::File::create("/home/jason/Documents/Rust/u8g2-font-reader/src/test.BDF").unwrap();
|
||||||
|
f.write_all(bdf_file.as_bytes()).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
@@ -191,10 +219,10 @@ struct FontHeader {
|
|||||||
bits_glyph_delta: u8,
|
bits_glyph_delta: u8,
|
||||||
bound_box_width: u8,
|
bound_box_width: u8,
|
||||||
bound_box_height: u8,
|
bound_box_height: u8,
|
||||||
bound_box_x: u8,
|
bound_box_x: i8,
|
||||||
bound_box_y: u8,
|
bound_box_y: i8,
|
||||||
ascent_capital_a: u8,
|
ascent_capital_a: i8,
|
||||||
descent_lowercase_g: u8,
|
descent_lowercase_g: i8,
|
||||||
paren_ascent: u8,
|
paren_ascent: u8,
|
||||||
paren_descent: u8,
|
paren_descent: u8,
|
||||||
offset_of_capital_a: u16,
|
offset_of_capital_a: u16,
|
||||||
|
|||||||
2627
src/test.BDF
Normal file
2627
src/test.BDF
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user