Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow missing glyph files for get_named_font_stack. #14

Merged
merged 1 commit into from
Jul 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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