Lib symbol editor, export SVG: fix incorrect position of the drawings.

Fixes #13249
https://gitlab.com/kicad/code/kicad/issues/13249
This commit is contained in:
jean-pierre charras 2022-12-23 16:31:35 +01:00
parent baf18dda47
commit e5363d164c
3 changed files with 17 additions and 10 deletions

View File

@ -297,8 +297,10 @@ public:
/** /**
* Create the SVG print file for the current edited symbol. * Create the SVG print file for the current edited symbol.
* @param aFullFileName is the full filename
* @param aOffset is a plot offset, in iu
*/ */
void SVGPlotSymbol( const wxString& aFullFileName ); void SVGPlotSymbol( const wxString& aFullFileName, VECTOR2I aOffset );
/** /**
* Synchronize the library manager to the symbol library table, and then the symbol tree * Synchronize the library manager to the symbol library table, and then the symbol tree

View File

@ -27,7 +27,7 @@
#include <locale_io.h> #include <locale_io.h>
#include <plotters/plotters_pslike.h> #include <plotters/plotters_pslike.h>
void SYMBOL_EDIT_FRAME::SVGPlotSymbol( const wxString& aFullFileName ) void SYMBOL_EDIT_FRAME::SVGPlotSymbol( const wxString& aFullFileName, VECTOR2I aOffset )
{ {
KIGFX::SCH_RENDER_SETTINGS renderSettings; KIGFX::SCH_RENDER_SETTINGS renderSettings;
renderSettings.LoadColors( GetColorSettings() ); renderSettings.LoadColors( GetColorSettings() );
@ -65,8 +65,8 @@ void SYMBOL_EDIT_FRAME::SVGPlotSymbol( const wxString& aFullFileName )
TRANSFORM temp; // Uses default transform TRANSFORM temp; // Uses default transform
wxPoint plotPos; wxPoint plotPos;
plotPos.x = pageInfo.GetWidthIU( schIUScale.IU_PER_MILS ) / 2; plotPos.x = aOffset.x;
plotPos.y = pageInfo.GetHeightIU( schIUScale.IU_PER_MILS ) / 2; plotPos.y = aOffset.y;
m_symbol->Plot( plotter, GetUnit(), GetConvert(), background, plotPos, temp, false ); m_symbol->Plot( plotter, GetUnit(), GetConvert(), background, plotPos, temp, false );

View File

@ -582,15 +582,20 @@ int SYMBOL_EDITOR_CONTROL::ExportSymbolAsSVG( const TOOL_EVENT& aEvent )
PAGE_INFO pageSave = editFrame->GetScreen()->GetPageSettings(); PAGE_INFO pageSave = editFrame->GetScreen()->GetPageSettings();
PAGE_INFO pageTemp = pageSave; PAGE_INFO pageTemp = pageSave;
VECTOR2I symbolSize = symbol->GetUnitBoundingBox( editFrame->GetUnit(), BOX2I symbolBBox = symbol->GetUnitBoundingBox( editFrame->GetUnit(),
editFrame->GetConvert(), false ).GetSize(); editFrame->GetConvert(), false );
// Add a small margin to the plot bounding box // Add a small margin (10% of size)to the plot bounding box
pageTemp.SetWidthMils( schIUScale.IUToMils( symbolSize.x * 1.2 ) ); symbolBBox.Inflate( symbolBBox.GetSize().x * 0.1, symbolBBox.GetSize().y * 0.1 );
pageTemp.SetHeightMils( schIUScale.IUToMils( symbolSize.y * 1.2 ) );
pageTemp.SetWidthMils( schIUScale.IUToMils( symbolBBox.GetSize().x ) );
pageTemp.SetHeightMils( schIUScale.IUToMils( symbolBBox.GetSize().y ) );
// Add an offet to plot the symbol centered on the page.
VECTOR2I plot_offset = symbolBBox.GetOrigin();
editFrame->GetScreen()->SetPageSettings( pageTemp ); editFrame->GetScreen()->SetPageSettings( pageTemp );
editFrame->SVGPlotSymbol( fullFileName ); editFrame->SVGPlotSymbol( fullFileName, -plot_offset );
editFrame->GetScreen()->SetPageSettings( pageSave ); editFrame->GetScreen()->SetPageSettings( pageSave );
} }