Skip to content

Commit

Permalink
Fix atlas print for png and svg format (just give back first page)
Browse files Browse the repository at this point in the history
  • Loading branch information
mhugent committed Jan 5, 2019
1 parent 22e54ba commit fedb1d8
Showing 1 changed file with 40 additions and 13 deletions.
53 changes: 40 additions & 13 deletions src/server/services/wms/qgswmsrenderer.cpp
Expand Up @@ -459,14 +459,8 @@ namespace QgsWms

}

if ( atlas )
{
QgsLayoutExporter exporter( layout.get() );
QgsLayoutExporter::PdfExportSettings exportSettings;
QString error;
exporter.exportToPdf( atlas, tempOutputFile.fileName(), exportSettings, error );
}
else if ( formatString.compare( QLatin1String( "svg" ), Qt::CaseInsensitive ) == 0 )
QString exportError;
if ( formatString.compare( QLatin1String( "svg" ), Qt::CaseInsensitive ) == 0 )
{
// Settings for the layout exporter
QgsLayoutExporter::SvgExportSettings exportSettings;
Expand All @@ -479,8 +473,21 @@ namespace QgsWms
}
// Draw selections
exportSettings.flags |= QgsLayoutRenderContext::FlagDrawSelection;
QgsLayoutExporter exporter( layout.get() );
exporter.exportToSvg( tempOutputFile.fileName(), exportSettings );
if ( atlas )
{
//export first page of atlas
atlas->beginRender();
if ( atlas->next() )
{
QgsLayoutExporter atlasSvgExport( atlas->layout() );
atlasSvgExport.exportToSvg( tempOutputFile.fileName(), exportSettings );
}
}
else
{
QgsLayoutExporter exporter( layout.get() );
exporter.exportToSvg( tempOutputFile.fileName(), exportSettings );
}
}
else if ( formatString.compare( QLatin1String( "png" ), Qt::CaseInsensitive ) == 0 || formatString.compare( QLatin1String( "jpg" ), Qt::CaseInsensitive ) == 0 )
{
Expand All @@ -505,8 +512,21 @@ namespace QgsWms
exportSettings.imageSize = QSize( static_cast<int>( width.length() * dpi / 25.4 ), static_cast<int>( height.length() * dpi / 25.4 ) );
// Export first page only (unless it's a pdf, see below)
exportSettings.pages.append( 0 );
QgsLayoutExporter exporter( layout.get() );
exporter.exportToImage( tempOutputFile.fileName(), exportSettings );
if ( atlas )
{
//only can give back one page in server rendering
atlas->beginRender();
if ( atlas->next() )
{
QgsLayoutExporter atlasPngExport( atlas->layout() );
atlasPngExport.exportToImage( tempOutputFile.fileName(), exportSettings );
}
}
else
{
QgsLayoutExporter exporter( layout.get() );
exporter.exportToImage( tempOutputFile.fileName(), exportSettings );
}
}
else if ( formatString.compare( QLatin1String( "pdf" ), Qt::CaseInsensitive ) == 0 )
{
Expand All @@ -524,7 +544,14 @@ namespace QgsWms
exportSettings.flags |= QgsLayoutRenderContext::FlagDrawSelection;
// Export all pages
QgsLayoutExporter exporter( layout.get() );
exporter.exportToPdf( tempOutputFile.fileName(), exportSettings );
if ( atlas )
{
exporter.exportToPdf( atlas, tempOutputFile.fileName(), exportSettings, exportError );
}
else
{
exporter.exportToPdf( tempOutputFile.fileName(), exportSettings );
}
}
else //unknown format
{
Expand Down

0 comments on commit fedb1d8

Please sign in to comment.