This file is indexed.

/usr/include/qgis/qgssvgcache.h is in libqgis-dev 2.14.11+dfsg-3+deb9u1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
/***************************************************************************
                              qgssvgcache.h
                            ------------------------------
  begin                :  2011
  copyright            : (C) 2011 by Marco Hugentobler
  email                : marco dot hugentobler at sourcepole dot ch
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#ifndef QGSSVGCACHE_H
#define QGSSVGCACHE_H

#include <QColor>
#include <QMap>
#include <QMultiHash>
#include <QMutex>
#include <QString>
#include <QUrl>
#include <QObject>
#include <QSizeF>

class QDomElement;
class QImage;
class QPicture;

class CORE_EXPORT QgsSvgCacheEntry
{
  public:
    QgsSvgCacheEntry();
    /** Constructor.
     * @param file Absolute path to SVG file (relative paths are not resolved).
     * @param size
     * @param outlineWidth width of outline
     * @param widthScaleFactor width scale factor
     * @param rasterScaleFactor raster scale factor
     * @param fill color of fill
     * @param outline color of outline
     * @param lookupKey the key string used in QgsSvgCache for quick lookup of this entry (relative or absolute path)
     */
    QgsSvgCacheEntry( const QString& file, double size, double outlineWidth, double widthScaleFactor, double rasterScaleFactor, const QColor& fill, const QColor& outline, const QString& lookupKey = QString() );
    ~QgsSvgCacheEntry();

    //! Absolute path to SVG file
    QString file;
    //! Lookup key used by QgsSvgCache's hashtable (relative or absolute path). Needed for removal from the hashtable
    QString lookupKey;
    double size; //size in pixels (cast to int for QImage)
    double outlineWidth;
    double widthScaleFactor;
    double rasterScaleFactor;

    /** SVG viewbox size.
     * @note added in QGIS 2.14
     */
    QSizeF viewboxSize;

    QColor fill;
    QColor outline;
    QImage* image;
    QPicture* picture;
    //content (with params replaced)
    QByteArray svgContent;

    //keep entries on a least, sorted by last access
    QgsSvgCacheEntry* nextEntry;
    QgsSvgCacheEntry* previousEntry;

    /** Don't consider image, picture, last used timestamp for comparison*/
    bool operator==( const QgsSvgCacheEntry& other ) const;
    /** Return memory usage in bytes*/
    int dataSize() const;

  private:

    QgsSvgCacheEntry( const QgsSvgCacheEntry& rh );
    QgsSvgCacheEntry& operator=( const QgsSvgCacheEntry& rh );
};

/** A cache for images / pictures derived from svg files. This class supports parameter replacement in svg files
according to the svg params specification (http://www.w3.org/TR/2009/WD-SVGParamPrimer-20090616/). Supported are
the parameters 'fill-color', 'pen-color', 'outline-width', 'stroke-width'. E.g. <circle fill="param(fill-color red)" stroke="param(pen-color black)" stroke-width="param(outline-width 1)"*/
class CORE_EXPORT QgsSvgCache : public QObject
{
    Q_OBJECT

  public:

    static QgsSvgCache* instance();
    ~QgsSvgCache();

    /** Get SVG as QImage.
     * @param file Absolute or relative path to SVG file.
     * @param size size of cached image
     * @param fill color of fill
     * @param outline color of outline
     * @param outlineWidth width of outline
     * @param widthScaleFactor width scale factor
     * @param rasterScaleFactor raster scale factor
     * @param fitsInCache
     */
    const QImage& svgAsImage( const QString& file, double size, const QColor& fill, const QColor& outline, double outlineWidth,
                              double widthScaleFactor, double rasterScaleFactor, bool& fitsInCache );
    /** Get SVG  as QPicture&.
     * @param file Absolute or relative path to SVG file.
     * @param size size of cached image
     * @param fill color of fill
     * @param outline color of outline
     * @param outlineWidth width of outline
     * @param widthScaleFactor width scale factor
     * @param rasterScaleFactor raster scale factor
     * @param forceVectorOutput
     */
    const QPicture& svgAsPicture( const QString& file, double size, const QColor& fill, const QColor& outline, double outlineWidth,
                                  double widthScaleFactor, double rasterScaleFactor, bool forceVectorOutput = false );

    /** Calculates the viewbox size of a (possibly cached) SVG file.
     * @param file Absolute or relative path to SVG file.
     * @param size size of cached image
     * @param fill color of fill
     * @param outline color of outline
     * @param outlineWidth width of outline
     * @param widthScaleFactor width scale factor
     * @param rasterScaleFactor raster scale factor
     * @returns viewbox size set in SVG file
     * @note added in QGIS 2.14
     */
    QSizeF svgViewboxSize( const QString& file, double size, const QColor& fill, const QColor& outline, double outlineWidth,
                           double widthScaleFactor, double rasterScaleFactor );

    /** Tests if an svg file contains parameters for fill, outline color, outline width. If yes, possible default values are returned. If there are several
      default values in the svg file, only the first one is considered*/
    void containsParams( const QString& path, bool& hasFillParam, QColor& defaultFillColor, bool& hasOutlineParam, QColor& defaultOutlineColor, bool& hasOutlineWidthParam,
                         double& defaultOutlineWidth ) const;

    /** Tests if an svg file contains parameters for fill, outline color, outline width. If yes, possible default values are returned. If there are several
     * default values in the svg file, only the first one is considered.
     * @param path path to SVG file
     * @param hasFillParam will be true if fill param present in SVG
     * @param hasDefaultFillParam will be true if fill param has a default value specified
     * @param defaultFillColor will be set to default fill color specified in SVG, if present
     * @param hasOutlineParam will be true if outline param present in SVG
     * @param hasDefaultOutlineColor will be true if outline param has a default value specified
     * @param defaultOutlineColor will be set to default outline color specified in SVG, if present
     * @param hasOutlineWidthParam will be true if outline width param present in SVG
     * @param hasDefaultOutlineWidth will be true if outline width param has a default value specified
     * @param defaultOutlineWidth will be set to default outline width specified in SVG, if present
     * @note available in python bindings as containsParamsV2
     * @note added in QGIS 2.12
     * @deprecated use variant with fill and outline opacity
     */
    Q_DECL_DEPRECATED void containsParams( const QString& path, bool& hasFillParam, bool& hasDefaultFillParam, QColor& defaultFillColor,
                                           bool& hasOutlineParam, bool& hasDefaultOutlineColor, QColor& defaultOutlineColor,
                                           bool& hasOutlineWidthParam, bool& hasDefaultOutlineWidth, double& defaultOutlineWidth ) const;

    /** Tests if an svg file contains parameters for fill, outline color, outline width. If yes, possible default values are returned. If there are several
     * default values in the svg file, only the first one is considered.
     * @param path path to SVG file
     * @param hasFillParam will be true if fill param present in SVG
     * @param hasDefaultFillParam will be true if fill param has a default value specified
     * @param defaultFillColor will be set to default fill color specified in SVG, if present
     * @param hasFillOpacityParam will be true if fill opacity param present in SVG
     * @param hasDefaultFillOpacity will be true if fill opacity param has a default value specified
     * @param defaultFillOpacity will be set to default fill opacity specified in SVG, if present
     * @param hasOutlineParam will be true if outline param present in SVG
     * @param hasDefaultOutlineColor will be true if outline param has a default value specified
     * @param defaultOutlineColor will be set to default outline color specified in SVG, if present
     * @param hasOutlineWidthParam will be true if outline width param present in SVG
     * @param hasDefaultOutlineWidth will be true if outline width param has a default value specified
     * @param defaultOutlineWidth will be set to default outline width specified in SVG, if present
     * @param hasOutlineOpacityParam will be true if outline opacity param present in SVG
     * @param hasDefaultOutlineOpacity will be true if outline opacity param has a default value specified
     * @param defaultOutlineOpacity will be set to default outline opacity specified in SVG, if present
     * @note available in python bindings as containsParamsV3
     * @note added in QGIS 2.14
     */
    void containsParams( const QString& path, bool& hasFillParam, bool& hasDefaultFillParam, QColor& defaultFillColor,
                         bool& hasFillOpacityParam, bool& hasDefaultFillOpacity, double& defaultFillOpacity,
                         bool& hasOutlineParam, bool& hasDefaultOutlineColor, QColor& defaultOutlineColor,
                         bool& hasOutlineWidthParam, bool& hasDefaultOutlineWidth, double& defaultOutlineWidth,
                         bool& hasOutlineOpacityParam, bool& hasDefaultOutlineOpacity, double& defaultOutlineOpacity ) const;

    /** Get image data*/
    QByteArray getImageData( const QString &path ) const;

    /** Get SVG content*/
    const QByteArray& svgContent( const QString& file, double size, const QColor& fill, const QColor& outline, double outlineWidth,
                                  double widthScaleFactor, double rasterScaleFactor );

  signals:
    /** Emit a signal to be caught by qgisapp and display a msg on status bar */
    void statusChanged( const QString&  theStatusQString );

  protected:
    //! protected constructor
    QgsSvgCache( QObject * parent = nullptr );

    /** Creates new cache entry and returns pointer to it
     * @param file Absolute or relative path to SVG file. If the path is relative the file is searched by QgsSymbolLayerV2Utils::symbolNameToPath() in SVG paths.
     * in settings svg/searchPathsForSVG
     * @param size size of cached image
     * @param fill color of fill
     * @param outline color of outline
     * @param outlineWidth width of outline
     * @param widthScaleFactor width scale factor
     * @param rasterScaleFactor raster scale factor
     */
    QgsSvgCacheEntry* insertSVG( const QString& file, double size, const QColor& fill, const QColor& outline, double outlineWidth,
                                 double widthScaleFactor, double rasterScaleFactor );

    void replaceParamsAndCacheSvg( QgsSvgCacheEntry* entry );
    void cacheImage( QgsSvgCacheEntry* entry );
    void cachePicture( QgsSvgCacheEntry* entry, bool forceVectorOutput = false );
    /** Returns entry from cache or creates a new entry if it does not exist already*/
    QgsSvgCacheEntry* cacheEntry( const QString& file, double size, const QColor& fill, const QColor& outline, double outlineWidth,
                                  double widthScaleFactor, double rasterScaleFactor );

    /** Removes the least used items until the maximum size is under the limit*/
    void trimToMaximumSize();

    //Removes entry from the ordered list (but does not delete the entry itself)
    void takeEntryFromList( QgsSvgCacheEntry* entry );

  private slots:
    void downloadProgress( qint64, qint64 );

  private:
    /** Entry pointers accessible by file name*/
    QMultiHash< QString, QgsSvgCacheEntry* > mEntryLookup;
    /** Estimated total size of all images, pictures and svgContent*/
    long mTotalSize;

    //The svg cache keeps the entries on a double connected list, moving the current entry to the front.
    //That way, removing entries for more space can start with the least used objects.
    QgsSvgCacheEntry* mLeastRecentEntry;
    QgsSvgCacheEntry* mMostRecentEntry;

    //Maximum cache size
    static const long mMaximumSize = 20000000;

    /** Replaces parameters in elements of a dom node and calls method for all child nodes*/
    void replaceElemParams( QDomElement& elem, const QColor& fill, const QColor& outline, double outlineWidth );

    void containsElemParams( const QDomElement& elem,
                             bool& hasFillParam, bool& hasDefaultFill, QColor& defaultFill,
                             bool& hasFillOpacityParam, bool& hasDefaultFillOpacity, double& defaultFillOpacity,
                             bool& hasOutlineParam, bool& hasDefaultOutline, QColor& defaultOutline,
                             bool& hasOutlineWidthParam, bool& hasDefaultOutlineWidth, double& defaultOutlineWidth,
                             bool& hasOutlineOpacityParam, bool& hasDefaultOutlineOpacity, double& defaultOutlineOpacity ) const;

    /** Calculates scaling for rendered image sizes to SVG logical sizes*/
    double calcSizeScaleFactor( QgsSvgCacheEntry* entry, const QDomElement& docElem, QSizeF& viewboxSize ) const;

    /** Release memory and remove cache entry from mEntryLookup*/
    void removeCacheEntry( const QString& s, QgsSvgCacheEntry* entry );

    /** For debugging*/
    void printEntryList();

    /** SVG content to be rendered if SVG file was not found. */
    QByteArray mMissingSvg;

    //! Mutex to prevent concurrent access to the class from multiple threads at once (may corrupt the entries otherwise).
    QMutex mMutex;

};

#endif // QGSSVGCACHE_H