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/string.h>
#include <wx/url.h> // 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<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
{
return ( IsVisible()
@ -1133,10 +1177,13 @@ static struct EDA_TEXT_DESC
&EDA_TEXT::SetText,
&EDA_TEXT::GetText ),
textProps );
propMgr.AddProperty( new PROPERTY<EDA_TEXT, wxString>( _HKI( "Hyperlink" ),
&EDA_TEXT::SetHyperlink,
&EDA_TEXT::GetHyperlink ),
textProps );
propMgr.AddProperty( new PROPERTY_ENUM<EDA_TEXT, int>( _HKI( "Font" ),
&EDA_TEXT::SetFontIndex,
&EDA_TEXT::GetFontIndex ),
textProps )
.SetIsHiddenFromRulesEditor();
propMgr.AddProperty( new PROPERTY<EDA_TEXT, int>( _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<EDA_TEXT, wxString>( _HKI( "Hyperlink" ),
&EDA_TEXT::SetHyperlink,
&EDA_TEXT::GetHyperlink ),
textProps );
}
} _EDA_TEXT_DESC;

View File

@ -21,6 +21,9 @@
#include "sch_properties_panel.h"
#include <font/fontconfig.h>
#include <font/kicad_font_name.h>
#include <pgm_base.h>
#include <connection_graph.h>
#include <properties/pg_editors.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 )
{
// 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;
void SetFontIndex( int aIdx );
int GetFontIndex() const;
void SetLineSpacing( double aLineSpacing );
double GetLineSpacing() const { return m_attributes.m_LineSpacing; }

View File

@ -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<BOARD_CONNECTED_ITEM, int>( _HKI( "Net" ),
&BOARD_CONNECTED_ITEM::SetNetCode,
&BOARD_CONNECTED_ITEM::GetNetCode ) )

View File

@ -21,6 +21,9 @@
#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 <tool/tool_manager.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 )
{
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<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 );
}