From 041ef798b7548e57c6f6377ae39f9bcc81fe9dbd Mon Sep 17 00:00:00 2001 From: Luke Seelenbinder Date: Sat, 15 Jul 2023 14:09:41 +0200 Subject: [PATCH] Allow missing glyph files for get_named_font_stack. --- Cargo.lock | 2 +- pbf_font_tools/Cargo.toml | 2 +- pbf_font_tools/src/tools.rs | 10 +++++--- .../tests/glyphs/Empty Light/.gitkeep | 0 pbf_font_tools/tests/integration_tests.rs | 24 +++++++++++++++++++ 5 files changed, 33 insertions(+), 5 deletions(-) create mode 100644 pbf_font_tools/tests/glyphs/Empty Light/.gitkeep diff --git a/Cargo.lock b/Cargo.lock index 738d353..5f97e56 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -407,7 +407,7 @@ checksum = "4d5d9eb14b174ee9aa2ef96dc2b94637a2d4b6e7cb873c7e171f0c20c6cf3eac" [[package]] name = "pbf_font_tools" -version = "2.4.0" +version = "2.5.0" dependencies = [ "futures", "glob", diff --git a/pbf_font_tools/Cargo.toml b/pbf_font_tools/Cargo.toml index e5c8ce2..9d4f00b 100644 --- a/pbf_font_tools/Cargo.toml +++ b/pbf_font_tools/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "pbf_font_tools" -version = "2.4.0" +version = "2.5.0" description = "Tools for working with SDF font glyphs encoded in protobuf format." readme = "README.md" keywords = ["sdf", "protobuf", "fonts"] diff --git a/pbf_font_tools/src/tools.rs b/pbf_font_tools/src/tools.rs index 2f8a37f..5e2de1e 100644 --- a/pbf_font_tools/src/tools.rs +++ b/pbf_font_tools/src/tools.rs @@ -2,7 +2,7 @@ use std::collections::HashSet; use std::fs::File; use std::path::Path; -use futures::future::try_join_all; +use futures::future::join_all; use protobuf::Message; use tokio::task::spawn_blocking; @@ -25,13 +25,17 @@ pub async fn get_named_font_stack>( if font_names.is_empty() { return Err(MissingFontFamilyName); } + // Load fonts - let glyph_data = try_join_all( + let glyph_data = join_all( font_names .iter() .map(|font| load_glyphs(font_path.as_ref(), font, start, end)), ) - .await?; + .await + .into_iter() + .filter_map(|g| g.ok()) + .collect(); // Combine all the glyphs into a single instance, using the ordering to determine priority. // This can take some time, so mark it blocking. diff --git a/pbf_font_tools/tests/glyphs/Empty Light/.gitkeep b/pbf_font_tools/tests/glyphs/Empty Light/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/pbf_font_tools/tests/integration_tests.rs b/pbf_font_tools/tests/integration_tests.rs index 53131c2..53d08d2 100644 --- a/pbf_font_tools/tests/integration_tests.rs +++ b/pbf_font_tools/tests/integration_tests.rs @@ -22,6 +22,30 @@ async fn test_load_glyphs() { } } +#[tokio::test] +async fn test_get_named_font_stack() { + let font_path = Path::new("tests").join("glyphs"); + let fonts = &["Empty Light", "SeoulNamsan L"]; + let result = pbf_font_tools::get_named_font_stack( + font_path.as_path(), + fonts, + "Test".to_string(), + 0, + 255, + ) + .await; + + match result { + Ok(glyphs) => { + let stack = &glyphs.stacks[0]; + let glyph_count = stack.glyphs.len(); + assert_eq!(stack.name, Some(String::from(fonts[1]))); + assert_eq!(glyph_count, 170); + } + Err(e) => panic!("Encountered error {e:#?}."), + } +} + #[tokio::test] async fn test_get_font_stack() { let font_path = Path::new("tests").join("glyphs");