@@ -166,19 +166,16 @@ void QgsComposerShape::drawShapeUsingSymbol( QPainter* p )
166
166
p->save ();
167
167
p->setRenderHint ( QPainter::Antialiasing );
168
168
169
- QgsRenderContext context;
169
+ // setup painter scaling to dots so that raster symbology is drawn to scale
170
+ double dotsPerMM = p->device ()->logicalDpiX () / 25.4 ;
171
+
172
+ // setup render context
173
+ QgsMapSettings ms = mComposition ->mapSettings ();
174
+ // context units should be in dots
175
+ ms.setOutputDpi ( p->device ()->logicalDpiX () );
176
+ QgsRenderContext context = QgsRenderContext::fromMapSettings ( ms );
170
177
context.setPainter ( p );
171
- context.setScaleFactor ( 1.0 );
172
- if ( mComposition ->plotStyle () == QgsComposition::Preview )
173
- {
174
- // Limit resolution of symbol fill if composition is not being exported
175
- // otherwise zooming into composition slows down renders
176
- context.setRasterScaleFactor ( qMin ( horizontalViewScaleFactor (), 3.0 ) );
177
- }
178
- else
179
- {
180
- context.setRasterScaleFactor ( mComposition ->printResolution () / 25.4 );
181
- }
178
+ p->scale ( 1 / dotsPerMM, 1 / dotsPerMM ); // scale painter from mm to dots
182
179
183
180
// generate polygon to draw
184
181
QList<QPolygonF> rings; // empty list
@@ -196,7 +193,7 @@ void QgsComposerShape::drawShapeUsingSymbol( QPainter* p )
196
193
{
197
194
// create an ellipse
198
195
QPainterPath ellipsePath;
199
- ellipsePath.addEllipse ( QRectF ( 0 , 0 , rect ().width (), rect ().height () ) );
196
+ ellipsePath.addEllipse ( QRectF ( 0 , 0 , rect ().width () * dotsPerMM , rect ().height () * dotsPerMM ) );
200
197
QPolygonF ellipsePoly = ellipsePath.toFillPolygon ( t );
201
198
shapePolygon = ti.map ( ellipsePoly );
202
199
break ;
@@ -207,22 +204,22 @@ void QgsComposerShape::drawShapeUsingSymbol( QPainter* p )
207
204
if ( mCornerRadius > 0 )
208
205
{
209
206
QPainterPath roundedRectPath;
210
- roundedRectPath.addRoundedRect ( QRectF ( 0 , 0 , rect ().width (), rect ().height () ), mCornerRadius , mCornerRadius );
207
+ roundedRectPath.addRoundedRect ( QRectF ( 0 , 0 , rect ().width () * dotsPerMM , rect ().height () * dotsPerMM ), mCornerRadius * dotsPerMM , mCornerRadius * dotsPerMM );
211
208
QPolygonF roundedPoly = roundedRectPath.toFillPolygon ( t );
212
209
shapePolygon = ti.map ( roundedPoly );
213
210
}
214
211
else
215
212
{
216
- shapePolygon = QPolygonF ( QRectF ( 0 , 0 , rect ().width (), rect ().height () ) );
213
+ shapePolygon = QPolygonF ( QRectF ( 0 , 0 , rect ().width () * dotsPerMM , rect ().height () * dotsPerMM ) );
217
214
}
218
215
break ;
219
216
}
220
217
case Triangle:
221
218
{
222
- shapePolygon << QPointF ( 0 , rect ().height () );
223
- shapePolygon << QPointF ( rect ().width () , rect ().height () );
224
- shapePolygon << QPointF ( rect ().width () / 2.0 , 0 );
225
- shapePolygon << QPointF ( 0 , rect ().height () );
219
+ shapePolygon << QPointF ( 0 , rect ().height () * dotsPerMM );
220
+ shapePolygon << QPointF ( rect ().width () * dotsPerMM , rect ().height () * dotsPerMM );
221
+ shapePolygon << QPointF ( rect ().width () / 2.0 * dotsPerMM , 0 );
222
+ shapePolygon << QPointF ( 0 , rect ().height () * dotsPerMM );
226
223
break ;
227
224
}
228
225
}
0 commit comments