mirror of
https://github.com/storytold/cadcraft.git
synced 2026-10-30 13:56:46 -06:00
Merge pull request #1683 from MarekSpodBiedry/issue-1667
Keep a layout's plot window corners when saving DXF (#1667)
This commit is contained in:
@@ -752,6 +752,8 @@ pub struct PageSetup {
|
||||
pub landscape: bool,
|
||||
/// "layout" | "extents" | "display" | "window" | "limits".
|
||||
pub plot_area: String,
|
||||
/// Plot window corners `[x1, y1, x2, y2]` (DXF plot layout groups 48, 49, 140, 141); used when `plot_area` is "window".
|
||||
pub plot_window: [f64; 4],
|
||||
pub scale_to_fit: bool,
|
||||
/// Paper units per drawing unit.
|
||||
pub scale: f64,
|
||||
@@ -779,6 +781,7 @@ impl Default for PageSetup {
|
||||
margins_mm: [6.35, 6.35, 6.35, 6.35],
|
||||
landscape: true,
|
||||
plot_area: "layout".into(),
|
||||
plot_window: [0.0; 4],
|
||||
scale_to_fit: false,
|
||||
scale: 1.0,
|
||||
plot_style_table: String::new(),
|
||||
|
||||
@@ -2248,6 +2248,7 @@ fn page_setup(t: &T) -> PageSetup {
|
||||
_ => "layout",
|
||||
}
|
||||
.into();
|
||||
p.plot_window = [t.fd(48, 0.0), t.fd(49, 0.0), t.fd(140, 0.0), t.fd(141, 0.0)].map(|v| if v.is_finite() { v } else { 0.0 });
|
||||
p.plot_style_table = t.s(7).unwrap_or_default();
|
||||
p
|
||||
}
|
||||
|
||||
@@ -2565,10 +2565,10 @@ fn tags_for(d: &Drawing, version: Version, target: Version) -> Vec<Tag> {
|
||||
(45, page.height_mm),
|
||||
(46, 0.0),
|
||||
(47, 0.0),
|
||||
(48, 0.0),
|
||||
(49, 0.0),
|
||||
(140, 0.0),
|
||||
(141, 0.0),
|
||||
(48, page.plot_window[0]),
|
||||
(49, page.plot_window[1]),
|
||||
(140, page.plot_window[2]),
|
||||
(141, page.plot_window[3]),
|
||||
(142, scale),
|
||||
(143, 1.0),
|
||||
] {
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
//! #1667: a layout whose page setup plots a window (DXF plot type 4) lost the window corners
|
||||
//! (groups 48, 49, 140, 141) on save: they were written as zero.
|
||||
|
||||
use cadcraft_doc::{Drawing, Layout, PageSetup};
|
||||
use cadcraft_io::{read, write_dxf};
|
||||
|
||||
#[test]
|
||||
fn plot_window_corners_round_trip_through_dxf() {
|
||||
let mut d = Drawing::new_metric();
|
||||
let mut l = Layout::new("WIN", 3);
|
||||
l.page = PageSetup {
|
||||
width_mm: 297.0,
|
||||
height_mm: 420.0,
|
||||
margins_mm: [0.0; 4],
|
||||
plot_area: "window".into(),
|
||||
plot_window: [0.0, -297.0, 420.0, 0.0],
|
||||
..PageSetup::default()
|
||||
};
|
||||
d.layouts.push(l);
|
||||
|
||||
let back = read(write_dxf(&d).as_bytes(), "win.dxf").unwrap();
|
||||
let page = &back.layouts.iter().find(|l| l.name == "WIN").unwrap().page;
|
||||
assert_eq!(page.plot_area, "window");
|
||||
assert_eq!(page.plot_window, [0.0, -297.0, 420.0, 0.0]);
|
||||
}
|
||||
Reference in New Issue
Block a user