Memory map fonts

This commit is contained in:
Jeremy Soller 2022-10-09 17:04:59 -06:00
parent 0365737908
commit 66ab1e6000
2 changed files with 9 additions and 3 deletions

View file

@ -42,10 +42,15 @@ fn main() {
("/usr/share/fonts/opentype/noto/NotoSansCJK-Regular.ttc", 2 /* simplified chinese */),
("/usr/share/fonts/truetype/noto/NotoColorEmoji.ttf", 0),
] {
match fs::read(font_path) {
Ok(font_data) => font_datas.push((font_path, font_data, *font_index)),
match fs::File::open(&font_path) {
Ok(font_file) => match unsafe { memmap2::Mmap::map(&font_file) } {
Ok(font_data) => font_datas.push((font_path, font_data, *font_index)),
Err(err) => {
eprintln!("failed to memory map font '{}': {}", font_path, err)
}
},
Err(err) => {
eprintln!("failed to read font '{}': {}", font_path, err)
eprintln!("failed to open font '{}': {}", font_path, err)
}
}
}