fix(paper): size inch paper-space sheets in their own units

Some layouts lay out paper space in inches (viewports and drawing limits
in inch units), but paper_width/height and plot margins are always
millimetres. paper_limits() drew the sheet at the mm size, 25.4x too
large, so the drawing shrank into the corner and the printable-area
dashes ran 25.4x too long.

Infer the mm->paper-space unit factor per layout from the limits/paper
ratio (plot_paper_units records the plot output unit and can disagree,
so it is not used). Scale the sheet, the printable-area margins and its
dash pattern by it. PDF export recovers physical mm by dividing back,
leaving millimetre layouts byte-identical.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Hakan Seven 2026-07-20 17:13:01 +03:00
commit 7d68eb0f10
2 changed files with 85 additions and 5 deletions

View file

@ -1165,7 +1165,11 @@ pub(super) fn on_open_file(&mut self) -> Task<Message> {
// Determine paper size and drawing offset.
let (paper_w, paper_h, mut draw_ox, mut draw_oy, rotation_deg) =
if let Some(((x0, y0), (x1, y1))) = scene.paper_limits() {
let (pw, ph) = (x1 - x0, y1 - y0);
// `paper_limits()` is in paper-space units; the PDF page is
// physical millimetres, so scale the sheet size back to mm via
// the layout's unit factor (identity for millimetre layouts).
let uf = scene.paper_space_unit_factor();
let (pw, ph) = ((x1 - x0) / uf, (y1 - y0) / uf);
// If PlotSettings says Extents, use model space extents instead.
let use_extents = ps_snap
@ -1379,7 +1383,11 @@ pub(super) fn on_open_file(&mut self) -> Task<Message> {
let ps_snap = scene.effective_plot_settings();
let (paper_w, paper_h, draw_ox, draw_oy, rotation_deg) =
if let Some(((x0, y0), (x1, y1))) = scene.paper_limits() {
let (pw, ph) = (x1 - x0, y1 - y0);
// `paper_limits()` is in paper-space units; the PDF page is
// physical millimetres, so scale the sheet size back to mm via
// the layout's unit factor (identity for millimetre layouts).
let uf = scene.paper_space_unit_factor();
let (pw, ph) = ((x1 - x0) / uf, (y1 - y0) / uf);
let use_extents = ps_snap
.as_ref()
.map(|ps| matches!(ps.plot_type, PlotType::Extents))