And Font to properties manager for EDA_TEXT items.

Fixes https://gitlab.com/kicad/code/kicad/-/issues/16004
This commit is contained in:
Jeff Young 2023-11-01 00:38:43 +00:00
parent 5d5682a225
commit 67d8b13b02
5 changed files with 95 additions and 7 deletions

View File

@ -52,6 +52,9 @@
#include <wx/debug.h> // for wxASSERT #include <wx/debug.h> // for wxASSERT
#include <wx/string.h> #include <wx/string.h>
#include <wx/url.h> // for wxURL #include <wx/url.h> // for wxURL
#include "font/kicad_font_name.h"
#include "font/fontconfig.h"
#include "pgm_base.h"
class OUTPUTFORMATTER; class OUTPUTFORMATTER;
class wxFindReplaceData; 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<std::string> 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<std::string> fontNames;
Fontconfig()->ListFonts( fontNames, std::string( Pgm().GetLanguageTag().utf8_str() ) );
SetFont( KIFONT::FONT::GetFont( fontNames[ aIdx ], IsBold(), IsItalic() ) );
}
}
bool EDA_TEXT::IsDefaultFormatting() const bool EDA_TEXT::IsDefaultFormatting() const
{ {
return ( IsVisible() return ( IsVisible()
@ -1133,10 +1177,13 @@ static struct EDA_TEXT_DESC
&EDA_TEXT::SetText, &EDA_TEXT::SetText,
&EDA_TEXT::GetText ), &EDA_TEXT::GetText ),
textProps ); textProps );
propMgr.AddProperty( new PROPERTY<EDA_TEXT, wxString>( _HKI( "Hyperlink" ),
&EDA_TEXT::SetHyperlink, propMgr.AddProperty( new PROPERTY_ENUM<EDA_TEXT, int>( _HKI( "Font" ),
&EDA_TEXT::GetHyperlink ), &EDA_TEXT::SetFontIndex,
textProps ); &EDA_TEXT::GetFontIndex ),
textProps )
.SetIsHiddenFromRulesEditor();
propMgr.AddProperty( new PROPERTY<EDA_TEXT, int>( _HKI( "Thickness" ), propMgr.AddProperty( new PROPERTY<EDA_TEXT, int>( _HKI( "Thickness" ),
&EDA_TEXT::SetTextThickness, &EDA_TEXT::SetTextThickness,
&EDA_TEXT::GetTextThickness, &EDA_TEXT::GetTextThickness,
@ -1179,6 +1226,11 @@ static struct EDA_TEXT_DESC
&EDA_TEXT::SetVertJustify, &EDA_TEXT::SetVertJustify,
&EDA_TEXT::GetVertJustify ), &EDA_TEXT::GetVertJustify ),
textProps ); textProps );
propMgr.AddProperty( new PROPERTY<EDA_TEXT, wxString>( _HKI( "Hyperlink" ),
&EDA_TEXT::SetHyperlink,
&EDA_TEXT::GetHyperlink ),
textProps );
} }
} _EDA_TEXT_DESC; } _EDA_TEXT_DESC;

View File

@ -21,6 +21,9 @@
#include "sch_properties_panel.h" #include "sch_properties_panel.h"
#include <font/fontconfig.h>
#include <font/kicad_font_name.h>
#include <pgm_base.h>
#include <connection_graph.h> #include <connection_graph.h>
#include <properties/pg_editors.h> #include <properties/pg_editors.h>
#include <properties/pg_properties.h> #include <properties/pg_properties.h>
@ -206,5 +209,18 @@ void SCH_PROPERTIES_PANEL::valueChanged( wxPropertyGridEvent& aEvent )
void SCH_PROPERTIES_PANEL::updateLists( const SCHEMATIC& aSchematic ) void SCH_PROPERTIES_PANEL::updateLists( const SCHEMATIC& aSchematic )
{ {
// No lists yet wxPGChoices fonts;
// Regnerate font names
std::vector<std::string> 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 );
} }

View File

@ -200,6 +200,9 @@ public:
wxString GetFontName() const; wxString GetFontName() const;
void SetFontIndex( int aIdx );
int GetFontIndex() const;
void SetLineSpacing( double aLineSpacing ); void SetLineSpacing( double aLineSpacing );
double GetLineSpacing() const { return m_attributes.m_LineSpacing; } double GetLineSpacing() const { return m_attributes.m_LineSpacing; }

View File

@ -169,7 +169,6 @@ static struct BOARD_CONNECTED_ITEM_DESC
layer->SetChoices( layerEnum.Choices() ); layer->SetChoices( layerEnum.Choices() );
propMgr.ReplaceProperty( TYPE_HASH( BOARD_ITEM ), _HKI( "Layer" ), layer ); propMgr.ReplaceProperty( TYPE_HASH( BOARD_ITEM ), _HKI( "Layer" ), layer );
// Not really deprecated, but hidden from rule editor suggestions
propMgr.AddProperty( new PROPERTY_ENUM<BOARD_CONNECTED_ITEM, int>( _HKI( "Net" ), propMgr.AddProperty( new PROPERTY_ENUM<BOARD_CONNECTED_ITEM, int>( _HKI( "Net" ),
&BOARD_CONNECTED_ITEM::SetNetCode, &BOARD_CONNECTED_ITEM::SetNetCode,
&BOARD_CONNECTED_ITEM::GetNetCode ) ) &BOARD_CONNECTED_ITEM::GetNetCode ) )

View File

@ -21,6 +21,9 @@
#include "pcb_properties_panel.h" #include "pcb_properties_panel.h"
#include <font/fontconfig.h>
#include <font/kicad_font_name.h>
#include <pgm_base.h>
#include <pcb_base_edit_frame.h> #include <pcb_base_edit_frame.h>
#include <tool/tool_manager.h> #include <tool/tool_manager.h>
#include <tools/pcb_actions.h> #include <tools/pcb_actions.h>
@ -232,7 +235,10 @@ void PCB_PROPERTIES_PANEL::valueChanged( wxPropertyGridEvent& aEvent )
void PCB_PROPERTIES_PANEL::updateLists( const BOARD* aBoard ) void PCB_PROPERTIES_PANEL::updateLists( const BOARD* aBoard )
{ {
wxPGChoices layersAll, layersCu, nets; wxPGChoices layersAll;
wxPGChoices layersCu;
wxPGChoices nets;
wxPGChoices fonts;
// Regenerate all layers // Regenerate all layers
for( LSEQ seq = aBoard->GetEnabledLayers().UIOrder(); seq; ++seq ) 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" ) ); auto netProperty = m_propMgr.GetProperty( TYPE_HASH( BOARD_CONNECTED_ITEM ), _HKI( "Net" ) );
netProperty->SetChoices( nets ); netProperty->SetChoices( nets );
// Regnerate font names
std::vector<std::string> 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 );
} }