Skip to content

Commit

Permalink
Fixes #54926 : Correct masking with SVG symbol
Browse files Browse the repository at this point in the history
  • Loading branch information
troopa81 committed Oct 24, 2023
1 parent 1f1e8b5 commit 3472bb7
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/core/qgsmaskpaintdevice.cpp
Expand Up @@ -34,18 +34,17 @@ QPainterPath QgsMaskPaintEngine::maskPainterPath() const

void QgsMaskPaintEngine::drawPath( const QPainterPath &path )
{
QPainterPath realPath = path;
if ( mUsePathStroker )
{
QPen pen = painter()->pen();
QPainterPathStroker stroker( pen );
QPainterPath strokedPath = stroker.createStroke( path );
strokedPath = painter()->combinedTransform().map( strokedPath );
mMaskPainterPath.addPath( strokedPath );
}
else
{
mMaskPainterPath.addPath( path );
realPath = strokedPath;
}

const QTransform transform = painter()->combinedTransform();
mMaskPainterPath.addPath( transform.map( realPath ) );
}

void QgsMaskPaintEngine::drawPolygon( const QPointF *points, int numPoints, QPaintEngine::PolygonDrawMode mode )
Expand All @@ -56,7 +55,9 @@ void QgsMaskPaintEngine::drawPolygon( const QPointF *points, int numPoints, QPai
polygon.reserve( numPoints );
for ( int i = 0; i < numPoints; ++i )
polygon << points[i];
mMaskPainterPath.addPolygon( polygon );

const QTransform transform = painter()->transform();
mMaskPainterPath.addPolygon( transform.map( polygon ) );
}

///@endcond
Expand Down
30 changes: 30 additions & 0 deletions tests/src/python/test_selective_masking.py
Expand Up @@ -35,12 +35,14 @@
QgsMaskMarkerSymbolLayer,
QgsOuterGlowEffect,
QgsPalLayerSettings,
QgsPathResolver,
QgsProject,
QgsProjectFileTransform,
QgsProperty,
QgsRectangle,
QgsRenderContext,
QgsSingleSymbolRenderer,
QgsSvgMarkerSymbolLayer,
QgsSymbolLayerId,
QgsSymbolLayerReference,
QgsSymbolLayerUtils,
Expand Down Expand Up @@ -1315,6 +1317,34 @@ def test_vector_random_generator_fill(self):

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

def test_layout_export_svg_marker_masking(self):
"""Test layout export with a svg marker symbol masking"""

svgPath = QgsSymbolLayerUtils.svgSymbolNameToPath('gpsicons/plane.svg', QgsPathResolver())

sl = QgsSvgMarkerSymbolLayer(svgPath, 5)
sl.setFillColor(QColor("blue"))

p = QgsMarkerSymbol()
p.changeSymbolLayer(0, sl)

self.points_layer.setRenderer(QgsSingleSymbolRenderer(p))

mask_layer = QgsMaskMarkerSymbolLayer()
maskSl = QgsSvgMarkerSymbolLayer(svgPath, 8)
pSl = QgsMarkerSymbol()
pSl.changeSymbolLayer(0, maskSl)
mask_layer.setSubSymbol(pSl)
mask_layer.setMasks([
# the black part of roads
self.get_symbollayer_ref(self.lines_layer, "", [0]),
])
# add this mask layer to the point layer
self.points_layer.renderer().symbol().appendSymbolLayer(mask_layer)

# no rasters
self.check_layout_export("layout_export_svg_marker_masking", 0, [self.points_layer, self.lines_layer])


if __name__ == '__main__':
start_app()
Expand Down
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 3472bb7

Please sign in to comment.