Skip to content

Commit

Permalink
Merge pull request #168 from w0rm/fix-breaking-long-words
Browse files Browse the repository at this point in the history
Fix breaking long words with wide utf8 characters
  • Loading branch information
bugadani authored May 3, 2024
2 parents 11ec450 + 5e110cd commit e1559ec
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 1 deletion.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
0.7.2 (2024-05-03)
==================

- [#168] Fix breaking long words with wide utf8 characters

[#168]: https://github.com/embedded-graphics/embedded-text/pull/168


0.7.1 (2024-04-29)
==================

Expand Down
2 changes: 1 addition & 1 deletion src/rendering/line_iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ where

if !remainder.is_empty() {
// Consume what was printed.
self.plugin.consume_partial(word.len());
self.plugin.consume_partial(word.chars().count());
return Ok(LineEndType::LineBreak);
}
}
Expand Down
42 changes: 42 additions & 0 deletions src/rendering/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -552,4 +552,46 @@ pub mod test {
"....................................... ",
]);
}

#[test]
fn correctly_breaks_long_words_with_wide_utf8_characters() {
let mut display = MockDisplay::new();
let character_style = MonoTextStyleBuilder::new()
.font(&FONT_6X10)
.text_color(BinaryColor::On)
.background_color(BinaryColor::Off)
.build();

TextBox::with_textbox_style(
"広広広", // MonoText replaces unrecognized characters with "?"
Rectangle::new(Point::zero(), size_for(&FONT_6X10, 2, 2)),
character_style,
TextBoxStyleBuilder::new().build(),
)
.draw(&mut display)
.unwrap();

display.assert_pattern(&[
"............",
".###...###..",
"#...#.#...#.",
"...#.....#..",
"..#.....#...",
"..#.....#...",
"............",
"..#.....#...",
"............",
"............",
"...... ",
".###.. ",
"#...#. ",
"...#.. ",
"..#... ",
"..#... ",
"...... ",
"..#... ",
"...... ",
"...... ",
]);
}
}

0 comments on commit e1559ec

Please sign in to comment.