Skip to content

Commit 3472bb7

Browse files
committed
Fixes #54926 : Correct masking with SVG symbol
1 parent 1f1e8b5 commit 3472bb7

3 files changed

Lines changed: 38 additions & 7 deletions

File tree

‎src/core/qgsmaskpaintdevice.cpp‎

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,17 @@ QPainterPath QgsMaskPaintEngine::maskPainterPath() const
3434

3535
void QgsMaskPaintEngine::drawPath( const QPainterPath &path )
3636
{
37+
QPainterPath realPath = path;
3738
if ( mUsePathStroker )
3839
{
3940
QPen pen = painter()->pen();
4041
QPainterPathStroker stroker( pen );
4142
QPainterPath strokedPath = stroker.createStroke( path );
42-
strokedPath = painter()->combinedTransform().map( strokedPath );
43-
mMaskPainterPath.addPath( strokedPath );
44-
}
45-
else
46-
{
47-
mMaskPainterPath.addPath( path );
43+
realPath = strokedPath;
4844
}
45+
46+
const QTransform transform = painter()->combinedTransform();
47+
mMaskPainterPath.addPath( transform.map( realPath ) );
4948
}
5049

5150
void QgsMaskPaintEngine::drawPolygon( const QPointF *points, int numPoints, QPaintEngine::PolygonDrawMode mode )
@@ -56,7 +55,9 @@ void QgsMaskPaintEngine::drawPolygon( const QPointF *points, int numPoints, QPai
5655
polygon.reserve( numPoints );
5756
for ( int i = 0; i < numPoints; ++i )
5857
polygon << points[i];
59-
mMaskPainterPath.addPolygon( polygon );
58+
59+
const QTransform transform = painter()->transform();
60+
mMaskPainterPath.addPolygon( transform.map( polygon ) );
6061
}
6162

6263
///@endcond

‎tests/src/python/test_selective_masking.py‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,14 @@
3535
QgsMaskMarkerSymbolLayer,
3636
QgsOuterGlowEffect,
3737
QgsPalLayerSettings,
38+
QgsPathResolver,
3839
QgsProject,
3940
QgsProjectFileTransform,
4041
QgsProperty,
4142
QgsRectangle,
4243
QgsRenderContext,
4344
QgsSingleSymbolRenderer,
45+
QgsSvgMarkerSymbolLayer,
4446
QgsSymbolLayerId,
4547
QgsSymbolLayerReference,
4648
QgsSymbolLayerUtils,
@@ -1315,6 +1317,34 @@ def test_vector_random_generator_fill(self):
13151317

13161318
self.check_layout_export("layout_export_random_generator_fill", 0, [layer], extent=extent)
13171319

1320+
def test_layout_export_svg_marker_masking(self):
1321+
"""Test layout export with a svg marker symbol masking"""
1322+
1323+
svgPath = QgsSymbolLayerUtils.svgSymbolNameToPath('gpsicons/plane.svg', QgsPathResolver())
1324+
1325+
sl = QgsSvgMarkerSymbolLayer(svgPath, 5)
1326+
sl.setFillColor(QColor("blue"))
1327+
1328+
p = QgsMarkerSymbol()
1329+
p.changeSymbolLayer(0, sl)
1330+
1331+
self.points_layer.setRenderer(QgsSingleSymbolRenderer(p))
1332+
1333+
mask_layer = QgsMaskMarkerSymbolLayer()
1334+
maskSl = QgsSvgMarkerSymbolLayer(svgPath, 8)
1335+
pSl = QgsMarkerSymbol()
1336+
pSl.changeSymbolLayer(0, maskSl)
1337+
mask_layer.setSubSymbol(pSl)
1338+
mask_layer.setMasks([
1339+
# the black part of roads
1340+
self.get_symbollayer_ref(self.lines_layer, "", [0]),
1341+
])
1342+
# add this mask layer to the point layer
1343+
self.points_layer.renderer().symbol().appendSymbolLayer(mask_layer)
1344+
1345+
# no rasters
1346+
self.check_layout_export("layout_export_svg_marker_masking", 0, [self.points_layer, self.lines_layer])
1347+
13181348

13191349
if __name__ == '__main__':
13201350
start_app()
29.5 KB
Loading

0 commit comments

Comments
 (0)