Apply page offsets to route-D preview pages
This commit is contained in:
1 parent
aea6c289ec
commit
d596ef2a95
3 files changed
+42
-4
No files matched your search
@@ -756,6 +756,7 @@ fn render_json(document: &Document, engine: &Engine, edit: Option<(&[usize], usi
|
||||
let mut list = page.display_list_with_layout(document.page_goal, document.text_float_sep);
|
||||
list.width = list.width.max(document.paper_width);
|
||||
list.height = list.height.max(document.paper_height);
|
||||
list.place(document.h_offset, document.v_offset);
|
||||
if index > 0 {
|
||||
json.push(',');
|
||||
}
|
||||
@@ -1011,4 +1012,38 @@ mod source_tests {
|
||||
.expect("paragraph style");
|
||||
assert_eq!(style.space_factor_codes, geometry.space_factor_codes);
|
||||
}
|
||||
#[test]
|
||||
fn preview_pages_honour_page_offsets() {
|
||||
let plain = preview_json("Hello route D").expect("plain preview");
|
||||
let shifted =
|
||||
preview_json("\\hoffset=10pt\n\\voffset=5pt\nHello route D").expect("shifted");
|
||||
fn first_text_position(json: &str) -> (f64, f64) {
|
||||
let value: serde_json::Value = serde_json::from_str(json).expect("JSON");
|
||||
let svg = value["pages"][0]["svg"].as_str().expect("svg");
|
||||
let start = svg.find("<text").expect("text element");
|
||||
let rest = &svg[start..];
|
||||
let x_start = rest.find("x=\"").expect("x") + 3;
|
||||
let x_end = rest[x_start..].find('"').expect("x end") + x_start;
|
||||
let y_start = rest.find("y=\"").expect("y") + 3;
|
||||
let y_end = rest[y_start..].find('"').expect("y end") + y_start;
|
||||
(
|
||||
rest[x_start..x_end].parse().expect("x value"),
|
||||
rest[y_start..y_end].parse().expect("y value"),
|
||||
)
|
||||
}
|
||||
let (plain_x, plain_y) = first_text_position(&plain);
|
||||
let (shifted_x, shifted_y) = first_text_position(&shifted);
|
||||
assert!(
|
||||
(shifted_x - plain_x - 10.0).abs() < 1.0,
|
||||
"x shift {} from {}",
|
||||
shifted_x,
|
||||
plain_x
|
||||
);
|
||||
assert!(
|
||||
(shifted_y - plain_y - 5.0).abs() < 1.0,
|
||||
"y shift {} from {}",
|
||||
shifted_y,
|
||||
plain_y
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user