From 281fa24a2dfe154f48f371928ec41801c6f9a0ad Mon Sep 17 00:00:00 2001 From: Gaute Lindkvist Date: Mon, 6 Jan 2020 09:06:10 +0100 Subject: [PATCH] Render at resolution required to match widget size --- .../RicSnapshotViewToFileFeature.cpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/ApplicationCode/Commands/ExportCommands/RicSnapshotViewToFileFeature.cpp b/ApplicationCode/Commands/ExportCommands/RicSnapshotViewToFileFeature.cpp index bf95a6ea85..744993047a 100644 --- a/ApplicationCode/Commands/ExportCommands/RicSnapshotViewToFileFeature.cpp +++ b/ApplicationCode/Commands/ExportCommands/RicSnapshotViewToFileFeature.cpp @@ -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() );