Skip to content

Commit ae954e8

Browse files
committed
dxf export:
* switch to rgb colors only (fixes black/white issues) * fix drawing of polygon outlines * distiguish polygon outlines from filled polygons in paint engine (fixes #12368) (cherry picked from commit 25e4e4d)
1 parent 81f9c73 commit ae954e8

File tree

3 files changed

+19
-22
lines changed

3 files changed

+19
-22
lines changed

src/core/dxf/qgsdxfexport.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,7 @@ void QgsDxfExport::writeGroup( int code, const QgsPoint &p, double z, bool skipz
418418

419419
void QgsDxfExport::writeGroup( QColor color, int exactMatchCode, int rgbCode, int transparencyCode )
420420
{
421+
#if 0
421422
int minDistAt = -1;
422423
int minDist = INT_MAX;
423424

@@ -437,6 +438,7 @@ void QgsDxfExport::writeGroup( QColor color, int exactMatchCode, int rgbCode, in
437438
// exact full opaque match
438439
return;
439440
}
441+
#endif
440442

441443
int c = ( color.red() & 0xff ) * 0x10000 + ( color.green() & 0xff ) * 0x100 + ( color.blue() & 0xff );
442444
writeGroup( rgbCode, c );
@@ -3694,7 +3696,7 @@ void QgsDxfExport::addFeature( const QgsSymbolV2RenderContext& ctx, const QStrin
36943696
QgsPolygon::const_iterator polyIt = polygon.constBegin();
36953697
for ( ; polyIt != polygon.constEnd(); ++polyIt ) // iterate over rings
36963698
{
3697-
writePolyline( geom->asPolyline(), layer, lineStyleName, penColor, width, false );
3699+
writePolyline( *polyIt, layer, lineStyleName, penColor, width, false );
36983700
}
36993701

37003702
if ( offsetPolygon != geom )

src/core/dxf/qgsdxfpaintengine.cpp

+16-20
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,19 @@ void QgsDxfPaintEngine::drawPolygon( const QPointF *points, int pointCount, Poly
8484
polyline[i] = toDxfCoordinates( points[i] );
8585
}
8686

87-
mDxf->writePolygon( polygon, mLayer, "SOLID", currentColor() );
87+
if ( mode == QPaintEngine::PolylineMode )
88+
{
89+
mDxf->writePolyline( polyline, mLayer, "CONTINUOUS", mPen.color(), currentWidth(), true );
90+
}
91+
else
92+
{
93+
mDxf->writePolygon( polygon, mLayer, "SOLID", mBrush.color() );
94+
}
8895
}
8996

9097
void QgsDxfPaintEngine::drawRects( const QRectF* rects, int rectCount )
9198
{
92-
if ( !mDxf || !mPaintDevice || !rects )
99+
if ( !mDxf || !mPaintDevice || !rects || mBrush.style() == Qt::NoBrush )
93100
{
94101
return;
95102
}
@@ -104,7 +111,7 @@ void QgsDxfPaintEngine::drawRects( const QRectF* rects, int rectCount )
104111
QgsPoint pt2 = toDxfCoordinates( QPointF( right, bottom ) );
105112
QgsPoint pt3 = toDxfCoordinates( QPointF( left, top ) );
106113
QgsPoint pt4 = toDxfCoordinates( QPointF( right, top ) );
107-
mDxf->writeSolid( mLayer, currentColor(), pt1, pt2, pt3, pt4 );
114+
mDxf->writeSolid( mLayer, mBrush.color(), pt1, pt2, pt3, pt4 );
108115
}
109116
}
110117

@@ -162,7 +169,10 @@ void QgsDxfPaintEngine::endPolygon()
162169
{
163170
if ( mCurrentPolygon.size() > 1 )
164171
{
165-
drawPolygon( mCurrentPolygon.constData(), mCurrentPolygon.size(), QPaintEngine::OddEvenMode );
172+
if ( mPen.style() != Qt::NoPen )
173+
drawPolygon( mCurrentPolygon.constData(), mCurrentPolygon.size(), QPaintEngine::PolylineMode );
174+
if ( mBrush.style() != Qt::NoBrush )
175+
drawPolygon( mCurrentPolygon.constData(), mCurrentPolygon.size(), QPaintEngine::OddEvenMode );
166176
}
167177
mCurrentPolygon.clear();
168178
}
@@ -198,7 +208,7 @@ void QgsDxfPaintEngine::endCurve()
198208

199209
void QgsDxfPaintEngine::drawLines( const QLineF* lines, int lineCount )
200210
{
201-
if ( !mDxf || !mPaintDevice || !lines )
211+
if ( !mDxf || !mPaintDevice || !lines || mPen.style() == Qt::NoPen )
202212
{
203213
return;
204214
}
@@ -207,7 +217,7 @@ void QgsDxfPaintEngine::drawLines( const QLineF* lines, int lineCount )
207217
{
208218
QgsPoint pt1 = toDxfCoordinates( lines[i].p1() );
209219
QgsPoint pt2 = toDxfCoordinates( lines[i].p2() );
210-
mDxf->writeLine( pt1, pt2, mLayer, "CONTINUOUS", currentColor(), currentWidth() );
220+
mDxf->writeLine( pt1, pt2, mLayer, "CONTINUOUS", mPen.color(), currentWidth() );
211221
}
212222
}
213223

@@ -222,20 +232,6 @@ QgsPoint QgsDxfPaintEngine::toDxfCoordinates( const QPointF& pt ) const
222232
return QgsPoint( dxfPt.x(), dxfPt.y() );
223233
}
224234

225-
QColor QgsDxfPaintEngine::currentColor() const
226-
{
227-
if ( !mDxf )
228-
{
229-
return QColor();
230-
}
231-
232-
QColor c = mPen.color();
233-
if ( mPen.style() == Qt::NoPen )
234-
{
235-
c = mBrush.color();
236-
}
237-
return c;
238-
}
239235

240236
double QgsDxfPaintEngine::currentWidth() const
241237
{

src/core/dxf/qgsdxfpaintengine.h

-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ class CORE_EXPORT QgsDxfPaintEngine: public QPaintEngine
6161
QList<QPointF> mCurrentCurve;
6262

6363
QgsPoint toDxfCoordinates( const QPointF& pt ) const;
64-
QColor currentColor() const;
6564
double currentWidth() const;
6665

6766
void moveTo( double dx, double dy );

0 commit comments

Comments
 (0)