From dba2fdb6d30e5aee653e3122050d964c3346bd43 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Sun, 25 Feb 2024 12:27:52 +0000 Subject: [PATCH] Don't import invalid polygons. If we *do* get a 2-point polygon in SVG, import it as a segment. Fixes https://gitlab.com/kicad/code/kicad/-/issues/17091 --- common/import_gfx/svg_import_plugin.cpp | 2 +- eeschema/import_gfx/graphics_importer_lib_symbol.cpp | 3 ++- pcbnew/import_gfx/graphics_importer_pcbnew.cpp | 4 +++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/common/import_gfx/svg_import_plugin.cpp b/common/import_gfx/svg_import_plugin.cpp index 456242ed63..f1cb4e116a 100644 --- a/common/import_gfx/svg_import_plugin.cpp +++ b/common/import_gfx/svg_import_plugin.cpp @@ -261,7 +261,7 @@ void SVG_IMPORT_PLUGIN::DrawPath( const float* aPoints, int aNumPoints, bool aCl if( aNumPoints > 0 ) DrawCubicBezierPath( aPoints, aNumPoints, collectedPathPoints ); - if( aClosedPath ) + if( aClosedPath && collectedPathPoints.size() > 2 ) DrawPolygon( collectedPathPoints, aStroke, aFilled, aFillColor ); else DrawLineSegments( collectedPathPoints, aStroke ); diff --git a/eeschema/import_gfx/graphics_importer_lib_symbol.cpp b/eeschema/import_gfx/graphics_importer_lib_symbol.cpp index 992a0dccff..06142f3625 100644 --- a/eeschema/import_gfx/graphics_importer_lib_symbol.cpp +++ b/eeschema/import_gfx/graphics_importer_lib_symbol.cpp @@ -176,7 +176,8 @@ void GRAPHICS_IMPORTER_LIB_SYMBOL::AddPolygon( const std::vector& aVer polygon->SetStroke( MapStrokeParams( aStroke ) ); - addItem( std::move( polygon ) ); + if( polygon->IsPolyShapeValid() ) + addItem( std::move( polygon ) ); } diff --git a/pcbnew/import_gfx/graphics_importer_pcbnew.cpp b/pcbnew/import_gfx/graphics_importer_pcbnew.cpp index 6abe668613..2fa94b8d6d 100644 --- a/pcbnew/import_gfx/graphics_importer_pcbnew.cpp +++ b/pcbnew/import_gfx/graphics_importer_pcbnew.cpp @@ -171,7 +171,9 @@ void GRAPHICS_IMPORTER_PCBNEW::AddPolygon( const std::vector& aVertice } polygon->SetStroke( MapStrokeParams( aStroke ) ); - addItem( std::move( polygon ) ); + + if( polygon->IsPolyShapeValid() ) + addItem( std::move( polygon ) ); }