From 66ab1e600075a2395596e07359823ce5f5fc8d1d Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Sun, 9 Oct 2022 17:04:59 -0600 Subject: [PATCH] Memory map fonts --- examples/text/Cargo.toml | 1 + examples/text/src/main.rs | 11 ++++++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/examples/text/Cargo.toml b/examples/text/Cargo.toml index 56971744..60f1b05d 100644 --- a/examples/text/Cargo.toml +++ b/examples/text/Cargo.toml @@ -8,6 +8,7 @@ publish = false [dependencies] ab_glyph = { version = "0.2", optional = true } orbclient = "0.3" +memmap2 = "0.5" rusttype = { version = "0.9", optional = true } rustybuzz = "0.5" swash = { version = "0.1", optional = true } diff --git a/examples/text/src/main.rs b/examples/text/src/main.rs index 79e4542f..09d78df4 100644 --- a/examples/text/src/main.rs +++ b/examples/text/src/main.rs @@ -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) } } }