Read parfillskip and interline glue from route-D sources
This commit is contained in:
1 parent
dc68e76cd3
commit
bd462448d5
3 files changed
+69
-8
No files matched your search
+64
-5
@@ -123,6 +123,9 @@ struct PageGeometry {
|
||||
xspace_skip: Option<(i64, i64, i64)>,
|
||||
hyphenation_exceptions: Vec<String>,
|
||||
par_shape: Vec<(i64, i64)>,
|
||||
lineskip: Option<i64>,
|
||||
lineskiplimit: Option<i64>,
|
||||
par_fillskip: Option<(i64, i64, bool)>,
|
||||
}
|
||||
|
||||
/// Pull `\hoffset`/`\voffset`/`\paperwidth`/`\paperheight`/`\vsize`/
|
||||
@@ -172,6 +175,12 @@ 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) = dimension_assignment(trimmed, "lineskip") {
|
||||
geometry.lineskip = Some(value);
|
||||
} else if let Some(value) = dimension_assignment(trimmed, "lineskiplimit") {
|
||||
geometry.lineskiplimit = Some(value);
|
||||
} else if let Some(value) = parfillskip_assignment(trimmed) {
|
||||
geometry.par_fillskip = Some(value);
|
||||
} else if let Some(value) = parshape_assignment(trimmed) {
|
||||
geometry.par_shape = value;
|
||||
} else if let Some(value) = braced_argument(trimmed, "\\hyphenation") {
|
||||
@@ -217,6 +226,31 @@ fn apply_geometry(document: &mut Document, geometry: &PageGeometry) {
|
||||
}
|
||||
}
|
||||
|
||||
/// Read a `\parfillskip` glue assignment, preserving the `1fil` order.
|
||||
fn parfillskip_assignment(line: &str) -> Option<(i64, i64, bool)> {
|
||||
let rest = line.strip_prefix("\\parfillskip")?.trim_start();
|
||||
let rest = rest.strip_prefix('=')?.trim();
|
||||
let (width, rest) = split_glue_part(rest)?;
|
||||
let mut stretch = 0_i64;
|
||||
let mut fil = false;
|
||||
let rest = rest.trim_start();
|
||||
let rest = if let Some(rest) = rest.strip_prefix("plus") {
|
||||
let rest = rest.trim_start();
|
||||
if let Some(rest) = rest.strip_prefix("1fil") {
|
||||
fil = true;
|
||||
rest
|
||||
} else {
|
||||
let (value, rest) = split_glue_part(rest)?;
|
||||
stretch = value;
|
||||
rest
|
||||
}
|
||||
} else {
|
||||
rest
|
||||
};
|
||||
let _ = rest;
|
||||
Some((width, stretch, fil))
|
||||
}
|
||||
|
||||
/// 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();
|
||||
@@ -601,14 +635,20 @@ fn build_document(paragraphs: &[SourceParagraph], geometry: &PageGeometry) -> Do
|
||||
hang_indent: geometry.hang_indent.unwrap_or(0),
|
||||
hang_after: geometry.hang_after.unwrap_or(1) as i32,
|
||||
par_shape: geometry.par_shape.clone(),
|
||||
par_fillskip: 0,
|
||||
par_fillskip_stretch: 0,
|
||||
par_fillskip_fil: true,
|
||||
par_fillskip: geometry
|
||||
.par_fillskip
|
||||
.map(|(width, _, _)| width)
|
||||
.unwrap_or(0),
|
||||
par_fillskip_stretch: geometry
|
||||
.par_fillskip
|
||||
.map(|(_, stretch, _)| stretch)
|
||||
.unwrap_or(0),
|
||||
par_fillskip_fil: geometry.par_fillskip.map(|(_, _, fil)| fil).unwrap_or(true),
|
||||
frenchspacing: geometry.french_spacing.unwrap_or(false),
|
||||
space_factor_codes: Vec::new(),
|
||||
baselineskip: geometry.baseline_skip.unwrap_or(12 * 65536),
|
||||
lineskip: 65536,
|
||||
lineskiplimit: 0,
|
||||
lineskip: geometry.lineskip.unwrap_or(65536),
|
||||
lineskiplimit: geometry.lineskiplimit.unwrap_or(0),
|
||||
par_indent: geometry.par_indent.unwrap_or(0),
|
||||
emergencystretch: geometry.emergency_stretch.unwrap_or(0),
|
||||
pretolerance: geometry.pretolerance.unwrap_or(100),
|
||||
@@ -839,4 +879,23 @@ mod source_tests {
|
||||
.expect("paragraph style");
|
||||
assert_eq!(style.par_shape, geometry.par_shape);
|
||||
}
|
||||
#[test]
|
||||
fn geometry_reads_parfillskip_and_lineskip() {
|
||||
let source = "\\documentclass{article}\n\\parfillskip=0pt plus 1fil\n\\lineskip=2pt\n\\lineskiplimit=3pt\n\\begin{document}\n\nSome words here.\n\n\\end{document}\n";
|
||||
let (body, geometry) = geometry_and_body(source);
|
||||
assert_eq!(geometry.par_fillskip, Some((0, 0, true)));
|
||||
assert_eq!(geometry.lineskip, Some(2 * SCALE));
|
||||
assert_eq!(geometry.lineskiplimit, Some(3 * SCALE));
|
||||
assert!(!body.contains("parfillskip"));
|
||||
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_fillskip, 0);
|
||||
assert!(style.par_fillskip_fil);
|
||||
assert_eq!(style.lineskip, 2 * SCALE);
|
||||
assert_eq!(style.lineskiplimit, 3 * SCALE);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user