Skip to content
Permalink
Browse files

Support alpha-transparency in svg markers and fills

  • Loading branch information
mhugent committed Jul 5, 2011
1 parent 9d3c904 commit a637ebcac2e5a0d4f74fbb09367995edaddf3c34
Showing with 18 additions and 27 deletions.
  1. +6 −26 src/core/symbology-ng/qgsfillsymbollayerv2.cpp
  2. +12 −1 src/core/symbology-ng/qgsmarkersymbollayerv2.cpp
@@ -210,37 +210,17 @@ void QgsSVGFillSymbolLayer::startRender( QgsSymbolV2RenderContext& context )
context.renderContext().scaleFactor(), context.renderContext().rasterScaleFactor() );
QTransform brushTransform;
brushTransform.scale( 1.0 / context.renderContext().rasterScaleFactor(), 1.0 / context.renderContext().rasterScaleFactor() );
mBrush.setTextureImage( patternImage );
mBrush.setTransform( brushTransform );

#if 0
//create QImage with appropriate dimensions
int pixelWidth = context.outputPixelSize( mPatternWidth );
int pixelHeight = pixelWidth / mSvgViewBox.width() * mSvgViewBox.height();

QImage textureImage( pixelWidth, pixelHeight, QImage::Format_ARGB32_Premultiplied );
textureImage.fill( 0 ); // transparent background

//rasterise byte array to image
QPainter p( &textureImage );
QSvgRenderer r( mSvgData );
if ( !r.isValid() )
if( !doubleNear( context.alpha(), 1.0 ) )
{
return;
QImage transparentImage = patternImage.copy();
QgsSymbolLayerV2Utils::multiplyImageOpacity( &transparentImage, context.alpha() );
mBrush.setTextureImage( transparentImage );
}

r.render( &p );

if ( context.alpha() < 1.0 )
else
{
QgsSymbolLayerV2Utils::multiplyImageOpacity( &textureImage, context.alpha() );
mBrush.setTextureImage( patternImage );
}

QTransform brushTransform;
brushTransform.scale( 1.0 / context.renderContext().rasterScaleFactor(), 1.0 / context.renderContext().rasterScaleFactor() );
mBrush.setTextureImage( textureImage );
mBrush.setTransform( brushTransform );
#endif //0

if ( mOutline )
{
@@ -564,10 +564,21 @@ void QgsSvgMarkerSymbolLayerV2::renderPoint( const QPointF& point, QgsSymbolV2Re
{
const QImage& img = QgsSvgCache::instance()->svgAsImage( mPath, size, mFillColor, mOutlineColor, mOutlineWidth,
context.renderContext().scaleFactor(), context.renderContext().rasterScaleFactor() );
p->drawImage( -img.width() / 2.0, -img.width() / 2.0, img );
//consider transparency
if( !doubleNear( context.alpha(), 1.0 ) )
{
QImage transparentImage = img.copy();
QgsSymbolLayerV2Utils::multiplyImageOpacity( &transparentImage, context.alpha() );
p->drawImage( -transparentImage.width() / 2.0, -transparentImage.height() / 2.0, transparentImage );
}
else
{
p->drawImage( -img.width() / 2.0, -img.height() / 2.0, img );
}
}
else
{
p->setOpacity( context.alpha( ) );
const QPicture& pct = QgsSvgCache::instance()->svgAsPicture( mPath, size, mFillColor, mOutlineColor, mOutlineWidth,
context.renderContext().scaleFactor(), context.renderContext().rasterScaleFactor() );
p->drawPicture( 0, 0, pct );

0 comments on commit a637ebc

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