Skip to content

Commit

Permalink
fix: text wrapping logic with leading empty space
Browse files Browse the repository at this point in the history
  • Loading branch information
zimond committed Aug 31, 2023
1 parent abb4115 commit 5182353
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
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.4.1"
version = "0.4.3"
edition = "2021"
authors = ["Zimon Dai <daizhuoxian@gmail.com>"]
description = "A simple library for font loading and indexing"
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "fontkit-rs",
"version": "0.0.5",
"version": "0.0.6",
"description": "Toolkit used to load, match, measure, and render texts",
"main": "pkg/bundler/index.js",
"directories": {
Expand Down
11 changes: 8 additions & 3 deletions src/metrics/compose.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ pub struct Span<T> {

impl<T> Span<T> {
fn width(&self) -> f32 {
if self.metrics.positions.is_empty() {
return 0.0;
}
let mut width = self.metrics.width(self.size, self.letter_spacing);
if self.swallow_leading_space && self.metrics.positions[0].metrics.c == ' ' {
let c = &self.metrics.positions[0];
Expand Down Expand Up @@ -303,9 +306,9 @@ where
}
let factor = span.size / span.metrics.units() as f32;
let range = if rtl {
(current_real_index + 1 - count)..total_count
(current_real_index + 1 - count)..current_real_index
} else {
0..(current_real_index + count)
current_real_index..(current_real_index + count)
};
let acc_seg_width = range
.map(|index| span.metrics.positions.get(index).unwrap())
Expand All @@ -321,14 +324,16 @@ where
} else {
real_index = current_real_index + count;
}
current_line_width += acc_seg_width;
} else {
real_index = current_real_index;
break;
}
}
if (real_index == 0 && !rtl)
|| (rtl && real_index == span.metrics.positions.len() - 1)
{
real_index = naive_break_index
real_index = naive_break_index;
}

// Split here, create a new span
Expand Down

0 comments on commit 5182353

Please sign in to comment.