Skip to content

Commit

Permalink
Douglas
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jun 5, 2024
1 parent 79591a5 commit e1ba2d1
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/core/layout/qgslayoutexporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
30 changes: 24 additions & 6 deletions src/core/painting/qgsgeometrypaintdevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
{
Expand Down Expand Up @@ -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 )
{
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/core/painting/qgsgeometrypaintdevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit e1ba2d1

Please sign in to comment.