Use a transform matrix to address some print bugs.

Sadly, this only works on MSW until wxWidgets 3.1.1.

Fixes: lp:1464773
* https://bugs.launchpad.net/kicad/+bug/1464773
This commit is contained in:
Jeff Young 2019-08-09 11:32:39 +01:00
parent 17d015ed5d
commit 441c2c240f
1 changed files with 29 additions and 21 deletions

View File

@ -395,29 +395,37 @@ void SCH_PRINTOUT::PrintPage( SCH_SCREEN* aScreen )
wxLogDebug( wxT( "Fit rectangle: x = %d, y = %d, w = %d, h = %d" ), wxLogDebug( wxT( "Fit rectangle: x = %d, y = %d, w = %d, h = %d" ),
fitRect.x, fitRect.y, fitRect.width, fitRect.height ); fitRect.x, fitRect.y, fitRect.width, fitRect.height );
// When is the actual paper size does not match the schematic page // When is the actual paper size does not match the schematic page size, the drawing will
// size, the drawing is not perfectly centered on X or Y axis. // not be centered on X or Y axis. Give a draw offset to center the schematic page on the
// Give a draw offset centers the schematic page on the paper draw area // paper draw area.
// Because the sizes are fitted, only an Y or X offset is needed
// and both are 0 when sizes are identical.
// Y or Y offset is not null when the X/Y size ratio differs between
// the actual paper size and the schematic page
int xoffset = ( fitRect.width - pageSizeIU.x ) / 2; int xoffset = ( fitRect.width - pageSizeIU.x ) / 2;
// For an obscure reason, OffsetLogicalOrigin creates issues,
// under some circumstances, when yoffset is not always null
// and changes from a page to another page
// This is only a workaround, not a fix
// see https://bugs.launchpad.net/kicad/+bug/1464773
// xoffset does not create issues.
#if 0 // FIX ME
int yoffset = ( fitRect.height - pageSizeIU.y ) / 2; int yoffset = ( fitRect.height - pageSizeIU.y ) / 2;
#else
// the Y centering will be not perfect, but this is less annoying if( dc->CanUseTransformMatrix() )
// than a blank page or a buggy centering {
int yoffset = 0; wxAffineMatrix2D matrix = dc->GetTransformMatrix();
#endif
OffsetLogicalOrigin( xoffset, yoffset ); // Check for portrait/landscape mismatch:
if( fitRect.width > fitRect.height != pageSizeIU.x > pageSizeIU.y )
{
matrix.Rotate( M_PI_2 );
xoffset = ( fitRect.height - pageSizeIU.x ) / 2;
yoffset = ( fitRect.width - pageSizeIU.y ) / 2;
}
matrix.Translate( xoffset, yoffset );
dc->SetTransformMatrix( matrix );
}
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;
OffsetLogicalOrigin( xoffset, yoffset );
}
dc->SetLogicalFunction( wxCOPY ); dc->SetLogicalFunction( wxCOPY );
GRResetPenAndBrush( dc ); GRResetPenAndBrush( dc );