Skip to content

Commit 00efc46

Browse files
committedJan 15, 2014
Set raster no data color back to 0,0,0,0 and overwrite that in raster drawer only for PDF output. Fixes #9101 and #9343
1 parent e721e7f commit 00efc46

File tree

3 files changed

+29
-7
lines changed

3 files changed

+29
-7
lines changed
 

‎src/core/raster/qgsrasterblock.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323
#include "qgslogger.h"
2424
#include "qgsrasterblock.h"
2525

26-
const QRgb QgsRasterBlock::mNoDataColor = qRgba( 255, 255, 255, 0 );
26+
// See #9101 before any change of NODATA_COLOR!
27+
const QRgb QgsRasterBlock::mNoDataColor = qRgba( 0, 0, 0, 0 );
2728

2829
QgsRasterBlock::QgsRasterBlock()
2930
: mValid( true )
@@ -301,7 +302,7 @@ QRgb QgsRasterBlock::color( qgssize index ) const
301302

302303
QRgb QgsRasterBlock::color( int row, int column ) const
303304
{
304-
if ( !mImage ) return qRgba( 255, 255, 255, 0 );
305+
if ( !mImage ) return mNoDataColor;
305306

306307
return mImage->pixel( column, row );
307308
}
@@ -597,7 +598,7 @@ bool QgsRasterBlock::setIsNoDataExcept( const QRect & theExceptRect )
597598
return false;
598599
}
599600

600-
QRgb nodataRgba = qRgba( 0, 0, 0, 0 );
601+
QRgb nodataRgba = mNoDataColor;
601602
QRgb *nodataRow = new QRgb[mWidth]; // full row of no data
602603
int rgbSize = sizeof( QRgb );
603604
for ( int c = 0; c < mWidth; c ++ )

‎src/core/raster/qgsrasterdrawer.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "qgsmaptopixel.h"
2323
#include <QImage>
2424
#include <QPainter>
25+
#include <QPrinter>
2526

2627
QgsRasterDrawer::QgsRasterDrawer( QgsRasterIterator* iterator ): mIterator( iterator )
2728
{
@@ -66,6 +67,28 @@ void QgsRasterDrawer::draw( QPainter* p, QgsRasterViewPort* viewPort, const QgsM
6667

6768
QImage img = block->image();
6869

70+
// Because of bug in Acrobat Reader we must use "white" transparent color instead
71+
// of "black" for PDF. See #9101.
72+
QPrinter *printer = dynamic_cast<QPrinter *>( p->device() );
73+
if ( printer && printer->outputFormat() == QPrinter::PdfFormat )
74+
{
75+
QgsDebugMsg( "PdfFormat" );
76+
77+
img = img.convertToFormat( QImage::Format_ARGB32 );
78+
QRgb transparentBlack = qRgba( 0, 0, 0, 0 );
79+
QRgb transparentWhite = qRgba( 255, 255, 255, 0 );
80+
for ( int x = 0; x < img.width(); x++ )
81+
{
82+
for ( int y = 0; y < img.height(); y++ )
83+
{
84+
if ( img.pixel( x, y ) == transparentBlack )
85+
{
86+
img.setPixel( x, y, transparentWhite );
87+
}
88+
}
89+
}
90+
}
91+
6992
drawImage( p, viewPort, img, topLeftCol, topLeftRow );
7093

7194
delete block;

‎src/core/raster/qgsrasterrenderer.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,8 @@
2626

2727
#define tr( sourceText ) QCoreApplication::translate ( "QgsRasterRenderer", sourceText )
2828

29-
// Changing RGB components of NODATA_COLOR may break tests
30-
// (changed 2013-11-30 from 0,0,0,0 to 255,255,255,0)
31-
// kepp NODATA_COLOR white, see #9101
32-
const QRgb QgsRasterRenderer::NODATA_COLOR = qRgba( 255, 255, 255, 0 );
29+
// See #9101 before any change of NODATA_COLOR!
30+
const QRgb QgsRasterRenderer::NODATA_COLOR = qRgba( 0, 0, 0, 0 );
3331

3432
QgsRasterRenderer::QgsRasterRenderer( QgsRasterInterface* input, const QString& type )
3533
: QgsRasterInterface( input )

0 commit comments

Comments
 (0)
Please sign in to comment.