Skip to content

Commit

Permalink
fix: tight_width should return 0 if unit is invalid
Browse files Browse the repository at this point in the history
  • Loading branch information
zimond committed Jun 20, 2024
1 parent 49d70dc commit 12cefa7
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "fontkit"
version = "0.6.0-beta.7"
version = "0.6.0-beta.8"
edition = "2021"
authors = ["Zimon Dai <[email protected]>"]
description = "A simple library for font loading and indexing"
Expand Down
3 changes: 3 additions & 0 deletions src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,9 @@ impl TextMetrics {
}

pub(crate) fn width_until(&self, font_size: f32, letter_spacing: f32, index: usize) -> f32 {
if self.units == 0 {
return 0.0;
}
let factor = font_size / self.units as f32;
let positions = self.positions.read().unwrap();
positions.iter().take(index).fold(0.0, |current, p| {
Expand Down

0 comments on commit 12cefa7

Please sign in to comment.