Reserve right skip in route-D paragraph lines

This commit is contained in:
gloamxun committed 2026-10-20 18:47:52 +08:00
1 parent 5c0946f990
commit 7e45732602
1 file changed
+20 -1
+20 -1
View File
@@ -35,6 +35,8 @@ pub enum HorizontalItem {
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct ParagraphStyle {
pub line_width: i64,
/// Right skip reserved at the end of every line (`\rightskip`).
pub right_skip: i64,
pub par_indent: i64,
pub line_height: i64,
pub char_width: i64,
@@ -47,6 +49,7 @@ impl Default for ParagraphStyle {
fn default() -> Self {
Self {
line_width: 400,
right_skip: 0,
par_indent: 0,
line_height: 12,
char_width: 10,
@@ -203,7 +206,7 @@ pub fn layout_items(items: &[HorizontalItem], style: &ParagraphStyle) -> Paragra
if !has_box {
continue;
}
let target = style.line_width
let target = (style.line_width - style.right_skip).max(1)
- if start_index == 0 {
style.par_indent
} else {
@@ -502,6 +505,22 @@ mod tests {
assert!(paragraph.height > 0);
}
#[test]
fn right_skip_narrows_the_measure() {
let narrow = ParagraphStyle {
line_width: 150,
right_skip: 50,
..ParagraphStyle::default()
};
let full = ParagraphStyle {
line_width: 150,
..ParagraphStyle::default()
};
let text = "alpha beta gamma delta epsilon zeta eta theta";
let narrow_lines = layout_paragraph(text, &narrow).lines.len();
let full_lines = layout_paragraph(text, &full).lines.len();
assert!(narrow_lines > full_lines);
}
#[test]
fn empty_paragraph_has_no_lines() {
assert_eq!(layout_paragraph("", &ParagraphStyle::default()).height, 0);