diff --git a/tests/src/python/test_qgslinesymbollayers.py b/tests/src/python/test_qgslinesymbollayers.py index c0c95fa69781..bf2f7bc8180a 100644 --- a/tests/src/python/test_qgslinesymbollayers.py +++ b/tests/src/python/test_qgslinesymbollayers.py @@ -90,6 +90,82 @@ def testSimpleLineWithOffset(self): self.assertTrue(self.imageCheck('symbol_layer', 'simpleline_offset', image)) + def testSimpleLineWithCustomDashPattern(self): + """ test that rendering a simple line symbol with custom dash pattern""" + layer = QgsSimpleLineSymbolLayer(QColor(0, 0, 0)) + layer.setWidth(0.5) + layer.setCustomDashVector([2, 5]) + layer.setUseCustomDashPattern(True) + + symbol = QgsLineSymbol() + symbol.changeSymbolLayer(0, layer) + + image = QImage(200, 200, QImage.Format_RGB32) + painter = QPainter() + ms = QgsMapSettings() + + geom = QgsGeometry.fromWkt('LineString (0 0, 10 0, 10 10, 0 10, 0 0)') + f = QgsFeature() + f.setGeometry(geom) + + extent = geom.constGet().boundingBox() + # buffer extent by 10% + extent = extent.buffered((extent.height() + extent.width()) / 20.0) + + ms.setExtent(extent) + ms.setOutputSize(image.size()) + context = QgsRenderContext.fromMapSettings(ms) + context.setPainter(painter) + context.setScaleFactor(96 / 25.4) # 96 DPI + + painter.begin(image) + image.fill(QColor(255, 255, 255)) + + symbol.startRender(context) + symbol.renderFeature(f, context) + symbol.stopRender(context) + painter.end() + + self.assertTrue(self.imageCheck('symbol_layer_simpleline_customdashpattern', 'simpleline_customdashpattern', image)) + + def testSimpleLineWithCustomDashPatternHairline(self): + """ test that rendering a simple line symbol with custom dash pattern""" + layer = QgsSimpleLineSymbolLayer(QColor(0, 0, 0)) + layer.setWidth(0) + layer.setCustomDashVector([3, 3, 2, 2]) + layer.setUseCustomDashPattern(True) + + symbol = QgsLineSymbol() + symbol.changeSymbolLayer(0, layer) + + image = QImage(200, 200, QImage.Format_RGB32) + painter = QPainter() + ms = QgsMapSettings() + + geom = QgsGeometry.fromWkt('LineString (0 0, 10 0, 10 10, 0 10, 0 0)') + f = QgsFeature() + f.setGeometry(geom) + + extent = geom.constGet().boundingBox() + # buffer extent by 10% + extent = extent.buffered((extent.height() + extent.width()) / 20.0) + + ms.setExtent(extent) + ms.setOutputSize(image.size()) + context = QgsRenderContext.fromMapSettings(ms) + context.setPainter(painter) + context.setScaleFactor(96 / 25.4) # 96 DPI + + painter.begin(image) + image.fill(QColor(255, 255, 255)) + + symbol.startRender(context) + symbol.renderFeature(f, context) + symbol.stopRender(context) + painter.end() + + self.assertTrue(self.imageCheck('symbol_layer_simpleline_customdashpattern_hairline', 'simpleline_customdashpattern_hairline', image)) + if __name__ == '__main__': unittest.main() diff --git a/tests/testdata/control_images/symbol_layer/expected_simpleline_customdashpattern/expected_simpleline_customdashpattern.png b/tests/testdata/control_images/symbol_layer/expected_simpleline_customdashpattern/expected_simpleline_customdashpattern.png new file mode 100644 index 000000000000..2d409566607a Binary files /dev/null and b/tests/testdata/control_images/symbol_layer/expected_simpleline_customdashpattern/expected_simpleline_customdashpattern.png differ diff --git a/tests/testdata/control_images/symbol_layer/expected_simpleline_customdashpattern_hairline/expected_simpleline_customdashpattern_hairline.png b/tests/testdata/control_images/symbol_layer/expected_simpleline_customdashpattern_hairline/expected_simpleline_customdashpattern_hairline.png new file mode 100644 index 000000000000..160d99e9f016 Binary files /dev/null and b/tests/testdata/control_images/symbol_layer/expected_simpleline_customdashpattern_hairline/expected_simpleline_customdashpattern_hairline.png differ