From 67d8b13b0206aa3fa4257eeb88399310b6636287 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Wed, 1 Nov 2023 00:38:43 +0000 Subject: [PATCH] And Font to properties manager for EDA_TEXT items. Fixes https://gitlab.com/kicad/code/kicad/-/issues/16004 --- common/eda_text.cpp | 60 +++++++++++++++++++++-- eeschema/widgets/sch_properties_panel.cpp | 18 ++++++- include/eda_text.h | 3 ++ pcbnew/board_connected_item.cpp | 1 - pcbnew/widgets/pcb_properties_panel.cpp | 20 +++++++- 5 files changed, 95 insertions(+), 7 deletions(-) diff --git a/common/eda_text.cpp b/common/eda_text.cpp index 34df1ed6c7..e822aa4748 100644 --- a/common/eda_text.cpp +++ b/common/eda_text.cpp @@ -52,6 +52,9 @@ #include // for wxASSERT #include #include // for wxURL +#include "font/kicad_font_name.h" +#include "font/fontconfig.h" +#include "pgm_base.h" class OUTPUTFORMATTER; class wxFindReplaceData; @@ -818,6 +821,47 @@ wxString EDA_TEXT::GetFontName() const } +int EDA_TEXT::GetFontIndex() const +{ + if( !GetFont() ) + return -1; + + if( GetFont()->GetName() == KICAD_FONT_NAME ) + return -2; + + std::vector fontNames; + Fontconfig()->ListFonts( fontNames, std::string( Pgm().GetLanguageTag().utf8_str() ) ); + + for( int ii = 0; ii < (int) fontNames.size(); ++ii ) + { + if( fontNames[ii] == GetFont()->GetName() ) + return ii; + } + + return 0; +} + + +void EDA_TEXT::SetFontIndex( int aIdx ) +{ + if( aIdx == -1 ) + { + SetFont( nullptr ); + } + else if( aIdx == -2 ) + { + SetFont( KIFONT::FONT::GetFont( wxEmptyString, IsBold(), IsItalic() ) ); + } + else + { + std::vector fontNames; + Fontconfig()->ListFonts( fontNames, std::string( Pgm().GetLanguageTag().utf8_str() ) ); + + SetFont( KIFONT::FONT::GetFont( fontNames[ aIdx ], IsBold(), IsItalic() ) ); + } +} + + bool EDA_TEXT::IsDefaultFormatting() const { return ( IsVisible() @@ -1133,10 +1177,13 @@ static struct EDA_TEXT_DESC &EDA_TEXT::SetText, &EDA_TEXT::GetText ), textProps ); - propMgr.AddProperty( new PROPERTY( _HKI( "Hyperlink" ), - &EDA_TEXT::SetHyperlink, - &EDA_TEXT::GetHyperlink ), - textProps ); + + propMgr.AddProperty( new PROPERTY_ENUM( _HKI( "Font" ), + &EDA_TEXT::SetFontIndex, + &EDA_TEXT::GetFontIndex ), + textProps ) + .SetIsHiddenFromRulesEditor(); + propMgr.AddProperty( new PROPERTY( _HKI( "Thickness" ), &EDA_TEXT::SetTextThickness, &EDA_TEXT::GetTextThickness, @@ -1179,6 +1226,11 @@ static struct EDA_TEXT_DESC &EDA_TEXT::SetVertJustify, &EDA_TEXT::GetVertJustify ), textProps ); + + propMgr.AddProperty( new PROPERTY( _HKI( "Hyperlink" ), + &EDA_TEXT::SetHyperlink, + &EDA_TEXT::GetHyperlink ), + textProps ); } } _EDA_TEXT_DESC; diff --git a/eeschema/widgets/sch_properties_panel.cpp b/eeschema/widgets/sch_properties_panel.cpp index 96d8b5690c..4d6de49b0b 100644 --- a/eeschema/widgets/sch_properties_panel.cpp +++ b/eeschema/widgets/sch_properties_panel.cpp @@ -21,6 +21,9 @@ #include "sch_properties_panel.h" +#include +#include +#include #include #include #include @@ -206,5 +209,18 @@ void SCH_PROPERTIES_PANEL::valueChanged( wxPropertyGridEvent& aEvent ) void SCH_PROPERTIES_PANEL::updateLists( const SCHEMATIC& aSchematic ) { - // No lists yet + wxPGChoices fonts; + + // Regnerate font names + std::vector fontNames; + Fontconfig()->ListFonts( fontNames, std::string( Pgm().GetLanguageTag().utf8_str() ) ); + + fonts.Add( _( "Default Font" ), -1 ); + fonts.Add( KICAD_FONT_NAME, -2 ); + + for( int ii = 0; ii < (int) fontNames.size(); ++ii ) + fonts.Add( wxString( fontNames[ii] ), ii ); + + auto fontProperty = m_propMgr.GetProperty( TYPE_HASH( EDA_TEXT ), _HKI( "Font" ) ); + fontProperty->SetChoices( fonts ); } diff --git a/include/eda_text.h b/include/eda_text.h index fa83069dd0..c042630547 100644 --- a/include/eda_text.h +++ b/include/eda_text.h @@ -200,6 +200,9 @@ public: wxString GetFontName() const; + void SetFontIndex( int aIdx ); + int GetFontIndex() const; + void SetLineSpacing( double aLineSpacing ); double GetLineSpacing() const { return m_attributes.m_LineSpacing; } diff --git a/pcbnew/board_connected_item.cpp b/pcbnew/board_connected_item.cpp index 51997128a2..6d4e03f5a1 100644 --- a/pcbnew/board_connected_item.cpp +++ b/pcbnew/board_connected_item.cpp @@ -169,7 +169,6 @@ static struct BOARD_CONNECTED_ITEM_DESC layer->SetChoices( layerEnum.Choices() ); propMgr.ReplaceProperty( TYPE_HASH( BOARD_ITEM ), _HKI( "Layer" ), layer ); - // Not really deprecated, but hidden from rule editor suggestions propMgr.AddProperty( new PROPERTY_ENUM( _HKI( "Net" ), &BOARD_CONNECTED_ITEM::SetNetCode, &BOARD_CONNECTED_ITEM::GetNetCode ) ) diff --git a/pcbnew/widgets/pcb_properties_panel.cpp b/pcbnew/widgets/pcb_properties_panel.cpp index f50e0fd0b1..e7315f8a1a 100644 --- a/pcbnew/widgets/pcb_properties_panel.cpp +++ b/pcbnew/widgets/pcb_properties_panel.cpp @@ -21,6 +21,9 @@ #include "pcb_properties_panel.h" +#include +#include +#include #include #include #include @@ -232,7 +235,10 @@ void PCB_PROPERTIES_PANEL::valueChanged( wxPropertyGridEvent& aEvent ) void PCB_PROPERTIES_PANEL::updateLists( const BOARD* aBoard ) { - wxPGChoices layersAll, layersCu, nets; + wxPGChoices layersAll; + wxPGChoices layersCu; + wxPGChoices nets; + wxPGChoices fonts; // Regenerate all layers for( LSEQ seq = aBoard->GetEnabledLayers().UIOrder(); seq; ++seq ) @@ -256,4 +262,16 @@ void PCB_PROPERTIES_PANEL::updateLists( const BOARD* aBoard ) auto netProperty = m_propMgr.GetProperty( TYPE_HASH( BOARD_CONNECTED_ITEM ), _HKI( "Net" ) ); netProperty->SetChoices( nets ); + + // Regnerate font names + std::vector fontNames; + Fontconfig()->ListFonts( fontNames, std::string( Pgm().GetLanguageTag().utf8_str() ) ); + + fonts.Add( KICAD_FONT_NAME, -1 ); + + for( int ii = 0; ii < (int) fontNames.size(); ++ii ) + fonts.Add( wxString( fontNames[ii] ), ii ); + + auto fontProperty = m_propMgr.GetProperty( TYPE_HASH( EDA_TEXT ), _HKI( "Font" ) ); + fontProperty->SetChoices( fonts ); }