I would like to open a font file and modify eg the usWeightClass and save it in a different location – using Rust: https://github.com/googlefonts/fontations
I am already able to load a file, read data from the font, but I am not able to modify and save it.
I expect, that it should work somehow with WriteFont (but I don't know how): https://docs.rs/write-fonts/0.5.0/write_fonts/trait.FontWrite.html#
Any help would be much appreciated. Thanks a lot in advance, Olli
Cargo.toml
[dependencies]
write-fonts = "0.5.0"
read-fonts = "0.3.0"
font-types = "0.1.8"
main.rs
use read_fonts::{FontRef, TableProvider};
fn main() {
pub static FONT_DATA: &[u8] = include_bytes!("/path/to/a/font/somefont.ttf");
let font = FontRef::new(FONT_DATA).unwrap();
let mut os2 = font.os2().expect("missing OS/2 table");
println!("os2.version: {}", os2.version());
println!("os2.us_weight_class: {}", os2.us_weight_class());
let mut name = font.name().expect("missing name table");
for item in name.name_record() {
println!("name_id: {:?}", item.name_id);
println!("language_id: {:?}", item.language_id);
let data = item.string(name.string_data()).unwrap();
println!("String entry: {:?}", data.chars().collect::<String>());
};
}