From e1ba2d13d8a6a2100af21e169960ca2899d707ee Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Wed, 5 Jun 2024 15:39:24 +1000 Subject: [PATCH] Douglas --- src/core/layout/qgslayoutexporter.cpp | 2 +- src/core/painting/qgsgeometrypaintdevice.cpp | 30 ++++++++++++++++---- src/core/painting/qgsgeometrypaintdevice.h | 2 ++ 3 files changed, 27 insertions(+), 7 deletions(-) diff --git a/src/core/layout/qgslayoutexporter.cpp b/src/core/layout/qgslayoutexporter.cpp index 3cbd5004cc3e..030ef5bcb06a 100644 --- a/src/core/layout/qgslayoutexporter.cpp +++ b/src/core/layout/qgslayoutexporter.cpp @@ -1919,7 +1919,7 @@ QgsMaskRenderSettings QgsLayoutExporter::createExportMaskSettings() QgsMaskRenderSettings settings; // we are quite aggressive here -- we can safely simplify masks without visual degradation, and we'd // rather have the smaller file sizes this results in - settings.setSimplificationTolerance( 2 ); + settings.setSimplificationTolerance( 10 ); return settings; } diff --git a/src/core/painting/qgsgeometrypaintdevice.cpp b/src/core/painting/qgsgeometrypaintdevice.cpp index d10ac229ae3e..67f82fea9e11 100644 --- a/src/core/painting/qgsgeometrypaintdevice.cpp +++ b/src/core/painting/qgsgeometrypaintdevice.cpp @@ -357,7 +357,7 @@ void QgsGeometryPaintEngine::addStrokedLine( const QgsLineString *line, double p { for ( auto it = bufferedCollection->const_parts_begin(); it != bufferedCollection->const_parts_end(); ++it ) { - mGeometry.addGeometry( ( *it )->snappedToGrid( mSimplifyTolerance, mSimplifyTolerance, 0, 0, true ) ); + mGeometry.addGeometry( simplifyGeometry( *it ) ); } } else @@ -369,7 +369,7 @@ void QgsGeometryPaintEngine::addStrokedLine( const QgsLineString *line, double p { if ( mSimplifyTolerance > 0 ) { - mGeometry.addGeometry( buffered->snappedToGrid( mSimplifyTolerance, mSimplifyTolerance, 0, 0, true ) ); + mGeometry.addGeometry( simplifyGeometry( buffered.get() ) ); } else { @@ -414,6 +414,24 @@ Qgis::JoinStyle QgsGeometryPaintEngine::penStyleToJoinStyle( Qt::PenJoinStyle st return Qgis::JoinStyle::Round; } +QgsAbstractGeometry *QgsGeometryPaintEngine::simplifyGeometry( const QgsAbstractGeometry *geometry ) const +{ + QgsGeos geos( geometry ); + return geos.simplify( mSimplifyTolerance ); +} + +QgsLineString *QgsGeometryPaintEngine::simplifyLine( const QgsLineString *geometry ) const +{ + QgsGeos geos( geometry ); + std::unique_ptr< QgsAbstractGeometry > res( geos.simplify( mSimplifyTolerance ) ); + if ( qgsgeometry_cast< QgsLineString * > ( res.get() ) ) + { + return qgsgeometry_cast< QgsLineString * > ( res.release() ); + } + QgsDebugError( "noooo" ); + return nullptr; +} + // based on QPainterPath::toSubpathPolygons() void QgsGeometryPaintEngine::addSubpathGeometries( const QPainterPath &path, const QTransform &matrix ) { @@ -455,7 +473,7 @@ void QgsGeometryPaintEngine::addSubpathGeometries( const QPainterPath &path, con if ( mSimplifyTolerance > 0 ) { - queuedPolygons.emplace_back( std::make_unique< QgsPolygon >( line->snappedToGrid( mSimplifyTolerance, mSimplifyTolerance, 0, 0, true ) ) ); + queuedPolygons.emplace_back( std::make_unique< QgsPolygon >( simplifyLine( line.get() ) ) ); line.reset(); } else @@ -469,7 +487,7 @@ void QgsGeometryPaintEngine::addSubpathGeometries( const QPainterPath &path, con line->transform( matrix ); if ( mSimplifyTolerance > 0 ) { - mGeometry.addGeometry( line->snappedToGrid( mSimplifyTolerance, mSimplifyTolerance, 0, 0, true ) ); + mGeometry.addGeometry( simplifyGeometry( line.get() ) ); line.reset(); } else @@ -541,7 +559,7 @@ void QgsGeometryPaintEngine::addSubpathGeometries( const QPainterPath &path, con line->transform( matrix ); if ( mSimplifyTolerance > 0 ) { - queuedPolygons.emplace_back( std::make_unique< QgsPolygon >( line->snappedToGrid( mSimplifyTolerance, mSimplifyTolerance, 0, 0, true ) ) ); + queuedPolygons.emplace_back( std::make_unique< QgsPolygon >( simplifyLine( line.get() ) ) ); line.reset(); } else @@ -555,7 +573,7 @@ void QgsGeometryPaintEngine::addSubpathGeometries( const QPainterPath &path, con line->transform( matrix ); if ( mSimplifyTolerance > 0 ) { - mGeometry.addGeometry( line->snappedToGrid( mSimplifyTolerance, mSimplifyTolerance, 0, 0, true ) ); + mGeometry.addGeometry( simplifyGeometry( line.get() ) ); line.reset(); } else diff --git a/src/core/painting/qgsgeometrypaintdevice.h b/src/core/painting/qgsgeometrypaintdevice.h index c10666948500..5e7d06b22efa 100644 --- a/src/core/painting/qgsgeometrypaintdevice.h +++ b/src/core/painting/qgsgeometrypaintdevice.h @@ -104,6 +104,8 @@ class QgsGeometryPaintEngine: public QPaintEngine void addStrokedLine( const QgsLineString *line, double penWidth, Qgis::EndCapStyle endCapStyle, Qgis::JoinStyle joinStyle, double miterLimit, const QTransform *matrix ); static Qgis::EndCapStyle penStyleToCapStyle( Qt::PenCapStyle style ); static Qgis::JoinStyle penStyleToJoinStyle( Qt::PenJoinStyle style ); + QgsAbstractGeometry *simplifyGeometry( const QgsAbstractGeometry *geometry ) const; + QgsLineString *simplifyLine( const QgsLineString *geometry ) const; bool mUsePathStroker = false; QPen mPen;