All layout boxes on the line should have trailing whitespace trimmed off of their measurements.

Flash has a weird bug where it will NOT trim trailing spaces off of the metrics reported to users if the text is left-aligned. We replicate this here so that tests pass.
This commit is contained in:
David Wendt 2020-06-01 21:54:15 -04:00
parent 50a05df998
commit 0e0b2fb85d
1 changed files with 9 additions and 9 deletions

View File

@ -85,17 +85,17 @@ impl<'a, 'gc> LayoutContext<'a, 'gc> {
let mut line = self.current_line;
let mut line_bounds = None;
while let Some(linebox) = line {
let read = linebox.read();
line = read.next_sibling();
let mut write = linebox.write(mc);
line = write.next_sibling();
let (start, end, _tf, font, size, _color) = write.text_node().expect("text");
//Flash ignores trailing spaces when aligning lines, so should we
if line.is_none() {
let trimmed_bounds = {
let (start, end, _tf, font, size, _color) = read.text_node().expect("text");
read.bounds()
.with_size(Size::from(font.measure(self.text[start..end].trim(), size)))
};
line_bounds += trimmed_bounds;
if self.current_line_span.align != swf::TextAlign::Left {
write.bounds = write.bounds.with_size(Size::from(
font.measure(self.text[start..end].trim_end(), size),
));
}
if let Some(mut line_bounds) = line_bounds {
line_bounds += write.bounds;
} else {