Honour renderSettings' default font.

This still leaves a few things out in the cold,
such as hit-testing and polygon generation.
But at least it allows us to plot with a default
font.

Fixes https://gitlab.com/kicad/code/kicad/-/issues/19031

(cherry picked from commit e230d5164dc80f67fab1377890a3c3d5915cfd42)
This commit is contained in:
Jeff Young 2025-07-16 23:20:37 +01:00
parent 593537c52e
commit f10d11d36c
33 changed files with 202 additions and 260 deletions

View File

@ -178,7 +178,7 @@ HANDLER_RESULT<types::Box2> API_HANDLER_COMMON::handleGetTextExtents(
types::Box2 response; types::Box2 response;
BOX2I bbox = text.GetTextBox(); BOX2I bbox = text.GetTextBox( nullptr );
EDA_ANGLE angle = text.GetTextAngle(); EDA_ANGLE angle = text.GetTextAngle();
if( !angle.IsZero() ) if( !angle.IsZero() )

View File

@ -701,7 +701,7 @@ void DS_DATA_ITEM_TEXT::SetConstrainedTextSize()
dummy.SetVertJustify( m_Vjustify ); dummy.SetVertJustify( m_Vjustify );
dummy.SetTextAngle( EDA_ANGLE( m_Orient, DEGREES_T ) ); dummy.SetTextAngle( EDA_ANGLE( m_Orient, DEGREES_T ) );
BOX2I rect = dummy.GetTextBox(); BOX2I rect = dummy.GetTextBox( nullptr );
VECTOR2D size; VECTOR2D size;
size.x = KiROUND( (int) rect.GetWidth() / FSCALE ); size.x = KiROUND( (int) rect.GetWidth() / FSCALE );
size.y = KiROUND( (int) rect.GetHeight() / FSCALE ); size.y = KiROUND( (int) rect.GetHeight() / FSCALE );

View File

@ -221,7 +221,7 @@ const BOX2I DS_DRAW_ITEM_TEXT::GetApproxBBox()
const BOX2I DS_DRAW_ITEM_TEXT::GetBoundingBox() const const BOX2I DS_DRAW_ITEM_TEXT::GetBoundingBox() const
{ {
return EDA_TEXT::GetTextBox(); return EDA_TEXT::GetTextBox( nullptr );
} }

View File

@ -631,12 +631,17 @@ void EDA_TEXT::cacheShownText()
} }
KIFONT::FONT* EDA_TEXT::getDrawFont() const KIFONT::FONT* EDA_TEXT::GetDrawFont( const RENDER_SETTINGS* aSettings ) const
{ {
KIFONT::FONT* font = GetFont(); KIFONT::FONT* font = GetFont();
if( !font ) if( !font )
{
if( aSettings )
font = KIFONT::FONT::GetFont( aSettings->GetDefaultFont(), IsBold(), IsItalic() );
else
font = KIFONT::FONT::GetFont( wxEmptyString, IsBold(), IsItalic() ); font = KIFONT::FONT::GetFont( wxEmptyString, IsBold(), IsItalic() );
}
return font; return font;
} }
@ -714,13 +719,13 @@ void EDA_TEXT::AddRenderCacheGlyph( const SHAPE_POLY_SET& aPoly )
} }
int EDA_TEXT::GetInterline() const int EDA_TEXT::GetInterline( const RENDER_SETTINGS* aSettings ) const
{ {
return KiROUND( getDrawFont()->GetInterline( GetTextHeight(), getFontMetrics() ) ); return KiROUND( GetDrawFont( aSettings )->GetInterline( GetTextHeight(), getFontMetrics() ) );
} }
BOX2I EDA_TEXT::GetTextBox( int aLine ) const BOX2I EDA_TEXT::GetTextBox( const RENDER_SETTINGS* aSettings, int aLine ) const
{ {
VECTOR2I drawPos = GetDrawPos(); VECTOR2I drawPos = GetDrawPos();
@ -748,12 +753,11 @@ BOX2I EDA_TEXT::GetTextBox( int aLine ) const
} }
// calculate the H and V size // calculate the H and V size
KIFONT::FONT* font = getDrawFont(); KIFONT::FONT* font = GetDrawFont( aSettings );
VECTOR2D fontSize( GetTextSize() ); VECTOR2D fontSize( GetTextSize() );
bool bold = IsBold(); bool bold = IsBold();
bool italic = IsItalic(); bool italic = IsItalic();
VECTOR2I extents = font->StringBoundaryLimits( text, fontSize, thickness, bold, italic, VECTOR2I extents = font->StringBoundaryLimits( text, fontSize, thickness, bold, italic, getFontMetrics() );
getFontMetrics() );
int overbarOffset = 0; int overbarOffset = 0;
// Creates bounding box (rectangle) for horizontal, left and top justified text. The // Creates bounding box (rectangle) for horizontal, left and top justified text. The
@ -779,15 +783,13 @@ BOX2I EDA_TEXT::GetTextBox( int aLine ) const
for( unsigned ii = 1; ii < strings.GetCount(); ii++ ) for( unsigned ii = 1; ii < strings.GetCount(); ii++ )
{ {
text = strings.Item( ii ); text = strings.Item( ii );
extents = font->StringBoundaryLimits( text, fontSize, thickness, bold, italic, extents = font->StringBoundaryLimits( text, fontSize, thickness, bold, italic, getFontMetrics() );
getFontMetrics() );
textsize.x = std::max( textsize.x, extents.x ); textsize.x = std::max( textsize.x, extents.x );
} }
// interline spacing is only *between* lines, so total height is the height of the first // interline spacing is only *between* lines, so total height is the height of the first
// line plus the interline distance (with interline spacing) for all subsequent lines // line plus the interline distance (with interline spacing) for all subsequent lines
textsize.y += KiROUND( ( strings.GetCount() - 1 ) textsize.y += KiROUND( ( strings.GetCount() - 1 ) * font->GetInterline( fontSize.y, getFontMetrics() ) );
* font->GetInterline( fontSize.y, getFontMetrics() ) );
} }
textsize.y += overbarOffset; textsize.y += overbarOffset;
@ -852,7 +854,7 @@ BOX2I EDA_TEXT::GetTextBox( int aLine ) const
bool EDA_TEXT::TextHitTest( const VECTOR2I& aPoint, int aAccuracy ) const bool EDA_TEXT::TextHitTest( const VECTOR2I& aPoint, int aAccuracy ) const
{ {
const BOX2I rect = GetTextBox().GetInflated( aAccuracy ); const BOX2I rect = GetTextBox( nullptr ).GetInflated( aAccuracy );
const VECTOR2I location = GetRotated( aPoint, GetDrawPos(), -GetDrawRotation() ); const VECTOR2I location = GetRotated( aPoint, GetDrawPos(), -GetDrawRotation() );
return rect.Contains( location ); return rect.Contains( location );
} }
@ -863,9 +865,9 @@ bool EDA_TEXT::TextHitTest( const BOX2I& aRect, bool aContains, int aAccuracy )
const BOX2I rect = aRect.GetInflated( aAccuracy ); const BOX2I rect = aRect.GetInflated( aAccuracy );
if( aContains ) if( aContains )
return rect.Contains( GetTextBox() ); return rect.Contains( GetTextBox( nullptr ) );
return rect.Intersects( GetTextBox(), GetDrawRotation() ); return rect.Intersects( GetTextBox( nullptr ), GetDrawRotation() );
} }
@ -880,7 +882,7 @@ void EDA_TEXT::Print( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset,
positions.reserve( strings.Count() ); positions.reserve( strings.Count() );
GetLinePositions( positions, (int) strings.Count() ); GetLinePositions( aSettings, positions, (int) strings.Count() );
for( unsigned ii = 0; ii < strings.Count(); ii++ ) for( unsigned ii = 0; ii < strings.Count(); ii++ )
printOneLineOfText( aSettings, aOffset, aColor, aFillMode, strings[ii], positions[ii] ); printOneLineOfText( aSettings, aOffset, aColor, aFillMode, strings[ii], positions[ii] );
@ -893,14 +895,15 @@ void EDA_TEXT::Print( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset,
} }
void EDA_TEXT::GetLinePositions( std::vector<VECTOR2I>& aPositions, int aLineCount ) const void EDA_TEXT::GetLinePositions( const RENDER_SETTINGS* aSettings, std::vector<VECTOR2I>& aPositions,
int aLineCount ) const
{ {
VECTOR2I pos = GetDrawPos(); // Position of first line of the multiline text according VECTOR2I pos = GetDrawPos(); // Position of first line of the multiline text according
// to the center of the multiline text block // to the center of the multiline text block
VECTOR2I offset; // Offset to next line. VECTOR2I offset; // Offset to next line.
offset.y = GetInterline(); offset.y = GetInterline( aSettings );
if( aLineCount > 1 ) if( aLineCount > 1 )
{ {
@ -952,10 +955,7 @@ void EDA_TEXT::printOneLineOfText( const RENDER_SETTINGS* aSettings, const VECTO
if( IsMirrored() ) if( IsMirrored() )
size.x = -size.x; size.x = -size.x;
KIFONT::FONT* font = GetFont(); KIFONT::FONT* font = GetDrawFont( aSettings );
if( !font )
font = KIFONT::FONT::GetFont( aSettings->GetDefaultFont(), IsBold(), IsItalic() );
GRPrintText( DC, aOffset + aPos, aColor, aText, GetDrawRotation(), size, GetHorizJustify(), GRPrintText( DC, aOffset + aPos, aColor, aText, GetDrawRotation(), size, GetHorizJustify(),
GetVertJustify(), penWidth, IsItalic(), IsBold(), font, getFontMetrics() ); GetVertJustify(), penWidth, IsItalic(), IsBold(), font, getFontMetrics() );
@ -1123,7 +1123,7 @@ std::shared_ptr<SHAPE_COMPOUND> EDA_TEXT::GetEffectiveTextShape( bool aTriangula
{ {
std::shared_ptr<SHAPE_COMPOUND> shape = std::make_shared<SHAPE_COMPOUND>(); std::shared_ptr<SHAPE_COMPOUND> shape = std::make_shared<SHAPE_COMPOUND>();
KIGFX::GAL_DISPLAY_OPTIONS empty_opts; KIGFX::GAL_DISPLAY_OPTIONS empty_opts;
KIFONT::FONT* font = getDrawFont(); KIFONT::FONT* font = GetDrawFont( nullptr );
int penWidth = GetEffectiveTextPenWidth(); int penWidth = GetEffectiveTextPenWidth();
wxString shownText( GetShownText( true ) ); wxString shownText( GetShownText( true ) );
VECTOR2I drawPos = GetDrawPos(); VECTOR2I drawPos = GetDrawPos();

View File

@ -2785,7 +2785,7 @@ void CADSTAR_ARCHIVE_PARSER::FixTextPositionNoAlignment( EDA_TEXT* aKiCadTextIte
{ {
if( !aKiCadTextItem->GetText().IsEmpty() ) if( !aKiCadTextItem->GetText().IsEmpty() )
{ {
VECTOR2I positionOffset( 0, aKiCadTextItem->GetInterline() ); VECTOR2I positionOffset( 0, aKiCadTextItem->GetInterline( nullptr ) );
RotatePoint( positionOffset, aKiCadTextItem->GetTextAngle() ); RotatePoint( positionOffset, aKiCadTextItem->GetTextAngle() );
//Count num of additional lines //Count num of additional lines

View File

@ -1658,9 +1658,8 @@ void PDF_PLOTTER::Text( const VECTOR2I& aPos,
wxStringTokenizer str_tok( aText, " ", wxTOKEN_RET_DELIMS ); wxStringTokenizer str_tok( aText, " ", wxTOKEN_RET_DELIMS );
// If aFont is not specilied (== nullptr), use the default kicad stroke font
if( !aFont ) if( !aFont )
aFont = KIFONT::FONT::GetFont(); aFont = KIFONT::FONT::GetFont( m_renderSettings->GetDefaultFont() );
VECTOR2I full_box( aFont->StringBoundaryLimits( aText, t_size, aWidth, aBold, aItalic, VECTOR2I full_box( aFont->StringBoundaryLimits( aText, t_size, aWidth, aBold, aItalic,
aFontMetrics ) ); aFontMetrics ) );

View File

@ -136,15 +136,9 @@ void PlotDrawingSheet( PLOTTER* plotter, const PROJECT* aProject, const TITLE_BL
case WSG_TEXT_T: case WSG_TEXT_T:
{ {
DS_DRAW_ITEM_TEXT* text = (DS_DRAW_ITEM_TEXT*) item; DS_DRAW_ITEM_TEXT* text = (DS_DRAW_ITEM_TEXT*) item;
KIFONT::FONT* font = text->GetFont(); KIFONT::FONT* font = text->GetDrawFont( settings );
COLOR4D color = plotColor; COLOR4D color = plotColor;
if( !font )
{
font = KIFONT::FONT::GetFont( settings->GetDefaultFont(), text->IsBold(),
text->IsItalic() );
}
if( plotter->GetColorMode() && text->GetTextColor() != COLOR4D::UNSPECIFIED ) if( plotter->GetColorMode() && text->GetTextColor() != COLOR4D::UNSPECIFIED )
color = text->GetTextColor(); color = text->GetTextColor();
@ -154,8 +148,8 @@ void PlotDrawingSheet( PLOTTER* plotter, const PROJECT* aProject, const TITLE_BL
text->GetTextAngle(), text->GetTextSize(), text->GetHorizJustify(), text->GetTextAngle(), text->GetTextSize(), text->GetHorizJustify(),
text->GetVertJustify(), penWidth, text->IsItalic(), text->IsBold(), text->GetVertJustify(), penWidth, text->IsItalic(), text->IsBold(),
text->IsMultilineAllowed(), font, text->GetFontMetrics() ); text->IsMultilineAllowed(), font, text->GetFontMetrics() );
}
break; break;
}
case WSG_POLY_T: case WSG_POLY_T:
{ {

View File

@ -745,7 +745,7 @@ void PLOTTER::Text( const VECTOR2I& aPos,
} }
if( !aFont ) if( !aFont )
aFont = KIFONT::FONT::GetFont(); aFont = KIFONT::FONT::GetFont( m_renderSettings->GetDefaultFont() );
aFont->Draw( &callback_gal, aText, aPos, attributes, aFontMetrics ); aFont->Draw( &callback_gal, aText, aPos, attributes, aFontMetrics );
} }
@ -790,7 +790,7 @@ void PLOTTER::PlotText( const VECTOR2I& aPos,
} ); } );
if( !aFont ) if( !aFont )
aFont = KIFONT::FONT::GetFont(); aFont = KIFONT::FONT::GetFont( m_renderSettings->GetDefaultFont() );
aFont->Draw( &callback_gal, aText, aPos, attributes, aFontMetrics ); aFont->Draw( &callback_gal, aText, aPos, attributes, aFontMetrics );
} }

View File

@ -310,7 +310,7 @@ void ERC_TESTER::TestTextVars( DS_PROXY_VIEW_ITEM* aDrawingSheet )
{ {
SCH_TEXTBOX* textboxItem = static_cast<SCH_TEXTBOX*>( child ); SCH_TEXTBOX* textboxItem = static_cast<SCH_TEXTBOX*>( child );
if( unresolved( textboxItem->GetShownText( &sheet, true ) ) ) if( unresolved( textboxItem->GetShownText( nullptr, &sheet, true ) ) )
{ {
auto ercItem = ERC_ITEM::Create( ERCE_UNRESOLVED_VARIABLE ); auto ercItem = ERC_ITEM::Create( ERCE_UNRESOLVED_VARIABLE );
ercItem->SetItems( symbol ); ercItem->SetItems( symbol );
@ -398,7 +398,7 @@ void ERC_TESTER::TestTextVars( DS_PROXY_VIEW_ITEM* aDrawingSheet )
} }
else if( SCH_TEXTBOX* textBox = dynamic_cast<SCH_TEXTBOX*>( item ) ) else if( SCH_TEXTBOX* textBox = dynamic_cast<SCH_TEXTBOX*>( item ) )
{ {
if( textBox->GetShownText( &sheet, true ).Matches( wxS( "*${*}*" ) ) ) if( textBox->GetShownText( nullptr, &sheet, true ).Matches( wxS( "*${*}*" ) ) )
{ {
auto ercItem = ERC_ITEM::Create( ERCE_UNRESOLVED_VARIABLE ); auto ercItem = ERC_ITEM::Create( ERCE_UNRESOLVED_VARIABLE );
ercItem->SetItems( textBox ); ercItem->SetItems( textBox );

View File

@ -945,8 +945,7 @@ void FIELDS_GRID_TABLE::SetValue( int aRow, int aCol, const wxString &aValue )
if( value == DEFAULT_FONT_NAME ) if( value == DEFAULT_FONT_NAME )
field.SetFont( nullptr ); field.SetFont( nullptr );
else if( value == KICAD_FONT_NAME ) else if( value == KICAD_FONT_NAME )
field.SetFont( KIFONT::FONT::GetFont( wxEmptyString, field.IsBold(), field.SetFont( KIFONT::FONT::GetFont( wxEmptyString, field.IsBold(), field.IsItalic() ) );
field.IsItalic() ) );
else else
field.SetFont( KIFONT::FONT::GetFont( aValue, field.IsBold(), field.IsItalic() ) ); field.SetFont( KIFONT::FONT::GetFont( aValue, field.IsBold(), field.IsItalic() ) );

View File

@ -348,12 +348,12 @@ int SCH_FIELD::GetPenWidth() const
} }
KIFONT::FONT* SCH_FIELD::getDrawFont() const KIFONT::FONT* SCH_FIELD::GetDrawFont( const RENDER_SETTINGS* aSettings ) const
{ {
KIFONT::FONT* font = EDA_TEXT::GetFont(); KIFONT::FONT* font = EDA_TEXT::GetFont();
if( !font ) if( !font )
font = KIFONT::FONT::GetFont( GetDefaultFont(), IsBold(), IsItalic() ); font = KIFONT::FONT::GetFont( GetDefaultFont( aSettings ), IsBold(), IsItalic() );
return font; return font;
} }
@ -377,10 +377,7 @@ std::vector<std::unique_ptr<KIFONT::GLYPH>>*
SCH_FIELD::GetRenderCache( const wxString& forResolvedText, const VECTOR2I& forPosition, SCH_FIELD::GetRenderCache( const wxString& forResolvedText, const VECTOR2I& forPosition,
TEXT_ATTRIBUTES& aAttrs ) const TEXT_ATTRIBUTES& aAttrs ) const
{ {
KIFONT::FONT* font = GetFont(); KIFONT::FONT* font = GetDrawFont( nullptr );
if( !font )
font = KIFONT::FONT::GetFont( GetDefaultFont(), IsBold(), IsItalic() );
if( font->IsOutline() ) if( font->IsOutline() )
{ {
@ -692,7 +689,7 @@ EDA_ANGLE SCH_FIELD::GetDrawRotation() const
const BOX2I SCH_FIELD::GetBoundingBox() const const BOX2I SCH_FIELD::GetBoundingBox() const
{ {
BOX2I bbox = GetTextBox(); BOX2I bbox = GetTextBox( nullptr );
// Calculate the bounding box position relative to the parent: // Calculate the bounding box position relative to the parent:
VECTOR2I origin = GetParentPosition(); VECTOR2I origin = GetParentPosition();
@ -1540,11 +1537,7 @@ void SCH_FIELD::Plot( PLOTTER* aPlotter, bool aBackground, const SCH_PLOT_OPTS&
color = nc->GetSchematicColor(); color = nc->GetSchematicColor();
} }
KIFONT::FONT* font = GetFont(); KIFONT::FONT* font = GetDrawFont( renderSettings );
if( !font )
font = KIFONT::FONT::GetFont( renderSettings->GetDefaultFont(), IsBold(), IsItalic() );
TEXT_ATTRIBUTES attrs = GetAttributes(); TEXT_ATTRIBUTES attrs = GetAttributes();
attrs.m_StrokeWidth = penWidth; attrs.m_StrokeWidth = penWidth;
attrs.m_Halign = hjustify; attrs.m_Halign = hjustify;

View File

@ -195,6 +195,8 @@ public:
*/ */
EDA_ANGLE GetDrawRotation() const override; EDA_ANGLE GetDrawRotation() const override;
KIFONT::FONT* GetDrawFont( const RENDER_SETTINGS* aSettings ) const override;
const BOX2I GetBoundingBox() const override; const BOX2I GetBoundingBox() const override;
/** /**
@ -329,8 +331,6 @@ public:
#endif #endif
protected: protected:
KIFONT::FONT* getDrawFont() const override;
const KIFONT::METRICS& getFontMetrics() const override { return GetFontMetrics(); } const KIFONT::METRICS& getFontMetrics() const override { return GetFontMetrics(); }
/** /**

View File

@ -1733,7 +1733,7 @@ const LIB_SYMBOL* CADSTAR_SCH_ARCHIVE_LOADER::loadSymdef( const SYMDEF_ID& aSymd
for( size_t ii = 0; ii < strings.size(); ++ii ) for( size_t ii = 0; ii < strings.size(); ++ii )
{ {
BOX2I bbox = libtext->GetTextBox( ii ); BOX2I bbox = libtext->GetTextBox( nullptr, ii );
VECTOR2I linePos = { bbox.GetLeft(), -bbox.GetBottom() }; VECTOR2I linePos = { bbox.GetLeft(), -bbox.GetBottom() };
RotatePoint( linePos, libtext->GetTextPos(), -libtext->GetTextAngle() ); RotatePoint( linePos, libtext->GetTextPos(), -libtext->GetTextAngle() );

View File

@ -22,6 +22,7 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/ */
#include "font/kicad_font_name.h"
#include <pgm_base.h> #include <pgm_base.h>
#include <settings/settings_manager.h> #include <settings/settings_manager.h>
#include <eeschema_settings.h> #include <eeschema_settings.h>
@ -475,12 +476,18 @@ int SCH_ITEM::compare( const SCH_ITEM& aOther, int aCompareFlags ) const
} }
const wxString& SCH_ITEM::GetDefaultFont() const const wxString& SCH_ITEM::GetDefaultFont( const RENDER_SETTINGS* aSettings ) const
{ {
SETTINGS_MANAGER& mgr = Pgm().GetSettingsManager(); static wxString defaultName = KICAD_FONT_NAME;
EESCHEMA_SETTINGS* cfg = mgr.GetAppSettings<EESCHEMA_SETTINGS>( "eeschema" );
SETTINGS_MANAGER& mgr = Pgm().GetSettingsManager();
if( aSettings )
return aSettings->GetDefaultFont();
else if( EESCHEMA_SETTINGS* cfg = mgr.GetAppSettings<EESCHEMA_SETTINGS>( "eeschema" ) )
return cfg->m_Appearance.default_font; return cfg->m_Appearance.default_font;
else
return defaultName;
} }

View File

@ -302,7 +302,7 @@ public:
int GetEffectivePenWidth( const SCH_RENDER_SETTINGS* aSettings ) const; int GetEffectivePenWidth( const SCH_RENDER_SETTINGS* aSettings ) const;
const wxString& GetDefaultFont() const; const wxString& GetDefaultFont( const RENDER_SETTINGS* aSettings ) const;
const KIFONT::METRICS& GetFontMetrics() const; const KIFONT::METRICS& GetFontMetrics() const;

View File

@ -560,7 +560,7 @@ double SCH_LABEL_BASE::Similarity( const SCH_ITEM& aOther ) const
void SCH_LABEL_BASE::AutoplaceFields( SCH_SCREEN* aScreen, AUTOPLACE_ALGO aAlgo ) void SCH_LABEL_BASE::AutoplaceFields( SCH_SCREEN* aScreen, AUTOPLACE_ALGO aAlgo )
{ {
int margin = GetTextOffset() * 2; int margin = GetTextOffset() * 2;
int labelLen = GetBodyBoundingBox().GetSizeMax(); int labelLen = GetBodyBoundingBox( nullptr ).GetSizeMax();
int accumulated = GetTextHeight() / 2; int accumulated = GetTextHeight() / 2;
if( Type() == SCH_GLOBAL_LABEL_T ) if( Type() == SCH_GLOBAL_LABEL_T )
@ -960,14 +960,14 @@ int SCH_LABEL_BASE::GetLabelBoxExpansion( const RENDER_SETTINGS* aSettings ) con
} }
const BOX2I SCH_LABEL_BASE::GetBodyBoundingBox() const const BOX2I SCH_LABEL_BASE::GetBodyBoundingBox( const RENDER_SETTINGS* aSettings ) const
{ {
// build the bounding box of the label only, without taking into account its fields // build the bounding box of the label only, without taking into account its fields
BOX2I box; BOX2I box;
std::vector<VECTOR2I> pts; std::vector<VECTOR2I> pts;
CreateGraphicShape( nullptr, pts, GetTextPos() ); CreateGraphicShape( aSettings, pts, GetTextPos() );
for( const VECTOR2I& pt : pts ) for( const VECTOR2I& pt : pts )
box.Merge( pt ); box.Merge( pt );
@ -982,7 +982,7 @@ const BOX2I SCH_LABEL_BASE::GetBoundingBox() const
{ {
// build the bounding box of the entire label, including its fields // build the bounding box of the entire label, including its fields
BOX2I box = GetBodyBoundingBox(); BOX2I box = GetBodyBoundingBox( nullptr );
for( const SCH_FIELD& field : m_fields ) for( const SCH_FIELD& field : m_fields )
{ {
@ -1005,7 +1005,7 @@ const BOX2I SCH_LABEL_BASE::GetBoundingBox() const
bool SCH_LABEL_BASE::HitTest( const VECTOR2I& aPosition, int aAccuracy ) const bool SCH_LABEL_BASE::HitTest( const VECTOR2I& aPosition, int aAccuracy ) const
{ {
BOX2I bbox = GetBodyBoundingBox(); BOX2I bbox = GetBodyBoundingBox( nullptr );
bbox.Inflate( aAccuracy ); bbox.Inflate( aAccuracy );
if( bbox.Contains( aPosition ) ) if( bbox.Contains( aPosition ) )
@ -1042,7 +1042,7 @@ bool SCH_LABEL_BASE::HitTest( const BOX2I& aRect, bool aContained, int aAccuracy
} }
else else
{ {
if( rect.Intersects( GetBodyBoundingBox() ) ) if( rect.Intersects( GetBodyBoundingBox( nullptr ) ) )
return true; return true;
for( const SCH_FIELD& field : m_fields ) for( const SCH_FIELD& field : m_fields )
@ -1285,13 +1285,10 @@ void SCH_LABEL_BASE::Plot( PLOTTER* aPlotter, bool aBackground, const SCH_PLOT_O
penWidth = std::max( penWidth, settings->GetMinPenWidth() ); penWidth = std::max( penWidth, settings->GetMinPenWidth() );
aPlotter->SetCurrentLineWidth( penWidth ); aPlotter->SetCurrentLineWidth( penWidth );
KIFONT::FONT* font = GetFont(); KIFONT::FONT* font = GetDrawFont( settings );
if( !font ) VECTOR2I textpos = GetTextPos() + GetSchematicTextOffset( settings );
font = KIFONT::FONT::GetFont( settings->GetDefaultFont(), IsBold(), IsItalic() ); CreateGraphicShape( settings, s_poly, GetTextPos() );
VECTOR2I textpos = GetTextPos() + GetSchematicTextOffset( aPlotter->RenderSettings() );
CreateGraphicShape( aPlotter->RenderSettings(), s_poly, GetTextPos() );
TEXT_ATTRIBUTES attrs = GetAttributes(); TEXT_ATTRIBUTES attrs = GetAttributes();
attrs.m_StrokeWidth = penWidth; attrs.m_StrokeWidth = penWidth;
@ -1303,8 +1300,7 @@ void SCH_LABEL_BASE::Plot( PLOTTER* aPlotter, bool aBackground, const SCH_PLOT_O
} }
else else
{ {
aPlotter->PlotText( textpos, color, GetShownText( sheet, true ), attrs, font, aPlotter->PlotText( textpos, color, GetShownText( sheet, true ), attrs, font, GetFontMetrics() );
GetFontMetrics() );
if( aPlotter->GetColorMode() ) if( aPlotter->GetColorMode() )
{ {
@ -1342,6 +1338,7 @@ void SCH_LABEL_BASE::Plot( PLOTTER* aPlotter, bool aBackground, const SCH_PLOT_O
// Make sheet pins and hierarchical labels clickable hyperlinks // Make sheet pins and hierarchical labels clickable hyperlinks
bool linkAlreadyPlotted = false; bool linkAlreadyPlotted = false;
BOX2I bodyBBox = GetBodyBoundingBox( settings );
if( aPlotOpts.m_PDFHierarchicalLinks ) if( aPlotOpts.m_PDFHierarchicalLinks )
{ {
@ -1351,8 +1348,7 @@ void SCH_LABEL_BASE::Plot( PLOTTER* aPlotter, bool aBackground, const SCH_PLOT_O
{ {
SCH_SHEET_PATH path = *sheet; SCH_SHEET_PATH path = *sheet;
path.pop_back(); path.pop_back();
aPlotter->HyperlinkBox( GetBodyBoundingBox(), aPlotter->HyperlinkBox( bodyBBox, EDA_TEXT::GotoPageHref( path.GetPageNumber() ) );
EDA_TEXT::GotoPageHref( path.GetPageNumber() ) );
linkAlreadyPlotted = true; linkAlreadyPlotted = true;
} }
} }
@ -1361,8 +1357,7 @@ void SCH_LABEL_BASE::Plot( PLOTTER* aPlotter, bool aBackground, const SCH_PLOT_O
SCH_SHEET_PATH path = *sheet; SCH_SHEET_PATH path = *sheet;
SCH_SHEET* parent = static_cast<SCH_SHEET*>( m_parent ); SCH_SHEET* parent = static_cast<SCH_SHEET*>( m_parent );
path.push_back( parent ); path.push_back( parent );
aPlotter->HyperlinkBox( GetBodyBoundingBox(), aPlotter->HyperlinkBox( bodyBBox, EDA_TEXT::GotoPageHref( path.GetPageNumber() ) );
EDA_TEXT::GotoPageHref( path.GetPageNumber() ) );
linkAlreadyPlotted = true; linkAlreadyPlotted = true;
} }
} }
@ -1378,8 +1373,8 @@ void SCH_LABEL_BASE::Plot( PLOTTER* aPlotter, bool aBackground, const SCH_PLOT_O
_( "Net" ), _( "Net" ),
connection->Name() ) ); connection->Name() ) );
properties.emplace_back( properties.emplace_back( wxString::Format( wxT( "!%s = %s" ),
wxString::Format( wxT( "!%s = %s" ), _( "Resolved netclass" ), _( "Resolved netclass" ),
GetEffectiveNetClass()->GetHumanReadableName() ) ); GetEffectiveNetClass()->GetHumanReadableName() ) );
} }
@ -1391,14 +1386,11 @@ void SCH_LABEL_BASE::Plot( PLOTTER* aPlotter, bool aBackground, const SCH_PLOT_O
} }
if( !properties.empty() ) if( !properties.empty() )
aPlotter->HyperlinkMenu( GetBodyBoundingBox(), properties ); aPlotter->HyperlinkMenu( bodyBBox, properties );
} }
if( Type() == SCH_HIER_LABEL_T ) if( Type() == SCH_HIER_LABEL_T )
{ aPlotter->Bookmark( bodyBBox, GetShownText( false ), _( "Hierarchical Labels" ) );
aPlotter->Bookmark( GetBodyBoundingBox(), GetShownText( false ),
_( "Hierarchical Labels" ) );
}
} }
for( SCH_FIELD& field : m_fields ) for( SCH_FIELD& field : m_fields )
@ -1498,9 +1490,9 @@ bool SCH_LABEL::Deserialize( const google::protobuf::Any &aContainer )
} }
const BOX2I SCH_LABEL::GetBodyBoundingBox() const const BOX2I SCH_LABEL::GetBodyBoundingBox( const RENDER_SETTINGS* aSettings ) const
{ {
BOX2I rect = GetTextBox(); BOX2I rect = GetTextBox( aSettings );
rect.Offset( 0, -GetTextOffset() ); rect.Offset( 0, -GetTextOffset() );
rect.Inflate( GetEffectiveTextPenWidth() ); rect.Inflate( GetEffectiveTextPenWidth() );
@ -1987,7 +1979,7 @@ void SCH_GLOBALLABEL::CreateGraphicShape( const RENDER_SETTINGS* aRenderSettings
int margin = GetLabelBoxExpansion( aRenderSettings ); int margin = GetLabelBoxExpansion( aRenderSettings );
int halfSize = ( GetTextHeight() / 2 ) + margin; int halfSize = ( GetTextHeight() / 2 ) + margin;
int linewidth = GetPenWidth(); int linewidth = GetPenWidth();
int symb_len = GetTextBox().GetWidth() + 2 * margin; int symb_len = GetTextBox( aRenderSettings ).GetWidth() + 2 * margin;
int x = symb_len + linewidth + 3; int x = symb_len + linewidth + 3;
int y = halfSize + linewidth + 3; int y = halfSize + linewidth + 3;
@ -2122,7 +2114,7 @@ void SCH_HIERLABEL::CreateGraphicShape( const RENDER_SETTINGS* aSettings,
} }
const BOX2I SCH_HIERLABEL::GetBodyBoundingBox() const const BOX2I SCH_HIERLABEL::GetBodyBoundingBox( const RENDER_SETTINGS* aSettings ) const
{ {
int penWidth = GetEffectiveTextPenWidth(); int penWidth = GetEffectiveTextPenWidth();
int margin = GetTextOffset(); int margin = GetTextOffset();
@ -2131,7 +2123,7 @@ const BOX2I SCH_HIERLABEL::GetBodyBoundingBox() const
int y = GetTextPos().y; int y = GetTextPos().y;
int height = GetTextHeight() + penWidth + margin; int height = GetTextHeight() + penWidth + margin;
int length = GetTextBox().GetWidth(); int length = GetTextBox( aSettings ).GetWidth();
length += height; // add height for triangular shapes length += height; // add height for triangular shapes

View File

@ -316,7 +316,7 @@ public:
/** /**
* Return the bounding box of the label only, without taking in account its fields. * Return the bounding box of the label only, without taking in account its fields.
*/ */
virtual const BOX2I GetBodyBoundingBox() const; virtual const BOX2I GetBodyBoundingBox( const RENDER_SETTINGS* aSettings ) const;
/** /**
* Return the bounding box of the label including its fields. * Return the bounding box of the label including its fields.
@ -412,7 +412,7 @@ public:
return wxT( "SCH_LABEL" ); return wxT( "SCH_LABEL" );
} }
const BOX2I GetBodyBoundingBox() const override; const BOX2I GetBodyBoundingBox( const RENDER_SETTINGS* aSettings ) const override;
bool IsConnectable() const override { return true; } bool IsConnectable() const override { return true; }
@ -612,7 +612,7 @@ public:
void CreateGraphicShape( const RENDER_SETTINGS* aSettings, std::vector<VECTOR2I>& aPoints, void CreateGraphicShape( const RENDER_SETTINGS* aSettings, std::vector<VECTOR2I>& aPoints,
const VECTOR2I& aPos, LABEL_FLAG_SHAPE aShape ) const; const VECTOR2I& aPos, LABEL_FLAG_SHAPE aShape ) const;
const BOX2I GetBodyBoundingBox() const override; const BOX2I GetBodyBoundingBox( const RENDER_SETTINGS* aSettings ) const override;
bool IsConnectable() const override { return true; } bool IsConnectable() const override { return true; }

View File

@ -272,11 +272,10 @@ bool SCH_PAINTER::isUnitAndConversionShown( const SCH_ITEM* aItem ) const
KIFONT::FONT* SCH_PAINTER::getFont( const EDA_TEXT* aItem ) const KIFONT::FONT* SCH_PAINTER::getFont( const EDA_TEXT* aItem ) const
{ {
if( KIFONT::FONT* font = aItem->GetFont() ) if( KIFONT::FONT* font = aItem->GetDrawFont( &m_schSettings ) )
return font; return font;
return KIFONT::FONT::GetFont( m_schSettings.GetDefaultFont(), aItem->IsBold(), return KIFONT::FONT::GetFont( m_schSettings.GetDefaultFont(), aItem->IsBold(), aItem->IsItalic() );
aItem->IsItalic() );
} }
@ -1084,7 +1083,8 @@ void SCH_PAINTER::draw( const SCH_PIN* aPin, int aLayer, bool aDimmed )
m_schSettings.m_ShowPinsElectricalType, m_schSettings.m_ShowPinsElectricalType,
m_schSettings.m_ShowPinAltIcons ); m_schSettings.m_ShowPinAltIcons );
const auto textRendersAsBitmap = [&]( KIGFX::GAL& aGal, int aTextSize ) const auto textRendersAsBitmap =
[&]( KIGFX::GAL& aGal, int aTextSize )
{ {
// Rendering text is expensive (particularly when using outline fonts). At small effective // Rendering text is expensive (particularly when using outline fonts). At small effective
// sizes (ie: zoomed out) the visual differences between outline and/or stroke fonts and the // sizes (ie: zoomed out) the visual differences between outline and/or stroke fonts and the
@ -1142,7 +1142,8 @@ void SCH_PAINTER::draw( const SCH_PIN* aPin, int aLayer, bool aDimmed )
} }
}; };
const auto getColorForLayer = [&]( int aDrawnLayer ) const auto getColorForLayer =
[&]( int aDrawnLayer )
{ {
if( !aPin->IsVisible() ) if( !aPin->IsVisible() )
return getRenderColor( aPin, LAYER_HIDDEN, drawingShadows, aDimmed ); return getRenderColor( aPin, LAYER_HIDDEN, drawingShadows, aDimmed );
@ -1775,7 +1776,7 @@ void SCH_PAINTER::draw( const SCH_TEXT* aText, int aLayer, bool aDimmed )
// SCH_FIELD text. // SCH_FIELD text.
if( font->IsOutline() && aText->Type() == SCH_TEXT_T ) if( font->IsOutline() && aText->Type() == SCH_TEXT_T )
{ {
BOX2I firstLineBBox = aText->GetTextBox( 0 ); BOX2I firstLineBBox = aText->GetTextBox( nullptr, 0 );
int sizeDiff = firstLineBBox.GetHeight() - aText->GetTextSize().y; int sizeDiff = firstLineBBox.GetHeight() - aText->GetTextSize().y;
int adjust = KiROUND( sizeDiff * 0.4 ); int adjust = KiROUND( sizeDiff * 0.4 );
VECTOR2I adjust_offset( 0, - adjust ); VECTOR2I adjust_offset( 0, - adjust );

View File

@ -82,7 +82,7 @@ void SCH_TEXT::NormalizeJustification( bool inverse )
return; return;
VECTOR2I delta( 0, 0 ); VECTOR2I delta( 0, 0 );
BOX2I bbox = GetTextBox(); BOX2I bbox = GetTextBox( nullptr );
if( GetTextAngle().IsHorizontal() ) if( GetTextAngle().IsHorizontal() )
{ {
@ -285,12 +285,12 @@ int SCH_TEXT::GetPenWidth() const
} }
KIFONT::FONT* SCH_TEXT::getDrawFont() const KIFONT::FONT* SCH_TEXT::GetDrawFont( const RENDER_SETTINGS* aSettings ) const
{ {
KIFONT::FONT* font = EDA_TEXT::GetFont(); KIFONT::FONT* font = EDA_TEXT::GetFont();
if( !font ) if( !font )
font = KIFONT::FONT::GetFont( GetDefaultFont(), IsBold(), IsItalic() ); font = KIFONT::FONT::GetFont( GetDefaultFont( aSettings ), IsBold(), IsItalic() );
return font; return font;
} }
@ -384,7 +384,7 @@ void SCH_TEXT::Print( const SCH_RENDER_SETTINGS* aSettings, int aUnit, int aBody
const BOX2I SCH_TEXT::GetBoundingBox() const const BOX2I SCH_TEXT::GetBoundingBox() const
{ {
BOX2I bbox = GetTextBox(); BOX2I bbox = GetTextBox( nullptr );
if( !GetTextAngle().IsZero() ) // Rotate bbox. if( !GetTextAngle().IsZero() ) // Rotate bbox.
{ {
@ -556,11 +556,7 @@ void SCH_TEXT::Plot( PLOTTER* aPlotter, bool aBackground, const SCH_PLOT_OPTS& a
penWidth = std::max( penWidth, renderSettings->GetMinPenWidth() ); penWidth = std::max( penWidth, renderSettings->GetMinPenWidth() );
aPlotter->SetCurrentLineWidth( penWidth ); aPlotter->SetCurrentLineWidth( penWidth );
KIFONT::FONT* font = GetFont(); KIFONT::FONT* font = GetDrawFont( renderSettings );
if( !font )
font = KIFONT::FONT::GetFont( renderSettings->GetDefaultFont(), IsBold(), IsItalic() );
TEXT_ATTRIBUTES attrs = GetAttributes(); TEXT_ATTRIBUTES attrs = GetAttributes();
attrs.m_StrokeWidth = penWidth; attrs.m_StrokeWidth = penWidth;
@ -602,7 +598,7 @@ void SCH_TEXT::Plot( PLOTTER* aPlotter, bool aBackground, const SCH_PLOT_OPTS& a
// SCH_FIELD text. // SCH_FIELD text.
if( font->IsOutline() ) if( font->IsOutline() )
{ {
BOX2I firstLineBBox = GetTextBox( 0 ); BOX2I firstLineBBox = GetTextBox( renderSettings, 0 );
int sizeDiff = firstLineBBox.GetHeight() - GetTextSize().y; int sizeDiff = firstLineBBox.GetHeight() - GetTextSize().y;
int adjust = KiROUND( sizeDiff * 0.4 ); int adjust = KiROUND( sizeDiff * 0.4 );
VECTOR2I adjust_offset( 0, - adjust ); VECTOR2I adjust_offset( 0, - adjust );
@ -616,7 +612,7 @@ void SCH_TEXT::Plot( PLOTTER* aPlotter, bool aBackground, const SCH_PLOT_OPTS& a
wxStringSplit( GetShownText( sheet, true ), strings_list, '\n' ); wxStringSplit( GetShownText( sheet, true ), strings_list, '\n' );
positions.reserve( strings_list.Count() ); positions.reserve( strings_list.Count() );
GetLinePositions( positions, (int) strings_list.Count() ); GetLinePositions( renderSettings, positions, (int) strings_list.Count() );
attrs.m_Multiline = false; attrs.m_Multiline = false;

View File

@ -59,6 +59,8 @@ public:
return _( "Text" ); return _( "Text" );
} }
KIFONT::FONT* GetDrawFont( const RENDER_SETTINGS* aSettings ) const override;
virtual wxString GetShownText( const SCH_SHEET_PATH* aPath, bool aAllowExtraText, virtual wxString GetShownText( const SCH_SHEET_PATH* aPath, bool aAllowExtraText,
int aDepth = 0 ) const; int aDepth = 0 ) const;
@ -174,8 +176,6 @@ public:
static HTML_MESSAGE_BOX* ShowSyntaxHelp( wxWindow* aParentWindow ); static HTML_MESSAGE_BOX* ShowSyntaxHelp( wxWindow* aParentWindow );
protected: protected:
KIFONT::FONT* getDrawFont() const override;
const KIFONT::METRICS& getFontMetrics() const override { return GetFontMetrics(); } const KIFONT::METRICS& getFontMetrics() const override { return GetFontMetrics(); }
/** /**

View File

@ -258,12 +258,12 @@ bool SCH_TEXTBOX::operator<( const SCH_ITEM& aItem ) const
} }
KIFONT::FONT* SCH_TEXTBOX::getDrawFont() const KIFONT::FONT* SCH_TEXTBOX::GetDrawFont( const RENDER_SETTINGS* aSettings ) const
{ {
KIFONT::FONT* font = EDA_TEXT::GetFont(); KIFONT::FONT* font = EDA_TEXT::GetFont();
if( !font ) if( !font )
font = KIFONT::FONT::GetFont( GetDefaultFont(), IsBold(), IsItalic() ); font = KIFONT::FONT::GetFont( GetDefaultFont( aSettings ), IsBold(), IsItalic() );
return font; return font;
} }
@ -345,8 +345,8 @@ void SCH_TEXTBOX::Print( const SCH_RENDER_SETTINGS* aSettings, int aUnit, int aB
} }
wxString SCH_TEXTBOX::GetShownText( const SCH_SHEET_PATH* aPath, bool aAllowExtraText, wxString SCH_TEXTBOX::GetShownText( const RENDER_SETTINGS* aSettings, const SCH_SHEET_PATH* aPath,
int aDepth ) const bool aAllowExtraText, int aDepth ) const
{ {
SCH_SHEET* sheet = nullptr; SCH_SHEET* sheet = nullptr;
@ -381,8 +381,8 @@ wxString SCH_TEXTBOX::GetShownText( const SCH_SHEET_PATH* aPath, bool aAllowExtr
else else
colWidth = abs( size.x ) - ( GetMarginLeft() + GetMarginRight() ); colWidth = abs( size.x ) - ( GetMarginLeft() + GetMarginRight() );
getDrawFont()->LinebreakText( text, colWidth, GetTextSize(), GetTextThickness(), IsBold(), GetDrawFont( aSettings )->LinebreakText( text, colWidth, GetTextSize(), GetEffectiveTextPenWidth(),
IsItalic() ); IsBold(), IsItalic() );
return text; return text;
} }
@ -463,7 +463,7 @@ void SCH_TEXTBOX::Plot( PLOTTER* aPlotter, bool aBackground, const SCH_PLOT_OPTS
COLOR4D color = GetStroke().GetColor(); COLOR4D color = GetStroke().GetColor();
COLOR4D bg = renderSettings->GetBackgroundColor(); COLOR4D bg = renderSettings->GetBackgroundColor();
KIFONT::FONT* font = getDrawFont(); KIFONT::FONT* font = GetDrawFont( renderSettings );
color = GetTextColor(); color = GetTextColor();
@ -487,7 +487,7 @@ void SCH_TEXTBOX::Plot( PLOTTER* aPlotter, bool aBackground, const SCH_PLOT_OPTS
std::vector<VECTOR2I> positions; std::vector<VECTOR2I> positions;
wxArrayString strings_list; wxArrayString strings_list;
wxStringSplit( GetShownText( sheet, true ), strings_list, '\n' ); wxStringSplit( GetShownText( renderSettings, sheet, true ), strings_list, '\n' );
positions.reserve( strings_list.Count() ); positions.reserve( strings_list.Count() );
if( renderSettings->m_Transform != TRANSFORM() || aOffset != VECTOR2I() ) if( renderSettings->m_Transform != TRANSFORM() || aOffset != VECTOR2I() )
@ -504,12 +504,12 @@ void SCH_TEXTBOX::Plot( PLOTTER* aPlotter, bool aBackground, const SCH_PLOT_OPTS
temp.SetEnd( renderSettings->TransformCoordinate( m_end ) + aOffset ); temp.SetEnd( renderSettings->TransformCoordinate( m_end ) + aOffset );
attrs = temp.GetAttributes(); attrs = temp.GetAttributes();
temp.GetLinePositions( positions, (int) strings_list.Count() ); temp.GetLinePositions( renderSettings, positions, (int) strings_list.Count() );
} }
else else
{ {
attrs = GetAttributes(); attrs = GetAttributes();
GetLinePositions( positions, (int) strings_list.Count() ); GetLinePositions( renderSettings, positions, (int) strings_list.Count() );
} }
attrs.m_StrokeWidth = penWidth; attrs.m_StrokeWidth = penWidth;

View File

@ -70,8 +70,10 @@ public:
VECTOR2I GetDrawPos() const override; VECTOR2I GetDrawPos() const override;
virtual wxString GetShownText( const SCH_SHEET_PATH* aPath, bool aAllowExtraText, KIFONT::FONT* GetDrawFont( const RENDER_SETTINGS* aSettings ) const override;
int aDepth = 0 ) const;
virtual wxString GetShownText( const RENDER_SETTINGS* aSettings, const SCH_SHEET_PATH* aPath,
bool aAllowExtraText, int aDepth = 0 ) const;
wxString GetShownText( bool aAllowExtraText, int aDepth = 0 ) const override wxString GetShownText( bool aAllowExtraText, int aDepth = 0 ) const override
{ {
@ -80,7 +82,7 @@ public:
if( SCHEMATIC* schematic = Schematic() ) if( SCHEMATIC* schematic = Schematic() )
sheetPath = &schematic->CurrentSheet(); sheetPath = &schematic->CurrentSheet();
return GetShownText( sheetPath, aAllowExtraText, aDepth ); return GetShownText( nullptr, sheetPath, aAllowExtraText, aDepth );
} }
bool IsHypertext() const override; bool IsHypertext() const override;
@ -143,8 +145,6 @@ public:
bool operator==( const SCH_ITEM& aOther ) const override; bool operator==( const SCH_ITEM& aOther ) const override;
protected: protected:
KIFONT::FONT* getDrawFont() const override;
const KIFONT::METRICS& getFontMetrics() const override { return GetFontMetrics(); } const KIFONT::METRICS& getFontMetrics() const override { return GetFontMetrics(); }
int compare( const SCH_ITEM& aOther, int aCompareFlags = 0 ) const override; int compare( const SCH_ITEM& aOther, int aCompareFlags = 0 ) const override;

View File

@ -318,7 +318,7 @@ public:
* this rectangle is calculated for 0 orient text. * this rectangle is calculated for 0 orient text.
* If orientation is not 0 the rect must be rotated to match the physical area * If orientation is not 0 the rect must be rotated to match the physical area
*/ */
BOX2I GetTextBox( int aLine = -1 ) const; BOX2I GetTextBox( const RENDER_SETTINGS* aSettings, int aLine = -1 ) const;
/** /**
* Return the distance between two lines of text. * Return the distance between two lines of text.
@ -327,7 +327,7 @@ public:
* interline distance plus room for characters like j, {, and [. It also used for single * interline distance plus room for characters like j, {, and [. It also used for single
* line text, to calculate the text bounding box. * line text, to calculate the text bounding box.
*/ */
int GetInterline() const; int GetInterline( const RENDER_SETTINGS* aSettings ) const;
/** /**
* @return a wxString with the style name( Normal, Italic, Bold, Bold+Italic). * @return a wxString with the style name( Normal, Italic, Bold, Bold+Italic).
@ -341,7 +341,8 @@ public:
* @param aPositions is the list to populate by the VECTOR2I positions. * @param aPositions is the list to populate by the VECTOR2I positions.
* @param aLineCount is the number of lines (not recalculated here for efficiency reasons. * @param aLineCount is the number of lines (not recalculated here for efficiency reasons.
*/ */
void GetLinePositions( std::vector<VECTOR2I>& aPositions, int aLineCount ) const; void GetLinePositions( const RENDER_SETTINGS* aSettings, std::vector<VECTOR2I>& aPositions,
int aLineCount ) const;
/** /**
* Return the levenstein distance between two texts. * Return the levenstein distance between two texts.
@ -365,6 +366,8 @@ public:
virtual EDA_ANGLE GetDrawRotation() const { return GetTextAngle(); } virtual EDA_ANGLE GetDrawRotation() const { return GetTextAngle(); }
virtual VECTOR2I GetDrawPos() const { return GetTextPos(); } virtual VECTOR2I GetDrawPos() const { return GetTextPos(); }
virtual KIFONT::FONT* GetDrawFont( const RENDER_SETTINGS* aSettings ) const;
virtual void ClearRenderCache(); virtual void ClearRenderCache();
virtual void ClearBoundingBoxCache(); virtual void ClearBoundingBoxCache();
@ -415,8 +418,6 @@ public:
static wxString GotoPageHref( const wxString& aDestination ); static wxString GotoPageHref( const wxString& aDestination );
protected: protected:
virtual KIFONT::FONT* getDrawFont() const;
virtual const KIFONT::METRICS& getFontMetrics() const; virtual const KIFONT::METRICS& getFontMetrics() const;
virtual void cacheShownText(); virtual void cacheShownText();

View File

@ -144,10 +144,7 @@ bool DRC_TEST_PROVIDER_TEXT_DIMS::Run()
if( constraint.GetSeverity() == RPT_SEVERITY_IGNORE ) if( constraint.GetSeverity() == RPT_SEVERITY_IGNORE )
return true; return true;
KIFONT::FONT* font = text->GetFont(); KIFONT::FONT* font = text->GetDrawFont( nullptr );
if( !font )
font = KIFONT::FONT::GetFont( wxEmptyString, text->IsBold(), text->IsItalic() );
if( font->IsOutline() ) if( font->IsOutline() )
{ {

View File

@ -805,7 +805,7 @@ void GENCAD_EXPORTER::createComponentsSection()
layer.c_str(), layer.c_str(),
TO_UTF8( escapeString( textItem->GetText() ) ) ); TO_UTF8( escapeString( textItem->GetText() ) ) );
BOX2I textBox = textItem->GetTextBox(); BOX2I textBox = textItem->GetTextBox( nullptr );
fprintf( m_file, " 0 0 %g %g\n", fprintf( m_file, " 0 0 %g %g\n",
textBox.GetWidth() / SCALE_FACTOR, textBox.GetWidth() / SCALE_FACTOR,

View File

@ -730,7 +730,7 @@ const BOX2I PCB_DIMENSION_BASE::GetBoundingBox() const
BOX2I bBox; BOX2I bBox;
int xmin, xmax, ymin, ymax; int xmin, xmax, ymin, ymax;
bBox = GetTextBox(); bBox = GetTextBox( nullptr );
xmin = bBox.GetX(); xmin = bBox.GetX();
xmax = bBox.GetRight(); xmax = bBox.GetRight();
ymin = bBox.GetY(); ymin = bBox.GetY();
@ -947,7 +947,7 @@ void PCB_DIM_ALIGNED::updateGeometry()
// Now that we have the text updated, we can determine how to draw the crossbar. // Now that we have the text updated, we can determine how to draw the crossbar.
// First we need to create an appropriate bounding polygon to collide with // First we need to create an appropriate bounding polygon to collide with
BOX2I textBox = GetTextBox().Inflate( GetTextWidth() / 2, - GetEffectiveTextPenWidth() ); BOX2I textBox = GetTextBox( nullptr ).Inflate( GetTextWidth() / 2, - GetEffectiveTextPenWidth() );
SHAPE_POLY_SET polyBox; SHAPE_POLY_SET polyBox;
polyBox.NewOutline(); polyBox.NewOutline();
@ -1183,7 +1183,7 @@ void PCB_DIM_ORTHOGONAL::updateGeometry()
// Now that we have the text updated, we can determine how to draw the crossbar. // Now that we have the text updated, we can determine how to draw the crossbar.
// First we need to create an appropriate bounding polygon to collide with // First we need to create an appropriate bounding polygon to collide with
BOX2I textBox = GetTextBox().Inflate( GetTextWidth() / 2, GetEffectiveTextPenWidth() ); BOX2I textBox = GetTextBox( nullptr ).Inflate( GetTextWidth() / 2, GetEffectiveTextPenWidth() );
SHAPE_POLY_SET polyBox; SHAPE_POLY_SET polyBox;
polyBox.NewOutline(); polyBox.NewOutline();
@ -1400,7 +1400,7 @@ void PCB_DIM_LEADER::updateGeometry()
// Now that we have the text updated, we can determine how to draw the second line // Now that we have the text updated, we can determine how to draw the second line
// First we need to create an appropriate bounding polygon to collide with // First we need to create an appropriate bounding polygon to collide with
BOX2I textBox = GetTextBox().Inflate( GetTextWidth() / 2, GetEffectiveTextPenWidth() * 2 ); BOX2I textBox = GetTextBox( nullptr ).Inflate( GetTextWidth() / 2, GetEffectiveTextPenWidth() * 2 );
SHAPE_POLY_SET polyBox; SHAPE_POLY_SET polyBox;
polyBox.NewOutline(); polyBox.NewOutline();
@ -1623,7 +1623,7 @@ void PCB_DIM_RADIAL::updateGeometry()
// Now that we have the text updated, we can determine how to draw the second line // Now that we have the text updated, we can determine how to draw the second line
// First we need to create an appropriate bounding polygon to collide with // First we need to create an appropriate bounding polygon to collide with
BOX2I textBox = GetTextBox().Inflate( GetTextWidth() / 2, GetEffectiveTextPenWidth() ); BOX2I textBox = GetTextBox( nullptr ).Inflate( GetTextWidth() / 2, GetEffectiveTextPenWidth() );
SHAPE_POLY_SET polyBox; SHAPE_POLY_SET polyBox;
polyBox.NewOutline(); polyBox.NewOutline();

View File

@ -1734,7 +1734,7 @@ void ALTIUM_PCB::HelperParseDimensions6Radial(const ADIMENSION6 &aElem)
dimension->SetVertJustify( GR_TEXT_V_ALIGN_BOTTOM ); dimension->SetVertJustify( GR_TEXT_V_ALIGN_BOTTOM );
dimension->SetHorizJustify( GR_TEXT_H_ALIGN_LEFT ); dimension->SetHorizJustify( GR_TEXT_H_ALIGN_LEFT );
int yAdjust = dimension->GetTextBox().GetCenter().y - dimension->GetTextPos().y; int yAdjust = dimension->GetTextBox( nullptr ).GetCenter().y - dimension->GetTextPos().y;
dimension->SetTextPos( dimension->GetTextPos() + VECTOR2I( 0, yAdjust + aElem.textgap ) ); dimension->SetTextPos( dimension->GetTextPos() + VECTOR2I( 0, yAdjust + aElem.textgap ) );
dimension->SetVertJustify( GR_TEXT_V_ALIGN_CENTER ); dimension->SetVertJustify( GR_TEXT_V_ALIGN_CENTER );

View File

@ -617,7 +617,7 @@ void PCB_IO_IPC2581::addText( wxXmlNode* aContentNode, EDA_TEXT* aText,
const KIFONT::METRICS& aFontMetrics ) const KIFONT::METRICS& aFontMetrics )
{ {
KIGFX::GAL_DISPLAY_OPTIONS empty_opts; KIGFX::GAL_DISPLAY_OPTIONS empty_opts;
KIFONT::FONT* font = aText->GetFont(); KIFONT::FONT* font = aText->GetDrawFont( nullptr );
TEXT_ATTRIBUTES attrs = aText->GetAttributes(); TEXT_ATTRIBUTES attrs = aText->GetAttributes();
attrs.m_StrokeWidth = aText->GetEffectiveTextPenWidth(); attrs.m_StrokeWidth = aText->GetEffectiveTextPenWidth();
@ -626,9 +626,6 @@ void PCB_IO_IPC2581::addText( wxXmlNode* aContentNode, EDA_TEXT* aText,
wxXmlNode* text_node = appendNode( aContentNode, "UserSpecial" ); wxXmlNode* text_node = appendNode( aContentNode, "UserSpecial" );
if( !font )
font = KIFONT::FONT::GetFont();
std::list<VECTOR2I> pts; std::list<VECTOR2I> pts;
auto push_pts = auto push_pts =

View File

@ -617,17 +617,7 @@ void FEATURES_MANAGER::InitFeatureList( PCB_LAYER_ID aLayer, std::vector<BOARD_I
isKnockout = static_cast<PCB_TEXTBOX*>( item )->IsKnockout(); isKnockout = static_cast<PCB_TEXTBOX*>( item )->IsKnockout();
const KIFONT::METRICS& fontMetrics = item->GetFontMetrics(); const KIFONT::METRICS& fontMetrics = item->GetFontMetrics();
KIFONT::FONT* font = text_item->GetDrawFont( nullptr );
KIFONT::FONT* font = text_item->GetFont();
if( !font )
{
wxString defaultFontName; // empty string is the KiCad stroke font
font = KIFONT::FONT::GetFont( defaultFontName, text_item->IsBold(),
text_item->IsItalic() );
}
wxString shownText( text_item->GetShownText( true ) ); wxString shownText( text_item->GetShownText( true ) );
if( shownText.IsEmpty() ) if( shownText.IsEmpty() )
@ -667,7 +657,7 @@ void FEATURES_MANAGER::InitFeatureList( PCB_LAYER_ID aLayer, std::vector<BOARD_I
wxStringSplit( shownText, strings_list, '\n' ); wxStringSplit( shownText, strings_list, '\n' );
positions.reserve( strings_list.Count() ); positions.reserve( strings_list.Count() );
text_item->GetLinePositions( positions, strings_list.Count() ); text_item->GetLinePositions( nullptr, positions, strings_list.Count() );
for( unsigned ii = 0; ii < strings_list.Count(); ii++ ) for( unsigned ii = 0; ii < strings_list.Count(); ii++ )
{ {

View File

@ -2248,13 +2248,7 @@ void PCB_PAINTER::draw( const PCB_TEXT* aText, int aLayer )
const COLOR4D& color = m_pcbSettings.GetColor( aText, aLayer ); const COLOR4D& color = m_pcbSettings.GetColor( aText, aLayer );
bool outline_mode = !viewer_settings()->m_ViewersDisplay.m_DisplayTextFill; bool outline_mode = !viewer_settings()->m_ViewersDisplay.m_DisplayTextFill;
KIFONT::FONT* font = aText->GetFont(); KIFONT::FONT* font = aText->GetDrawFont( &m_pcbSettings );
if( !font )
{
font = KIFONT::FONT::GetFont( m_pcbSettings.GetDefaultFont(), aText->IsBold(),
aText->IsItalic() );
}
m_gal->SetStrokeColor( color ); m_gal->SetStrokeColor( color );
m_gal->SetFillColor( color ); m_gal->SetFillColor( color );
@ -2283,7 +2277,7 @@ void PCB_PAINTER::draw( const PCB_TEXT* aText, int aLayer )
// So we need to recalculate the text position to keep it at the same position // So we need to recalculate the text position to keep it at the same position
// on the canvas // on the canvas
VECTOR2I textPos = aText->GetTextPos(); VECTOR2I textPos = aText->GetTextPos();
VECTOR2I textWidth = VECTOR2I( aText->GetTextBox().GetWidth(), 0 ); VECTOR2I textWidth = VECTOR2I( aText->GetTextBox( &m_pcbSettings ).GetWidth(), 0 );
if( aText->GetHorizJustify() == GR_TEXT_H_ALIGN_RIGHT ) if( aText->GetHorizJustify() == GR_TEXT_H_ALIGN_RIGHT )
textWidth.x = -textWidth.x; textWidth.x = -textWidth.x;
@ -2344,14 +2338,7 @@ void PCB_PAINTER::draw( const PCB_TEXTBOX* aTextBox, int aLayer )
int thickness = getLineThickness( aTextBox->GetWidth() ); int thickness = getLineThickness( aTextBox->GetWidth() );
LINE_STYLE lineStyle = aTextBox->GetStroke().GetLineStyle(); LINE_STYLE lineStyle = aTextBox->GetStroke().GetLineStyle();
wxString resolvedText( aTextBox->GetShownText( true ) ); wxString resolvedText( aTextBox->GetShownText( true ) );
KIFONT::FONT* font = aTextBox->GetDrawFont( &m_pcbSettings );
KIFONT::FONT* font = aTextBox->GetFont();
if( !font )
{
font = KIFONT::FONT::GetFont( m_pcbSettings.GetDefaultFont(), aTextBox->IsBold(),
aTextBox->IsItalic() );
}
if( aLayer == LAYER_LOCKED_ITEM_SHADOW ) // happens only if locked if( aLayer == LAYER_LOCKED_ITEM_SHADOW ) // happens only if locked
{ {

View File

@ -342,7 +342,7 @@ void PCB_TEXT::KeepUpright()
const BOX2I PCB_TEXT::GetBoundingBox() const const BOX2I PCB_TEXT::GetBoundingBox() const
{ {
EDA_ANGLE angle = GetDrawRotation(); EDA_ANGLE angle = GetDrawRotation();
BOX2I rect = GetTextBox(); BOX2I rect = GetTextBox( nullptr );
if( IsKnockout() ) if( IsKnockout() )
rect.Inflate( getKnockoutMargin() ); rect.Inflate( getKnockoutMargin() );
@ -551,7 +551,7 @@ void PCB_TEXT::TransformTextToPolySet( SHAPE_POLY_SET& aBuffer, int aClearance,
ERROR_LOC aErrorLoc ) const ERROR_LOC aErrorLoc ) const
{ {
KIGFX::GAL_DISPLAY_OPTIONS empty_opts; KIGFX::GAL_DISPLAY_OPTIONS empty_opts;
KIFONT::FONT* font = getDrawFont(); KIFONT::FONT* font = GetDrawFont( nullptr );
int penWidth = GetEffectiveTextPenWidth(); int penWidth = GetEffectiveTextPenWidth();
TEXT_ATTRIBUTES attrs = GetAttributes(); TEXT_ATTRIBUTES attrs = GetAttributes();
wxString shownText = GetShownText( true ); wxString shownText = GetShownText( true );

View File

@ -443,7 +443,7 @@ wxString PCB_TEXTBOX::GetShownText( bool aAllowExtraText, int aDepth ) const
text = ExpandTextVars( text, &resolver ); text = ExpandTextVars( text, &resolver );
} }
KIFONT::FONT* font = getDrawFont(); KIFONT::FONT* font = GetDrawFont( nullptr );
EDA_ANGLE drawAngle = GetDrawRotation(); EDA_ANGLE drawAngle = GetDrawRotation();
std::vector<VECTOR2I> corners = GetCornersInSequence( drawAngle ); std::vector<VECTOR2I> corners = GetCornersInSequence( drawAngle );
int colWidth = ( corners[1] - corners[0] ).EuclideanNorm(); int colWidth = ( corners[1] - corners[0] ).EuclideanNorm();
@ -621,7 +621,7 @@ void PCB_TEXTBOX::TransformTextToPolySet( SHAPE_POLY_SET& aBuffer, int aClearanc
ERROR_LOC aErrorLoc ) const ERROR_LOC aErrorLoc ) const
{ {
KIGFX::GAL_DISPLAY_OPTIONS empty_opts; KIGFX::GAL_DISPLAY_OPTIONS empty_opts;
KIFONT::FONT* font = getDrawFont(); KIFONT::FONT* font = GetDrawFont( nullptr );
int penWidth = GetEffectiveTextPenWidth(); int penWidth = GetEffectiveTextPenWidth();
// Note: this function is mainly used in 3D viewer. // Note: this function is mainly used in 3D viewer.

View File

@ -691,18 +691,7 @@ void BRDITEMS_PLOTTER::PlotFootprintGraphicItems( const FOOTPRINT* aFootprint )
void BRDITEMS_PLOTTER::PlotText( const EDA_TEXT* aText, PCB_LAYER_ID aLayer, bool aIsKnockout, void BRDITEMS_PLOTTER::PlotText( const EDA_TEXT* aText, PCB_LAYER_ID aLayer, bool aIsKnockout,
const KIFONT::METRICS& aFontMetrics, bool aStrikeout ) const KIFONT::METRICS& aFontMetrics, bool aStrikeout )
{ {
KIFONT::FONT* font = aText->GetFont(); KIFONT::FONT* font = aText->GetDrawFont( m_plotter->RenderSettings() );
if( !font )
{
wxString defaultFontName; // empty string is the KiCad stroke font
if( m_plotter->RenderSettings() )
defaultFontName = m_plotter->RenderSettings()->GetDefaultFont();
font = KIFONT::FONT::GetFont( defaultFontName, aText->IsBold(), aText->IsItalic() );
}
wxString shownText( aText->GetShownText( true ) ); wxString shownText( aText->GetShownText( true ) );
if( shownText.IsEmpty() ) if( shownText.IsEmpty() )
@ -787,7 +776,7 @@ void BRDITEMS_PLOTTER::PlotText( const EDA_TEXT* aText, PCB_LAYER_ID aLayer, boo
wxStringSplit( shownText, strings_list, '\n' ); wxStringSplit( shownText, strings_list, '\n' );
positions.reserve( strings_list.Count() ); positions.reserve( strings_list.Count() );
aText->GetLinePositions( positions, (int) strings_list.Count() ); aText->GetLinePositions( m_plotter->RenderSettings(), positions, (int) strings_list.Count() );
for( unsigned ii = 0; ii < strings_list.Count(); ii++ ) for( unsigned ii = 0; ii < strings_list.Count(); ii++ )
{ {