From f10d11d36c6a45fc982b17becb5451bece36ec01 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Wed, 16 Jul 2025 23:20:37 +0100 Subject: [PATCH] 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) --- common/api/api_handler_common.cpp | 2 +- common/drawing_sheet/ds_data_item.cpp | 2 +- common/drawing_sheet/ds_draw_item.cpp | 2 +- common/eda_text.cpp | 46 +++---- common/io/cadstar/cadstar_archive_parser.cpp | 2 +- common/plotters/PDF_plotter.cpp | 3 +- common/plotters/common_plot_functions.cpp | 10 +- common/plotters/plotter.cpp | 6 +- eeschema/erc/erc.cpp | 4 +- eeschema/fields_grid_table.cpp | 3 +- eeschema/sch_field.cpp | 17 +-- eeschema/sch_field.h | 4 +- .../cadstar/cadstar_sch_archive_loader.cpp | 2 +- eeschema/sch_item.cpp | 13 +- eeschema/sch_item.h | 2 +- eeschema/sch_label.cpp | 56 ++++---- eeschema/sch_label.h | 6 +- eeschema/sch_painter.cpp | 125 +++++++++--------- eeschema/sch_text.cpp | 18 +-- eeschema/sch_text.h | 4 +- eeschema/sch_textbox.cpp | 20 +-- eeschema/sch_textbox.h | 10 +- include/eda_text.h | 11 +- pcbnew/drc/drc_test_provider_text_dims.cpp | 5 +- pcbnew/exporters/export_gencad_writer.cpp | 2 +- pcbnew/pcb_dimension.cpp | 10 +- pcbnew/pcb_io/altium/altium_pcb.cpp | 2 +- pcbnew/pcb_io/ipc2581/pcb_io_ipc2581.cpp | 5 +- pcbnew/pcb_io/odbpp/odb_feature.cpp | 16 +-- pcbnew/pcb_painter.cpp | 27 +--- pcbnew/pcb_text.cpp | 4 +- pcbnew/pcb_textbox.cpp | 4 +- pcbnew/plot_brditems_plotter.cpp | 17 +-- 33 files changed, 201 insertions(+), 259 deletions(-) diff --git a/common/api/api_handler_common.cpp b/common/api/api_handler_common.cpp index a6ac0d3dfe..a0b2a810e6 100644 --- a/common/api/api_handler_common.cpp +++ b/common/api/api_handler_common.cpp @@ -178,7 +178,7 @@ HANDLER_RESULT API_HANDLER_COMMON::handleGetTextExtents( types::Box2 response; - BOX2I bbox = text.GetTextBox(); + BOX2I bbox = text.GetTextBox( nullptr ); EDA_ANGLE angle = text.GetTextAngle(); if( !angle.IsZero() ) diff --git a/common/drawing_sheet/ds_data_item.cpp b/common/drawing_sheet/ds_data_item.cpp index 341f5918c7..d7e6fa847f 100644 --- a/common/drawing_sheet/ds_data_item.cpp +++ b/common/drawing_sheet/ds_data_item.cpp @@ -701,7 +701,7 @@ void DS_DATA_ITEM_TEXT::SetConstrainedTextSize() dummy.SetVertJustify( m_Vjustify ); dummy.SetTextAngle( EDA_ANGLE( m_Orient, DEGREES_T ) ); - BOX2I rect = dummy.GetTextBox(); + BOX2I rect = dummy.GetTextBox( nullptr ); VECTOR2D size; size.x = KiROUND( (int) rect.GetWidth() / FSCALE ); size.y = KiROUND( (int) rect.GetHeight() / FSCALE ); diff --git a/common/drawing_sheet/ds_draw_item.cpp b/common/drawing_sheet/ds_draw_item.cpp index 2a791657d6..22ebf19a4e 100644 --- a/common/drawing_sheet/ds_draw_item.cpp +++ b/common/drawing_sheet/ds_draw_item.cpp @@ -221,7 +221,7 @@ const BOX2I DS_DRAW_ITEM_TEXT::GetApproxBBox() const BOX2I DS_DRAW_ITEM_TEXT::GetBoundingBox() const { - return EDA_TEXT::GetTextBox(); + return EDA_TEXT::GetTextBox( nullptr ); } diff --git a/common/eda_text.cpp b/common/eda_text.cpp index 73ab6991bf..b2fbfb6d75 100644 --- a/common/eda_text.cpp +++ b/common/eda_text.cpp @@ -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(); if( !font ) - font = KIFONT::FONT::GetFont( wxEmptyString, IsBold(), IsItalic() ); + { + if( aSettings ) + font = KIFONT::FONT::GetFont( aSettings->GetDefaultFont(), IsBold(), IsItalic() ); + else + font = KIFONT::FONT::GetFont( wxEmptyString, IsBold(), IsItalic() ); + } 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(); @@ -748,12 +753,11 @@ BOX2I EDA_TEXT::GetTextBox( int aLine ) const } // calculate the H and V size - KIFONT::FONT* font = getDrawFont(); + KIFONT::FONT* font = GetDrawFont( aSettings ); VECTOR2D fontSize( GetTextSize() ); bool bold = IsBold(); bool italic = IsItalic(); - VECTOR2I extents = font->StringBoundaryLimits( text, fontSize, thickness, bold, italic, - getFontMetrics() ); + VECTOR2I extents = font->StringBoundaryLimits( text, fontSize, thickness, bold, italic, getFontMetrics() ); int overbarOffset = 0; // 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++ ) { text = strings.Item( ii ); - extents = font->StringBoundaryLimits( text, fontSize, thickness, bold, italic, - getFontMetrics() ); + extents = font->StringBoundaryLimits( text, fontSize, thickness, bold, italic, getFontMetrics() ); textsize.x = std::max( textsize.x, extents.x ); } // 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 - textsize.y += KiROUND( ( strings.GetCount() - 1 ) - * font->GetInterline( fontSize.y, getFontMetrics() ) ); + textsize.y += KiROUND( ( strings.GetCount() - 1 ) * font->GetInterline( fontSize.y, getFontMetrics() ) ); } textsize.y += overbarOffset; @@ -852,7 +854,7 @@ BOX2I EDA_TEXT::GetTextBox( int aLine ) 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() ); 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 ); 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() ); - GetLinePositions( positions, (int) strings.Count() ); + GetLinePositions( aSettings, positions, (int) strings.Count() ); for( unsigned ii = 0; ii < strings.Count(); 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& aPositions, int aLineCount ) const +void EDA_TEXT::GetLinePositions( const RENDER_SETTINGS* aSettings, std::vector& aPositions, + int aLineCount ) const { VECTOR2I pos = GetDrawPos(); // Position of first line of the multiline text according // to the center of the multiline text block VECTOR2I offset; // Offset to next line. - offset.y = GetInterline(); + offset.y = GetInterline( aSettings ); if( aLineCount > 1 ) { @@ -952,10 +955,7 @@ void EDA_TEXT::printOneLineOfText( const RENDER_SETTINGS* aSettings, const VECTO if( IsMirrored() ) size.x = -size.x; - KIFONT::FONT* font = GetFont(); - - if( !font ) - font = KIFONT::FONT::GetFont( aSettings->GetDefaultFont(), IsBold(), IsItalic() ); + KIFONT::FONT* font = GetDrawFont( aSettings ); GRPrintText( DC, aOffset + aPos, aColor, aText, GetDrawRotation(), size, GetHorizJustify(), GetVertJustify(), penWidth, IsItalic(), IsBold(), font, getFontMetrics() ); @@ -1123,7 +1123,7 @@ std::shared_ptr EDA_TEXT::GetEffectiveTextShape( bool aTriangula { std::shared_ptr shape = std::make_shared(); KIGFX::GAL_DISPLAY_OPTIONS empty_opts; - KIFONT::FONT* font = getDrawFont(); + KIFONT::FONT* font = GetDrawFont( nullptr ); int penWidth = GetEffectiveTextPenWidth(); wxString shownText( GetShownText( true ) ); VECTOR2I drawPos = GetDrawPos(); diff --git a/common/io/cadstar/cadstar_archive_parser.cpp b/common/io/cadstar/cadstar_archive_parser.cpp index c2dc39a170..5984503f29 100644 --- a/common/io/cadstar/cadstar_archive_parser.cpp +++ b/common/io/cadstar/cadstar_archive_parser.cpp @@ -2785,7 +2785,7 @@ void CADSTAR_ARCHIVE_PARSER::FixTextPositionNoAlignment( EDA_TEXT* aKiCadTextIte { if( !aKiCadTextItem->GetText().IsEmpty() ) { - VECTOR2I positionOffset( 0, aKiCadTextItem->GetInterline() ); + VECTOR2I positionOffset( 0, aKiCadTextItem->GetInterline( nullptr ) ); RotatePoint( positionOffset, aKiCadTextItem->GetTextAngle() ); //Count num of additional lines diff --git a/common/plotters/PDF_plotter.cpp b/common/plotters/PDF_plotter.cpp index 43f6b46141..ecc74c2ba4 100644 --- a/common/plotters/PDF_plotter.cpp +++ b/common/plotters/PDF_plotter.cpp @@ -1658,9 +1658,8 @@ void PDF_PLOTTER::Text( const VECTOR2I& aPos, wxStringTokenizer str_tok( aText, " ", wxTOKEN_RET_DELIMS ); - // If aFont is not specilied (== nullptr), use the default kicad stroke font if( !aFont ) - aFont = KIFONT::FONT::GetFont(); + aFont = KIFONT::FONT::GetFont( m_renderSettings->GetDefaultFont() ); VECTOR2I full_box( aFont->StringBoundaryLimits( aText, t_size, aWidth, aBold, aItalic, aFontMetrics ) ); diff --git a/common/plotters/common_plot_functions.cpp b/common/plotters/common_plot_functions.cpp index 90d0915ec3..8827e7da8c 100644 --- a/common/plotters/common_plot_functions.cpp +++ b/common/plotters/common_plot_functions.cpp @@ -136,15 +136,9 @@ void PlotDrawingSheet( PLOTTER* plotter, const PROJECT* aProject, const TITLE_BL case WSG_TEXT_T: { DS_DRAW_ITEM_TEXT* text = (DS_DRAW_ITEM_TEXT*) item; - KIFONT::FONT* font = text->GetFont(); + KIFONT::FONT* font = text->GetDrawFont( settings ); COLOR4D color = plotColor; - if( !font ) - { - font = KIFONT::FONT::GetFont( settings->GetDefaultFont(), text->IsBold(), - text->IsItalic() ); - } - if( plotter->GetColorMode() && text->GetTextColor() != COLOR4D::UNSPECIFIED ) color = text->GetTextColor(); @@ -154,8 +148,8 @@ void PlotDrawingSheet( PLOTTER* plotter, const PROJECT* aProject, const TITLE_BL text->GetTextAngle(), text->GetTextSize(), text->GetHorizJustify(), text->GetVertJustify(), penWidth, text->IsItalic(), text->IsBold(), text->IsMultilineAllowed(), font, text->GetFontMetrics() ); - } break; + } case WSG_POLY_T: { diff --git a/common/plotters/plotter.cpp b/common/plotters/plotter.cpp index 95c7946d30..8f607af591 100644 --- a/common/plotters/plotter.cpp +++ b/common/plotters/plotter.cpp @@ -688,7 +688,7 @@ void PLOTTER::PlotPoly( const SHAPE_LINE_CHAIN& aCornerList, FILL_T aFill, int a } -void PLOTTER::Text( const VECTOR2I& aPos, +void PLOTTER::Text( const VECTOR2I& aPos, const COLOR4D& aColor, const wxString& aText, const EDA_ANGLE& aOrient, @@ -745,7 +745,7 @@ void PLOTTER::Text( const VECTOR2I& aPos, } if( !aFont ) - aFont = KIFONT::FONT::GetFont(); + aFont = KIFONT::FONT::GetFont( m_renderSettings->GetDefaultFont() ); aFont->Draw( &callback_gal, aText, aPos, attributes, aFontMetrics ); } @@ -790,7 +790,7 @@ void PLOTTER::PlotText( const VECTOR2I& aPos, } ); if( !aFont ) - aFont = KIFONT::FONT::GetFont(); + aFont = KIFONT::FONT::GetFont( m_renderSettings->GetDefaultFont() ); aFont->Draw( &callback_gal, aText, aPos, attributes, aFontMetrics ); } diff --git a/eeschema/erc/erc.cpp b/eeschema/erc/erc.cpp index 3a2403fa72..5b1d2bf287 100644 --- a/eeschema/erc/erc.cpp +++ b/eeschema/erc/erc.cpp @@ -310,7 +310,7 @@ void ERC_TESTER::TestTextVars( DS_PROXY_VIEW_ITEM* aDrawingSheet ) { SCH_TEXTBOX* textboxItem = static_cast( child ); - if( unresolved( textboxItem->GetShownText( &sheet, true ) ) ) + if( unresolved( textboxItem->GetShownText( nullptr, &sheet, true ) ) ) { auto ercItem = ERC_ITEM::Create( ERCE_UNRESOLVED_VARIABLE ); ercItem->SetItems( symbol ); @@ -398,7 +398,7 @@ void ERC_TESTER::TestTextVars( DS_PROXY_VIEW_ITEM* aDrawingSheet ) } else if( SCH_TEXTBOX* textBox = dynamic_cast( item ) ) { - if( textBox->GetShownText( &sheet, true ).Matches( wxS( "*${*}*" ) ) ) + if( textBox->GetShownText( nullptr, &sheet, true ).Matches( wxS( "*${*}*" ) ) ) { auto ercItem = ERC_ITEM::Create( ERCE_UNRESOLVED_VARIABLE ); ercItem->SetItems( textBox ); diff --git a/eeschema/fields_grid_table.cpp b/eeschema/fields_grid_table.cpp index c744904545..e0efc79b23 100644 --- a/eeschema/fields_grid_table.cpp +++ b/eeschema/fields_grid_table.cpp @@ -945,8 +945,7 @@ void FIELDS_GRID_TABLE::SetValue( int aRow, int aCol, const wxString &aValue ) if( value == DEFAULT_FONT_NAME ) field.SetFont( nullptr ); else if( value == KICAD_FONT_NAME ) - field.SetFont( KIFONT::FONT::GetFont( wxEmptyString, field.IsBold(), - field.IsItalic() ) ); + field.SetFont( KIFONT::FONT::GetFont( wxEmptyString, field.IsBold(), field.IsItalic() ) ); else field.SetFont( KIFONT::FONT::GetFont( aValue, field.IsBold(), field.IsItalic() ) ); diff --git a/eeschema/sch_field.cpp b/eeschema/sch_field.cpp index 3ff5fc50f6..a06ba56d9f 100644 --- a/eeschema/sch_field.cpp +++ b/eeschema/sch_field.cpp @@ -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(); if( !font ) - font = KIFONT::FONT::GetFont( GetDefaultFont(), IsBold(), IsItalic() ); + font = KIFONT::FONT::GetFont( GetDefaultFont( aSettings ), IsBold(), IsItalic() ); return font; } @@ -377,10 +377,7 @@ std::vector>* SCH_FIELD::GetRenderCache( const wxString& forResolvedText, const VECTOR2I& forPosition, TEXT_ATTRIBUTES& aAttrs ) const { - KIFONT::FONT* font = GetFont(); - - if( !font ) - font = KIFONT::FONT::GetFont( GetDefaultFont(), IsBold(), IsItalic() ); + KIFONT::FONT* font = GetDrawFont( nullptr ); if( font->IsOutline() ) { @@ -692,7 +689,7 @@ EDA_ANGLE SCH_FIELD::GetDrawRotation() const const BOX2I SCH_FIELD::GetBoundingBox() const { - BOX2I bbox = GetTextBox(); + BOX2I bbox = GetTextBox( nullptr ); // Calculate the bounding box position relative to the parent: VECTOR2I origin = GetParentPosition(); @@ -1540,11 +1537,7 @@ void SCH_FIELD::Plot( PLOTTER* aPlotter, bool aBackground, const SCH_PLOT_OPTS& color = nc->GetSchematicColor(); } - KIFONT::FONT* font = GetFont(); - - if( !font ) - font = KIFONT::FONT::GetFont( renderSettings->GetDefaultFont(), IsBold(), IsItalic() ); - + KIFONT::FONT* font = GetDrawFont( renderSettings ); TEXT_ATTRIBUTES attrs = GetAttributes(); attrs.m_StrokeWidth = penWidth; attrs.m_Halign = hjustify; diff --git a/eeschema/sch_field.h b/eeschema/sch_field.h index 8d9307b0d7..8cf6e7f037 100644 --- a/eeschema/sch_field.h +++ b/eeschema/sch_field.h @@ -195,6 +195,8 @@ public: */ EDA_ANGLE GetDrawRotation() const override; + KIFONT::FONT* GetDrawFont( const RENDER_SETTINGS* aSettings ) const override; + const BOX2I GetBoundingBox() const override; /** @@ -329,8 +331,6 @@ public: #endif protected: - KIFONT::FONT* getDrawFont() const override; - const KIFONT::METRICS& getFontMetrics() const override { return GetFontMetrics(); } /** diff --git a/eeschema/sch_io/cadstar/cadstar_sch_archive_loader.cpp b/eeschema/sch_io/cadstar/cadstar_sch_archive_loader.cpp index d6924298ff..8296082dce 100644 --- a/eeschema/sch_io/cadstar/cadstar_sch_archive_loader.cpp +++ b/eeschema/sch_io/cadstar/cadstar_sch_archive_loader.cpp @@ -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 ) { - BOX2I bbox = libtext->GetTextBox( ii ); + BOX2I bbox = libtext->GetTextBox( nullptr, ii ); VECTOR2I linePos = { bbox.GetLeft(), -bbox.GetBottom() }; RotatePoint( linePos, libtext->GetTextPos(), -libtext->GetTextAngle() ); diff --git a/eeschema/sch_item.cpp b/eeschema/sch_item.cpp index 4f32a4c4ed..f3f8cc8b1f 100644 --- a/eeschema/sch_item.cpp +++ b/eeschema/sch_item.cpp @@ -22,6 +22,7 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ +#include "font/kicad_font_name.h" #include #include #include @@ -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 { + static wxString defaultName = KICAD_FONT_NAME; + SETTINGS_MANAGER& mgr = Pgm().GetSettingsManager(); - EESCHEMA_SETTINGS* cfg = mgr.GetAppSettings( "eeschema" ); - return cfg->m_Appearance.default_font; + if( aSettings ) + return aSettings->GetDefaultFont(); + else if( EESCHEMA_SETTINGS* cfg = mgr.GetAppSettings( "eeschema" ) ) + return cfg->m_Appearance.default_font; + else + return defaultName; } diff --git a/eeschema/sch_item.h b/eeschema/sch_item.h index 1628b8edd5..2d2061c824 100644 --- a/eeschema/sch_item.h +++ b/eeschema/sch_item.h @@ -302,7 +302,7 @@ public: 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; diff --git a/eeschema/sch_label.cpp b/eeschema/sch_label.cpp index b152e848d5..0848f2c8c0 100644 --- a/eeschema/sch_label.cpp +++ b/eeschema/sch_label.cpp @@ -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 ) { int margin = GetTextOffset() * 2; - int labelLen = GetBodyBoundingBox().GetSizeMax(); + int labelLen = GetBodyBoundingBox( nullptr ).GetSizeMax(); int accumulated = GetTextHeight() / 2; 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 BOX2I box; std::vector pts; - CreateGraphicShape( nullptr, pts, GetTextPos() ); + CreateGraphicShape( aSettings, pts, GetTextPos() ); for( const VECTOR2I& pt : pts ) 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 - BOX2I box = GetBodyBoundingBox(); + BOX2I box = GetBodyBoundingBox( nullptr ); 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 { - BOX2I bbox = GetBodyBoundingBox(); + BOX2I bbox = GetBodyBoundingBox( nullptr ); bbox.Inflate( aAccuracy ); if( bbox.Contains( aPosition ) ) @@ -1042,7 +1042,7 @@ bool SCH_LABEL_BASE::HitTest( const BOX2I& aRect, bool aContained, int aAccuracy } else { - if( rect.Intersects( GetBodyBoundingBox() ) ) + if( rect.Intersects( GetBodyBoundingBox( nullptr ) ) ) return true; 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() ); aPlotter->SetCurrentLineWidth( penWidth ); - KIFONT::FONT* font = GetFont(); + KIFONT::FONT* font = GetDrawFont( settings ); - if( !font ) - font = KIFONT::FONT::GetFont( settings->GetDefaultFont(), IsBold(), IsItalic() ); - - VECTOR2I textpos = GetTextPos() + GetSchematicTextOffset( aPlotter->RenderSettings() ); - CreateGraphicShape( aPlotter->RenderSettings(), s_poly, GetTextPos() ); + VECTOR2I textpos = GetTextPos() + GetSchematicTextOffset( settings ); + CreateGraphicShape( settings, s_poly, GetTextPos() ); TEXT_ATTRIBUTES attrs = GetAttributes(); attrs.m_StrokeWidth = penWidth; @@ -1303,8 +1300,7 @@ void SCH_LABEL_BASE::Plot( PLOTTER* aPlotter, bool aBackground, const SCH_PLOT_O } else { - aPlotter->PlotText( textpos, color, GetShownText( sheet, true ), attrs, font, - GetFontMetrics() ); + aPlotter->PlotText( textpos, color, GetShownText( sheet, true ), attrs, font, GetFontMetrics() ); if( aPlotter->GetColorMode() ) { @@ -1341,7 +1337,8 @@ void SCH_LABEL_BASE::Plot( PLOTTER* aPlotter, bool aBackground, const SCH_PLOT_O } // Make sheet pins and hierarchical labels clickable hyperlinks - bool linkAlreadyPlotted = false; + bool linkAlreadyPlotted = false; + BOX2I bodyBBox = GetBodyBoundingBox( settings ); 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; path.pop_back(); - aPlotter->HyperlinkBox( GetBodyBoundingBox(), - EDA_TEXT::GotoPageHref( path.GetPageNumber() ) ); + aPlotter->HyperlinkBox( bodyBBox, EDA_TEXT::GotoPageHref( path.GetPageNumber() ) ); 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* parent = static_cast( m_parent ); path.push_back( parent ); - aPlotter->HyperlinkBox( GetBodyBoundingBox(), - EDA_TEXT::GotoPageHref( path.GetPageNumber() ) ); + aPlotter->HyperlinkBox( bodyBBox, EDA_TEXT::GotoPageHref( path.GetPageNumber() ) ); linkAlreadyPlotted = true; } } @@ -1378,9 +1373,9 @@ void SCH_LABEL_BASE::Plot( PLOTTER* aPlotter, bool aBackground, const SCH_PLOT_O _( "Net" ), connection->Name() ) ); - properties.emplace_back( - wxString::Format( wxT( "!%s = %s" ), _( "Resolved netclass" ), - GetEffectiveNetClass()->GetHumanReadableName() ) ); + properties.emplace_back( wxString::Format( wxT( "!%s = %s" ), + _( "Resolved netclass" ), + GetEffectiveNetClass()->GetHumanReadableName() ) ); } for( const SCH_FIELD& field : GetFields() ) @@ -1391,14 +1386,11 @@ void SCH_LABEL_BASE::Plot( PLOTTER* aPlotter, bool aBackground, const SCH_PLOT_O } if( !properties.empty() ) - aPlotter->HyperlinkMenu( GetBodyBoundingBox(), properties ); + aPlotter->HyperlinkMenu( bodyBBox, properties ); } if( Type() == SCH_HIER_LABEL_T ) - { - aPlotter->Bookmark( GetBodyBoundingBox(), GetShownText( false ), - _( "Hierarchical Labels" ) ); - } + aPlotter->Bookmark( bodyBBox, GetShownText( false ), _( "Hierarchical Labels" ) ); } 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.Inflate( GetEffectiveTextPenWidth() ); @@ -1987,7 +1979,7 @@ void SCH_GLOBALLABEL::CreateGraphicShape( const RENDER_SETTINGS* aRenderSettings int margin = GetLabelBoxExpansion( aRenderSettings ); int halfSize = ( GetTextHeight() / 2 ) + margin; 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 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 margin = GetTextOffset(); @@ -2131,7 +2123,7 @@ const BOX2I SCH_HIERLABEL::GetBodyBoundingBox() const int y = GetTextPos().y; int height = GetTextHeight() + penWidth + margin; - int length = GetTextBox().GetWidth(); + int length = GetTextBox( aSettings ).GetWidth(); length += height; // add height for triangular shapes diff --git a/eeschema/sch_label.h b/eeschema/sch_label.h index 55520c99fa..65c267df72 100644 --- a/eeschema/sch_label.h +++ b/eeschema/sch_label.h @@ -316,7 +316,7 @@ public: /** * 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. @@ -412,7 +412,7 @@ public: return wxT( "SCH_LABEL" ); } - const BOX2I GetBodyBoundingBox() const override; + const BOX2I GetBodyBoundingBox( const RENDER_SETTINGS* aSettings ) const override; bool IsConnectable() const override { return true; } @@ -612,7 +612,7 @@ public: void CreateGraphicShape( const RENDER_SETTINGS* aSettings, std::vector& aPoints, 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; } diff --git a/eeschema/sch_painter.cpp b/eeschema/sch_painter.cpp index d1826b728b..b70cde51ab 100644 --- a/eeschema/sch_painter.cpp +++ b/eeschema/sch_painter.cpp @@ -272,11 +272,10 @@ bool SCH_PAINTER::isUnitAndConversionShown( const SCH_ITEM* 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 KIFONT::FONT::GetFont( m_schSettings.GetDefaultFont(), aItem->IsBold(), - aItem->IsItalic() ); + return KIFONT::FONT::GetFont( m_schSettings.GetDefaultFont(), aItem->IsBold(), aItem->IsItalic() ); } @@ -1084,71 +1083,73 @@ void SCH_PAINTER::draw( const SCH_PIN* aPin, int aLayer, bool aDimmed ) m_schSettings.m_ShowPinsElectricalType, m_schSettings.m_ShowPinAltIcons ); - const auto textRendersAsBitmap = [&]( KIGFX::GAL& aGal, int aTextSize ) - { - // 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 - // bitmap font becomes immaterial, and there's often more to draw when zoomed out so the - // performance gain becomes more significant. - static const float BITMAP_FONT_SIZE_THRESHOLD = 3.5; - - // Any text non bitmappable? - return aTextSize * aGal.GetWorldScale() < BITMAP_FONT_SIZE_THRESHOLD; - }; + const auto textRendersAsBitmap = + [&]( KIGFX::GAL& aGal, int aTextSize ) + { + // 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 + // bitmap font becomes immaterial, and there's often more to draw when zoomed out so the + // performance gain becomes more significant. + static const float BITMAP_FONT_SIZE_THRESHOLD = 3.5; + + // Any text non bitmappable? + return aTextSize * aGal.GetWorldScale() < BITMAP_FONT_SIZE_THRESHOLD; + }; const auto drawTextInfo = [&]( const PIN_LAYOUT_CACHE::TEXT_INFO& aTextInfo, const COLOR4D& aColor ) - { - // const double iconSize = std::min( aPin->GetNameTextSize(), schIUScale.mmToIU( 1.5 ) ); - const bool renderTextAsBitmap = textRendersAsBitmap( *m_gal, aTextInfo.m_TextSize ); - - // Which of these gets used depends on the font technology, so set both - m_gal->SetStrokeColor( aColor ); - m_gal->SetFillColor( aColor ); - - TEXT_ATTRIBUTES attrs; - attrs.m_Font = KIFONT::FONT::GetFont( eeconfig()->m_Appearance.default_font ); - attrs.m_Size = VECTOR2I( aTextInfo.m_TextSize, aTextInfo.m_TextSize ); - attrs.m_Halign = aTextInfo.m_HAlign; - attrs.m_Valign = aTextInfo.m_VAlign; - attrs.m_Angle = aTextInfo.m_Angle; - attrs.m_StrokeWidth = aTextInfo.m_Thickness; + { + // const double iconSize = std::min( aPin->GetNameTextSize(), schIUScale.mmToIU( 1.5 ) ); + const bool renderTextAsBitmap = textRendersAsBitmap( *m_gal, aTextInfo.m_TextSize ); + + // Which of these gets used depends on the font technology, so set both + m_gal->SetStrokeColor( aColor ); + m_gal->SetFillColor( aColor ); + + TEXT_ATTRIBUTES attrs; + attrs.m_Font = KIFONT::FONT::GetFont( eeconfig()->m_Appearance.default_font ); + attrs.m_Size = VECTOR2I( aTextInfo.m_TextSize, aTextInfo.m_TextSize ); + attrs.m_Halign = aTextInfo.m_HAlign; + attrs.m_Valign = aTextInfo.m_VAlign; + attrs.m_Angle = aTextInfo.m_Angle; + attrs.m_StrokeWidth = aTextInfo.m_Thickness; + + if( drawingShadows ) + { + attrs.m_StrokeWidth += KiROUND( shadowWidth ); - if( drawingShadows ) - { - attrs.m_StrokeWidth += KiROUND( shadowWidth ); + if( !attrs.m_Font->IsOutline() ) + { + strokeText( *m_gal, aTextInfo.m_Text, aTextInfo.m_TextPosition, attrs, + aPin->GetFontMetrics() ); + } + else + { + boxText( *m_gal, aTextInfo.m_Text, aTextInfo.m_TextPosition, attrs, + aPin->GetFontMetrics() ); + } + } + else if( nonCached( aPin ) && renderTextAsBitmap ) + { + bitmapText( *m_gal, aTextInfo.m_Text, aTextInfo.m_TextPosition, attrs ); + const_cast( aPin )->SetFlags( IS_SHOWN_AS_BITMAP ); + } + else + { + strokeText( *m_gal, aTextInfo.m_Text, aTextInfo.m_TextPosition, attrs, + aPin->GetFontMetrics() ); + const_cast( aPin )->SetFlags( IS_SHOWN_AS_BITMAP ); + } + }; - if( !attrs.m_Font->IsOutline() ) + const auto getColorForLayer = + [&]( int aDrawnLayer ) { - strokeText( *m_gal, aTextInfo.m_Text, aTextInfo.m_TextPosition, attrs, - aPin->GetFontMetrics() ); - } - else - { - boxText( *m_gal, aTextInfo.m_Text, aTextInfo.m_TextPosition, attrs, - aPin->GetFontMetrics() ); - } - } - else if( nonCached( aPin ) && renderTextAsBitmap ) - { - bitmapText( *m_gal, aTextInfo.m_Text, aTextInfo.m_TextPosition, attrs ); - const_cast( aPin )->SetFlags( IS_SHOWN_AS_BITMAP ); - } - else - { - strokeText( *m_gal, aTextInfo.m_Text, aTextInfo.m_TextPosition, attrs, - aPin->GetFontMetrics() ); - const_cast( aPin )->SetFlags( IS_SHOWN_AS_BITMAP ); - } - }; - - const auto getColorForLayer = [&]( int aDrawnLayer ) - { - if( !aPin->IsVisible() ) - return getRenderColor( aPin, LAYER_HIDDEN, drawingShadows, aDimmed ); + if( !aPin->IsVisible() ) + return getRenderColor( aPin, LAYER_HIDDEN, drawingShadows, aDimmed ); - return getRenderColor( aPin, aDrawnLayer, drawingShadows, aDimmed ); - }; + return getRenderColor( aPin, aDrawnLayer, drawingShadows, aDimmed ); + }; // Request text layout info and draw it @@ -1775,7 +1776,7 @@ void SCH_PAINTER::draw( const SCH_TEXT* aText, int aLayer, bool aDimmed ) // SCH_FIELD text. 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 adjust = KiROUND( sizeDiff * 0.4 ); VECTOR2I adjust_offset( 0, - adjust ); diff --git a/eeschema/sch_text.cpp b/eeschema/sch_text.cpp index 97112d80ce..7fa35927dd 100644 --- a/eeschema/sch_text.cpp +++ b/eeschema/sch_text.cpp @@ -82,7 +82,7 @@ void SCH_TEXT::NormalizeJustification( bool inverse ) return; VECTOR2I delta( 0, 0 ); - BOX2I bbox = GetTextBox(); + BOX2I bbox = GetTextBox( nullptr ); 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(); if( !font ) - font = KIFONT::FONT::GetFont( GetDefaultFont(), IsBold(), IsItalic() ); + font = KIFONT::FONT::GetFont( GetDefaultFont( aSettings ), IsBold(), IsItalic() ); 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 { - BOX2I bbox = GetTextBox(); + BOX2I bbox = GetTextBox( nullptr ); 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() ); aPlotter->SetCurrentLineWidth( penWidth ); - KIFONT::FONT* font = GetFont(); - - if( !font ) - font = KIFONT::FONT::GetFont( renderSettings->GetDefaultFont(), IsBold(), IsItalic() ); - + KIFONT::FONT* font = GetDrawFont( renderSettings ); TEXT_ATTRIBUTES attrs = GetAttributes(); attrs.m_StrokeWidth = penWidth; @@ -602,7 +598,7 @@ void SCH_TEXT::Plot( PLOTTER* aPlotter, bool aBackground, const SCH_PLOT_OPTS& a // SCH_FIELD text. if( font->IsOutline() ) { - BOX2I firstLineBBox = GetTextBox( 0 ); + BOX2I firstLineBBox = GetTextBox( renderSettings, 0 ); int sizeDiff = firstLineBBox.GetHeight() - GetTextSize().y; int adjust = KiROUND( sizeDiff * 0.4 ); 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' ); positions.reserve( strings_list.Count() ); - GetLinePositions( positions, (int) strings_list.Count() ); + GetLinePositions( renderSettings, positions, (int) strings_list.Count() ); attrs.m_Multiline = false; diff --git a/eeschema/sch_text.h b/eeschema/sch_text.h index cad4a36133..83f60ba11a 100644 --- a/eeschema/sch_text.h +++ b/eeschema/sch_text.h @@ -59,6 +59,8 @@ public: return _( "Text" ); } + KIFONT::FONT* GetDrawFont( const RENDER_SETTINGS* aSettings ) const override; + virtual wxString GetShownText( const SCH_SHEET_PATH* aPath, bool aAllowExtraText, int aDepth = 0 ) const; @@ -174,8 +176,6 @@ public: static HTML_MESSAGE_BOX* ShowSyntaxHelp( wxWindow* aParentWindow ); protected: - KIFONT::FONT* getDrawFont() const override; - const KIFONT::METRICS& getFontMetrics() const override { return GetFontMetrics(); } /** diff --git a/eeschema/sch_textbox.cpp b/eeschema/sch_textbox.cpp index 30c76c77c2..ccc5e36ef9 100644 --- a/eeschema/sch_textbox.cpp +++ b/eeschema/sch_textbox.cpp @@ -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(); if( !font ) - font = KIFONT::FONT::GetFont( GetDefaultFont(), IsBold(), IsItalic() ); + font = KIFONT::FONT::GetFont( GetDefaultFont( aSettings ), IsBold(), IsItalic() ); 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, - int aDepth ) const +wxString SCH_TEXTBOX::GetShownText( const RENDER_SETTINGS* aSettings, const SCH_SHEET_PATH* aPath, + bool aAllowExtraText, int aDepth ) const { SCH_SHEET* sheet = nullptr; @@ -381,8 +381,8 @@ wxString SCH_TEXTBOX::GetShownText( const SCH_SHEET_PATH* aPath, bool aAllowExtr else colWidth = abs( size.x ) - ( GetMarginLeft() + GetMarginRight() ); - getDrawFont()->LinebreakText( text, colWidth, GetTextSize(), GetTextThickness(), IsBold(), - IsItalic() ); + GetDrawFont( aSettings )->LinebreakText( text, colWidth, GetTextSize(), GetEffectiveTextPenWidth(), + IsBold(), IsItalic() ); return text; } @@ -463,7 +463,7 @@ void SCH_TEXTBOX::Plot( PLOTTER* aPlotter, bool aBackground, const SCH_PLOT_OPTS COLOR4D color = GetStroke().GetColor(); COLOR4D bg = renderSettings->GetBackgroundColor(); - KIFONT::FONT* font = getDrawFont(); + KIFONT::FONT* font = GetDrawFont( renderSettings ); color = GetTextColor(); @@ -487,7 +487,7 @@ void SCH_TEXTBOX::Plot( PLOTTER* aPlotter, bool aBackground, const SCH_PLOT_OPTS std::vector positions; wxArrayString strings_list; - wxStringSplit( GetShownText( sheet, true ), strings_list, '\n' ); + wxStringSplit( GetShownText( renderSettings, sheet, true ), strings_list, '\n' ); positions.reserve( strings_list.Count() ); 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 ); attrs = temp.GetAttributes(); - temp.GetLinePositions( positions, (int) strings_list.Count() ); + temp.GetLinePositions( renderSettings, positions, (int) strings_list.Count() ); } else { attrs = GetAttributes(); - GetLinePositions( positions, (int) strings_list.Count() ); + GetLinePositions( renderSettings, positions, (int) strings_list.Count() ); } attrs.m_StrokeWidth = penWidth; diff --git a/eeschema/sch_textbox.h b/eeschema/sch_textbox.h index e33ccb262e..4e2b8e07d3 100644 --- a/eeschema/sch_textbox.h +++ b/eeschema/sch_textbox.h @@ -70,8 +70,10 @@ public: VECTOR2I GetDrawPos() const override; - virtual wxString GetShownText( const SCH_SHEET_PATH* aPath, bool aAllowExtraText, - int aDepth = 0 ) const; + KIFONT::FONT* GetDrawFont( const RENDER_SETTINGS* aSettings ) const override; + + 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 { @@ -80,7 +82,7 @@ public: if( SCHEMATIC* schematic = Schematic() ) sheetPath = &schematic->CurrentSheet(); - return GetShownText( sheetPath, aAllowExtraText, aDepth ); + return GetShownText( nullptr, sheetPath, aAllowExtraText, aDepth ); } bool IsHypertext() const override; @@ -143,8 +145,6 @@ public: bool operator==( const SCH_ITEM& aOther ) const override; protected: - KIFONT::FONT* getDrawFont() const override; - const KIFONT::METRICS& getFontMetrics() const override { return GetFontMetrics(); } int compare( const SCH_ITEM& aOther, int aCompareFlags = 0 ) const override; diff --git a/include/eda_text.h b/include/eda_text.h index 26c4326297..3fa0d966ed 100644 --- a/include/eda_text.h +++ b/include/eda_text.h @@ -318,7 +318,7 @@ public: * this rectangle is calculated for 0 orient text. * 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. @@ -327,7 +327,7 @@ public: * interline distance plus room for characters like j, {, and [. It also used for single * 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). @@ -341,7 +341,8 @@ public: * @param aPositions is the list to populate by the VECTOR2I positions. * @param aLineCount is the number of lines (not recalculated here for efficiency reasons. */ - void GetLinePositions( std::vector& aPositions, int aLineCount ) const; + void GetLinePositions( const RENDER_SETTINGS* aSettings, std::vector& aPositions, + int aLineCount ) const; /** * Return the levenstein distance between two texts. @@ -365,6 +366,8 @@ public: virtual EDA_ANGLE GetDrawRotation() const { return GetTextAngle(); } virtual VECTOR2I GetDrawPos() const { return GetTextPos(); } + virtual KIFONT::FONT* GetDrawFont( const RENDER_SETTINGS* aSettings ) const; + virtual void ClearRenderCache(); virtual void ClearBoundingBoxCache(); @@ -415,8 +418,6 @@ public: static wxString GotoPageHref( const wxString& aDestination ); protected: - virtual KIFONT::FONT* getDrawFont() const; - virtual const KIFONT::METRICS& getFontMetrics() const; virtual void cacheShownText(); diff --git a/pcbnew/drc/drc_test_provider_text_dims.cpp b/pcbnew/drc/drc_test_provider_text_dims.cpp index 33ca5ad599..8e9222e366 100644 --- a/pcbnew/drc/drc_test_provider_text_dims.cpp +++ b/pcbnew/drc/drc_test_provider_text_dims.cpp @@ -144,10 +144,7 @@ bool DRC_TEST_PROVIDER_TEXT_DIMS::Run() if( constraint.GetSeverity() == RPT_SEVERITY_IGNORE ) return true; - KIFONT::FONT* font = text->GetFont(); - - if( !font ) - font = KIFONT::FONT::GetFont( wxEmptyString, text->IsBold(), text->IsItalic() ); + KIFONT::FONT* font = text->GetDrawFont( nullptr ); if( font->IsOutline() ) { diff --git a/pcbnew/exporters/export_gencad_writer.cpp b/pcbnew/exporters/export_gencad_writer.cpp index b2ca7914a1..c26626a6e3 100644 --- a/pcbnew/exporters/export_gencad_writer.cpp +++ b/pcbnew/exporters/export_gencad_writer.cpp @@ -805,7 +805,7 @@ void GENCAD_EXPORTER::createComponentsSection() layer.c_str(), TO_UTF8( escapeString( textItem->GetText() ) ) ); - BOX2I textBox = textItem->GetTextBox(); + BOX2I textBox = textItem->GetTextBox( nullptr ); fprintf( m_file, " 0 0 %g %g\n", textBox.GetWidth() / SCALE_FACTOR, diff --git a/pcbnew/pcb_dimension.cpp b/pcbnew/pcb_dimension.cpp index f4fae037c5..42096a5812 100644 --- a/pcbnew/pcb_dimension.cpp +++ b/pcbnew/pcb_dimension.cpp @@ -730,7 +730,7 @@ const BOX2I PCB_DIMENSION_BASE::GetBoundingBox() const BOX2I bBox; int xmin, xmax, ymin, ymax; - bBox = GetTextBox(); + bBox = GetTextBox( nullptr ); xmin = bBox.GetX(); xmax = bBox.GetRight(); 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. // 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; 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. // 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; 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 // 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; 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 // 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; polyBox.NewOutline(); diff --git a/pcbnew/pcb_io/altium/altium_pcb.cpp b/pcbnew/pcb_io/altium/altium_pcb.cpp index a19b1558bc..eac90d693f 100644 --- a/pcbnew/pcb_io/altium/altium_pcb.cpp +++ b/pcbnew/pcb_io/altium/altium_pcb.cpp @@ -1734,7 +1734,7 @@ void ALTIUM_PCB::HelperParseDimensions6Radial(const ADIMENSION6 &aElem) dimension->SetVertJustify( GR_TEXT_V_ALIGN_BOTTOM ); 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->SetVertJustify( GR_TEXT_V_ALIGN_CENTER ); diff --git a/pcbnew/pcb_io/ipc2581/pcb_io_ipc2581.cpp b/pcbnew/pcb_io/ipc2581/pcb_io_ipc2581.cpp index cbb461ff4c..30b95d8010 100644 --- a/pcbnew/pcb_io/ipc2581/pcb_io_ipc2581.cpp +++ b/pcbnew/pcb_io/ipc2581/pcb_io_ipc2581.cpp @@ -617,7 +617,7 @@ void PCB_IO_IPC2581::addText( wxXmlNode* aContentNode, EDA_TEXT* aText, const KIFONT::METRICS& aFontMetrics ) { KIGFX::GAL_DISPLAY_OPTIONS empty_opts; - KIFONT::FONT* font = aText->GetFont(); + KIFONT::FONT* font = aText->GetDrawFont( nullptr ); TEXT_ATTRIBUTES attrs = aText->GetAttributes(); 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" ); - if( !font ) - font = KIFONT::FONT::GetFont(); - std::list pts; auto push_pts = diff --git a/pcbnew/pcb_io/odbpp/odb_feature.cpp b/pcbnew/pcb_io/odbpp/odb_feature.cpp index 752e5a1c77..41114173fb 100644 --- a/pcbnew/pcb_io/odbpp/odb_feature.cpp +++ b/pcbnew/pcb_io/odbpp/odb_feature.cpp @@ -617,18 +617,8 @@ void FEATURES_MANAGER::InitFeatureList( PCB_LAYER_ID aLayer, std::vector( item )->IsKnockout(); const KIFONT::METRICS& fontMetrics = item->GetFontMetrics(); - - 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 ) ); + KIFONT::FONT* font = text_item->GetDrawFont( nullptr ); + wxString shownText( text_item->GetShownText( true ) ); if( shownText.IsEmpty() ) return; @@ -667,7 +657,7 @@ void FEATURES_MANAGER::InitFeatureList( PCB_LAYER_ID aLayer, std::vectorGetLinePositions( positions, strings_list.Count() ); + text_item->GetLinePositions( nullptr, positions, strings_list.Count() ); for( unsigned ii = 0; ii < strings_list.Count(); ii++ ) { diff --git a/pcbnew/pcb_painter.cpp b/pcbnew/pcb_painter.cpp index 9400b99a58..2714791242 100644 --- a/pcbnew/pcb_painter.cpp +++ b/pcbnew/pcb_painter.cpp @@ -2248,13 +2248,7 @@ void PCB_PAINTER::draw( const PCB_TEXT* aText, int aLayer ) const COLOR4D& color = m_pcbSettings.GetColor( aText, aLayer ); bool outline_mode = !viewer_settings()->m_ViewersDisplay.m_DisplayTextFill; - KIFONT::FONT* font = aText->GetFont(); - - if( !font ) - { - font = KIFONT::FONT::GetFont( m_pcbSettings.GetDefaultFont(), aText->IsBold(), - aText->IsItalic() ); - } + KIFONT::FONT* font = aText->GetDrawFont( &m_pcbSettings ); m_gal->SetStrokeColor( 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 // on the canvas 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 ) textWidth.x = -textWidth.x; @@ -2340,18 +2334,11 @@ void PCB_PAINTER::draw( const PCB_TEXTBOX* aTextBox, int aLayer ) return; } - COLOR4D color = m_pcbSettings.GetColor( aTextBox, aLayer ); - int thickness = getLineThickness( aTextBox->GetWidth() ); - LINE_STYLE lineStyle = aTextBox->GetStroke().GetLineStyle(); - wxString resolvedText( aTextBox->GetShownText( true ) ); - - KIFONT::FONT* font = aTextBox->GetFont(); - - if( !font ) - { - font = KIFONT::FONT::GetFont( m_pcbSettings.GetDefaultFont(), aTextBox->IsBold(), - aTextBox->IsItalic() ); - } + COLOR4D color = m_pcbSettings.GetColor( aTextBox, aLayer ); + int thickness = getLineThickness( aTextBox->GetWidth() ); + LINE_STYLE lineStyle = aTextBox->GetStroke().GetLineStyle(); + wxString resolvedText( aTextBox->GetShownText( true ) ); + KIFONT::FONT* font = aTextBox->GetDrawFont( &m_pcbSettings ); if( aLayer == LAYER_LOCKED_ITEM_SHADOW ) // happens only if locked { diff --git a/pcbnew/pcb_text.cpp b/pcbnew/pcb_text.cpp index d5fd724175..743f3a5b64 100644 --- a/pcbnew/pcb_text.cpp +++ b/pcbnew/pcb_text.cpp @@ -342,7 +342,7 @@ void PCB_TEXT::KeepUpright() const BOX2I PCB_TEXT::GetBoundingBox() const { EDA_ANGLE angle = GetDrawRotation(); - BOX2I rect = GetTextBox(); + BOX2I rect = GetTextBox( nullptr ); if( IsKnockout() ) rect.Inflate( getKnockoutMargin() ); @@ -551,7 +551,7 @@ void PCB_TEXT::TransformTextToPolySet( SHAPE_POLY_SET& aBuffer, int aClearance, ERROR_LOC aErrorLoc ) const { KIGFX::GAL_DISPLAY_OPTIONS empty_opts; - KIFONT::FONT* font = getDrawFont(); + KIFONT::FONT* font = GetDrawFont( nullptr ); int penWidth = GetEffectiveTextPenWidth(); TEXT_ATTRIBUTES attrs = GetAttributes(); wxString shownText = GetShownText( true ); diff --git a/pcbnew/pcb_textbox.cpp b/pcbnew/pcb_textbox.cpp index da120eebd5..5d0e9df34c 100644 --- a/pcbnew/pcb_textbox.cpp +++ b/pcbnew/pcb_textbox.cpp @@ -443,7 +443,7 @@ wxString PCB_TEXTBOX::GetShownText( bool aAllowExtraText, int aDepth ) const text = ExpandTextVars( text, &resolver ); } - KIFONT::FONT* font = getDrawFont(); + KIFONT::FONT* font = GetDrawFont( nullptr ); EDA_ANGLE drawAngle = GetDrawRotation(); std::vector corners = GetCornersInSequence( drawAngle ); 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 { KIGFX::GAL_DISPLAY_OPTIONS empty_opts; - KIFONT::FONT* font = getDrawFont(); + KIFONT::FONT* font = GetDrawFont( nullptr ); int penWidth = GetEffectiveTextPenWidth(); // Note: this function is mainly used in 3D viewer. diff --git a/pcbnew/plot_brditems_plotter.cpp b/pcbnew/plot_brditems_plotter.cpp index bc9ac99e52..d8512a70be 100644 --- a/pcbnew/plot_brditems_plotter.cpp +++ b/pcbnew/plot_brditems_plotter.cpp @@ -691,19 +691,8 @@ void BRDITEMS_PLOTTER::PlotFootprintGraphicItems( const FOOTPRINT* aFootprint ) void BRDITEMS_PLOTTER::PlotText( const EDA_TEXT* aText, PCB_LAYER_ID aLayer, bool aIsKnockout, const KIFONT::METRICS& aFontMetrics, bool aStrikeout ) { - KIFONT::FONT* font = aText->GetFont(); - - 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 ) ); + KIFONT::FONT* font = aText->GetDrawFont( m_plotter->RenderSettings() ); + wxString shownText( aText->GetShownText( true ) ); if( shownText.IsEmpty() ) return; @@ -787,7 +776,7 @@ void BRDITEMS_PLOTTER::PlotText( const EDA_TEXT* aText, PCB_LAYER_ID aLayer, boo wxStringSplit( shownText, strings_list, '\n' ); 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++ ) {