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) } } }