Don't assume all glyphs are outline with an outline font.

Underline and overbar may be stroke glyphs.

Fixes https://gitlab.com/kicad/code/kicad/-/issues/17478
This commit is contained in:
Jeff Young 2024-03-18 22:10:36 +00:00
parent 4ed2a0674a
commit 05cdd44404
3 changed files with 23 additions and 4 deletions

View File

@ -82,19 +82,19 @@ std::unique_ptr<GLYPH> STROKE_GLYPH::Transform( const VECTOR2D& aGlyphSize, cons
end.x *= aGlyphSize.x;
end.y *= aGlyphSize.y;
if( aTilt )
if( aTilt != 0.0 )
end.x -= end.y * aTilt;
glyph->m_boundingBox.SetEnd( end );
glyph->m_boundingBox.Offset( aOffset );
for( std::vector<VECTOR2D>& pointList : *glyph.get() )
for( std::vector<VECTOR2D>& pointList : *glyph )
{
for( VECTOR2D& point : pointList )
{
point *= aGlyphSize;
if( aTilt )
if( aTilt != 0.0 )
point.x -= point.y * aTilt;
point += aOffset;
@ -111,6 +111,18 @@ std::unique_ptr<GLYPH> STROKE_GLYPH::Transform( const VECTOR2D& aGlyphSize, cons
}
void STROKE_GLYPH::Move( const VECTOR2I& aOffset )
{
m_boundingBox.Offset( aOffset );
for( std::vector<VECTOR2D>& pointList : *this )
{
for( VECTOR2D& point : pointList )
point += aOffset;
}
}
BOX2D OUTLINE_GLYPH::BoundingBox()
{
BOX2I bbox = BBox();

View File

@ -332,7 +332,12 @@ SCH_FIELD::GetRenderCache( const wxString& forResolvedText, const VECTOR2I& forP
VECTOR2I delta = forPosition - m_renderCachePos;
for( std::unique_ptr<KIFONT::GLYPH>& glyph : m_renderCache )
static_cast<KIFONT::OUTLINE_GLYPH*>( glyph.get() )->Move( delta );
{
if( glyph->IsOutline() )
static_cast<KIFONT::OUTLINE_GLYPH*>( glyph.get() )->Move( delta );
else
static_cast<KIFONT::STROKE_GLYPH*>( glyph.get() )->Move( delta );
}
m_renderCachePos = forPosition;
}

View File

@ -120,6 +120,8 @@ public:
double aTilt, const EDA_ANGLE& aAngle, bool aMirror,
const VECTOR2I& aOrigin );
void Move( const VECTOR2I& aOffset );
private:
bool m_penIsDown = false;
BOX2D m_boundingBox;