Read hang indent, spacing and tolerance registers from route-D sources
This commit is contained in:
1 parent
53436f8177
commit
96cd98f833
4 files changed
+160
-10
No files matched your search
@@ -781,6 +781,68 @@ fn route_d_renders_flushright_blocks() {
|
||||
assert!(x > 50.0, "{x}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn route_d_applies_hang_indent_from_source() {
|
||||
let server = TestServer::start("route-d-hangindent");
|
||||
let body = "word ".repeat(120);
|
||||
let source = format!("\\hangindent=20pt\n\\hangafter=1\n\n{body}");
|
||||
|
||||
let plain = server.request(
|
||||
"POST",
|
||||
"/api/route-d/preview",
|
||||
body.as_bytes(),
|
||||
"text/plain",
|
||||
);
|
||||
assert_eq!(plain.status, 200, "{}", plain.text());
|
||||
let plain: Value = serde_json::from_slice(&plain.body).expect("route-D JSON");
|
||||
let plain_starts = line_starts(plain["pages"][0]["svg"].as_str().unwrap());
|
||||
assert!(
|
||||
plain_starts.len() >= 3,
|
||||
"need several lines: {plain_starts:?}"
|
||||
);
|
||||
assert!(plain_starts[1].1 < 3.0, "plain lines start at zero");
|
||||
|
||||
let hung = server.request(
|
||||
"POST",
|
||||
"/api/route-d/preview",
|
||||
source.as_bytes(),
|
||||
"text/plain",
|
||||
);
|
||||
assert_eq!(hung.status, 200, "{}", hung.text());
|
||||
let hung: Value = serde_json::from_slice(&hung.body).expect("route-D JSON");
|
||||
let hung_starts = line_starts(hung["pages"][0]["svg"].as_str().unwrap());
|
||||
assert!(hung_starts[0].1 < 3.0, "first line is not hung");
|
||||
assert!(
|
||||
hung_starts[1].1 > 15.0,
|
||||
"hangindent should shift later lines: {hung_starts:?}"
|
||||
);
|
||||
}
|
||||
|
||||
/// (y, x) of the leftmost glyph on each distinct text baseline.
|
||||
fn line_starts(svg: &str) -> Vec<(f64, f64)> {
|
||||
let mut lines: Vec<(f64, f64)> = Vec::new();
|
||||
let mut rest = svg;
|
||||
while let Some(start) = rest.find("<text x=\"") {
|
||||
let after = &rest[start + 9..];
|
||||
let x: f64 = after.split('"').next().unwrap().parse().unwrap();
|
||||
let y_start = after.find(" y=\"").expect("text y");
|
||||
let y: f64 = after[y_start + 4..]
|
||||
.split('"')
|
||||
.next()
|
||||
.unwrap()
|
||||
.parse()
|
||||
.unwrap();
|
||||
let key = (y * 100.0).round() / 100.0;
|
||||
match lines.iter_mut().find(|(line_y, _)| *line_y == key) {
|
||||
Some((_, line_x)) => *line_x = line_x.min(x),
|
||||
None => lines.push((key, x)),
|
||||
}
|
||||
rest = &after[y_start..];
|
||||
}
|
||||
lines.sort_by(|left, right| left.0.total_cmp(&right.0));
|
||||
lines
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn route_d_applies_source_paragraph_registers() {
|
||||
let server = TestServer::start("route-d-parregisters");
|
||||
|
||||
Reference in new issue
Block a user