#8818 PDF Export : Avoid manipulation of resolution

The exported pdf is dependent on the width of the plot window. Remove code related to change of resolution when exporting to PDF. This makes the PDF export consistent and independent to width of view.
This commit is contained in:
Magne Sjaastad 2022-04-21 13:27:58 +02:00
parent 1840a95810
commit ed6cbce71e

View File

@ -51,7 +51,7 @@ CAF_CMD_SOURCE_INIT( RicSnapshotViewToFileFeature, "RicSnapshotViewToFileFeature
//--------------------------------------------------------------------------------------------------
void RicSnapshotViewToFileFeature::saveSnapshotAs( const QString& fileName, RimViewWindow* viewWindow )
{
RimPlotWindow* plotWindow = dynamic_cast<RimPlotWindow*>( viewWindow );
auto* plotWindow = dynamic_cast<RimPlotWindow*>( viewWindow );
if ( plotWindow && fileName.endsWith( ".pdf" ) )
{
savePlotPdfReportAs( fileName, plotWindow );
@ -95,28 +95,15 @@ void RicSnapshotViewToFileFeature::savePlotPdfReportAs( const QString& fileName,
QFile pdfFile( fileName );
if ( pdfFile.open( QIODevice::WriteOnly ) )
{
int resolution = RiaGuiApplication::applicationResolution();
int pageWidth = plot->pageLayout().fullRectPixels( resolution ).width();
int widgetWidth = viewWidget->width();
int deltaWidth = widgetWidth - pageWidth;
int resolution = RiaGuiApplication::applicationResolution();
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() );
pdfPrinter.setResolution( resolution );
QRect widgetRect = viewWidget->contentsRect();
RimMultiPlot* multiPlot = dynamic_cast<RimMultiPlot*>( plot );
auto* multiPlot = dynamic_cast<RimMultiPlot*>( plot );
if ( multiPlot && multiPlot->previewModeEnabled() )
{
QRect pageRect = pdfPrinter.pageLayout().fullRectPixels( resolution );
@ -144,7 +131,7 @@ void RicSnapshotViewToFileFeature::savePlotPdfReportAs( const QString& fileName,
void RicSnapshotViewToFileFeature::saveViewWindowToFile( RimViewWindow* viewWindow,
const QString& defaultFileBaseName /*= "image" */ )
{
RimPlotWindow* plotWindow = dynamic_cast<RimPlotWindow*>( viewWindow );
auto* plotWindow = dynamic_cast<RimPlotWindow*>( viewWindow );
QString fileName = generateSaveFileName( defaultFileBaseName, plotWindow != nullptr );
if ( !fileName.isEmpty() )