From a3b942021f8d3e28fb6b3c73ab2a920b74c5da80 Mon Sep 17 00:00:00 2001 From: Eric Kaden <608341+EricKaden@users.noreply.github.com> Date: Mon, 19 Oct 2026 23:46:45 -0400 Subject: [PATCH] M12: doc comments, and words keeps its own --- crates/xfa/src/tests.rs | 3 +++ crates/xfa/src/text.rs | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/crates/xfa/src/tests.rs b/crates/xfa/src/tests.rs index 9784986feb..1d027162b2 100644 --- a/crates/xfa/src/tests.rs +++ b/crates/xfa/src/tests.rs @@ -2085,6 +2085,8 @@ fn draw_spans(xdp: &str) -> Vec { layout_xml(xdp).unwrap().pages[0].items.iter().filter_map(|i| if let Item::Text(s) = i { Some(s.clone()) } else { None }).collect() } +/// A label that fits its box but is written with trailing spaces stays on one line and measures +/// as tall as without them; text wider than the box still wraps. #[test] fn a_space_at_the_end_of_a_line_does_not_count_when_fitting_it() { // The box is just wide enough for "a. DATE"; the label is written "a. DATE " (as forms @@ -2107,6 +2109,7 @@ fn a_space_at_the_end_of_a_line_does_not_count_when_fitting_it() { assert_eq!(baselines.len(), 2, "{spans:?}"); } +/// Centered and right-aligned text is placed by its drawn width, whatever spaces follow it. #[test] fn trailing_spaces_do_not_shift_centered_or_right_aligned_text() { let w = 200.0; diff --git a/crates/xfa/src/text.rs b/crates/xfa/src/text.rs index cbfd9fbc52..76035a2c4d 100644 --- a/crates/xfa/src/text.rs +++ b/crates/xfa/src/text.rs @@ -144,7 +144,6 @@ struct Word { width: f64, } -/// Break the runs of a paragraph into words (spaces stay attached to the word before them). /// The width of `w` without the spaces it ends with: what it takes at the end of a line, where /// a space is never drawn. fn ink_width(w: &Word) -> f64 { @@ -152,6 +151,7 @@ fn ink_width(w: &Word) -> f64 { if ink.len() == w.text.len() { w.width } else { w.face.width(ink) } } +/// Break the runs of a paragraph into words (spaces stay attached to the word before them). fn words(runs: &[Run], base: &Face, embed: &dyn Fn(&str) -> String) -> Vec { let mut out = Vec::new(); for run in runs {