fix(plot): follow the fixture's page-setup conventions

A drawing saved by a commercial CAD application (tests/fixtures/plot,
provided by Panos: one 10 m line, three layouts) corrects several
assumptions of the previous commit:

- rotation is relative to the medium's own orientation: an unchanged sheet
  keeps the driver's exact medium (its PDF driver lists landscape media of
  its own, written with rotation 0; a system printer's portrait A3 plotted
  landscape carries 90); only a newly picked sheet is written as the
  catalogue's portrait medium
- the stored scale factor (DXF 147) is the ratio × 25.4 on millimetre page
  setups and the plain ratio on inch ones; the "use standard scale" bit
  stays clear for standard and custom scales and is set for fit-to-paper;
  a standard code is kept across a paper-unit conversion ("1:1" on an
  inch page setup over a millimetre paper space is 1 in = 25.4 units)
- layout plots take the same scale path as every other area, so a foreign
  layout's paper-space unit survives
- "plot with plot styles" / "display plot styles" round-trip as the
  dialog's checkboxes, independent of a style table being named
- layout limits place the sheet at minus its displayed margins, the way the
  source application does (the printable corner is the paper-space origin);
  the margin ↔ rotation mapping shared by the printable-area guide now
  turns the medium's top margin into the layout's left one at 90°

The fixture round-trips through the dialog with every stored field
unchanged; picking a new sheet on it writes the canonical form.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
PanosandClaude Opus 5 committed 2026-09-17 18:04:38 +03:00
1 parent 276e7c7bf1
commit 8e09bd8463
6 files changed
+16235 -112

No files matched your search

+3 -8
View File
@@ -33,7 +33,7 @@ pub(crate) mod centermark;
pub(crate) mod dimension_assoc;
pub(crate) mod dimension_assoc_chain;
pub use dimension_assoc::{ReferenceStatus, ResolvedReference};
pub use page_setup::apply_default_page_setup;
pub use page_setup::{apply_default_page_setup, rotated_margins};
mod dwg_native_constraints;
mod entity;
#[cfg(test)]
@@ -4362,13 +4362,8 @@ impl Scene {
None
})?;
// `paper_limits()` already swaps the sheet for a 90°/270° rotation, so the
// margins must rotate to the same edges: a margin on a physical side moves
// to the displayed side that side rotates onto.
let (ml, mb, mr, mt) = match rot {
1 | 3 => (bottom, left, top, right),
2 => (right, top, left, bottom),
_ => (left, bottom, right, top),
};
// margins must rotate to the same edges.
let (ml, mb, mr, mt) = page_setup::rotated_margins((left, bottom, right, top), rot);
// Plot margins are millimetres like the paper size; scale them into the
// layout's paper-space units so the inset matches the (already scaled)
// sheet rect. Without this an inch paper space insets an ~8-inch sheet
+19
View File
@@ -40,6 +40,25 @@ pub fn apply_default_page_setup(layout: &mut Layout, plot_style: &str) {
layout.plot_printer_name = crate::io::plot_device::PlotDevice::None.canonical_name();
}
/// The unprintable margins of a sheet as they appear on the rotated layout,
/// `(left, bottom, right, top)`. Stored margins belong to the medium's own
/// edges; a plot rotated by a quarter turn (`rotation` is the file's 0–3
/// code) shows the medium turned on the layout, so each margin moves to the
/// edge its side lands on — verified against limits written by the
/// commercial application: at 90° the medium's top margin is the layout's
/// left one and its left margin the layout's bottom one.
pub fn rotated_margins(
(left, bottom, right, top): (f64, f64, f64, f64),
rotation: i16,
) -> (f64, f64, f64, f64) {
match rotation {
1 => (top, left, bottom, right),
2 => (right, top, left, bottom),
3 => (bottom, right, top, left),
_ => (left, bottom, right, top),
}
}
impl Scene {
/// Handle of the `ACAD_PLOTSETTINGS` dictionary, located robustly.
///