Fix some logic errors in importing SVG polygons with holes.

Fixes https://gitlab.com/kicad/code/kicad/issues/11479
This commit is contained in:
Jeff Young 2022-09-27 17:44:17 +01:00
parent 5b8cf96736
commit 1a812727cb
2 changed files with 13 additions and 22 deletions

View File

@ -178,7 +178,7 @@ void GRAPHICS_IMPORTER_BUFFER::PostprocessNestedPolygons()
std::list<std::unique_ptr<IMPORTED_SHAPE>> newShapes;
std::vector<IMPORTED_POLYGON*> polypaths;
for( auto& shape : m_shapes )
for( std::unique_ptr<IMPORTED_SHAPE>& shape : m_shapes )
{
IMPORTED_POLYGON* poly = dynamic_cast<IMPORTED_POLYGON*>( 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 );
}

View File

@ -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 );