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

fontique: Remove unsafe in fontconfig cache #78

Merged
Merged
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
10 changes: 3 additions & 7 deletions fontique/src/backend/fontconfig/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,7 @@ fn parse_font(
.extend_from_slice(set.numbers().ok()?.as_slice().ok()?);
for leaf in set.leaves().ok()? {
let leaf = leaf.ok()?;
font.coverage
.leaves
.push(unsafe { core::mem::transmute(leaf) });
font.coverage.leaves.push(leaf);
}
}
}
Expand All @@ -213,7 +211,7 @@ fn parse_font(
#[derive(Clone, Default)]
pub struct Coverage {
numbers: Vec<u16>,
leaves: Vec<[u32; 8]>,
leaves: Vec<CharSetLeaf>,
}

impl Coverage {
Expand All @@ -230,9 +228,7 @@ impl Coverage {
Ok(idx) => {
let leaf = self.leaves.get(idx)?;
let lo = (ch & 0xff) as u8;
let map_idx = (lo >> 5) as usize;
let bit_idx = (lo & 0x1f) as u32;
Some((leaf[map_idx] >> bit_idx) & 1 != 0)
Some(leaf.contains_byte(lo))
}
Err(_) => Some(false),
}
Expand Down