Skip to content

Commit

Permalink
Support alpha-transparency in svg markers and fills
Browse files Browse the repository at this point in the history
  • Loading branch information
mhugent committed Jul 5, 2011
1 parent db7501a commit 91cddd1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 27 deletions.
32 changes: 6 additions & 26 deletions src/core/symbology-ng/qgsfillsymbollayerv2.cpp
Expand Up @@ -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 )
{
Expand Down
13 changes: 12 additions & 1 deletion src/core/symbology-ng/qgsmarkersymbollayerv2.cpp
Expand Up @@ -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 );
Expand Down

0 comments on commit 91cddd1

Please sign in to comment.