Skip to content

Commit

Permalink
Fix invalid ids bug
Browse files Browse the repository at this point in the history
  • Loading branch information
notgull committed May 9, 2023
1 parent 4154407 commit 37c5800
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 3 deletions.
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.

0 comments on commit 37c5800

Please sign in to comment.