Read demerit registers from route-D sources
This commit is contained in:
1 parent
e823a1f415
commit
de35d1bcae
3 files changed
+56
-12
No files matched your search
@@ -48,7 +48,7 @@ floats (`\floatsep`, `\textfloatsep`, `\intextsep`, `\topfraction`,
|
||||
`\bottomnumber`, `\totalnumber`), insertion classes (`\skip`, fraction and
|
||||
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
|
||||
PDF opt-in with `?engine=route-d`). 432 workspace tests are green and no oracle
|
||||
PDF opt-in with `?engine=route-d`). 433 workspace tests are green and no oracle
|
||||
fixture is ignored.
|
||||
|
||||
Known gaps, in dependency order:
|
||||
@@ -56,8 +56,8 @@ Known gaps, in dependency order:
|
||||
1. paragraph breaking reproduces TeX's passes and demerits (including
|
||||
`\adjdemerits`, `\doublehyphendemerits`, `\finalhyphendemerits`,
|
||||
source-level `\hyphenation{...}` exceptions and `\parshape` measures,
|
||||
`\parfillskip`, `\lineskip`, `\lineskiplimit`, `\topskip`, `\maxdepth`
|
||||
and `\splittopskip`,
|
||||
`\parfillskip`, `\lineskip`, `\lineskiplimit`, `\topskip`, `\maxdepth`,
|
||||
`\splittopskip` and the demerit registers,
|
||||
`\hyphenpenalty`, `\exhyphenpenalty`, `\hyphenation` exceptions,
|
||||
`\hangindent`/`\hangafter`/`\parshape` line geometry, `\parfillskip`
|
||||
with or without `fil`, default `\sfcode` sentence spacing,
|
||||
|
||||
+5
-3
@@ -74,8 +74,10 @@ and clamps shrink at the declared limit, so overfull lines stay overfull
|
||||
exactly as in TeX. Each line can take its measure and left offset from
|
||||
`\hangindent`/`\hangafter` or an explicit `\parshape` list (the route-D
|
||||
service reads `\parshape=...`, `\parfillskip`, `\lineskip`,
|
||||
`\lineskiplimit`, `\topskip`, `\maxdepth` and `\splittopskip` lines from the
|
||||
source); the display list
|
||||
`\lineskiplimit`, `\topskip`, `\maxdepth`, `\splittopskip` and the demerit
|
||||
registers (`\hyphenpenalty`, `\exhyphenpenalty`, `\doublehyphendemerits`,
|
||||
`\finalhyphendemerits`, `\linepenalty`, `\adjdemerits`) from the source); the
|
||||
display list
|
||||
honours the same offsets. The bounds and hyphen demerits are `ParagraphStyle`
|
||||
fields mirroring `\pretolerance`, `\tolerance`, `\hyphenpenalty` and
|
||||
`\exhyphenpenalty`, `\linepenalty`, `\adjdemerits`,
|
||||
@@ -350,7 +352,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.
|
||||
|
||||
The crate currently has 289 unit tests plus seven route-D integration tests and twenty-seven oracle fixtures. Workspace verification: `cargo fmt --all -- --check`; `cargo test --workspace --offline` runs 432 tests (289 route-D unit, 7 route-D integration, 27 oracle, 71 v1 integration, 26 server, 4 v1 unit, 1 core unit, 7 binary units), with none ignored. v1 remains the live server path.
|
||||
The crate currently has 289 unit tests plus seven route-D integration tests and twenty-seven oracle fixtures. Workspace verification: `cargo fmt --all -- --check`; `cargo test --workspace --offline` runs 433 tests (289 route-D unit, 7 route-D integration, 27 oracle, 71 v1 integration, 26 server, 4 v1 unit, 1 core unit, 8 binary units), with none ignored. v1 remains the live server path.
|
||||
|
||||
### M0 incremental demo
|
||||
|
||||
|
||||
+48
-6
@@ -129,6 +129,12 @@ struct PageGeometry {
|
||||
top_skip: Option<i64>,
|
||||
max_depth: Option<i64>,
|
||||
split_top_skip: Option<i64>,
|
||||
hyphen_penalty: Option<i64>,
|
||||
ex_hyphen_penalty: Option<i64>,
|
||||
double_hyphen_demerits: Option<i64>,
|
||||
final_hyphen_demerits: Option<i64>,
|
||||
line_penalty: Option<i64>,
|
||||
adj_demerits: Option<i64>,
|
||||
}
|
||||
|
||||
/// Pull `\hoffset`/`\voffset`/`\paperwidth`/`\paperheight`/`\vsize`/
|
||||
@@ -182,6 +188,18 @@ fn strip_page_geometry(source: &str) -> (String, PageGeometry) {
|
||||
geometry.lineskip = Some(value);
|
||||
} else if let Some(value) = dimension_assignment(trimmed, "lineskiplimit") {
|
||||
geometry.lineskiplimit = Some(value);
|
||||
} else if let Some(value) = integer_assignment(trimmed, "hyphenpenalty") {
|
||||
geometry.hyphen_penalty = Some(value);
|
||||
} else if let Some(value) = integer_assignment(trimmed, "exhyphenpenalty") {
|
||||
geometry.ex_hyphen_penalty = Some(value);
|
||||
} else if let Some(value) = integer_assignment(trimmed, "doublehyphendemerits") {
|
||||
geometry.double_hyphen_demerits = Some(value);
|
||||
} else if let Some(value) = integer_assignment(trimmed, "finalhyphendemerits") {
|
||||
geometry.final_hyphen_demerits = Some(value);
|
||||
} else if let Some(value) = integer_assignment(trimmed, "linepenalty") {
|
||||
geometry.line_penalty = Some(value);
|
||||
} else if let Some(value) = integer_assignment(trimmed, "adjdemerits") {
|
||||
geometry.adj_demerits = Some(value);
|
||||
} else if let Some(value) = dimension_assignment(trimmed, "topskip") {
|
||||
geometry.top_skip = Some(value);
|
||||
} else if let Some(value) = dimension_assignment(trimmed, "maxdepth") {
|
||||
@@ -671,12 +689,12 @@ fn build_document(paragraphs: &[SourceParagraph], geometry: &PageGeometry) -> Do
|
||||
emergencystretch: geometry.emergency_stretch.unwrap_or(0),
|
||||
pretolerance: geometry.pretolerance.unwrap_or(100),
|
||||
tolerance: geometry.tolerance.unwrap_or(200),
|
||||
hyphen_penalty: 50,
|
||||
ex_hyphen_penalty: 50,
|
||||
double_hyphen_demerits: 10_000,
|
||||
final_hyphen_demerits: 5_000,
|
||||
line_penalty: 10,
|
||||
adj_demerits: 10_000,
|
||||
hyphen_penalty: geometry.hyphen_penalty.unwrap_or(50),
|
||||
ex_hyphen_penalty: geometry.ex_hyphen_penalty.unwrap_or(50),
|
||||
double_hyphen_demerits: geometry.double_hyphen_demerits.unwrap_or(10_000),
|
||||
final_hyphen_demerits: geometry.final_hyphen_demerits.unwrap_or(5_000),
|
||||
line_penalty: geometry.line_penalty.unwrap_or(10),
|
||||
adj_demerits: geometry.adj_demerits.unwrap_or(10_000),
|
||||
hyphenation_exceptions: geometry.hyphenation_exceptions.clone(),
|
||||
line_height: if paragraph.line_height == 12 {
|
||||
geometry.baseline_skip.unwrap_or(12 * 65536)
|
||||
@@ -931,4 +949,28 @@ mod source_tests {
|
||||
assert_eq!(document.max_depth, 5 * SCALE);
|
||||
assert_eq!(document.split_top_skip, 3 * SCALE);
|
||||
}
|
||||
#[test]
|
||||
fn geometry_reads_demerit_registers() {
|
||||
let source = "\\documentclass{article}\n\\hyphenpenalty=77\n\\exhyphenpenalty=88\n\\doublehyphendemerits=1234\n\\finalhyphendemerits=4321\n\\linepenalty=20\n\\adjdemerits=999\n\\begin{document}\n\nSome words here.\n\n\\end{document}\n";
|
||||
let (body, geometry) = geometry_and_body(source);
|
||||
assert_eq!(geometry.hyphen_penalty, Some(77));
|
||||
assert_eq!(geometry.ex_hyphen_penalty, Some(88));
|
||||
assert_eq!(geometry.double_hyphen_demerits, Some(1234));
|
||||
assert_eq!(geometry.final_hyphen_demerits, Some(4321));
|
||||
assert_eq!(geometry.line_penalty, Some(20));
|
||||
assert_eq!(geometry.adj_demerits, Some(999));
|
||||
assert!(!body.contains("hyphenpenalty"));
|
||||
let paragraphs = paragraphs(&body).expect("paragraphs");
|
||||
let document = build_document(¶graphs, &geometry);
|
||||
let style = document.units[0]
|
||||
.paragraph_style
|
||||
.clone()
|
||||
.expect("paragraph style");
|
||||
assert_eq!(style.hyphen_penalty, 77);
|
||||
assert_eq!(style.ex_hyphen_penalty, 88);
|
||||
assert_eq!(style.double_hyphen_demerits, 1234);
|
||||
assert_eq!(style.final_hyphen_demerits, 4321);
|
||||
assert_eq!(style.line_penalty, 20);
|
||||
assert_eq!(style.adj_demerits, 999);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user