From 38d679ef29640ded9bad6815e3d6d37f2df55268 Mon Sep 17 00:00:00 2001 From: David Wendt Date: Mon, 25 May 2020 21:25:22 -0400 Subject: [PATCH] `wrap_line` should take spaces into account when sizing lines. --- core/src/font.rs | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/core/src/font.rs b/core/src/font.rs index c6d2dad1f..af941e696 100644 --- a/core/src/font.rs +++ b/core/src/font.rs @@ -221,7 +221,14 @@ impl<'gc> Font<'gc> { current_width = width; } else { current_word = &text[line_start..word_end]; - current_width -= measure.0; + + let measure_with_space = self.measure( + text.get(word_start..word_end + 1).unwrap_or(word), + font_size, + ); + current_width = current_width + .checked_sub(measure_with_space.0) + .unwrap_or_else(|| Twips::from_pixels(0.0)); } } @@ -379,7 +386,7 @@ mod tests { Twips::from_pixels(0.0), ); - assert_eq!(Some(11), breakpoint); + assert_eq!(Some(6), breakpoint); last_bp += breakpoint.unwrap() + 1; @@ -390,7 +397,7 @@ mod tests { Twips::from_pixels(0.0), ); - assert_eq!(Some(6), breakpoint2); + assert_eq!(Some(4), breakpoint2); last_bp += breakpoint2.unwrap() + 1; @@ -401,7 +408,18 @@ mod tests { Twips::from_pixels(0.0), ); - assert_eq!(None, breakpoint3); + assert_eq!(Some(4), breakpoint3); + + last_bp += breakpoint3.unwrap() + 1; + + let breakpoint4 = df.wrap_line( + &string[last_bp..], + Twips::from_pixels(12.0), + Twips::from_pixels(30.0), + Twips::from_pixels(0.0), + ); + + assert_eq!(None, breakpoint4); }); } }