From 21144481d237bb358c76dd0a60f81119450d15cf Mon Sep 17 00:00:00 2001
From: jean-pierre charras <jp.charras@wanadoo.fr>
Date: Tue, 22 Mar 2022 09:40:16 +0100
Subject: [PATCH] PLOTTER: do not clamp coordinates to an arbitrary value.
 Previously, coordinates were clamped to +- 60 inches. It makes no sense to
 clamp them at plotter level: max cooed depends on the editor
 (schematic/board...) Rename MAX_PAGE_SIZE_MILS to MAX_PAGE_SIZE_EESCHEMA_MILS
 and use it only for Eeschema. Fixes #11196
 https://gitlab.com/kicad/code/kicad/issues/11196

---
 common/plotters/plotter.cpp                     | 6 ------
 eeschema/sch_plugins/kicad/sch_sexpr_parser.cpp | 8 ++++----
 eeschema/sch_view.cpp                           | 2 +-
 eeschema/tools/sch_editor_control.cpp           | 3 ++-
 include/page_info.h                             | 6 +++---
 pagelayout_editor/tools/pl_editor_control.cpp   | 4 +++-
 6 files changed, 13 insertions(+), 16 deletions(-)

diff --git a/common/plotters/plotter.cpp b/common/plotters/plotter.cpp
index 4872ceacfc..8b291b84cf 100644
--- a/common/plotters/plotter.cpp
+++ b/common/plotters/plotter.cpp
@@ -92,12 +92,6 @@ VECTOR2D PLOTTER::userToDeviceCoordinates( const VECTOR2I& aCoordinate )
 {
     VECTOR2I pos = aCoordinate - m_plotOffset;
 
-    // Don't allow overflows; they can cause rendering failures in some file viewers
-    // (such as Acrobat)
-    int clampSize = MAX_PAGE_SIZE_MILS * m_IUsPerDecimil * 10 / 2;
-    pos.x = std::max( -clampSize, std::min( pos.x, clampSize ) );
-    pos.y = std::max( -clampSize, std::min( pos.y, clampSize ) );
-
     double x = pos.x * m_plotScale;
     double y = ( m_paperSize.y - pos.y * m_plotScale );
 
diff --git a/eeschema/sch_plugins/kicad/sch_sexpr_parser.cpp b/eeschema/sch_plugins/kicad/sch_sexpr_parser.cpp
index 6fe95dced4..8acab58d33 100644
--- a/eeschema/sch_plugins/kicad/sch_sexpr_parser.cpp
+++ b/eeschema/sch_plugins/kicad/sch_sexpr_parser.cpp
@@ -1700,15 +1700,15 @@ void SCH_SEXPR_PARSER::parsePAGE_INFO( PAGE_INFO& aPageInfo )
         // Perform some controls to avoid crashes if the size is edited by hands
         if( width < MIN_PAGE_SIZE_MILS )
             width = MIN_PAGE_SIZE_MILS;
-        else if( width > MAX_PAGE_SIZE_MILS )
-            width = MAX_PAGE_SIZE_MILS;
+        else if( width > MAX_PAGE_SIZE_EESCHEMA_MILS )
+            width = MAX_PAGE_SIZE_EESCHEMA_MILS;
 
         int height = Mm2mils( parseDouble( "height" ) ); // height stored in mm so we convert to mils
 
         if( height < MIN_PAGE_SIZE_MILS )
             height = MIN_PAGE_SIZE_MILS;
-        else if( height > MAX_PAGE_SIZE_MILS )
-            height = MAX_PAGE_SIZE_MILS;
+        else if( height > MAX_PAGE_SIZE_EESCHEMA_MILS )
+            height = MAX_PAGE_SIZE_EESCHEMA_MILS;
 
         aPageInfo.SetWidthMils( width );
         aPageInfo.SetHeightMils( height );
diff --git a/eeschema/sch_view.cpp b/eeschema/sch_view.cpp
index 5c71c585f8..9c8e041f40 100644
--- a/eeschema/sch_view.cpp
+++ b/eeschema/sch_view.cpp
@@ -50,7 +50,7 @@ SCH_VIEW::SCH_VIEW( bool aIsDynamic, SCH_BASE_FRAME* aFrame ) :
     // Set m_boundary to define the max working area size. The default value is acceptable for
     // Pcbnew and Gerbview, but too large for Eeschema due to very different internal units.
     // A full size = 3 * MAX_PAGE_SIZE_MILS size allows a wide margin around the drawing-sheet.
-    double max_size = Mils2iu( MAX_PAGE_SIZE_MILS ) * 3.0;
+    double max_size = Mils2iu( MAX_PAGE_SIZE_EESCHEMA_MILS ) * 3.0;
     m_boundary.SetOrigin( -max_size/4, -max_size/4 );
     m_boundary.SetSize( max_size, max_size );
 }
diff --git a/eeschema/tools/sch_editor_control.cpp b/eeschema/tools/sch_editor_control.cpp
index 07a0be5ba7..8bee6a2e34 100644
--- a/eeschema/tools/sch_editor_control.cpp
+++ b/eeschema/tools/sch_editor_control.cpp
@@ -129,7 +129,8 @@ int SCH_EDITOR_CONTROL::PageSetup( const TOOL_EVENT& aEvent )
     undoCmd.PushItem( wrapper );
     m_frame->SaveCopyInUndoList( undoCmd, UNDO_REDO::PAGESETTINGS, false, false );
 
-    DIALOG_EESCHEMA_PAGE_SETTINGS dlg( m_frame, wxSize( MAX_PAGE_SIZE_MILS, MAX_PAGE_SIZE_MILS ) );
+    DIALOG_EESCHEMA_PAGE_SETTINGS dlg( m_frame, wxSize( MAX_PAGE_SIZE_EESCHEMA_MILS,
+                                                        MAX_PAGE_SIZE_EESCHEMA_MILS ) );
     dlg.SetWksFileName( BASE_SCREEN::m_DrawingSheetFileName );
 
     if( dlg.ShowModal() )
diff --git a/include/page_info.h b/include/page_info.h
index 9c9c40b6e3..aa0631cbc1 100644
--- a/include/page_info.h
+++ b/include/page_info.h
@@ -36,9 +36,9 @@
 #include <base_units.h>     // for IU_PER_MILS
 
 /// Min and max page sizes for clamping, in mils.
-#define MIN_PAGE_SIZE_MILS           100
-#define MAX_PAGE_SIZE_PCBNEW_MILS  48000
-#define MAX_PAGE_SIZE_MILS        120000
+#define MIN_PAGE_SIZE_MILS          100
+#define MAX_PAGE_SIZE_PCBNEW_MILS   48000
+#define MAX_PAGE_SIZE_EESCHEMA_MILS 120000
 
 
 /**
diff --git a/pagelayout_editor/tools/pl_editor_control.cpp b/pagelayout_editor/tools/pl_editor_control.cpp
index 414693addd..3fd2f2008e 100644
--- a/pagelayout_editor/tools/pl_editor_control.cpp
+++ b/pagelayout_editor/tools/pl_editor_control.cpp
@@ -89,7 +89,9 @@ int PL_EDITOR_CONTROL::PageSetup( const TOOL_EVENT& aEvent )
 {
     m_frame->SaveCopyInUndoList();
 
-    DIALOG_PAGES_SETTINGS dlg( m_frame, IU_PER_MILS, wxSize( MAX_PAGE_SIZE_MILS, MAX_PAGE_SIZE_MILS ) );
+    DIALOG_PAGES_SETTINGS dlg( m_frame, IU_PER_MILS,
+                               wxSize( MAX_PAGE_SIZE_EESCHEMA_MILS,
+                                       MAX_PAGE_SIZE_EESCHEMA_MILS ) );
     dlg.SetWksFileName( m_frame->GetCurrentFileName() );
     dlg.EnableWksFileNamePicker( false );