From 7e45732602e89aa2e9e63164b6eee4c39f05b57c Mon Sep 17 00:00:00 2001 From: GloamXun Date: Tue, 20 Oct 2026 18:47:52 +0800 Subject: [PATCH] Reserve right skip in route-D paragraph lines --- crates/texrra-tex-core/src/paragraph.rs | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/crates/texrra-tex-core/src/paragraph.rs b/crates/texrra-tex-core/src/paragraph.rs index 857b710..a43a116 100755 --- a/crates/texrra-tex-core/src/paragraph.rs +++ b/crates/texrra-tex-core/src/paragraph.rs @@ -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);