Skip to content

Commit

Permalink
Also respect layout dpi when rendering pdf using older deprecated code
Browse files Browse the repository at this point in the history
paths
  • Loading branch information
nyalldawson committed Sep 27, 2021
1 parent f01022e commit efb9971
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/core/layout/qgslayoutitempicture.cpp
Expand Up @@ -384,6 +384,21 @@ void QgsLayoutItemPicture::loadRemotePicture( const QString &url )
if ( reply )
{
QImageReader imageReader( reply );

if ( imageReader.format() == "pdf" )
{
// special handling for this format -- we need to pass the desired target size onto the image reader
// so that it can correctly render the (vector) pdf content at the desired dpi. Otherwise it returns
// a very low resolution image (the driver assumes points == pixels!)
// For other image formats, we read the original image size only and defer resampling to later in this
// function. That gives us more control over the resampling method used.

// driver assumes points == pixels, so driver image size is reported assuming 72 dpi.
const QSize sizeAt72Dpi = imageReader.size();
const QSize sizeAtTargetDpi = sizeAt72Dpi * mLayout->renderContext().dpi() / 72;
imageReader.setScaledSize( sizeAtTargetDpi );
}

mImage = imageReader.read();
mMode = FormatRaster;
}
Expand Down Expand Up @@ -434,6 +449,21 @@ void QgsLayoutItemPicture::loadLocalPicture( const QString &path )
{
//try to open raster with QImageReader
QImageReader imageReader( pic.fileName() );

if ( imageReader.format() == "pdf" )
{
// special handling for this format -- we need to pass the desired target size onto the image reader
// so that it can correctly render the (vector) pdf content at the desired dpi. Otherwise it returns
// a very low resolution image (the driver assumes points == pixels!)
// For other image formats, we read the original image size only and defer resampling to later in this
// function. That gives us more control over the resampling method used.

// driver assumes points == pixels, so driver image size is reported assuming 72 dpi.
const QSize sizeAt72Dpi = imageReader.size();
const QSize sizeAtTargetDpi = sizeAt72Dpi * mLayout->renderContext().dpi() / 72;
imageReader.setScaledSize( sizeAtTargetDpi );
}

if ( imageReader.read( &mImage ) )
{
mMode = FormatRaster;
Expand Down

0 comments on commit efb9971

Please sign in to comment.