Skip to content

Commit b64f256

Browse files
committed
Fixes 16707, export of hairline results in a different visual thickness
1 parent 7aec4d1 commit b64f256

3 files changed

Lines changed: 17 additions & 0 deletions

File tree

src/core/symbology-ng/qgssymbollayerutils.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1845,7 +1845,14 @@ void QgsSymbolLayerUtils::lineToSld( QDomDocument &doc, QDomElement &element,
18451845
element.appendChild( createSvgParameterElement( doc, QStringLiteral( "stroke-opacity" ), encodeSldAlpha( color.alpha() ) ) );
18461846
}
18471847
if ( width > 0 )
1848+
{
18481849
element.appendChild( createSvgParameterElement( doc, QStringLiteral( "stroke-width" ), qgsDoubleToString( width ) ) );
1850+
}
1851+
else if ( width == 0 )
1852+
{
1853+
// hairline, yet not zero. it's actually painted in qgis
1854+
element.appendChild( createSvgParameterElement( doc, QStringLiteral( "stroke-width" ), QStringLiteral( "0.5" ) ) );
1855+
}
18491856
if ( penJoinStyle )
18501857
element.appendChild( createSvgParameterElement( doc, QStringLiteral( "stroke-linejoin" ), encodeSldLineJoinStyle( *penJoinStyle ) ) );
18511858
if ( penCapStyle )

tests/src/python/test_qgssymbollayer_createsld.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,15 @@ def testEllipseMarkerUnitPixel(self):
231231
self.assertStrokeWidth(root, 2, 1)
232232
self.assertStaticDisplacement(root, 5, 10)
233233

234+
def testSimpleLineHairline(self):
235+
symbol = QgsSimpleLineSymbolLayer(QColor("black"), 0)
236+
dom, root = self.symbolToSld(symbol)
237+
238+
# print ("Simple line px: \n" + dom.toString())
239+
240+
# Hairline is turned into 0.5px
241+
self.assertStrokeWidth(root, 1, 0.5)
242+
234243
def testSimpleLineUnitDefault(self):
235244
symbol = QgsSimpleLineSymbolLayer(QColor("black"), 1)
236245
symbol.setCustomDashVector([10, 10])

tests/testdata/qgis_server/getstyles.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Content-Type: text/xml; charset=utf-8
1919
</se:Fill>
2020
<se:Stroke>
2121
<se:SvgParameter name="stroke">#000000</se:SvgParameter>
22+
<se:SvgParameter name="stroke-width">0.5</se:SvgParameter>
2223
</se:Stroke>
2324
</se:Mark>
2425
<se:Size>7</se:Size>

0 commit comments

Comments
 (0)