mirror of
https://github.com/storytold/pdfcraft.git
synced 2026-11-01 22:19:10 -06:00
M12: doc comments, and words keeps its own
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user