Skip to content

Commit

Permalink
Allow missing glyph files for get_named_font_stack.
Browse files Browse the repository at this point in the history
  • Loading branch information
lseelenbinder committed Jul 15, 2023
1 parent 5f3d7ec commit 041ef79
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pbf_font_tools/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"]
Expand Down
10 changes: 7 additions & 3 deletions pbf_font_tools/src/tools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -25,13 +25,17 @@ pub async fn get_named_font_stack<P: AsRef<Path>>(
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.
Expand Down
Empty file.
24 changes: 24 additions & 0 deletions pbf_font_tools/tests/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down

0 comments on commit 041ef79

Please sign in to comment.