Split paragraphs at line boundaries across pages
This commit is contained in:
1 parent
daf9f5c57e
commit
b7b75fbff1
8 files changed
+263
-77
No files matched your search
@@ -294,6 +294,43 @@ impl Paragraph {
|
||||
pub fn line_count(&self) -> usize {
|
||||
self.lines.len()
|
||||
}
|
||||
|
||||
/// Move every line after `lines` into a new paragraph that starts at the
|
||||
/// remaining baselines. Used to continue a paragraph on the next page.
|
||||
pub fn split_at(&mut self, lines: usize) -> Paragraph {
|
||||
let lines = lines.min(self.lines.len().saturating_sub(1));
|
||||
let total = self.lines.len().max(1) as i64;
|
||||
let line_height = (self.height / total).max(1);
|
||||
let head_height = line_height * lines as i64;
|
||||
let tail_lines = self.lines.split_off(lines);
|
||||
let tail_indents = if self.line_indents.len() > lines {
|
||||
self.line_indents.split_off(lines)
|
||||
} else {
|
||||
Vec::new()
|
||||
};
|
||||
let tail_baselines = if self.line_baselines.len() > lines {
|
||||
self.line_baselines
|
||||
.split_off(lines)
|
||||
.into_iter()
|
||||
.map(|baseline| baseline - head_height)
|
||||
.collect()
|
||||
} else {
|
||||
Vec::new()
|
||||
};
|
||||
let tail_height = (self.height - head_height).max(1);
|
||||
self.height = head_height;
|
||||
Paragraph {
|
||||
lines: tail_lines,
|
||||
height: tail_height,
|
||||
width: self.width,
|
||||
font: self.font,
|
||||
left_skip: self.left_skip,
|
||||
line_indents: tail_indents,
|
||||
line_baselines: tail_baselines,
|
||||
centered: self.centered,
|
||||
right_aligned: self.right_aligned,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Convert text into a horizontal item stream: one box per character, one
|
||||
|
||||
Reference in new issue
Block a user