diff --git a/crates/text/src/layout/flow.rs b/crates/text/src/layout/flow.rs index e6b74b17e..de0de5bbc 100644 --- a/crates/text/src/layout/flow.rs +++ b/crates/text/src/layout/flow.rs @@ -719,9 +719,11 @@ fn tab_glyph<'p>( if justification.last_tab != Some(glyph_index) { return (advance, leader); } - // The width of what follows up to the line's end (nothing, when the tab ends the line). + // The width of what follows up to the line's end (nothing, when the tab ends the line), with + // the hyphen a hyphenated line ends with. let after = sg.get(glyph_index + 1..line.trimmed).unwrap_or_default(); - let rest = if after.is_empty() { 0.0 } else { after.iter().map(|g| g.adv).sum::() - line.end_trim }; + let hyphen = line.hyphen.as_ref().map_or(0.0, |g| g.adv); + let rest = if after.is_empty() { 0.0 } else { after.iter().map(|g| g.adv).sum::() - line.end_trim + hyphen }; ((line.ax1 + line.opt_r - rest - x).max(0.0), leader) } diff --git a/crates/text/src/tests.rs b/crates/text/src/tests.rs index 636f71c22..1958b4357 100644 --- a/crates/text/src/tests.rs +++ b/crates/text/src/tests.rs @@ -702,6 +702,16 @@ fn right_aligned_area_type_sets_the_text_after_its_last_tab_against_the_edge() { assert!(lay.glyphs.first().unwrap().origin.x.abs() < 1e-6, "{}", lay.glyphs.first().unwrap().origin.x); let tab = lay.glyphs.iter().find(|g| g.byte == 7).unwrap(); assert!((tab.origin.x + tab.advance - 336.0).abs() < 1e-6, "the tab ends at {}", tab.origin.x + tab.advance); + // Text after the last tab that breaks with a hyphen: the hyphen ends on the edge too. + let text = "A\tinternationalization"; + let mut hyphenated = area(text, style(13.0), Rect::new(0.0, 0.0, 100.0, 200.0), Justify::Right); + hyphenated.para.hyphenate = true; + hyphenated.para.composer = vectorcraft_doc::Composer::SingleLine; + let lay = layout(db(), &hyphenated); + let line = &lay.lines[0]; + assert!(line.end > 2 && line.end < text.len(), "the first line breaks inside the word: {line:?}"); + let last = lay.glyphs.get(line.glyph_end - 1).unwrap(); + assert!((last.origin.x + last.advance - 100.0).abs() < 1e-6, "the hyphen ends at {}", last.origin.x + last.advance); // Without a tab, the line is right aligned as a whole. let lay = layout(db(), &area("Name", style(13.0), frame, Justify::Right)); assert!(lay.glyphs.first().unwrap().origin.x > 200.0);