Pcbnew: fix crash when trying to save a board with a text with overbar and
using a non Kicad font PCB_PLUGIN::formatRenderCache() was considering all shapes in cache are polygons, but this is not true: some items can be stroke shapes. Fixes #14804 https://gitlab.com/kicad/code/kicad/-/issues/14804
This commit is contained in:
parent
cd904dc2b9
commit
76d66571e4
|
@ -480,16 +480,45 @@ void PCB_PLUGIN::formatPolyPts( const SHAPE_LINE_CHAIN& outline, int aNestLevel,
|
||||||
|
|
||||||
void PCB_PLUGIN::formatRenderCache( const EDA_TEXT* aText, int aNestLevel ) const
|
void PCB_PLUGIN::formatRenderCache( const EDA_TEXT* aText, int aNestLevel ) const
|
||||||
{
|
{
|
||||||
const wxString& shownText = aText->GetShownText( true );
|
wxString resolvedText( aText->GetShownText( true ) );
|
||||||
std::vector<std::unique_ptr<KIFONT::GLYPH>>* cache = aText->GetRenderCache( aText->GetFont(),
|
std::vector<std::unique_ptr<KIFONT::GLYPH>>* cache = aText->GetRenderCache( aText->GetFont(),
|
||||||
shownText );
|
resolvedText );
|
||||||
|
|
||||||
m_out->Print( aNestLevel, "(render_cache %s %s\n",
|
m_out->Print( aNestLevel, "(render_cache %s %s\n",
|
||||||
m_out->Quotew( shownText ).c_str(),
|
m_out->Quotew( resolvedText ).c_str(),
|
||||||
EDA_UNIT_UTILS::FormatAngle( aText->GetDrawRotation() ).c_str() );
|
EDA_UNIT_UTILS::FormatAngle( aText->GetDrawRotation() ).c_str() );
|
||||||
|
|
||||||
for( const std::unique_ptr<KIFONT::GLYPH>& baseGlyph : *cache )
|
for( const std::unique_ptr<KIFONT::GLYPH>& baseGlyph : *cache )
|
||||||
{
|
{
|
||||||
|
// A glyph is not aways a polygon. it can be a stroke (for instance a text with overbar)
|
||||||
|
// we save only polygons from cache
|
||||||
|
// So convert any stroke to a polygon
|
||||||
|
if( baseGlyph->IsStroke() )
|
||||||
|
{
|
||||||
|
const KIFONT::STROKE_GLYPH& strokeGlyph = static_cast<const KIFONT::STROKE_GLYPH&>( *baseGlyph );
|
||||||
|
|
||||||
|
for( const std::vector<VECTOR2D>& points : strokeGlyph )
|
||||||
|
{
|
||||||
|
SHAPE_LINE_CHAIN outline;
|
||||||
|
|
||||||
|
for( size_t idx = 0; idx < points.size(); idx++ )
|
||||||
|
outline.Append( (int)points[idx].x, (int)points[idx].y );
|
||||||
|
|
||||||
|
for( int idx = 1; idx < outline.PointCount(); idx++ )
|
||||||
|
{
|
||||||
|
SHAPE_POLY_SET buffer;
|
||||||
|
TransformOvalToPolygon( buffer, outline.CPoint( idx-1 ), outline.CPoint( idx ),
|
||||||
|
aText->GetTextThickness(), ARC_LOW_DEF, ERROR_INSIDE );
|
||||||
|
|
||||||
|
m_out->Print( aNestLevel + 1, "(polygon\n" );
|
||||||
|
formatPolyPts( buffer.Outline(0), aNestLevel + 2, true );
|
||||||
|
m_out->Print( aNestLevel + 1, ")\n" );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
KIFONT::OUTLINE_GLYPH* glyph = static_cast<KIFONT::OUTLINE_GLYPH*>( baseGlyph.get() );
|
KIFONT::OUTLINE_GLYPH* glyph = static_cast<KIFONT::OUTLINE_GLYPH*>( baseGlyph.get() );
|
||||||
|
|
||||||
if( glyph->OutlineCount() > 0 )
|
if( glyph->OutlineCount() > 0 )
|
||||||
|
|
Loading…
Reference in New Issue