mirror of
https://github.com/storytold/cadcraft.git
synced 2026-12-02 10:47:31 -06:00
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
88f76a91f6 |
@@ -122,19 +122,19 @@ fn page_setup_takes_a_device_and_its_papers() {
|
||||
/// turn back to the axes the user gave, and PLOT hands them on that way (#1266).
|
||||
fn a_landscape_page_gets_the_papers_margins_back() {
|
||||
let mut s = session();
|
||||
s.execute("plottermanager", &json!({"action": "new", "name": "Banner Printer", "output": "pdf"})).unwrap();
|
||||
s.execute("plottermanager", &json!({"action": "new", "name": "Landscape Banner Printer", "output": "pdf"})).unwrap();
|
||||
let paper = json!({"name": "Banner", "width": 400, "height": 200, "margins": [150, 0, 150, 0]});
|
||||
s.execute("plottermanager", &json!({"action": "set", "name": "Banner Printer", "paper": paper})).unwrap();
|
||||
s.execute("plottermanager", &json!({"action": "set", "name": "Landscape Banner Printer", "paper": paper})).unwrap();
|
||||
// Stored portrait, 200 x 400, the side margins on the long axis.
|
||||
let stored = |s: &mut Session| {
|
||||
let r = s.execute("plottermanager", &json!({"action": "get", "name": "Banner Printer"})).unwrap();
|
||||
let r = s.execute("plottermanager", &json!({"action": "get", "name": "Landscape Banner Printer"})).unwrap();
|
||||
r["papers"].as_array().unwrap().iter().find(|p| p["name"] == "Banner").cloned().unwrap()
|
||||
};
|
||||
let p = stored(&mut s);
|
||||
assert_eq!((p["width"].as_f64(), p["height"].as_f64()), (Some(200.0), Some(400.0)));
|
||||
assert_eq!(p["margins"], json!([0.0, 150.0, 0.0, 150.0]));
|
||||
|
||||
s.execute("pagesetup", &json!({"layout": "Layout1", "device": "Banner Printer", "paper": "Banner", "landscape": true})).unwrap();
|
||||
s.execute("pagesetup", &json!({"layout": "Layout1", "device": "Landscape Banner Printer", "paper": "Banner", "landscape": true})).unwrap();
|
||||
let page = s.doc().unwrap().layout("Layout1").unwrap().page.clone();
|
||||
assert_eq!((page.width_mm, page.height_mm, page.margins_mm), (200.0, 400.0, [150.0, 0.0, 150.0, 0.0]));
|
||||
// The 400 x 200 sheet's printable area is 100 x 200 mm, not the whole sheet.
|
||||
@@ -150,8 +150,11 @@ fn a_landscape_page_gets_the_papers_margins_back() {
|
||||
assert_eq!(o["margins"], json!([150.0, 0.0, 150.0, 0.0]));
|
||||
|
||||
// Naming the paper landscape again at a new size keeps the margins' axes as well.
|
||||
s.execute("plottermanager", &json!({"action": "set", "name": "Banner Printer", "paper": {"name": "Banner", "width": 500, "height": 200}}))
|
||||
.unwrap();
|
||||
s.execute(
|
||||
"plottermanager",
|
||||
&json!({"action": "set", "name": "Landscape Banner Printer", "paper": {"name": "Banner", "width": 500, "height": 200}}),
|
||||
)
|
||||
.unwrap();
|
||||
let p = stored(&mut s);
|
||||
assert_eq!((p["width"].as_f64(), p["height"].as_f64()), (Some(200.0), Some(500.0)));
|
||||
assert_eq!(p["margins"], json!([0.0, 150.0, 0.0, 150.0]), "the margins keep the short sides");
|
||||
@@ -163,11 +166,11 @@ fn a_landscape_page_gets_the_papers_margins_back() {
|
||||
/// instead of being saved against the wrong axes (#1266).
|
||||
fn an_orientation_only_pagesetup_turns_the_retained_margins() {
|
||||
let mut s = session();
|
||||
s.execute("plottermanager", &json!({"action": "new", "name": "Banner Printer", "output": "pdf"})).unwrap();
|
||||
s.execute("plottermanager", &json!({"action": "new", "name": "Turning Banner Printer", "output": "pdf"})).unwrap();
|
||||
let paper = json!({"name": "Banner", "width": 400, "height": 200, "margins": [150, 0, 150, 0]});
|
||||
s.execute("plottermanager", &json!({"action": "set", "name": "Banner Printer", "paper": paper})).unwrap();
|
||||
s.execute("plottermanager", &json!({"action": "set", "name": "Turning Banner Printer", "paper": paper})).unwrap();
|
||||
// The landscape page carries the margins on its 400 mm sides: 150 mm left and right.
|
||||
s.execute("pagesetup", &json!({"layout": "Layout1", "device": "Banner Printer", "paper": "Banner", "landscape": true})).unwrap();
|
||||
s.execute("pagesetup", &json!({"layout": "Layout1", "device": "Turning Banner Printer", "paper": "Banner", "landscape": true})).unwrap();
|
||||
let page = s.doc().unwrap().layout("Layout1").unwrap().page.clone();
|
||||
assert_eq!((page.width_mm, page.height_mm, page.margins_mm), (200.0, 400.0, [150.0, 0.0, 150.0, 0.0]));
|
||||
|
||||
@@ -345,23 +348,23 @@ fn plotwindow_picks_both_corners_with_ortho_on() {
|
||||
#[test]
|
||||
fn paper_margins_are_checked_against_their_own_axis() {
|
||||
let mut s = session();
|
||||
s.execute("plottermanager", &json!({"action": "new", "name": "Banner Printer", "output": "png"})).unwrap();
|
||||
let paper = |margins: Value| json!({"action": "set", "name": "Banner Printer", "paper": {"name": "Banner", "width": 400, "height": 200, "margins": margins}});
|
||||
s.execute("plottermanager", &json!({"action": "new", "name": "Margin Banner Printer", "output": "png"})).unwrap();
|
||||
let paper = |margins: Value| json!({"action": "set", "name": "Margin Banner Printer", "paper": {"name": "Banner", "width": 400, "height": 200, "margins": margins}});
|
||||
// 250 mm of bottom + top margin leaves no printable height on a 200 mm paper.
|
||||
assert!(s.execute("plottermanager", &paper(json!([0, 250, 0, 0]))).is_err());
|
||||
// 300 mm of left + right margin still leaves 100 mm of printable width on a 400 mm paper.
|
||||
assert!(s.execute("plottermanager", &paper(json!([150, 0, 150, 0]))).is_ok());
|
||||
// The paper is stored portrait and the margins turn with it: the 100 x 200 printable area
|
||||
// of the requested sheet stays 200 x 100 on the stored 200 x 400 one.
|
||||
let stored = s.execute("plottermanager", &json!({"action": "get", "name": "Banner Printer"})).unwrap();
|
||||
let stored = s.execute("plottermanager", &json!({"action": "get", "name": "Margin Banner Printer"})).unwrap();
|
||||
let banner = stored["papers"].as_array().unwrap().iter().find(|p| p["name"] == "Banner").unwrap().clone();
|
||||
assert_eq!((banner["width"].as_f64().unwrap(), banner["height"].as_f64().unwrap()), (200.0, 400.0));
|
||||
assert_eq!(banner["margins"], json!([0.0, 150.0, 0.0, 150.0]));
|
||||
// Setting the same sheet again without margins keeps them: the stored margins belong to the
|
||||
// portrait sheet and turn back before the per-axis check.
|
||||
s.execute("plottermanager", &json!({"action": "set", "name": "Banner Printer", "paper": {"name": "Banner", "width": 400, "height": 200}}))
|
||||
s.execute("plottermanager", &json!({"action": "set", "name": "Margin Banner Printer", "paper": {"name": "Banner", "width": 400, "height": 200}}))
|
||||
.unwrap();
|
||||
let stored = s.execute("plottermanager", &json!({"action": "get", "name": "Banner Printer"})).unwrap();
|
||||
let stored = s.execute("plottermanager", &json!({"action": "get", "name": "Margin Banner Printer"})).unwrap();
|
||||
let banner = stored["papers"].as_array().unwrap().iter().find(|p| p["name"] == "Banner").unwrap().clone();
|
||||
assert_eq!(banner["margins"], json!([0.0, 150.0, 0.0, 150.0]));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user