Skip to content
Permalink
Browse files

Turn antialising render flag on when appropriate in QgsRenderContext:…

…:fromQPainter()
  • Loading branch information
nirvn committed Apr 22, 2019
1 parent fe45af0 commit 1fd6b555ff9df08ee2cca563c83fa9481ddc01d9
@@ -105,6 +105,10 @@ QgsRenderContext QgsRenderContext::fromQPainter( QPainter *painter )
{
context.setScaleFactor( 3.465 ); //assume 88 dpi as standard value
}
if ( painter && painter->renderHints() & QPainter::Antialiasing )
{
context.setFlag( QgsRenderContext::Antialiasing, true );
}
return context;
}

@@ -73,15 +73,18 @@ def testFromQPainter(self):
p = QPainter()
c = QgsRenderContext.fromQPainter(p)
self.assertEqual(c.painter(), p)
self.assertEqual(c.testFlag(QgsRenderContext.Antialiasing), False)
self.assertAlmostEqual(c.scaleFactor(), 88 / 25.4, 3)

im = QImage(1000, 600, QImage.Format_RGB32)
dots_per_m = 300 / 25.4 * 1000 # 300 dpi to dots per m
im.setDotsPerMeterX(dots_per_m)
im.setDotsPerMeterY(dots_per_m)
p = QPainter(im)
p.setRenderHint(QPainter.Antialiasing)
c = QgsRenderContext.fromQPainter(p)
self.assertEqual(c.painter(), p)
self.assertEqual(c.testFlag(QgsRenderContext.Antialiasing), True)
self.assertAlmostEqual(c.scaleFactor(), dots_per_m / 1000, 3) # scaleFactor should be pixels/mm

def testFromMapSettings(self):
Binary file not shown.

0 comments on commit 1fd6b55

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