@@ -328,7 +328,13 @@ void QgsSvgCache::replaceParamsAndCacheSvg( QgsSvgCacheEntry* entry )
328
328
entry->viewboxSize = viewboxSize;
329
329
replaceElemParams ( docElem, entry->fill , entry->outline , entry->outlineWidth * sizeScaleFactor );
330
330
331
- entry->svgContent = svgDoc.toByteArray ();
331
+ entry->svgContent = svgDoc.toByteArray ( 0 );
332
+
333
+ // toByteArray screws up tspans inside text by adding new lines before and after each span... this should help, at the
334
+ // risk of potentially breaking some svgs where the newline is desired
335
+ entry->svgContent .replace ( " \n <tspan" , " <tspan" );
336
+ entry->svgContent .replace ( " </tspan>\n " , " </tspan>" );
337
+
332
338
mTotalSize += entry->svgContent .size ();
333
339
}
334
340
@@ -342,16 +348,23 @@ double QgsSvgCache::calcSizeScaleFactor( QgsSvgCacheEntry* entry, const QDomElem
342
348
343
349
// find svg viewbox attribute
344
350
// first check if docElem is svg element
345
- if ( docElem.tagName () == " svg" )
351
+ if ( docElem.tagName () == " svg" && docElem. hasAttribute ( " viewBox " ) )
346
352
{
347
353
viewBox = docElem.attribute ( " viewBox" , QString () );
348
354
}
355
+ else if ( docElem.tagName () == " svg" && docElem.hasAttribute ( " viewbox" ) )
356
+ {
357
+ viewBox = docElem.attribute ( " viewbox" , QString () );
358
+ }
349
359
else
350
360
{
351
361
QDomElement svgElem = docElem.firstChildElement ( " svg" ) ;
352
362
if ( !svgElem.isNull () )
353
363
{
354
- viewBox = svgElem.attribute ( " viewBox" , QString () );
364
+ if ( svgElem.hasAttribute ( " viewBox" ) )
365
+ viewBox = svgElem.attribute ( " viewBox" , QString () );
366
+ else if ( svgElem.hasAttribute ( " viewbox" ) )
367
+ viewBox = svgElem.attribute ( " viewbox" , QString () );
355
368
}
356
369
}
357
370
0 commit comments