From e230d5164dc80f67fab1377890a3c3d5915cfd42 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 --- 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 | 8 +- 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 | 11 +- 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 | 15 +-- pcbnew/pcb_painter.cpp | 27 +--- pcbnew/pcb_text.cpp | 4 +- pcbnew/pcb_textbox.cpp | 4 +- pcbnew/plot_brditems_plotter.cpp | 17 +-- 33 files changed, 197 insertions(+), 258 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 10d33bf844..0937f522d6 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 04e57a8609..4d75bfffeb 100644 --- a/common/eda_text.cpp +++ b/common/eda_text.cpp @@ -638,12 +638,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; } @@ -721,13 +726,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(); @@ -755,12 +760,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 @@ -786,15 +790,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; @@ -859,7 +861,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 ); } @@ -870,9 +872,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() ); } @@ -886,7 +888,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, strings[ii], positions[ii] ); @@ -898,14 +900,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 ) { @@ -953,10 +956,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() ); @@ -1124,7 +1124,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 4d9c936d59..facca97d8c 100644 --- a/common/io/cadstar/cadstar_archive_parser.cpp +++ b/common/io/cadstar/cadstar_archive_parser.cpp @@ -2784,7 +2784,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 793b87d369..4f5edeee24 100644 --- a/common/plotters/PDF_plotter.cpp +++ b/common/plotters/PDF_plotter.cpp @@ -1729,9 +1729,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 9b495085bf..a24940d956 100644 --- a/common/plotters/common_plot_functions.cpp +++ b/common/plotters/common_plot_functions.cpp @@ -135,15 +135,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(); diff --git a/common/plotters/plotter.cpp b/common/plotters/plotter.cpp index 5b66344dfa..4ee21cedd4 100644 --- a/common/plotters/plotter.cpp +++ b/common/plotters/plotter.cpp @@ -621,7 +621,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, @@ -678,7 +678,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 ); } @@ -723,7 +723,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 dad45aa924..d9e4058b97 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 ); @@ -399,7 +399,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 685a036601..bb410cce8f 100644 --- a/eeschema/fields_grid_table.cpp +++ b/eeschema/fields_grid_table.cpp @@ -933,8 +933,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 b36ac9d523..c872c3db5c 100644 --- a/eeschema/sch_field.cpp +++ b/eeschema/sch_field.cpp @@ -319,12 +319,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; } @@ -348,10 +348,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() ) { @@ -491,7 +488,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(); @@ -1286,11 +1283,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 8848b1170e..26f0aaa45a 100644 --- a/eeschema/sch_field.h +++ b/eeschema/sch_field.h @@ -181,6 +181,8 @@ public: */ EDA_ANGLE GetDrawRotation() const override; + KIFONT::FONT* GetDrawFont( const RENDER_SETTINGS* aSettings ) const override; + const BOX2I GetBoundingBox() const override; /** @@ -303,8 +305,6 @@ public: protected: friend class SCH_IO_KICAD_SEXPR_PARSER; - 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 d5cad455c1..c267c850ec 100644 --- a/eeschema/sch_io/cadstar/cadstar_sch_archive_loader.cpp +++ b/eeschema/sch_io/cadstar/cadstar_sch_archive_loader.cpp @@ -1722,7 +1722,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 bce30e5276..692fa8206a 100644 --- a/eeschema/sch_item.cpp +++ b/eeschema/sch_item.cpp @@ -568,13 +568,16 @@ 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; - EESCHEMA_SETTINGS* cfg = GetAppSettings( "eeschema" ); - - return cfg ? cfg->m_Appearance.default_font : defaultName; + if( aSettings ) + return aSettings->GetDefaultFont(); + else if( EESCHEMA_SETTINGS* cfg = GetAppSettings( "eeschema" ) ) + return cfg->m_Appearance.default_font; + else + return defaultName; } diff --git a/eeschema/sch_item.h b/eeschema/sch_item.h index 1354f85e49..0ba64f7a96 100644 --- a/eeschema/sch_item.h +++ b/eeschema/sch_item.h @@ -321,7 +321,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 c2223a992e..5ef90dd7a7 100644 --- a/eeschema/sch_label.cpp +++ b/eeschema/sch_label.cpp @@ -567,7 +567,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 ) @@ -1018,14 +1018,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 ); @@ -1040,7 +1040,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 ) { @@ -1063,7 +1063,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 ) ) @@ -1100,7 +1100,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 ) @@ -1343,13 +1343,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; @@ -1361,8 +1358,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() ) { @@ -1399,7 +1395,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 ) { @@ -1409,8 +1406,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; } } @@ -1419,8 +1415,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; } } @@ -1436,9 +1431,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() ) @@ -1449,14 +1444,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 ) @@ -1510,9 +1502,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() ); @@ -2027,7 +2019,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; @@ -2162,7 +2154,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(); @@ -2171,7 +2163,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 276b61be66..40698cfe6c 100644 --- a/eeschema/sch_label.h +++ b/eeschema/sch_label.h @@ -308,7 +308,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. @@ -400,7 +400,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; } @@ -609,7 +609,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 cfcae398f8..1bae9ed4f7 100644 --- a/eeschema/sch_painter.cpp +++ b/eeschema/sch_painter.cpp @@ -276,11 +276,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() ); } @@ -1168,71 +1167,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; + 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; - }; + // 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; - - 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 + // 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( !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 ); + } + }; + + const auto getColorForLayer = + [&]( int aDrawnLayer ) { - 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( !aPin->IsVisible() ) + return getRenderColor( aPin, LAYER_HIDDEN, drawingShadows, aDimmed ); - const auto getColorForLayer = [&]( int aDrawnLayer ) - { - 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 @@ -1913,7 +1914,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 0baa11aeb6..884f6d78c0 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() ) { @@ -283,12 +283,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; } @@ -296,7 +296,7 @@ KIFONT::FONT* SCH_TEXT::getDrawFont() const const BOX2I SCH_TEXT::GetBoundingBox() const { - BOX2I bbox = GetTextBox(); + BOX2I bbox = GetTextBox( nullptr ); if( !GetTextAngle().IsZero() ) // Rotate bbox. { @@ -464,11 +464,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; @@ -510,7 +506,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 ); @@ -524,7 +520,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 2115d3bf9c..48396aa18e 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; @@ -168,8 +170,6 @@ public: protected: void swapData( SCH_ITEM* aItem ) override; - 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 087f23eded..a71e9b576e 100644 --- a/eeschema/sch_textbox.cpp +++ b/eeschema/sch_textbox.cpp @@ -258,19 +258,19 @@ 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; } -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; @@ -305,8 +305,8 @@ wxString SCH_TEXTBOX::GetShownText( const SCH_SHEET_PATH* aPath, bool aAllowExtr else colWidth = abs( size.x ) - ( GetMarginLeft() + GetMarginRight() ); - getDrawFont()->LinebreakText( text, colWidth, GetTextSize(), GetEffectiveTextPenWidth(), - IsBold(), IsItalic() ); + GetDrawFont( aSettings )->LinebreakText( text, colWidth, GetTextSize(), GetEffectiveTextPenWidth(), + IsBold(), IsItalic() ); return text; } @@ -387,7 +387,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(); @@ -411,7 +411,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() ) @@ -428,12 +428,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 2bb5b903d4..5674e99b5c 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; @@ -140,8 +142,6 @@ public: protected: void swapData( SCH_ITEM* aItem ) override; - 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 f7c4941b2f..0f0b8c31b0 100644 --- a/include/eda_text.h +++ b/include/eda_text.h @@ -326,7 +326,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. @@ -335,7 +335,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). @@ -349,7 +349,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. @@ -373,6 +374,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(); @@ -423,8 +426,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 c03a0af23b..f4681b4b12 100644 --- a/pcbnew/drc/drc_test_provider_text_dims.cpp +++ b/pcbnew/drc/drc_test_provider_text_dims.cpp @@ -133,10 +133,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 810b403371..4773b03362 100644 --- a/pcbnew/exporters/export_gencad_writer.cpp +++ b/pcbnew/exporters/export_gencad_writer.cpp @@ -804,7 +804,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 fa5796bdd1..7d18d44e4a 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 200f6f746d..63b72eb34d 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 9c5f40e7be..e529ac9c7c 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 97025035e9..adbc156993 100644 --- a/pcbnew/pcb_io/odbpp/odb_feature.cpp +++ b/pcbnew/pcb_io/odbpp/odb_feature.cpp @@ -613,17 +613,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; @@ -662,7 +653,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 faf795f7e2..de5cf5c527 100644 --- a/pcbnew/pcb_painter.cpp +++ b/pcbnew/pcb_painter.cpp @@ -2289,13 +2289,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 ); @@ -2324,7 +2318,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; @@ -2381,18 +2375,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 9d3d232741..fb17886fc7 100644 --- a/pcbnew/pcb_text.cpp +++ b/pcbnew/pcb_text.cpp @@ -345,7 +345,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() ); @@ -554,7 +554,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 f4efe11c36..f0e2cf8c93 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(); @@ -626,7 +626,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(); TEXT_ATTRIBUTES attrs = GetAttributes(); wxString shownText = GetShownText( true ); diff --git a/pcbnew/plot_brditems_plotter.cpp b/pcbnew/plot_brditems_plotter.cpp index 33a4bee71e..ba235db9ea 100644 --- a/pcbnew/plot_brditems_plotter.cpp +++ b/pcbnew/plot_brditems_plotter.cpp @@ -736,19 +736,8 @@ void BRDITEMS_PLOTTER::PlotText( const EDA_TEXT* aText, PCB_LAYER_ID aLayer, boo const KIFONT::METRICS& aFontMetrics, bool aStrikeout ) { int maxError = m_board->GetDesignSettings().m_MaxError; - 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; @@ -834,7 +823,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++ ) {