Skip to content

Commit

Permalink
Fix tests on different dpi setups
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Mar 31, 2023
1 parent 37f3de3 commit fd7b2fb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
12 changes: 9 additions & 3 deletions tests/src/python/test_qgsannotationlinetextitem.py
Expand Up @@ -31,7 +31,7 @@
QgsProject,
QgsReadWriteContext,
QgsRectangle,
QgsRenderChecker,
QgsMultiRenderChecker,
QgsRenderContext,
QgsTextFormat,
QgsVertexId,
Expand Down Expand Up @@ -226,6 +226,7 @@ def testRenderLine(self):
settings.setFlag(QgsMapSettings.Antialiasing, False)

rc = QgsRenderContext.fromMapSettings(settings)
rc.setScaleFactor(96 / 25.4) # 96 DPI
image = QImage(600, 300, QImage.Format_ARGB32)
image.setDotsPerMeterX(int(96 / 25.4 * 1000))
image.setDotsPerMeterY(int(96 / 25.4 * 1000))
Expand Down Expand Up @@ -259,6 +260,7 @@ def testRenderLineOffsetPositive(self):
settings.setFlag(QgsMapSettings.Antialiasing, False)

rc = QgsRenderContext.fromMapSettings(settings)
rc.setScaleFactor(96 / 25.4) # 96 DPI
image = QImage(600, 300, QImage.Format_ARGB32)
image.setDotsPerMeterX(int(96 / 25.4 * 1000))
image.setDotsPerMeterY(int(96 / 25.4 * 1000))
Expand Down Expand Up @@ -292,6 +294,7 @@ def testRenderLineOffsetNegative(self):
settings.setFlag(QgsMapSettings.Antialiasing, False)

rc = QgsRenderContext.fromMapSettings(settings)
rc.setScaleFactor(96 / 25.4) # 96 DPI
image = QImage(600, 300, QImage.Format_ARGB32)
image.setDotsPerMeterX(int(96 / 25.4 * 1000))
image.setDotsPerMeterY(int(96 / 25.4 * 1000))
Expand Down Expand Up @@ -323,6 +326,7 @@ def testRenderLineTruncate(self):
settings.setFlag(QgsMapSettings.Antialiasing, False)

rc = QgsRenderContext.fromMapSettings(settings)
rc.setScaleFactor(96 / 25.4) # 96 DPI
image = QImage(600, 300, QImage.Format_ARGB32)
image.setDotsPerMeterX(int(96 / 25.4 * 1000))
image.setDotsPerMeterY(int(96 / 25.4 * 1000))
Expand Down Expand Up @@ -354,6 +358,7 @@ def testRenderLineTextExpression(self):
settings.setFlag(QgsMapSettings.Antialiasing, False)

rc = QgsRenderContext.fromMapSettings(settings)
rc.setScaleFactor(96 / 25.4) # 96 DPI
image = QImage(600, 300, QImage.Format_ARGB32)
image.setDotsPerMeterX(int(96 / 25.4 * 1000))
image.setDotsPerMeterY(int(96 / 25.4 * 1000))
Expand Down Expand Up @@ -386,6 +391,7 @@ def testRenderWithTransform(self):
settings.setFlag(QgsMapSettings.Antialiasing, False)

rc = QgsRenderContext.fromMapSettings(settings)
rc.setScaleFactor(96 / 25.4) # 96 DPI
rc.setCoordinateTransform(QgsCoordinateTransform(QgsCoordinateReferenceSystem('EPSG:4326'), settings.destinationCrs(), QgsProject.instance()))
image = QImage(600, 300, QImage.Format_ARGB32)
image.setDotsPerMeterX(int(96 / 25.4 * 1000))
Expand All @@ -406,12 +412,12 @@ def imageCheck(self, name, reference_image, image):
temp_dir = QDir.tempPath() + '/'
file_name = temp_dir + 'annotation_' + name + ".png"
image.save(file_name, "PNG")
checker = QgsRenderChecker()
checker = QgsMultiRenderChecker()
checker.setControlPathPrefix("annotation_layer")
checker.setControlName("expected_" + reference_image)
checker.setRenderedImage(file_name)
checker.setColorTolerance(2)
result = checker.compareImages(name, 20)
result = checker.runTest(name, 20)
TestQgsAnnotationLineTextItem.report += checker.report()
return result

Expand Down
3 changes: 3 additions & 0 deletions tests/src/python/test_qgsannotationpointtextitem.py
Expand Up @@ -196,6 +196,7 @@ def testRenderMarker(self):
settings.setFlag(QgsMapSettings.Antialiasing, False)

rc = QgsRenderContext.fromMapSettings(settings)
rc.setScaleFactor(96 / 25.4) # 96 DPI
image = QImage(200, 200, QImage.Format_ARGB32)
image.setDotsPerMeterX(int(96 / 25.4 * 1000))
image.setDotsPerMeterY(int(96 / 25.4 * 1000))
Expand Down Expand Up @@ -230,6 +231,7 @@ def testRenderMarkerExpression(self):
settings.setFlag(QgsMapSettings.Antialiasing, False)

rc = QgsRenderContext.fromMapSettings(settings)
rc.setScaleFactor(96 / 25.4) # 96 DPI
image = QImage(200, 200, QImage.Format_ARGB32)
image.setDotsPerMeterX(int(96 / 25.4 * 1000))
image.setDotsPerMeterY(int(96 / 25.4 * 1000))
Expand Down Expand Up @@ -264,6 +266,7 @@ def testRenderWithTransform(self):
settings.setFlag(QgsMapSettings.Antialiasing, False)

rc = QgsRenderContext.fromMapSettings(settings)
rc.setScaleFactor(96 / 25.4) # 96 DPI
rc.setCoordinateTransform(QgsCoordinateTransform(QgsCoordinateReferenceSystem('EPSG:4326'), settings.destinationCrs(), QgsProject.instance()))
image = QImage(200, 200, QImage.Format_ARGB32)
image.setDotsPerMeterX(int(96 / 25.4 * 1000))
Expand Down

0 comments on commit fd7b2fb

Please sign in to comment.