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

Fix invalid IDs bug #55

Merged
merged 1 commit into from
May 10, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,12 @@ impl Database {

for index in 0..n {
match parse_face_info(source.clone(), data, index) {
Ok(info) => {
ids.push(info.id);
self.push_face_info(info);
Ok(mut info) => {
let id = self.faces.insert_with_key(|k| {
info.id = ID(k);
info
});
ids.push(ID(id));
}
Err(e) => log::warn!(
"Failed to load a font face {} from source cause {}.",
Expand Down
15 changes: 15 additions & 0 deletions tests/add_fonts.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const DEMO_TTF: &[u8] = include_bytes!("./fonts/Tuffy.ttf");
use std::sync::Arc;

#[test]
fn add_fonts_and_get_ids_back() {
env_logger::init();
let mut font_db = fontdb::Database::new();
let ids = font_db.load_font_source(fontdb::Source::Binary(Arc::new(DEMO_TTF)));

assert_eq!(ids.len(), 1);
let id = ids[0];

let font = font_db.face(id).unwrap();
assert!(font.families.iter().any(|(name, _)| name == "Tuffy"));
}
11 changes: 11 additions & 0 deletions tests/fonts/LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
We, the copyright holders of this work, hereby release it into the
public domain. This applies worldwide.

In case this is not legally possible,

We grant any entity the right to use this work for any purpose, without
any conditions, unless such conditions are required by law.

Thatcher Ulrich <tu@tulrich.com> http://tulrich.com
Karoly Barta bartakarcsi@gmail.com
Michael Evans http://www.evertype.com
Binary file added tests/fonts/Tuffy.ttf
Binary file not shown.