Read hyphenation exceptions from route-D sources
This commit is contained in:
1 parent
e00e0038c1
commit
f86b507615
3 files changed
+52
-5
No files matched your search
@@ -48,13 +48,14 @@ 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`). 428 workspace tests are green and no oracle
|
||||
PDF opt-in with `?engine=route-d`). 429 workspace tests are green and no oracle
|
||||
fixture is ignored.
|
||||
|
||||
Known gaps, in dependency order:
|
||||
|
||||
1. paragraph breaking reproduces TeX's passes and demerits (including
|
||||
`\adjdemerits`, `\doublehyphendemerits`, `\finalhyphendemerits`,
|
||||
and source-level `\hyphenation{...}` exceptions,
|
||||
`\hyphenpenalty`, `\exhyphenpenalty`, `\hyphenation` exceptions,
|
||||
`\hangindent`/`\hangafter`/`\parshape` line geometry, `\parfillskip`
|
||||
with or without `fil`, default `\sfcode` sentence spacing,
|
||||
|
||||
+3
-2
@@ -77,7 +77,8 @@ honours the same offsets. The bounds and hyphen demerits are `ParagraphStyle`
|
||||
fields mirroring `\pretolerance`, `\tolerance`, `\hyphenpenalty` and
|
||||
`\exhyphenpenalty`, `\linepenalty`, `\adjdemerits`,
|
||||
`\doublehyphendemerits`, `\finalhyphendemerits` and `\emergencystretch`,
|
||||
plus document-level `\hyphenation` exceptions; `\hyphenpenalty` at 10000 or
|
||||
plus document-level `\hyphenation` exceptions (the route-D service reads
|
||||
`\hyphenation{...}` lines from the source); `\hyphenpenalty` at 10000 or
|
||||
more disables hyphenation and switches the fallback to a first-fit scan.
|
||||
|
||||
`tests/oracle.rs` compares a matrix of measures (90, 100, 110, 120, 130, 150, 160, 180, 200, 220 and
|
||||
@@ -346,7 +347,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 428 tests (289 route-D unit, 7 route-D integration, 27 oracle, 71 v1 integration, 26 server, 4 v1 unit, 1 core unit, 3 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 429 tests (289 route-D unit, 7 route-D integration, 27 oracle, 71 v1 integration, 26 server, 4 v1 unit, 1 core unit, 4 binary units), with none ignored. v1 remains the live server path.
|
||||
|
||||
### M0 incremental demo
|
||||
|
||||
|
||||
+47
-2
@@ -100,7 +100,7 @@ pub fn project_preview_json(project_id: &str, source: &str) -> Result<String, St
|
||||
}
|
||||
|
||||
/// Page geometry pulled out of the source preamble.
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq)]
|
||||
struct PageGeometry {
|
||||
origin: PageOrigin,
|
||||
paper_width: Option<i64>,
|
||||
@@ -121,6 +121,7 @@ struct PageGeometry {
|
||||
french_spacing: Option<bool>,
|
||||
space_skip: Option<(i64, i64, i64)>,
|
||||
xspace_skip: Option<(i64, i64, i64)>,
|
||||
hyphenation_exceptions: Vec<String>,
|
||||
}
|
||||
|
||||
/// Pull `\hoffset`/`\voffset`/`\paperwidth`/`\paperheight`/`\vsize`/
|
||||
@@ -170,6 +171,10 @@ fn strip_page_geometry(source: &str) -> (String, PageGeometry) {
|
||||
geometry.space_skip = Some(value);
|
||||
} else if let Some(value) = glue_assignment(trimmed, "xspaceskip") {
|
||||
geometry.xspace_skip = Some(value);
|
||||
} else if let Some(value) = braced_argument(trimmed, "\\hyphenation") {
|
||||
geometry
|
||||
.hyphenation_exceptions
|
||||
.extend(value.split_whitespace().map(str::to_string));
|
||||
} else if trimmed == "\\frenchspacing" {
|
||||
geometry.french_spacing = Some(true);
|
||||
} else if trimmed == "\\nonfrenchspacing" {
|
||||
@@ -209,6 +214,26 @@ fn apply_geometry(document: &mut Document, geometry: &PageGeometry) {
|
||||
}
|
||||
}
|
||||
|
||||
/// Read a braced argument such as `\hyphenation{hy-phen-a-tion}`.
|
||||
fn braced_argument<'a>(line: &'a str, command: &str) -> Option<&'a str> {
|
||||
let rest = line.strip_prefix(command)?.trim_start();
|
||||
let rest = rest.strip_prefix('{')?;
|
||||
let mut depth = 1_usize;
|
||||
for (index, character) in rest.char_indices() {
|
||||
match character {
|
||||
'{' => depth += 1,
|
||||
'}' => {
|
||||
depth -= 1;
|
||||
if depth == 0 {
|
||||
return Some(&rest[..index]);
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
/// Read a plain integer assignment such as `\tolerance=1000`.
|
||||
fn glue_assignment(line: &str, name: &str) -> Option<(i64, i64, i64)> {
|
||||
let rest = line.strip_prefix('\\')?;
|
||||
@@ -576,7 +601,7 @@ fn build_document(paragraphs: &[SourceParagraph], geometry: &PageGeometry) -> Do
|
||||
final_hyphen_demerits: 5_000,
|
||||
line_penalty: 10,
|
||||
adj_demerits: 10_000,
|
||||
hyphenation_exceptions: Vec::new(),
|
||||
hyphenation_exceptions: geometry.hyphenation_exceptions.clone(),
|
||||
line_height: if paragraph.line_height == 12 {
|
||||
geometry.baseline_skip.unwrap_or(12 * 65536)
|
||||
} else {
|
||||
@@ -759,4 +784,24 @@ mod source_tests {
|
||||
assert_eq!(style.space_skip, Some((6 * pt, pt, pt / 2)));
|
||||
assert!(style.frenchspacing);
|
||||
}
|
||||
#[test]
|
||||
fn geometry_reads_hyphenation_exceptions() {
|
||||
let source = "\\documentclass{article}\n\\hyphenation{zzz-zzz alpha-beta}\n\\begin{document}\n\nzzzzzz\n\n\\end{document}\n";
|
||||
let (body, geometry) = geometry_and_body(source);
|
||||
assert_eq!(
|
||||
geometry.hyphenation_exceptions,
|
||||
vec!["zzz-zzz".to_string(), "alpha-beta".to_string()]
|
||||
);
|
||||
assert!(!body.contains("hyphenation"));
|
||||
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.hyphenation_exceptions,
|
||||
geometry.hyphenation_exceptions
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user