Carry plus and minus on inter-paragraph skip glue
This commit is contained in:
1 parent
6f1310a876
commit
08a312be82
4 files changed
+101
-13
No files matched your search
@@ -670,6 +670,12 @@ pub struct Document {
|
|||||||
/// TeX `\parskip`: vertical glue inserted between paragraphs.
|
/// TeX `\parskip`: vertical glue inserted between paragraphs.
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub par_skip: i64,
|
pub par_skip: i64,
|
||||||
|
/// TeX stretch for the `\parskip` glue inserted between paragraphs.
|
||||||
|
#[serde(default)]
|
||||||
|
pub par_skip_stretch: i64,
|
||||||
|
/// TeX shrink for the `\parskip` glue inserted between paragraphs.
|
||||||
|
#[serde(default)]
|
||||||
|
pub par_skip_shrink: i64,
|
||||||
/// Extra horizontal displacement of the page origin (`\hoffset`).
|
/// Extra horizontal displacement of the page origin (`\hoffset`).
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub h_offset: i64,
|
pub h_offset: i64,
|
||||||
@@ -767,6 +773,8 @@ impl Document {
|
|||||||
text_float_sep: default_text_float_sep(),
|
text_float_sep: default_text_float_sep(),
|
||||||
in_text_sep: default_in_text_sep(),
|
in_text_sep: default_in_text_sep(),
|
||||||
par_skip: 0,
|
par_skip: 0,
|
||||||
|
par_skip_stretch: 0,
|
||||||
|
par_skip_shrink: 0,
|
||||||
h_offset: 0,
|
h_offset: 0,
|
||||||
v_offset: 0,
|
v_offset: 0,
|
||||||
max_deadcycles: default_max_deadcycles(),
|
max_deadcycles: default_max_deadcycles(),
|
||||||
@@ -887,11 +895,15 @@ fn document_nodes(
|
|||||||
if position == 0 && previous_paragraph && matches!(item, VerticalItem::Paragraph(_)) {
|
if position == 0 && previous_paragraph && matches!(item, VerticalItem::Paragraph(_)) {
|
||||||
nodes.push(VerticalNode::Glue(VerticalGlue::new(
|
nodes.push(VerticalNode::Glue(VerticalGlue::new(
|
||||||
document.par_skip,
|
document.par_skip,
|
||||||
0,
|
document.par_skip_stretch,
|
||||||
0,
|
document.par_skip_shrink,
|
||||||
)));
|
)));
|
||||||
owners.push(index);
|
owners.push(index);
|
||||||
items.push(VerticalItem::Glue(document.par_skip));
|
items.push(VerticalItem::StretchGlue(VerticalGlue::new(
|
||||||
|
document.par_skip,
|
||||||
|
document.par_skip_stretch,
|
||||||
|
document.par_skip_shrink,
|
||||||
|
)));
|
||||||
}
|
}
|
||||||
let node = match item {
|
let node = match item {
|
||||||
VerticalItem::Box(vertical_box) => VerticalNode::Box {
|
VerticalItem::Box(vertical_box) => VerticalNode::Box {
|
||||||
@@ -1104,6 +1116,8 @@ fn place_paragraph_flow(
|
|||||||
page_goal: i64,
|
page_goal: i64,
|
||||||
top_skip: i64,
|
top_skip: i64,
|
||||||
par_skip: i64,
|
par_skip: i64,
|
||||||
|
par_skip_stretch: i64,
|
||||||
|
par_skip_shrink: i64,
|
||||||
bottom: i64,
|
bottom: i64,
|
||||||
) {
|
) {
|
||||||
let mut pending = paragraph.clone();
|
let mut pending = paragraph.clone();
|
||||||
@@ -1114,6 +1128,16 @@ fn place_paragraph_flow(
|
|||||||
} else {
|
} else {
|
||||||
par_skip
|
par_skip
|
||||||
};
|
};
|
||||||
|
let skip_stretch = if current.items.is_empty() {
|
||||||
|
0
|
||||||
|
} else {
|
||||||
|
par_skip_stretch
|
||||||
|
};
|
||||||
|
let skip_shrink = if current.items.is_empty() {
|
||||||
|
0
|
||||||
|
} else {
|
||||||
|
par_skip_shrink
|
||||||
|
};
|
||||||
let base = if at_top { top_skip } else { *used + skip };
|
let base = if at_top { top_skip } else { *used + skip };
|
||||||
let available = page_goal - *insertion_height - bottom - base;
|
let available = page_goal - *insertion_height - bottom - base;
|
||||||
let lines = pending.lines.len();
|
let lines = pending.lines.len();
|
||||||
@@ -1121,8 +1145,14 @@ fn place_paragraph_flow(
|
|||||||
if at_top {
|
if at_top {
|
||||||
*used = top_skip.max(pending.height);
|
*used = top_skip.max(pending.height);
|
||||||
} else {
|
} else {
|
||||||
if skip > 0 {
|
if skip != 0 || skip_stretch != 0 || skip_shrink != 0 {
|
||||||
current.items.push(VerticalItem::Glue(skip));
|
current
|
||||||
|
.items
|
||||||
|
.push(VerticalItem::StretchGlue(VerticalGlue::new(
|
||||||
|
skip,
|
||||||
|
skip_stretch,
|
||||||
|
skip_shrink,
|
||||||
|
)));
|
||||||
}
|
}
|
||||||
*used = base + pending.height;
|
*used = base + pending.height;
|
||||||
}
|
}
|
||||||
@@ -1148,8 +1178,14 @@ fn place_paragraph_flow(
|
|||||||
if at_top {
|
if at_top {
|
||||||
*used = top_skip.max(head.height);
|
*used = top_skip.max(head.height);
|
||||||
} else {
|
} else {
|
||||||
if skip > 0 {
|
if skip != 0 || skip_stretch != 0 || skip_shrink != 0 {
|
||||||
current.items.push(VerticalItem::Glue(skip));
|
current
|
||||||
|
.items
|
||||||
|
.push(VerticalItem::StretchGlue(VerticalGlue::new(
|
||||||
|
skip,
|
||||||
|
skip_stretch,
|
||||||
|
skip_shrink,
|
||||||
|
)));
|
||||||
}
|
}
|
||||||
*used = base + head.height;
|
*used = base + head.height;
|
||||||
}
|
}
|
||||||
@@ -1533,6 +1569,8 @@ impl Engine {
|
|||||||
document.page_goal,
|
document.page_goal,
|
||||||
document.top_skip,
|
document.top_skip,
|
||||||
document.par_skip.max(0),
|
document.par_skip.max(0),
|
||||||
|
document.par_skip_stretch.max(0),
|
||||||
|
document.par_skip_shrink.max(0),
|
||||||
bottom,
|
bottom,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -2296,7 +2334,10 @@ impl Engine {
|
|||||||
// replaying at the unit's first real item instead.
|
// replaying at the unit's first real item instead.
|
||||||
while first_node < nodes.len()
|
while first_node < nodes.len()
|
||||||
&& owners[first_node] == unit_index
|
&& owners[first_node] == unit_index
|
||||||
&& matches!(node_items[first_node], VerticalItem::Glue(_))
|
&& matches!(
|
||||||
|
node_items[first_node],
|
||||||
|
VerticalItem::Glue(_) | VerticalItem::StretchGlue(_)
|
||||||
|
)
|
||||||
&& !matches!(
|
&& !matches!(
|
||||||
document.units[unit_index].items.first(),
|
document.units[unit_index].items.first(),
|
||||||
Some(VerticalItem::Glue(_))
|
Some(VerticalItem::Glue(_))
|
||||||
@@ -2595,6 +2636,8 @@ impl Engine {
|
|||||||
next.page_goal,
|
next.page_goal,
|
||||||
next.top_skip,
|
next.top_skip,
|
||||||
next.par_skip.max(0),
|
next.par_skip.max(0),
|
||||||
|
next.par_skip_stretch.max(0),
|
||||||
|
next.par_skip_shrink.max(0),
|
||||||
bottom,
|
bottom,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -5887,6 +5930,29 @@ mod tests {
|
|||||||
assert_eq!(engine.pages()[0].sources, vec![(1, source_hash(""))]);
|
assert_eq!(engine.pages()[0].sources, vec![(1, source_hash(""))]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn paragraph_skip_carries_its_stretch_into_pages() {
|
||||||
|
let first = Unit::paragraph(1, "alpha beta gamma delta epsilon zeta");
|
||||||
|
let second = Unit::paragraph(2, "eta theta iota kappa lambda mu nu");
|
||||||
|
let mut document = Document::new(550 * 65_536, vec![first, second]);
|
||||||
|
document.top_skip = 12 * 65_536;
|
||||||
|
document.par_skip_stretch = 6 * 65_536;
|
||||||
|
document.par_skip_shrink = 2 * 65_536;
|
||||||
|
let engine = Engine::layout_paged(&document).expect("paged layout");
|
||||||
|
let page = &engine.pages()[0];
|
||||||
|
assert!(
|
||||||
|
page.items.iter().any(|item| matches!(
|
||||||
|
item,
|
||||||
|
VerticalItem::StretchGlue(glue)
|
||||||
|
if glue.width == 0
|
||||||
|
&& glue.stretch == 6 * 65_536
|
||||||
|
&& glue.shrink == 2 * 65_536
|
||||||
|
)),
|
||||||
|
"parskip stretch missing from page items: {:?}",
|
||||||
|
page.items
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn paged_layout_inserts_par_skip_between_paragraphs() {
|
fn paged_layout_inserts_par_skip_between_paragraphs() {
|
||||||
let mut style = ParagraphStyle::default();
|
let mut style = ParagraphStyle::default();
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ floats (`\floatsep`, `\textfloatsep`, `\intextsep`, `\topfraction`,
|
|||||||
`\bottomnumber`, `\totalnumber`), insertion classes (`\skip`, fraction and
|
`\bottomnumber`, `\totalnumber`), insertion classes (`\skip`, fraction and
|
||||||
absolute limits, splitting), marks, Rust output hook, multi-page PDF, and the
|
absolute limits, splitting), marks, Rust output hook, multi-page PDF, and the
|
||||||
route-D service endpoints (`/api/route-d/preview|pdf|edit`, project preview and
|
route-D service endpoints (`/api/route-d/preview|pdf|edit`, project preview and
|
||||||
PDF opt-in with `?engine=route-d`). 447 workspace tests are green and no oracle
|
PDF opt-in with `?engine=route-d`). 449 workspace tests are green and no oracle
|
||||||
fixture is ignored.
|
fixture is ignored.
|
||||||
|
|
||||||
Known gaps, in dependency order:
|
Known gaps, in dependency order:
|
||||||
@@ -63,6 +63,7 @@ source-level `\hyphenation{...}` exceptions and `\parshape` measures,
|
|||||||
with or without `fil`, default `\sfcode` sentence spacing,
|
with or without `fil`, default `\sfcode` sentence spacing,
|
||||||
`\looseness`, and `\baselineskip`/`\lineskip`/`\parskip` interline
|
`\looseness`, and `\baselineskip`/`\lineskip`/`\parskip` interline
|
||||||
glue), custom `\sfcode` overrides, explicit `\spaceskip`/`\xspaceskip`,
|
glue), custom `\sfcode` overrides, explicit `\spaceskip`/`\xspaceskip`,
|
||||||
|
stretch and shrink on the inter-paragraph `\parskip` glue,
|
||||||
`\raggedright` (infinite `\rightskip` fil), explicit
|
`\raggedright` (infinite `\rightskip` fil), explicit
|
||||||
`\hfil`/`\hfill` glue orders, and `\prevgraf` visibility in the output
|
`\hfil`/`\hfill` glue orders, and `\prevgraf` visibility in the output
|
||||||
routine;
|
routine;
|
||||||
|
|||||||
+3
-2
@@ -358,7 +358,7 @@ Math coverage includes fractions/roots, scripts, `\left...\right` with body-scal
|
|||||||
|
|
||||||
Paragraph units carry a `ParagraphFont`; `Unit::paragraph_with_face` and `Unit::paragraph_with_style_and_face` select Roman, bold, italic, mono, or sans. The corresponding Computer Modern TFM (`cmr10`, `cmbx10`, `cmti10`, `cmbxti10`, `cmtt10`, `cmss10`) supplies advances, kerns, ligatures, and italic correction for layout, while the display list and PDF select the matching Liberation face. `Engine::edit` preserves the face when reflowing an edited paragraph.
|
Paragraph units carry a `ParagraphFont`; `Unit::paragraph_with_face` and `Unit::paragraph_with_style_and_face` select Roman, bold, italic, mono, or sans. The corresponding Computer Modern TFM (`cmr10`, `cmbx10`, `cmti10`, `cmbxti10`, `cmtt10`, `cmss10`) supplies advances, kerns, ligatures, and italic correction for layout, while the display list and PDF select the matching Liberation face. `Engine::edit` preserves the face when reflowing an edited paragraph.
|
||||||
|
|
||||||
The crate currently has 296 unit tests plus seven route-D integration tests and thirty oracle fixtures. Workspace verification: `cargo fmt --all -- --check`; `cargo test --workspace --offline` runs 447 tests (296 route-D unit, 7 route-D integration, 30 oracle, 71 v1 integration, 26 server, 4 v1 unit, 1 core unit, 12 binary units), with none ignored. v1 remains the live server path.
|
The crate currently has 297 unit tests plus seven route-D integration tests and thirty oracle fixtures. Workspace verification: `cargo fmt --all -- --check`; `cargo test --workspace --offline` runs 449 tests (297 route-D unit, 7 route-D integration, 30 oracle, 71 v1 integration, 26 server, 4 v1 unit, 1 core unit, 12 binary units), with none ignored. v1 remains the live server path.
|
||||||
|
|
||||||
### M0 incremental demo
|
### M0 incremental demo
|
||||||
|
|
||||||
@@ -391,7 +391,8 @@ deliberately open rather than approximated:
|
|||||||
`\hyphenation` exceptions, `\hangindent`/`\parshape`, `\parfillskip` with
|
`\hyphenation` exceptions, `\hangindent`/`\parshape`, `\parfillskip` with
|
||||||
or without `fil`, `\looseness`, `\baselineskip`/`\lineskip`/`\parskip`
|
or without `fil`, `\looseness`, `\baselineskip`/`\lineskip`/`\parskip`
|
||||||
interline glue, the default `\sfcode`/`\frenchspacing` sentence spacing,
|
interline glue, the default `\sfcode`/`\frenchspacing` sentence spacing,
|
||||||
explicit `\spaceskip`/`\xspaceskip`, and `\raggedright` (infinite `\rightskip` fil) are modelled.
|
explicit `\spaceskip`/`\xspaceskip`, stretch and shrink on the
|
||||||
|
inter-paragraph `\parskip` glue, and `\raggedright` (infinite `\rightskip` fil) are modelled.
|
||||||
- **M2**: the scrolling builder still drives `Document`; `page::PageBuilder`
|
- **M2**: the scrolling builder still drives `Document`; `page::PageBuilder`
|
||||||
implements TeX's candidate-breakpoint cost (badness + penalty, glue
|
implements TeX's candidate-breakpoint cost (badness + penalty, glue
|
||||||
stretch/shrink, `\topskip`, `\maxdepth`); a break at glue is only legal
|
stretch/shrink, `\topskip`, `\maxdepth`); a break at glue is only legal
|
||||||
|
|||||||
+22
-2
@@ -109,6 +109,8 @@ struct PageGeometry {
|
|||||||
textheight: Option<i64>,
|
textheight: Option<i64>,
|
||||||
par_indent: Option<i64>,
|
par_indent: Option<i64>,
|
||||||
par_skip: Option<i64>,
|
par_skip: Option<i64>,
|
||||||
|
par_skip_stretch: Option<i64>,
|
||||||
|
par_skip_shrink: Option<i64>,
|
||||||
baseline_skip: Option<i64>,
|
baseline_skip: Option<i64>,
|
||||||
left_skip: Option<i64>,
|
left_skip: Option<i64>,
|
||||||
right_skip: Option<i64>,
|
right_skip: Option<i64>,
|
||||||
@@ -161,8 +163,10 @@ fn strip_page_geometry(source: &str) -> (String, PageGeometry) {
|
|||||||
geometry.textheight = Some(value);
|
geometry.textheight = Some(value);
|
||||||
} else if let Some(value) = dimension_assignment(trimmed, "parindent") {
|
} else if let Some(value) = dimension_assignment(trimmed, "parindent") {
|
||||||
geometry.par_indent = Some(value);
|
geometry.par_indent = Some(value);
|
||||||
} else if let Some(value) = dimension_assignment(trimmed, "parskip") {
|
} else if let Some((width, stretch, shrink)) = glue_assignment(trimmed, "parskip") {
|
||||||
geometry.par_skip = Some(value);
|
geometry.par_skip = Some(width);
|
||||||
|
geometry.par_skip_stretch = Some(stretch);
|
||||||
|
geometry.par_skip_shrink = Some(shrink);
|
||||||
} else if let Some(value) = dimension_assignment(trimmed, "baselineskip") {
|
} else if let Some(value) = dimension_assignment(trimmed, "baselineskip") {
|
||||||
geometry.baseline_skip = Some(value);
|
geometry.baseline_skip = Some(value);
|
||||||
} else if let Some(value) = dimension_assignment(trimmed, "leftskip") {
|
} else if let Some(value) = dimension_assignment(trimmed, "leftskip") {
|
||||||
@@ -254,6 +258,12 @@ fn apply_geometry(document: &mut Document, geometry: &PageGeometry) {
|
|||||||
if let Some(skip) = geometry.par_skip {
|
if let Some(skip) = geometry.par_skip {
|
||||||
document.par_skip = skip;
|
document.par_skip = skip;
|
||||||
}
|
}
|
||||||
|
if let Some(stretch) = geometry.par_skip_stretch {
|
||||||
|
document.par_skip_stretch = stretch;
|
||||||
|
}
|
||||||
|
if let Some(shrink) = geometry.par_skip_shrink {
|
||||||
|
document.par_skip_shrink = shrink;
|
||||||
|
}
|
||||||
if let Some(skip) = geometry.top_skip {
|
if let Some(skip) = geometry.top_skip {
|
||||||
document.top_skip = skip;
|
document.top_skip = skip;
|
||||||
}
|
}
|
||||||
@@ -1064,6 +1074,16 @@ mod source_tests {
|
|||||||
assert_eq!(style.lineskip, 2 * SCALE);
|
assert_eq!(style.lineskip, 2 * SCALE);
|
||||||
assert_eq!(style.lineskiplimit, 3 * SCALE);
|
assert_eq!(style.lineskiplimit, 3 * SCALE);
|
||||||
}
|
}
|
||||||
|
#[test]
|
||||||
|
fn geometry_reads_stretchy_parskip() {
|
||||||
|
let source = "\\documentclass{article}\n\\parskip=2pt plus 5pt minus 1pt\n\\begin{document}\n\nSome words here.\n\n\\end{document}\n";
|
||||||
|
let (body, geometry) = geometry_and_body(source);
|
||||||
|
assert!(!body.contains("parskip"));
|
||||||
|
assert_eq!(geometry.par_skip, Some(2 * 65_536));
|
||||||
|
assert_eq!(geometry.par_skip_stretch, Some(5 * 65_536));
|
||||||
|
assert_eq!(geometry.par_skip_shrink, Some(65_536));
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn geometry_reads_page_skip_registers() {
|
fn geometry_reads_page_skip_registers() {
|
||||||
let source = "\\documentclass{article}\n\\topskip=10pt\n\\maxdepth=5pt\n\\splittopskip=3pt\n\\begin{document}\n\nSome words here.\n\n\\end{document}\n";
|
let source = "\\documentclass{article}\n\\topskip=10pt\n\\maxdepth=5pt\n\\splittopskip=3pt\n\\begin{document}\n\nSome words here.\n\n\\end{document}\n";
|
||||||
|
|||||||
Reference in new issue
Block a user