Skip to content
Permalink
Browse files
Add simple line custom dash pattern tests
  • Loading branch information
nirvn committed Apr 28, 2019
1 parent c547fc6 commit 472ab7722d209cf5d5eb4958391285d9652fa6f8
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 0 deletions.
@@ -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()
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 472ab77

Please sign in to comment.