Eeschema printing: fix some issues.

The offset setting was incorrect when using wxAffineMatrix2D.
It was especially visible when printing more than one sheet.
Note also when not using wxAffineMatrix2D, all pages must have the same orientation
(PORTRAIT/LANDSCAPE is not managed)
Fixes #12211
https://gitlab.com/kicad/code/kicad/issues/12211
This commit is contained in:
jean-pierre charras 2022-10-09 15:27:22 +02:00
parent 4a66203493
commit 79c301800a
1 changed files with 26 additions and 10 deletions

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 2015-2021 KiCad Developers, see AUTHORS.TXT for contributors.
* Copyright (C) 2015-2022 KiCad Developers, see AUTHORS.TXT for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -406,6 +406,11 @@ bool SCH_PRINTOUT::OnBeginDocument( int startPage, int endPage )
*/
void SCH_PRINTOUT::PrintPage( SCH_SCREEN* aScreen )
{
// Warning:
// When printing many pages, changes in the current wxDC will affect all next printings
// because all prints are using the same wxPrinterDC after creation
// So be careful and reinit parameters, especially when using offsets.
VECTOR2I tmp_startvisu;
wxSize pageSizeIU; // Page size in internal units
VECTOR2I old_org;
@ -436,16 +441,31 @@ void SCH_PRINTOUT::PrintPage( SCH_SCREEN* aScreen )
int xoffset = ( fitRect.width - pageSizeIU.x ) / 2;
int yoffset = ( fitRect.height - pageSizeIU.y ) / 2;
// Using a wxAffineMatrix2D has a big advantage: it handles different pages orientations
//(PORTRAIT/LANDSCAPE), but the affine matrix is not always supported
if( dc->CanUseTransformMatrix() )
{
wxAffineMatrix2D matrix = dc->GetTransformMatrix();
wxAffineMatrix2D matrix; // starts from a unity matrix (the current wxDC default)
// Check for portrait/landscape mismatch:
if( ( fitRect.width > fitRect.height ) != ( pageSizeIU.x > pageSizeIU.y ) )
{
// Rotate the coordinates, and keep the draw coordinates inside the page
matrix.Rotate( M_PI_2 );
xoffset = ( fitRect.height - pageSizeIU.x ) / 2;
yoffset = ( fitRect.width - pageSizeIU.y ) / 2;
matrix.Translate( 0, -pageSizeIU.y );
// Recalculate the offsets and page sizes according to the page rotation
std::swap( pageSizeIU.x, pageSizeIU.y );
FitThisSizeToPaper( pageSizeIU );
fitRect = GetLogicalPaperRect();
xoffset = ( fitRect.width - pageSizeIU.x ) / 2;
yoffset = ( fitRect.height - pageSizeIU.y ) / 2;
// All the coordinates will be rotated 90 deg when printing,
// so the X,Y offset vector must be rotated -90 deg before printing
std::swap( xoffset, yoffset );
yoffset = -yoffset;
}
matrix.Translate( xoffset, yoffset );
@ -453,12 +473,8 @@ void SCH_PRINTOUT::PrintPage( SCH_SCREEN* aScreen )
}
else
{
// wxWidgets appears to have a bug when OffsetLogicalOrigin()'s yoffset changes from
// page to page.
// NB: this is a workaround, not a fix. The Y centering will be off, but this is less
// annoying than a blank page. See https://bugs.launchpad.net/kicad/+bug/1464773.
yoffset = 0;
SetLogicalOrigin( 0, 0 ); // Reset all offset settings made previously.
// When printing previous pages (all prints are using the same wxDC)
OffsetLogicalOrigin( xoffset, yoffset );
}