29#include <QApplication>
30#include <QCoreApplication>
32#include <QDomDocument>
37#include <QNetworkReply>
38#include <QNetworkRequest>
41#include <QRegularExpression>
43#include <QSvgRenderer>
45#include "moc_qgssvgcache.cpp"
47using namespace Qt::StringLiterals;
55QgsSvgCacheEntry::QgsSvgCacheEntry(
56 const QString &path,
double size,
double strokeWidth,
double widthScaleFactor,
const QColor &fill,
const QColor &stroke,
double fixedAspectRatio,
const QMap<QString, QString> ¶meters
60 , strokeWidth( strokeWidth )
61 , widthScaleFactor( widthScaleFactor )
62 , fixedAspectRatio( fixedAspectRatio )
65 , parameters( parameters )
70 const QgsSvgCacheEntry *otherSvg =
dynamic_cast< const QgsSvgCacheEntry *
>( other );
73 || !
qgsDoubleNear( otherSvg->fixedAspectRatio, fixedAspectRatio )
76 || !
qgsDoubleNear( otherSvg->widthScaleFactor, widthScaleFactor )
77 || otherSvg->fill != fill
78 || otherSvg->stroke != stroke
79 || otherSvg->path != path
80 || otherSvg->parameters != parameters )
86int QgsSvgCacheEntry::dataSize()
const
88 int size = svgContent.size();
91 size += picture->size();
95 size += ( image->width() * image->height() * 32 );
100void QgsSvgCacheEntry::dump()
const
102 QgsDebugMsgLevel( u
"path: %1, size %2, width scale factor %3"_s.arg( path ).arg( size ).arg( widthScaleFactor ), 4 );
114 mMissingSvg = u
"<svg width='10' height='10'><text x='5' y='10' font-size='10' text-anchor='middle'>?</text></svg>"_s.toLatin1();
117 if ( QFile::exists( downloadingSvgPath ) )
119 QFile file( downloadingSvgPath );
120 if ( file.open( QIODevice::ReadOnly ) )
122 mFetchingSvg = file.readAll();
126 if ( mFetchingSvg.isEmpty() )
128 mFetchingSvg = u
"<svg width='10' height='10'><text x='5' y='10' font-size='10' text-anchor='middle'>?</text></svg>"_s.toLatin1();
138 const QColor &stroke,
140 double widthScaleFactor,
142 double fixedAspectRatio,
144 const QMap<QString, QString> ¶meters
147 const QMutexLocker locker( &
mMutex );
150 QgsSvgCacheEntry *currentEntry = cacheEntry( file, size, fill, stroke, strokeWidth, widthScaleFactor, fixedAspectRatio, parameters, blocking );
157 if ( !currentEntry->image )
159 const QSvgRenderer r( currentEntry->svgContent );
160 double hwRatio = 1.0;
161 if ( r.viewBoxF().width() > 0 )
163 if ( currentEntry->fixedAspectRatio > 0 )
165 hwRatio = currentEntry->fixedAspectRatio;
169 hwRatio = r.viewBoxF().height() / r.viewBoxF().width();
172 long cachedDataSize = 0;
173 cachedDataSize += currentEntry->svgContent.size();
174 cachedDataSize +=
static_cast< int >( currentEntry->size * currentEntry->size * hwRatio * 32 );
178 currentEntry->image.reset();
181 if ( !currentEntry->picture )
183 cachePicture( currentEntry,
false );
187 result = imageFromCachedPicture( *currentEntry );
191 cacheImage( currentEntry );
192 result = *( currentEntry->image );
198 result = *( currentEntry->image );
208 const QColor &stroke,
210 double widthScaleFactor,
211 bool forceVectorOutput,
212 double fixedAspectRatio,
214 const QMap<QString, QString> ¶meters
217 const QMutexLocker locker( &
mMutex );
219 QgsSvgCacheEntry *currentEntry = cacheEntry( path, size, fill, stroke, strokeWidth, widthScaleFactor, fixedAspectRatio, parameters, blocking );
223 if ( !currentEntry->picture )
225 cachePicture( currentEntry, forceVectorOutput );
236 const QColor &stroke,
238 double widthScaleFactor,
239 double fixedAspectRatio,
241 const QMap<QString, QString> ¶meters,
245 const QMutexLocker locker( &
mMutex );
247 QgsSvgCacheEntry *currentEntry = cacheEntry( path, size, fill, stroke, strokeWidth, widthScaleFactor, fixedAspectRatio, parameters, blocking, isMissingImage );
249 return currentEntry->svgContent;
253 const QString &path,
double size,
const QColor &fill,
const QColor &stroke,
double strokeWidth,
double widthScaleFactor,
double fixedAspectRatio,
bool blocking,
const QMap<QString, QString> ¶meters
256 const QMutexLocker locker( &
mMutex );
258 QgsSvgCacheEntry *currentEntry = cacheEntry( path, size, fill, stroke, strokeWidth, widthScaleFactor, fixedAspectRatio, parameters, blocking );
259 return currentEntry->viewboxSize;
263 const QString &path,
bool &hasFillParam, QColor &defaultFillColor,
bool &hasStrokeParam, QColor &defaultStrokeColor,
bool &hasStrokeWidthParam,
double &defaultStrokeWidth,
bool blocking
266 bool hasDefaultFillColor =
false;
267 bool hasFillOpacityParam =
false;
268 bool hasDefaultFillOpacity =
false;
269 double defaultFillOpacity = 1.0;
270 bool hasDefaultStrokeColor =
false;
271 bool hasDefaultStrokeWidth =
false;
272 bool hasStrokeOpacityParam =
false;
273 bool hasDefaultStrokeOpacity =
false;
274 double defaultStrokeOpacity = 1.0;
282 hasDefaultFillOpacity,
285 hasDefaultStrokeColor,
288 hasDefaultStrokeWidth,
290 hasStrokeOpacityParam,
291 hasDefaultStrokeOpacity,
292 defaultStrokeOpacity,
300 bool &hasDefaultFillParam,
301 QColor &defaultFillColor,
302 bool &hasFillOpacityParam,
303 bool &hasDefaultFillOpacity,
304 double &defaultFillOpacity,
305 bool &hasStrokeParam,
306 bool &hasDefaultStrokeColor,
307 QColor &defaultStrokeColor,
308 bool &hasStrokeWidthParam,
309 bool &hasDefaultStrokeWidth,
310 double &defaultStrokeWidth,
311 bool &hasStrokeOpacityParam,
312 bool &hasDefaultStrokeOpacity,
313 double &defaultStrokeOpacity,
317 hasFillParam =
false;
318 hasFillOpacityParam =
false;
319 hasStrokeParam =
false;
320 hasStrokeWidthParam =
false;
321 hasStrokeOpacityParam =
false;
322 defaultFillColor = QColor( Qt::white );
323 defaultFillOpacity = 1.0;
324 defaultStrokeColor = QColor( Qt::black );
325 defaultStrokeWidth = 0.2;
326 defaultStrokeOpacity = 1.0;
328 hasDefaultFillParam =
false;
329 hasDefaultFillOpacity =
false;
330 hasDefaultStrokeColor =
false;
331 hasDefaultStrokeWidth =
false;
332 hasDefaultStrokeOpacity =
false;
335 if ( !svgDoc.setContent(
getContent( path, mMissingSvg, mFetchingSvg, blocking ) ) )
340 const QDomElement docElem = svgDoc.documentElement();
347 hasDefaultFillOpacity,
350 hasDefaultStrokeColor,
353 hasDefaultStrokeWidth,
355 hasStrokeOpacityParam,
356 hasDefaultStrokeOpacity,
361void QgsSvgCache::replaceParamsAndCacheSvg( QgsSvgCacheEntry *entry,
bool blocking )
368 const QByteArray content =
getContent( entry->path, mMissingSvg, mFetchingSvg, blocking );
369 entry->isMissingImage = content == mMissingSvg;
371 if ( !svgDoc.setContent( content ) )
377 QDomElement docElem = svgDoc.documentElement();
380 const double sizeScaleFactor = calcSizeScaleFactor( entry, docElem, viewboxSize );
381 entry->viewboxSize = viewboxSize;
382 replaceElemParams( docElem, entry->fill, entry->stroke, entry->strokeWidth * sizeScaleFactor, entry->parameters );
384 entry->svgContent = svgDoc.toByteArray( 0 );
389 entry->svgContent.replace(
"\n<tspan",
"<tspan" );
390 entry->svgContent.replace(
"</tspan>\n",
"</tspan>" );
395double QgsSvgCache::calcSizeScaleFactor( QgsSvgCacheEntry *entry,
const QDomElement &docElem, QSizeF &viewboxSize )
const
405 if ( docElem.tagName() ==
"svg"_L1 && docElem.hasAttribute( u
"viewBox"_s ) )
407 viewBox = docElem.attribute( u
"viewBox"_s, QString() );
409 else if ( docElem.tagName() ==
"svg"_L1 && docElem.hasAttribute( u
"viewbox"_s ) )
411 viewBox = docElem.attribute( u
"viewbox"_s, QString() );
415 const QDomElement svgElem = docElem.firstChildElement( u
"svg"_s );
416 if ( !svgElem.isNull() )
418 if ( svgElem.hasAttribute( u
"viewBox"_s ) )
419 viewBox = svgElem.attribute( u
"viewBox"_s, QString() );
420 else if ( svgElem.hasAttribute( u
"viewbox"_s ) )
421 viewBox = svgElem.attribute( u
"viewbox"_s, QString() );
426 if ( viewBox.isEmpty() )
429 if ( docElem.tagName() ==
"svg"_L1 && docElem.hasAttribute( u
"width"_s ) )
431 const QString widthString = docElem.attribute( u
"width"_s );
432 const thread_local QRegularExpression measureRegEx( u
"([\\d\\.]+).*?$"_s );
433 const QRegularExpressionMatch widthMatch = measureRegEx.match( widthString );
434 if ( widthMatch.hasMatch() )
436 const double width = widthMatch.captured( 1 ).toDouble();
437 const QString heightString = docElem.attribute( u
"height"_s );
439 const QRegularExpressionMatch heightMatch = measureRegEx.match( heightString );
440 if ( heightMatch.hasMatch() )
442 const double height = heightMatch.captured( 1 ).toDouble();
443 viewboxSize = QSizeF( width, height );
444 return width / entry->size;
454 const QStringList parts = viewBox.split(
' ' );
455 if ( parts.count() != 4 )
458 bool heightOk =
false;
459 const double height = parts.at( 3 ).toDouble( &heightOk );
461 bool widthOk =
false;
462 const double width = parts.at( 2 ).toDouble( &widthOk );
466 viewboxSize = QSizeF( width, height );
467 return width / entry->size;
476 return getContent( path, mMissingSvg, mFetchingSvg, blocking );
483 const QString contentType = reply->header( QNetworkRequest::ContentTypeHeader ).toString();
484 if ( !contentType.startsWith(
"image/svg+xml"_L1, Qt::CaseInsensitive ) && !contentType.startsWith(
"text/plain"_L1, Qt::CaseInsensitive ) )
492void QgsSvgCache::cacheImage( QgsSvgCacheEntry *entry )
499 entry->image.reset();
503 const QSize imageSize = sizeForImage( *entry, viewBoxSize, scaledSize );
506 auto image = std::make_unique< QImage >( imageSize, QImage::Format_ARGB32_Premultiplied );
509 const bool isFixedAR = entry->fixedAspectRatio > 0;
511 QPainter p( image.get() );
512 QSvgRenderer r( entry->svgContent );
513 if (
qgsDoubleNear( viewBoxSize.width(), viewBoxSize.height() ) )
519 QSizeF s( viewBoxSize );
520 s.scale( scaledSize.width(), scaledSize.height(), isFixedAR ? Qt::IgnoreAspectRatio : Qt::KeepAspectRatio );
521 const QRectF rect( ( imageSize.width() - s.width() ) / 2, ( imageSize.height() - s.height() ) / 2, s.width(), s.height() );
522 r.render( &p, rect );
525 mTotalSize += ( image->width() * image->height() * 32 );
526 entry->image = std::move( image );
529void QgsSvgCache::cachePicture( QgsSvgCacheEntry *entry,
bool forceVectorOutput )
531 Q_UNUSED( forceVectorOutput )
537 entry->picture.reset();
539 const bool isFixedAR = entry->fixedAspectRatio > 0;
542 auto picture = std::make_unique< QPicture >();
544 QSvgRenderer r( entry->svgContent );
545 double hwRatio = 1.0;
546 if ( r.viewBoxF().width() > 0 )
550 hwRatio = entry->fixedAspectRatio;
554 hwRatio = r.viewBoxF().height() / r.viewBoxF().width();
558 const double wSize = entry->size;
559 const double hSize = wSize * hwRatio;
561 QSizeF s( r.viewBoxF().size() );
562 s.scale( wSize, hSize, isFixedAR ? Qt::IgnoreAspectRatio : Qt::KeepAspectRatio );
563 rect = QRectF( -s.width() / 2.0, -s.height() / 2.0, s.width(), s.height() );
565 QPainter p( picture.get() );
566 r.render( &p, rect );
567 entry->picture = std::move( picture );
571QgsSvgCacheEntry *QgsSvgCache::cacheEntry(
575 const QColor &stroke,
577 double widthScaleFactor,
578 double fixedAspectRatio,
579 const QMap<QString, QString> ¶meters,
584 QgsSvgCacheEntry *currentEntry =
findExistingEntry(
new QgsSvgCacheEntry( path, size, strokeWidth, widthScaleFactor, fill, stroke, fixedAspectRatio, parameters ) );
586 if ( currentEntry->svgContent.isEmpty() )
588 replaceParamsAndCacheSvg( currentEntry, blocking );
591 if ( isMissingImage )
592 *isMissingImage = currentEntry->isMissingImage;
598void QgsSvgCache::replaceElemParams( QDomElement &elem,
const QColor &fill,
const QColor &stroke,
double strokeWidth,
const QMap<QString, QString> ¶meters )
606 const QDomNamedNodeMap attributes = elem.attributes();
607 const int nAttributes = attributes.count();
608 for (
int i = 0; i < nAttributes; ++i )
610 const QDomAttr attribute = attributes.item( i ).toAttr();
612 if ( attribute.name().compare(
"style"_L1, Qt::CaseInsensitive ) == 0 )
615 QString newAttributeString;
617 const QStringList entryList = attribute.value().split(
';' );
618 QStringList::const_iterator entryIt = entryList.constBegin();
619 for ( ; entryIt != entryList.constEnd(); ++entryIt )
621 const QStringList keyValueSplit = entryIt->split(
':' );
622 if ( keyValueSplit.size() < 2 )
626 const QString key = keyValueSplit.at( 0 );
627 QString value = keyValueSplit.at( 1 );
628 QString newValue = value;
629 value = value.trimmed().toLower();
631 if ( value.startsWith(
"param(fill)"_L1 ) )
633 newValue = fill.name();
635 else if ( value.startsWith(
"param(fill-opacity)"_L1 ) )
637 newValue = QString::number( fill.alphaF() );
639 else if ( value.startsWith(
"param(outline)"_L1 ) )
641 newValue = stroke.name();
643 else if ( value.startsWith(
"param(outline-opacity)"_L1 ) )
645 newValue = QString::number( stroke.alphaF() );
647 else if ( value.startsWith(
"param(outline-width)"_L1 ) )
649 newValue = QString::number( strokeWidth );
652 if ( entryIt != entryList.constBegin() )
654 newAttributeString.append(
';' );
656 newAttributeString.append( key +
':' + newValue );
658 elem.setAttribute( attribute.name(), newAttributeString );
662 const QString value = attribute.value().trimmed().toLower();
663 if ( value.startsWith(
"param(fill)"_L1 ) )
665 elem.setAttribute( attribute.name(), fill.name() );
667 else if ( value.startsWith(
"param(fill-opacity)"_L1 ) )
669 elem.setAttribute( attribute.name(), fill.alphaF() );
671 else if ( value.startsWith(
"param(outline)"_L1 ) )
673 elem.setAttribute( attribute.name(), stroke.name() );
675 else if ( value.startsWith(
"param(outline-opacity)"_L1 ) )
677 elem.setAttribute( attribute.name(), stroke.alphaF() );
679 else if ( value.startsWith(
"param(outline-width)"_L1 ) )
681 elem.setAttribute( attribute.name(), QString::number( strokeWidth ) );
685 QMap<QString, QString>::const_iterator paramIt = parameters.constBegin();
686 for ( ; paramIt != parameters.constEnd(); ++paramIt )
688 if ( value.startsWith( QString(
"param(%1)"_L1 ).arg( paramIt.key() ) ) )
690 elem.setAttribute( attribute.name(), paramIt.value() );
698 QDomNode child = elem.firstChild();
699 if ( child.isText() && child.nodeValue().startsWith(
"param(" ) )
701 QMap<QString, QString>::const_iterator paramIt = parameters.constBegin();
702 for ( ; paramIt != parameters.constEnd(); ++paramIt )
704 if ( child.toText().data().startsWith( QString(
"param(%1)"_L1 ).arg( paramIt.key() ) ) )
706 child.setNodeValue( paramIt.value() );
712 const QDomNodeList childList = elem.childNodes();
713 const int nChildren = childList.count();
714 for (
int i = 0; i < nChildren; ++i )
716 QDomElement childElem = childList.at( i ).toElement();
717 replaceElemParams( childElem, fill, stroke, strokeWidth, parameters );
721void QgsSvgCache::containsElemParams(
722 const QDomElement &elem,
724 bool &hasDefaultFill,
726 bool &hasFillOpacityParam,
727 bool &hasDefaultFillOpacity,
728 double &defaultFillOpacity,
729 bool &hasStrokeParam,
730 bool &hasDefaultStroke,
731 QColor &defaultStroke,
732 bool &hasStrokeWidthParam,
733 bool &hasDefaultStrokeWidth,
734 double &defaultStrokeWidth,
735 bool &hasStrokeOpacityParam,
736 bool &hasDefaultStrokeOpacity,
737 double &defaultStrokeOpacity
746 if ( hasFillParam && hasStrokeParam && hasStrokeWidthParam && hasFillOpacityParam && hasStrokeOpacityParam )
752 const QDomNamedNodeMap attributes = elem.attributes();
753 const int nAttributes = attributes.count();
755 QStringList valueSplit;
756 for (
int i = 0; i < nAttributes; ++i )
758 const QDomAttr attribute = attributes.item( i ).toAttr();
759 if ( attribute.name().compare(
"style"_L1, Qt::CaseInsensitive ) == 0 )
762 const QStringList entryList = attribute.value().split(
';' );
763 QStringList::const_iterator entryIt = entryList.constBegin();
764 for ( ; entryIt != entryList.constEnd(); ++entryIt )
766 const QStringList keyValueSplit = entryIt->split(
':' );
767 if ( keyValueSplit.size() < 2 )
771 const QString value = keyValueSplit.at( 1 );
772 valueSplit = value.split(
' ' );
773 if ( !hasFillParam && value.startsWith(
"param(fill)"_L1 ) )
776 if ( valueSplit.size() > 1 )
778 defaultFill = QColor( valueSplit.at( 1 ) );
779 hasDefaultFill =
true;
782 else if ( !hasFillOpacityParam && value.startsWith(
"param(fill-opacity)"_L1 ) )
784 hasFillOpacityParam =
true;
785 if ( valueSplit.size() > 1 )
788 const double opacity = valueSplit.at( 1 ).toDouble( &ok );
791 defaultFillOpacity = opacity;
792 hasDefaultFillOpacity =
true;
796 else if ( !hasStrokeParam && value.startsWith(
"param(outline)"_L1 ) )
798 hasStrokeParam =
true;
799 if ( valueSplit.size() > 1 )
801 defaultStroke = QColor( valueSplit.at( 1 ) );
802 hasDefaultStroke =
true;
805 else if ( !hasStrokeWidthParam && value.startsWith(
"param(outline-width)"_L1 ) )
807 hasStrokeWidthParam =
true;
808 if ( valueSplit.size() > 1 )
810 defaultStrokeWidth = valueSplit.at( 1 ).toDouble();
811 hasDefaultStrokeWidth =
true;
814 else if ( !hasStrokeOpacityParam && value.startsWith(
"param(outline-opacity)"_L1 ) )
816 hasStrokeOpacityParam =
true;
817 if ( valueSplit.size() > 1 )
820 const double opacity = valueSplit.at( 1 ).toDouble( &ok );
823 defaultStrokeOpacity = opacity;
824 hasDefaultStrokeOpacity =
true;
832 const QString value = attribute.value();
833 valueSplit = value.split(
' ' );
834 if ( !hasFillParam && value.startsWith(
"param(fill)"_L1 ) )
837 if ( valueSplit.size() > 1 )
839 defaultFill = QColor( valueSplit.at( 1 ) );
840 hasDefaultFill =
true;
843 else if ( !hasFillOpacityParam && value.startsWith(
"param(fill-opacity)"_L1 ) )
845 hasFillOpacityParam =
true;
846 if ( valueSplit.size() > 1 )
849 const double opacity = valueSplit.at( 1 ).toDouble( &ok );
852 defaultFillOpacity = opacity;
853 hasDefaultFillOpacity =
true;
857 else if ( !hasStrokeParam && value.startsWith(
"param(outline)"_L1 ) )
859 hasStrokeParam =
true;
860 if ( valueSplit.size() > 1 )
862 defaultStroke = QColor( valueSplit.at( 1 ) );
863 hasDefaultStroke =
true;
866 else if ( !hasStrokeWidthParam && value.startsWith(
"param(outline-width)"_L1 ) )
868 hasStrokeWidthParam =
true;
869 if ( valueSplit.size() > 1 )
871 defaultStrokeWidth = valueSplit.at( 1 ).toDouble();
872 hasDefaultStrokeWidth =
true;
875 else if ( !hasStrokeOpacityParam && value.startsWith(
"param(outline-opacity)"_L1 ) )
877 hasStrokeOpacityParam =
true;
878 if ( valueSplit.size() > 1 )
881 const double opacity = valueSplit.at( 1 ).toDouble( &ok );
884 defaultStrokeOpacity = opacity;
885 hasDefaultStrokeOpacity =
true;
893 const QDomNodeList childList = elem.childNodes();
894 const int nChildren = childList.count();
895 for (
int i = 0; i < nChildren; ++i )
897 const QDomElement childElem = childList.at( i ).toElement();
904 hasDefaultFillOpacity,
910 hasDefaultStrokeWidth,
912 hasStrokeOpacityParam,
913 hasDefaultStrokeOpacity,
919QSize QgsSvgCache::sizeForImage(
const QgsSvgCacheEntry &entry, QSizeF &viewBoxSize, QSizeF &scaledSize )
const
921 const bool isFixedAR = entry.fixedAspectRatio > 0;
923 const QSvgRenderer r( entry.svgContent );
924 double hwRatio = 1.0;
925 viewBoxSize = r.viewBoxF().size();
926 if ( viewBoxSize.width() > 0 )
930 hwRatio = entry.fixedAspectRatio;
934 hwRatio = viewBoxSize.height() / viewBoxSize.width();
939 scaledSize.setWidth( entry.size );
940 int wImgSize =
static_cast< int >( scaledSize.width() );
945 scaledSize.setHeight( scaledSize.width() * hwRatio );
946 int hImgSize =
static_cast< int >( scaledSize.height() );
951 return QSize( wImgSize, hImgSize );
954QImage QgsSvgCache::imageFromCachedPicture(
const QgsSvgCacheEntry &entry )
const
958 QImage image( sizeForImage( entry, viewBoxSize, scaledSize ), QImage::Format_ARGB32_Premultiplied );
961 QPainter p( &image );
962 p.drawPicture( QPoint( 0, 0 ), *entry.picture );
void remoteContentFetched(const QString &url)
Emitted when the cache has finished retrieving content from a remote url.
Base class for entries in a QgsAbstractContentCache.
Abstract base class for file content caches, such as SVG or raster image caches.
QByteArray getContent(const QString &path, const QByteArray &missingContent, const QByteArray &fetchingContent, bool blocking=false) const
QgsSvgCacheEntry * findExistingEntry(QgsSvgCacheEntry *entryTemplate)
QgsAbstractContentCache(QObject *parent=nullptr, const QString &typeString=QString(), long maxCacheSize=20000000, int fileModifiedCheckTimeout=30000)
static QString defaultThemePath()
Returns the path to the default theme directory.
static void logMessage(const QString &message, const QString &tag=QString(), Qgis::MessageLevel level=Qgis::MessageLevel::Warning, bool notifyUser=true, const char *file=__builtin_FILE(), const char *function=__builtin_FUNCTION(), int line=__builtin_LINE(), Qgis::StringFormat format=Qgis::StringFormat::PlainText)
Adds a message to the log instance (and creates it if necessary).
static QPicture deepCopyQPicture(const QPicture &picture)
Deep copies a QPicture, making a copy which is safe to use in a different thread.
QSizeF svgViewboxSize(const QString &path, double size, const QColor &fill, const QColor &stroke, double strokeWidth, double widthScaleFactor, double fixedAspectRatio=0, bool blocking=false, const QMap< QString, QString > ¶meters=QMap< QString, QString >())
Calculates the viewbox size of a (possibly cached) SVG file.
QByteArray getImageData(const QString &path, bool blocking=false) const
Gets the SVG content corresponding to the given path.
QPicture svgAsPicture(const QString &path, double size, const QColor &fill, const QColor &stroke, double strokeWidth, double widthScaleFactor, bool forceVectorOutput=false, double fixedAspectRatio=0, bool blocking=false, const QMap< QString, QString > ¶meters=QMap< QString, QString >())
Returns an SVG drawing as a QPicture.
QgsSvgCache(QObject *parent=nullptr)
Constructor for QgsSvgCache.
bool checkReply(QNetworkReply *reply, const QString &path) const override
Runs additional checks on a network reply to ensure that the reply content is consistent with that re...
void containsParams(const QString &path, bool &hasFillParam, QColor &defaultFillColor, bool &hasStrokeParam, QColor &defaultStrokeColor, bool &hasStrokeWidthParam, double &defaultStrokeWidth, bool blocking=false) const
Tests if an SVG file contains parameters for fill, stroke color, stroke width.
void remoteSvgFetched(const QString &url)
Emitted when the cache has finished retrieving an SVG file from a remote url.
QImage svgAsImage(const QString &path, double size, const QColor &fill, const QColor &stroke, double strokeWidth, double widthScaleFactor, bool &fitsInCache, double fixedAspectRatio=0, bool blocking=false, const QMap< QString, QString > ¶meters=QMap< QString, QString >())
Returns an SVG drawing as a QImage.
QByteArray svgContent(const QString &path, double size, const QColor &fill, const QColor &stroke, double strokeWidth, double widthScaleFactor, double fixedAspectRatio=0, bool blocking=false, const QMap< QString, QString > ¶meters=QMap< QString, QString >(), bool *isMissingImage=nullptr)
Gets the SVG content corresponding to the given path.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference).
#define QgsDebugMsgLevel(str, level)