M12: doc comments, and words keeps its own

This commit is contained in:
Eric Kaden
2026-10-19 23:46:56 -04:00
parent 6dc8ad933b
commit a3b942021f
2 changed files with 4 additions and 1 deletions
+3
View File
@@ -2085,6 +2085,8 @@ fn draw_spans(xdp: &str) -> Vec<text::Span> {
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;
+1 -1
View File
@@ -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<Word> {
let mut out = Vec::new();
for run in runs {