示例#1
0
QImage QgsSvgCache::svgAsImage( const QString &file, double size, const QColor &fill, const QColor &stroke, double strokeWidth,
                                double widthScaleFactor, bool &fitsInCache, double fixedAspectRatio )
{
  QMutexLocker locker( &mMutex );

  fitsInCache = true;
  QgsSvgCacheEntry *currentEntry = cacheEntry( file, size, fill, stroke, strokeWidth, widthScaleFactor, fixedAspectRatio );

  QImage result;

  //if current entry image is 0: cache image for entry
  // checks to see if image will fit into cache
  //update stats for memory usage
  if ( !currentEntry->image )
  {
    QSvgRenderer r( currentEntry->svgContent );
    double hwRatio = 1.0;
    if ( r.viewBoxF().width() > 0 )
    {
      if ( currentEntry->fixedAspectRatio > 0 )
      {
        hwRatio = currentEntry->fixedAspectRatio;
      }
      else
      {
        hwRatio = r.viewBoxF().height() / r.viewBoxF().width();
      }
    }
    long cachedDataSize = 0;
    cachedDataSize += currentEntry->svgContent.size();
    cachedDataSize += static_cast< int >( currentEntry->size * currentEntry->size * hwRatio * 32 );
    if ( cachedDataSize > MAXIMUM_SIZE / 2 )
    {
      fitsInCache = false;
      currentEntry->image.reset();

      // instead cache picture
      if ( !currentEntry->picture )
      {
        cachePicture( currentEntry, false );
      }

      // ...and render cached picture to result image
      result = imageFromCachedPicture( *currentEntry );
    }
    else
    {
      cacheImage( currentEntry );
      result = *( currentEntry->image );
    }
    trimToMaximumSize();
  }
  else
  {
    result = *( currentEntry->image );
  }

  return result;
}
示例#2
0
const QPicture& QgsSvgCache::svgAsPicture( const QString& file, double size, const QColor& fill, const QColor& outline, double outlineWidth,
    double widthScaleFactor, double rasterScaleFactor, bool forceVectorOutput )
{
  QgsSvgCacheEntry* currentEntry = cacheEntry( file, size, fill, outline, outlineWidth, widthScaleFactor, rasterScaleFactor );

  //if current entry picture is 0: cache picture for entry
  //update stats for memory usage
  if ( !currentEntry->picture )
  {
    cachePicture( currentEntry, forceVectorOutput );
    trimToMaximumSize();
  }

  return *( currentEntry->picture );
}
示例#3
0
QPicture QgsSvgCache::svgAsPicture( const QString &path, double size, const QColor &fill, const QColor &stroke, double strokeWidth,
                                    double widthScaleFactor, bool forceVectorOutput, double fixedAspectRatio )
{
  QMutexLocker locker( &mMutex );

  QgsSvgCacheEntry *currentEntry = cacheEntry( path, size, fill, stroke, strokeWidth, widthScaleFactor, fixedAspectRatio );

  //if current entry picture is 0: cache picture for entry
  //update stats for memory usage
  if ( !currentEntry->picture )
  {
    cachePicture( currentEntry, forceVectorOutput );
    trimToMaximumSize();
  }

  return *( currentEntry->picture );
}
示例#4
0
const QImage& QgsSvgCache::svgAsImage( const QString& file, double size, const QColor& fill, const QColor& outline, double outlineWidth,
                                       double widthScaleFactor, double rasterScaleFactor, bool& fitsInCache )
{
  QMutexLocker locker( &mMutex );

  fitsInCache = true;
  QgsSvgCacheEntry* currentEntry = cacheEntry( file, size, fill, outline, outlineWidth, widthScaleFactor, rasterScaleFactor );

  //if current entry image is 0: cache image for entry
  // checks to see if image will fit into cache
  //update stats for memory usage
  if ( !currentEntry->image )
  {
    QSvgRenderer r( currentEntry->svgContent );
    double hwRatio = 1.0;
    if ( r.viewBoxF().width() > 0 )
    {
      hwRatio = r.viewBoxF().height() / r.viewBoxF().width();
    }
    long cachedDataSize = 0;
    cachedDataSize += currentEntry->svgContent.size();
    cachedDataSize += ( int )( currentEntry->size * currentEntry->size * hwRatio * 32 );
    if ( cachedDataSize > mMaximumSize / 2 )
    {
      fitsInCache = false;
      delete currentEntry->image;
      currentEntry->image = 0;
      //currentEntry->image = new QImage( 0, 0 );

      // instead cache picture
      if ( !currentEntry->picture )
      {
        cachePicture( currentEntry, false );
      }
    }
    else
    {
      cacheImage( currentEntry );
    }
    trimToMaximumSize();
  }

  return *( currentEntry->image );
}
示例#5
0
QPicture QgsSvgCache::svgAsPicture( const QString &path, double size, const QColor &fill, const QColor &stroke, double strokeWidth,
                                    double widthScaleFactor, bool forceVectorOutput, double fixedAspectRatio )
{
  QMutexLocker locker( &mMutex );

  QgsSvgCacheEntry *currentEntry = cacheEntry( path, size, fill, stroke, strokeWidth, widthScaleFactor, fixedAspectRatio );

  //if current entry picture is 0: cache picture for entry
  //update stats for memory usage
  if ( !currentEntry->picture )
  {
    cachePicture( currentEntry, forceVectorOutput );
    trimToMaximumSize();
  }

  QPicture p;
  // For some reason p.detach() doesn't seem to always work as intended, at
  // least with QT 5.5 on Ubuntu 16.04
  // Serialization/deserialization is a safe way to be ensured we don't
  // share a copy.
  p.setData( currentEntry->picture->data(), currentEntry->picture->size() );
  return p;
}