From 1a812727cb64fc4f42954db2a48ece7b22ad45b5 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Tue, 27 Sep 2022 17:44:17 +0100 Subject: [PATCH] Fix some logic errors in importing SVG polygons with holes. Fixes https://gitlab.com/kicad/code/kicad/issues/11479 --- .../import_gfx/graphics_importer_buffer.cpp | 25 ++++++------------- pcbnew/import_gfx/svg_import_plugin.cpp | 10 ++++---- 2 files changed, 13 insertions(+), 22 deletions(-) diff --git a/pcbnew/import_gfx/graphics_importer_buffer.cpp b/pcbnew/import_gfx/graphics_importer_buffer.cpp index a9910cb3a3..c04a62bcbd 100644 --- a/pcbnew/import_gfx/graphics_importer_buffer.cpp +++ b/pcbnew/import_gfx/graphics_importer_buffer.cpp @@ -178,7 +178,7 @@ void GRAPHICS_IMPORTER_BUFFER::PostprocessNestedPolygons() std::list> newShapes; std::vector polypaths; - for( auto& shape : m_shapes ) + for( std::unique_ptr& shape : m_shapes ) { IMPORTED_POLYGON* poly = dynamic_cast( shape.get() ); @@ -188,30 +188,21 @@ void GRAPHICS_IMPORTER_BUFFER::PostprocessNestedPolygons() continue; } - lastWidth = poly->GetWidth(); int index = poly->GetParentShapeIndex(); - if( curShapeIdx < 0 ) - index = curShapeIdx; - - if( index == curShapeIdx ) - { - polypaths.push_back( poly ); - } - else if( index >= curShapeIdx + 1 ) + if( index != curShapeIdx && curShapeIdx >= 0 ) { convertPolygon( newShapes, polypaths, m_shapeFillRules[curShapeIdx], lastWidth ); - curShapeIdx++; polypaths.clear(); - polypaths.push_back( poly ); } + + curShapeIdx = index; + lastWidth = poly->GetWidth(); + polypaths.push_back( poly ); } - POLY_FILL_RULE last_rule = ( m_shapeFillRules.size() && curShapeIdx >= 0 ) - ? m_shapeFillRules[curShapeIdx] - : POLY_FILL_RULE::PF_EVEN_ODD; - - convertPolygon( newShapes, polypaths, last_rule, lastWidth ); + if( curShapeIdx >= 0 ) + convertPolygon( newShapes, polypaths, m_shapeFillRules[curShapeIdx], lastWidth ); m_shapes.swap( newShapes ); } diff --git a/pcbnew/import_gfx/svg_import_plugin.cpp b/pcbnew/import_gfx/svg_import_plugin.cpp index 4a3ba6a044..65b175234d 100644 --- a/pcbnew/import_gfx/svg_import_plugin.cpp +++ b/pcbnew/import_gfx/svg_import_plugin.cpp @@ -87,8 +87,8 @@ bool SVG_IMPORT_PLUGIN::Import() for( NSVGpath* path = shape->paths; path != nullptr; path = path->next ) { - DrawPath( path->pts, path->npts, path->closed, shape->fill.type == NSVG_PAINT_COLOR, - lineWidth ); + DrawPath( path->pts, path->npts, path->closed || rule == GRAPHICS_IMPORTER::PF_EVEN_ODD, + shape->fill.type == NSVG_PAINT_COLOR, lineWidth ); } } @@ -124,15 +124,15 @@ double SVG_IMPORT_PLUGIN::GetImageWidth() const } -void SVG_IMPORT_PLUGIN::DrawPath( const float* aPoints, int aNumPoints, bool aClosedPath, - bool aFilled, double aLineWidth ) +void SVG_IMPORT_PLUGIN::DrawPath( const float* aPoints, int aNumPoints, bool aPoly, bool aFilled, + double aLineWidth ) { std::vector< VECTOR2D > collectedPathPoints; if( aNumPoints > 0 ) DrawCubicBezierPath( aPoints, aNumPoints, collectedPathPoints ); - if( aFilled ) + if( aPoly && aFilled ) DrawPolygon( collectedPathPoints, aLineWidth ); else DrawLineSegments( collectedPathPoints, aLineWidth );