Fix issues rendering SVG with text (fix #14644, #14794)

This commit is contained in:
Nyall Dawson 2016-06-08 16:33:48 +10:00
parent 0510da77ee
commit 2265115f80
5 changed files with 228 additions and 3 deletions

View File

@ -328,7 +328,13 @@ void QgsSvgCache::replaceParamsAndCacheSvg( QgsSvgCacheEntry* entry )
entry->viewboxSize = viewboxSize;
replaceElemParams( docElem, entry->fill, entry->outline, entry->outlineWidth * sizeScaleFactor );
entry->svgContent = svgDoc.toByteArray();
entry->svgContent = svgDoc.toByteArray( 0 );
// toByteArray screws up tspans inside text by adding new lines before and after each span... this should help, at the
// risk of potentially breaking some svgs where the newline is desired
entry->svgContent.replace( "\n<tspan", "<tspan" );
entry->svgContent.replace( "</tspan>\n", "</tspan>" );
mTotalSize += entry->svgContent.size();
}
@ -342,16 +348,23 @@ double QgsSvgCache::calcSizeScaleFactor( QgsSvgCacheEntry* entry, const QDomElem
//find svg viewbox attribute
//first check if docElem is svg element
if ( docElem.tagName() == "svg" )
if ( docElem.tagName() == "svg" && docElem.hasAttribute( "viewBox" ) )
{
viewBox = docElem.attribute( "viewBox", QString() );
}
else if ( docElem.tagName() == "svg" && docElem.hasAttribute( "viewbox" ) )
{
viewBox = docElem.attribute( "viewbox", QString() );
}
else
{
QDomElement svgElem = docElem.firstChildElement( "svg" ) ;
if ( !svgElem.isNull() )
{
viewBox = svgElem.attribute( "viewBox", QString() );
if ( svgElem.hasAttribute( "viewBox" ) )
viewBox = svgElem.attribute( "viewBox", QString() );
else if ( svgElem.hasAttribute( "viewbox" ) )
viewBox = svgElem.attribute( "viewbox", QString() );
}
}

View File

@ -57,10 +57,12 @@ class TestQgsComposerPicture : public QObject
void pictureSvgFrameToImage();
void svgParameters();
void issue_14644();
void pictureExpression();
void pictureInvalidExpression();
private:
QgsComposition* mComposition;
QgsComposerPicture* mComposerPicture;
@ -387,6 +389,22 @@ void TestQgsComposerPicture::svgParameters()
mComposerPicture->setPicturePath( mPngImage );
}
void TestQgsComposerPicture::issue_14644()
{
//test rendering SVG file with text
mComposition->addComposerPicture( mComposerPicture );
mComposerPicture->setResizeMode( QgsComposerPicture::Zoom );
mComposerPicture->setPicturePath( QString( TEST_DATA_DIR ) + "/svg/issue_14644.svg" );
QgsCompositionChecker checker( "composerpicture_issue_14644", mComposition );
checker.setControlPathPrefix( "composer_picture" );
QVERIFY( checker.testComposition( mReport, 0, 0 ) );
mComposition->removeItem( mComposerPicture );
mComposerPicture->setSceneRect( QRectF( 70, 70, 100, 100 ) );
mComposerPicture->setPicturePath( mPngImage );
}
void TestQgsComposerPicture::pictureExpression()
{
//test picture source via expression

Binary file not shown.

After

Width:  |  Height:  |  Size: 33 KiB

194
tests/testdata/svg/issue_14644.svg vendored Normal file

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 24 KiB