Skip to content
Permalink
Browse files

Fix flexible aspect ratio is ignored when rendering marker svg symbols

  • Loading branch information
github-actions authored and nyalldawson committed Jul 21, 2020
1 parent a79f0e5 commit 9484aff9ed59cd47d8ab5afee788799db519a9e2
@@ -407,6 +407,8 @@ void QgsSvgCache::cacheImage( QgsSvgCacheEntry *entry )
std::unique_ptr< QImage > image = qgis::make_unique< QImage >( imageSize, QImage::Format_ARGB32_Premultiplied );
image->fill( 0 ); // transparent background

const bool isFixedAR = entry->fixedAspectRatio > 0;

QPainter p( image.get() );
QSvgRenderer r( entry->svgContent );
if ( qgsDoubleNear( viewBoxSize.width(), viewBoxSize.height() ) )
@@ -416,7 +418,7 @@ void QgsSvgCache::cacheImage( QgsSvgCacheEntry *entry )
else
{
QSizeF s( viewBoxSize );
s.scale( scaledSize.width(), scaledSize.height(), Qt::KeepAspectRatio );
s.scale( scaledSize.width(), scaledSize.height(), isFixedAR ? Qt::IgnoreAspectRatio : Qt::KeepAspectRatio );
QRectF rect( ( imageSize.width() - s.width() ) / 2, ( imageSize.height() - s.height() ) / 2, s.width(), s.height() );
r.render( &p, rect );
}
@@ -54,6 +54,7 @@ class TestQgsSvgCache : public QObject
void changeImage(); //check that cache is updated if svg source file changes
void base64();
void replaceParams();
void aspectRatio();

};

@@ -332,6 +333,18 @@ void TestQgsSvgCache::replaceParams()

}

void TestQgsSvgCache::aspectRatio()
{
// test rendering SVGs with manual aspect ratio
QgsSvgCache cache;
bool inCache = false;

const QString originalImage = TEST_DATA_DIR + QStringLiteral( "/test_symbol_svg.svg" );
QImage img = cache.svgAsImage( originalImage, 200, QColor( 0, 0, 0 ), QColor( 0, 0, 0 ), 1.0,
1.0, inCache, 0.5 );
QVERIFY( imageCheck( QStringLiteral( "svgcache_aspect_ratio" ), img, 30 ) );
}

bool TestQgsSvgCache::imageCheck( const QString &testName, QImage &image, int mismatchCount )
{
//draw background
Binary file not shown.
Binary file not shown.

0 comments on commit 9484aff

Please sign in to comment.
You can’t perform that action at this time.