Read parshape measures from route-D sources
This commit is contained in:
1 parent
f86b507615
commit
dc68e76cd3
3 files changed
+41
-5
No files matched your search
@@ -48,14 +48,14 @@ 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`). 429 workspace tests are green and no oracle
|
PDF opt-in with `?engine=route-d`). 430 workspace tests are green and no oracle
|
||||||
fixture is ignored.
|
fixture is ignored.
|
||||||
|
|
||||||
Known gaps, in dependency order:
|
Known gaps, in dependency order:
|
||||||
|
|
||||||
1. paragraph breaking reproduces TeX's passes and demerits (including
|
1. paragraph breaking reproduces TeX's passes and demerits (including
|
||||||
`\adjdemerits`, `\doublehyphendemerits`, `\finalhyphendemerits`,
|
`\adjdemerits`, `\doublehyphendemerits`, `\finalhyphendemerits`,
|
||||||
and source-level `\hyphenation{...}` exceptions,
|
source-level `\hyphenation{...}` exceptions and `\parshape` measures,
|
||||||
`\hyphenpenalty`, `\exhyphenpenalty`, `\hyphenation` exceptions,
|
`\hyphenpenalty`, `\exhyphenpenalty`, `\hyphenation` exceptions,
|
||||||
`\hangindent`/`\hangafter`/`\parshape` line geometry, `\parfillskip`
|
`\hangindent`/`\hangafter`/`\parshape` line geometry, `\parfillskip`
|
||||||
with or without `fil`, default `\sfcode` sentence spacing,
|
with or without `fil`, default `\sfcode` sentence spacing,
|
||||||
|
|||||||
+3
-2
@@ -72,7 +72,8 @@ tolerance and otherwise the first prefix that overflows. Justification
|
|||||||
stretches normal glue past its nominal stretch (badness simply exceeds 100)
|
stretches normal glue past its nominal stretch (badness simply exceeds 100)
|
||||||
and clamps shrink at the declared limit, so overfull lines stay overfull
|
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
|
exactly as in TeX. Each line can take its measure and left offset from
|
||||||
`\hangindent`/`\hangafter` or an explicit `\parshape` list; the display list
|
`\hangindent`/`\hangafter` or an explicit `\parshape` list (the route-D
|
||||||
|
service reads `\parshape=...` lines from the source); the display list
|
||||||
honours the same offsets. The bounds and hyphen demerits are `ParagraphStyle`
|
honours the same offsets. The bounds and hyphen demerits are `ParagraphStyle`
|
||||||
fields mirroring `\pretolerance`, `\tolerance`, `\hyphenpenalty` and
|
fields mirroring `\pretolerance`, `\tolerance`, `\hyphenpenalty` and
|
||||||
`\exhyphenpenalty`, `\linepenalty`, `\adjdemerits`,
|
`\exhyphenpenalty`, `\linepenalty`, `\adjdemerits`,
|
||||||
@@ -347,7 +348,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 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.
|
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 430 tests (289 route-D unit, 7 route-D integration, 27 oracle, 71 v1 integration, 26 server, 4 v1 unit, 1 core unit, 5 binary units), with none ignored. v1 remains the live server path.
|
||||||
|
|
||||||
### M0 incremental demo
|
### M0 incremental demo
|
||||||
|
|
||||||
|
|||||||
+36
-1
@@ -122,6 +122,7 @@ struct PageGeometry {
|
|||||||
space_skip: Option<(i64, i64, i64)>,
|
space_skip: Option<(i64, i64, i64)>,
|
||||||
xspace_skip: Option<(i64, i64, i64)>,
|
xspace_skip: Option<(i64, i64, i64)>,
|
||||||
hyphenation_exceptions: Vec<String>,
|
hyphenation_exceptions: Vec<String>,
|
||||||
|
par_shape: Vec<(i64, i64)>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Pull `\hoffset`/`\voffset`/`\paperwidth`/`\paperheight`/`\vsize`/
|
/// Pull `\hoffset`/`\voffset`/`\paperwidth`/`\paperheight`/`\vsize`/
|
||||||
@@ -171,6 +172,8 @@ fn strip_page_geometry(source: &str) -> (String, PageGeometry) {
|
|||||||
geometry.space_skip = Some(value);
|
geometry.space_skip = Some(value);
|
||||||
} else if let Some(value) = glue_assignment(trimmed, "xspaceskip") {
|
} else if let Some(value) = glue_assignment(trimmed, "xspaceskip") {
|
||||||
geometry.xspace_skip = Some(value);
|
geometry.xspace_skip = Some(value);
|
||||||
|
} else if let Some(value) = parshape_assignment(trimmed) {
|
||||||
|
geometry.par_shape = value;
|
||||||
} else if let Some(value) = braced_argument(trimmed, "\\hyphenation") {
|
} else if let Some(value) = braced_argument(trimmed, "\\hyphenation") {
|
||||||
geometry
|
geometry
|
||||||
.hyphenation_exceptions
|
.hyphenation_exceptions
|
||||||
@@ -214,6 +217,21 @@ fn apply_geometry(document: &mut Document, geometry: &PageGeometry) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Read a `\parshape` specification such as `\parshape=2 0pt 100pt 20pt 80pt`.
|
||||||
|
fn parshape_assignment(line: &str) -> Option<Vec<(i64, i64)>> {
|
||||||
|
let rest = line.strip_prefix("\\parshape")?.trim_start();
|
||||||
|
let rest = rest.strip_prefix('=').unwrap_or(rest).trim();
|
||||||
|
let mut parts = rest.split_whitespace();
|
||||||
|
let count: usize = parts.next()?.parse().ok()?;
|
||||||
|
let mut shape = Vec::with_capacity(count);
|
||||||
|
for _ in 0..count {
|
||||||
|
let indent = parse_dimension(parts.next()?)?;
|
||||||
|
let width = parse_dimension(parts.next()?)?;
|
||||||
|
shape.push((indent, width));
|
||||||
|
}
|
||||||
|
Some(shape)
|
||||||
|
}
|
||||||
|
|
||||||
/// Read a braced argument such as `\hyphenation{hy-phen-a-tion}`.
|
/// Read a braced argument such as `\hyphenation{hy-phen-a-tion}`.
|
||||||
fn braced_argument<'a>(line: &'a str, command: &str) -> Option<&'a str> {
|
fn braced_argument<'a>(line: &'a str, command: &str) -> Option<&'a str> {
|
||||||
let rest = line.strip_prefix(command)?.trim_start();
|
let rest = line.strip_prefix(command)?.trim_start();
|
||||||
@@ -582,7 +600,7 @@ fn build_document(paragraphs: &[SourceParagraph], geometry: &PageGeometry) -> Do
|
|||||||
right_skip: geometry.right_skip.unwrap_or(0),
|
right_skip: geometry.right_skip.unwrap_or(0),
|
||||||
hang_indent: geometry.hang_indent.unwrap_or(0),
|
hang_indent: geometry.hang_indent.unwrap_or(0),
|
||||||
hang_after: geometry.hang_after.unwrap_or(1) as i32,
|
hang_after: geometry.hang_after.unwrap_or(1) as i32,
|
||||||
par_shape: Vec::new(),
|
par_shape: geometry.par_shape.clone(),
|
||||||
par_fillskip: 0,
|
par_fillskip: 0,
|
||||||
par_fillskip_stretch: 0,
|
par_fillskip_stretch: 0,
|
||||||
par_fillskip_fil: true,
|
par_fillskip_fil: true,
|
||||||
@@ -804,4 +822,21 @@ mod source_tests {
|
|||||||
geometry.hyphenation_exceptions
|
geometry.hyphenation_exceptions
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
#[test]
|
||||||
|
fn geometry_reads_parshape() {
|
||||||
|
let source = "\\documentclass{article}\n\\parshape=2 0pt 100pt 20pt 80pt\n\\begin{document}\n\nSome words here.\n\n\\end{document}\n";
|
||||||
|
let (body, geometry) = geometry_and_body(source);
|
||||||
|
assert_eq!(
|
||||||
|
geometry.par_shape,
|
||||||
|
vec![(0, 100 * SCALE), (20 * SCALE, 80 * SCALE)]
|
||||||
|
);
|
||||||
|
assert!(!body.contains("parshape"));
|
||||||
|
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.par_shape, geometry.par_shape);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user