plot: Correct a couple SVG output errors

Plotting to closed lines for polygons in SVG.  Also correct the filled
polygon line width for non-copper zones.

Fixes: lp:1813964
* https://bugs.launchpad.net/kicad/+bug/1813964
This commit is contained in:
Seth Hillbrand 2019-01-30 07:25:57 -08:00
parent 0415c89c5b
commit 37741048ce
3 changed files with 29 additions and 22 deletions

View File

@ -206,12 +206,13 @@ void SVG_PLOTTER::setFillMode( FILL_T fill )
} }
void SVG_PLOTTER::setSVGPlotStyle() void SVG_PLOTTER::setSVGPlotStyle( bool aIsGroup, const std::string& aExtraStyle )
{ {
fputs( "</g>\n<g style=\"", outputFile ); if( aIsGroup )
fputs( "fill:#", outputFile ); fputs( "</g>\n<g ", outputFile );
// output the background fill color // output the background fill color
fprintf( outputFile, "%6.6lX; ", m_brush_rgb_color ); fprintf( outputFile, "style=\"fill:#%6.6lX; ", m_brush_rgb_color );
switch( m_fillMode ) switch( m_fillMode )
{ {
@ -249,9 +250,20 @@ void SVG_PLOTTER::setSVGPlotStyle()
break; break;
} }
fputs( "\">\n", outputFile ); if( aExtraStyle.length() )
{
fputs( aExtraStyle.c_str(), outputFile );
}
m_graphics_changed = false; fputs( "\"", outputFile );
if( aIsGroup )
{
fputs( ">", outputFile );
m_graphics_changed = false;
}
fputs( "\n", outputFile );
} }
/* Set the current line width (in IUs) for the next plot /* Set the current line width (in IUs) for the next plot
@ -470,21 +482,22 @@ void SVG_PLOTTER::PlotPoly( const std::vector<wxPoint>& aCornerList,
setFillMode( aFill ); setFillMode( aFill );
SetCurrentLineWidth( aWidth ); SetCurrentLineWidth( aWidth );
fprintf( outputFile, "<path ");
switch( aFill ) switch( aFill )
{ {
case NO_FILL: case NO_FILL:
fprintf( outputFile, "<polyline fill=\"none;\"\n" ); setSVGPlotStyle( false, "fill:none" );
break; break;
case FILLED_WITH_BG_BODYCOLOR: case FILLED_WITH_BG_BODYCOLOR:
case FILLED_SHAPE: case FILLED_SHAPE:
fprintf( outputFile, "<polyline style=\"fill-rule:evenodd;\"\n" ); setSVGPlotStyle( false, "fill-rule:evenodd;" );
break; break;
} }
DPOINT pos = userToDeviceCoordinates( aCornerList[0] ); DPOINT pos = userToDeviceCoordinates( aCornerList[0] );
fprintf( outputFile, "points=\"%d,%d\n", (int) pos.x, (int) pos.y ); fprintf( outputFile, "d=\"M %d,%d\n", (int) pos.x, (int) pos.y );
for( unsigned ii = 1; ii < aCornerList.size(); ii++ ) for( unsigned ii = 1; ii < aCornerList.size(); ii++ )
{ {
@ -492,16 +505,7 @@ void SVG_PLOTTER::PlotPoly( const std::vector<wxPoint>& aCornerList,
fprintf( outputFile, "%d,%d\n", (int) pos.x, (int) pos.y ); fprintf( outputFile, "%d,%d\n", (int) pos.x, (int) pos.y );
} }
// ensure the shape is closed, for filled shapes (that are closed polygons): fprintf( outputFile, "Z\" /> \n" );
// (svg does not close automatically a polygon
if( aCornerList.front() != aCornerList.back() && aFill != NO_FILL )
{
pos = userToDeviceCoordinates( aCornerList.front() );
fprintf( outputFile, "%d,%d\n", (int) pos.x, (int) pos.y );
}
// Close/(fill) the path
fprintf( outputFile, "\" /> \n" );
} }

View File

@ -975,9 +975,12 @@ protected:
/** /**
* function setSVGPlotStyle() * function setSVGPlotStyle()
* output the string which define pen and brush color, shape, transparence * output the string which define pen and brush color, shape, transparency
*
* @param aIsGroup If false, do not form a new group for the style.
* @param aExtraStyle If given, the string will be added into the style string before closing
*/ */
void setSVGPlotStyle(); void setSVGPlotStyle( bool aIsGroup = true, const std::string& aExtraStyle = {} );
/** /**
* function setFillMode() * function setFillMode()

View File

@ -681,7 +681,7 @@ void BRDITEMS_PLOTTER::PlotFilledAreas( ZONE_CONTAINER* aZone )
{ {
// Plot the filled area polygon. // Plot the filled area polygon.
// The area can be filled by segments or uses solid polygons // The area can be filled by segments or uses solid polygons
if( aZone->GetFillMode() == 0 ) // We are using solid polygons if( aZone->GetFillMode() == ZONE_FILL_MODE::ZFM_POLYGONS ) // We are using solid polygons
{ {
m_plotter->PlotPoly( cornerList, FILLED_SHAPE, aZone->GetMinThickness(), &gbr_metadata ); m_plotter->PlotPoly( cornerList, FILLED_SHAPE, aZone->GetMinThickness(), &gbr_metadata );
} }