Skip to content
Permalink
Browse files

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

  • Loading branch information
nyalldawson committed Jun 8, 2016
1 parent 0510da7 commit 2265115f8003857e538f07287c1337fed463a39c
@@ -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() );
}
}

@@ -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.
Binary file not shown.

Large diffs are not rendered by default.

0 comments on commit 2265115

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