Render at resolution required to match widget size

This commit is contained in:
Gaute Lindkvist 2020-01-06 09:06:10 +01:00
parent 81c092f2c4
commit 281fa24a2d

View File

@ -84,7 +84,22 @@ void RicSnapshotViewToFileFeature::savePlotPDFReportAs( const QString& fileName,
QFile pdfFile( fileName );
if ( pdfFile.open( QIODevice::WriteOnly ) )
{
const int resolution = RiaGuiApplication::instance()->desktop()->logicalDpiX();
int resolution = RiaGuiApplication::applicationResolution();
int pageWidth = plot->pageLayout().fullRectPixels( resolution ).width();
int widgetWidth = plot->viewWidget()->width();
int deltaWidth = widgetWidth - pageWidth;
while ( std::abs( deltaWidth ) > 1 )
{
int newResolution = resolution + deltaWidth / std::abs( deltaWidth );
pageWidth = plot->pageLayout().fullRectPixels( resolution ).width();
int newDeltaWidth = widgetWidth - pageWidth;
if ( std::abs( newDeltaWidth ) > std::abs( deltaWidth ) ) break;
resolution = newResolution;
deltaWidth = newDeltaWidth;
}
QPdfWriter pdfPrinter( fileName );
pdfPrinter.setPageLayout( plot->pageLayout() );
pdfPrinter.setCreator( QCoreApplication::applicationName() );