Skip to content

Commit 3762a01

Browse files
committed
Bug fix: multiline text layout does not work
1 parent 7d8612e commit 3762a01

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed

Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ rand_distr = "0.2.2"
7070
criterion = "0.3.0"
7171
rayon = "1.2.0"
7272
rand_xorshift = "0.2.0"
73+
cpuprofiler = "*"
7374

7475
[target.'cfg(target_arch = "wasm32")'.dev-dependencies]
7576
wasm-bindgen-test = "0.3.4"
@@ -78,3 +79,6 @@ wasm-bindgen-test = "0.3.4"
7879
name = "benchmark"
7980
harness = false
8081
path = "benches/main.rs"
82+
83+
[profile.bench]
84+
debug = true

benches/benches/rasterizer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ fn draw_line(c: &mut Criterion) {
7272
}
7373

7474
fn fill_background(c: &mut Criterion) {
75-
let mut group = c.benchmark_group("rasterizer::draw_background");
75+
let mut group = c.benchmark_group("rasterizer::fill_background");
7676

7777
group.bench_function("rgb", |b| {
7878
let mut buffer = vec![0; (W * H * 3) as usize];

src/element/text.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -128,14 +128,11 @@ fn layout_multiline_text<'a, F: FnMut(&'a str)>(
128128
} else {
129129
let mut remaining = &line[0..];
130130

131-
while remaining.is_empty() {
132-
let mut width = 0;
131+
while !remaining.is_empty() {
133132
let mut left = 0;
134133
while left < remaining.len() {
135-
let char_width =
136-
font.box_size(&remaining[left..=left]).unwrap_or((0, 0)).0 as i32;
137-
138-
width += char_width;
134+
let width =
135+
font.box_size(&remaining[0..=left]).unwrap_or((0, 0)).0 as i32;
139136

140137
if width > max_width as i32 {
141138
break;

0 commit comments

Comments
 (0)