diff --git a/src/core/symbology-ng/qgssymbollayerutils.cpp b/src/core/symbology-ng/qgssymbollayerutils.cpp
index 600dea67ee0..98b2dea526b 100644
--- a/src/core/symbology-ng/qgssymbollayerutils.cpp
+++ b/src/core/symbology-ng/qgssymbollayerutils.cpp
@@ -1845,7 +1845,14 @@ void QgsSymbolLayerUtils::lineToSld( QDomDocument &doc, QDomElement &element,
element.appendChild( createSvgParameterElement( doc, QStringLiteral( "stroke-opacity" ), encodeSldAlpha( color.alpha() ) ) );
}
if ( width > 0 )
+ {
element.appendChild( createSvgParameterElement( doc, QStringLiteral( "stroke-width" ), qgsDoubleToString( width ) ) );
+ }
+ else if ( width == 0 )
+ {
+ // hairline, yet not zero. it's actually painted in qgis
+ element.appendChild( createSvgParameterElement( doc, QStringLiteral( "stroke-width" ), QStringLiteral( "0.5" ) ) );
+ }
if ( penJoinStyle )
element.appendChild( createSvgParameterElement( doc, QStringLiteral( "stroke-linejoin" ), encodeSldLineJoinStyle( *penJoinStyle ) ) );
if ( penCapStyle )
diff --git a/tests/src/python/test_qgssymbollayer_createsld.py b/tests/src/python/test_qgssymbollayer_createsld.py
index 5272cdb3092..cd452cb4116 100644
--- a/tests/src/python/test_qgssymbollayer_createsld.py
+++ b/tests/src/python/test_qgssymbollayer_createsld.py
@@ -231,6 +231,15 @@ class TestQgsSymbolLayerCreateSld(unittest.TestCase):
self.assertStrokeWidth(root, 2, 1)
self.assertStaticDisplacement(root, 5, 10)
+ def testSimpleLineHairline(self):
+ symbol = QgsSimpleLineSymbolLayer(QColor("black"), 0)
+ dom, root = self.symbolToSld(symbol)
+
+ # print ("Simple line px: \n" + dom.toString())
+
+ # Hairline is turned into 0.5px
+ self.assertStrokeWidth(root, 1, 0.5)
+
def testSimpleLineUnitDefault(self):
symbol = QgsSimpleLineSymbolLayer(QColor("black"), 1)
symbol.setCustomDashVector([10, 10])
diff --git a/tests/testdata/qgis_server/getstyles.txt b/tests/testdata/qgis_server/getstyles.txt
index 194f939cffd..1fcc74f60ca 100644
--- a/tests/testdata/qgis_server/getstyles.txt
+++ b/tests/testdata/qgis_server/getstyles.txt
@@ -19,6 +19,7 @@ Content-Type: text/xml; charset=utf-8
#000000
+ 0.5
7