From 7470ec80e461db653be61cf01818ee62dfa290b4 Mon Sep 17 00:00:00 2001 From: Jon Evans Date: Fri, 22 Dec 2023 18:34:26 -0500 Subject: [PATCH] Fix some issues with Font property Prevent out-of-bounds access Make sure list is initialized in symbol editor frame Don't re-init the list more frequently than necessary Fixes https://gitlab.com/kicad/code/kicad/-/issues/16399 --- common/eda_text.cpp | 5 ++++- common/widgets/properties_panel.h | 5 +++++ eeschema/sch_edit_frame.cpp | 2 ++ eeschema/symbol_editor/symbol_edit_frame.cpp | 2 ++ eeschema/widgets/sch_properties_panel.cpp | 14 +++++++++----- eeschema/widgets/sch_properties_panel.h | 6 ++++-- 6 files changed, 26 insertions(+), 8 deletions(-) diff --git a/common/eda_text.cpp b/common/eda_text.cpp index 62c63fcbd8..1906abc206 100644 --- a/common/eda_text.cpp +++ b/common/eda_text.cpp @@ -857,7 +857,10 @@ void EDA_TEXT::SetFontIndex( int aIdx ) std::vector fontNames; Fontconfig()->ListFonts( fontNames, std::string( Pgm().GetLanguageTag().utf8_str() ) ); - SetFont( KIFONT::FONT::GetFont( fontNames[ aIdx ], IsBold(), IsItalic() ) ); + if( aIdx >= 0 && aIdx < static_cast( fontNames.size() ) ) + SetFont( KIFONT::FONT::GetFont( fontNames[ aIdx ], IsBold(), IsItalic() ) ); + else + SetFont( nullptr ); } } diff --git a/common/widgets/properties_panel.h b/common/widgets/properties_panel.h index d578e0fb6d..18ffce4d0f 100644 --- a/common/widgets/properties_panel.h +++ b/common/widgets/properties_panel.h @@ -49,6 +49,11 @@ public: virtual void AfterCommit() {} + /** + * Parents will call this when the user changes the UI language + */ + virtual void LanguageChanged() {} + wxPropertyGrid* GetPropertyGrid() { return m_grid; diff --git a/eeschema/sch_edit_frame.cpp b/eeschema/sch_edit_frame.cpp index ceb5aa3180..f11a853a37 100644 --- a/eeschema/sch_edit_frame.cpp +++ b/eeschema/sch_edit_frame.cpp @@ -1912,6 +1912,8 @@ void SCH_EDIT_FRAME::ShowChangedLanguage() m_auimgr.Update(); m_hierarchy->UpdateHierarchyTree(); + m_propertiesPanel->LanguageChanged(); + // status bar UpdateMsgPanel(); diff --git a/eeschema/symbol_editor/symbol_edit_frame.cpp b/eeschema/symbol_editor/symbol_edit_frame.cpp index 7da69722c8..32e0d53dce 100644 --- a/eeschema/symbol_editor/symbol_edit_frame.cpp +++ b/eeschema/symbol_editor/symbol_edit_frame.cpp @@ -1250,6 +1250,8 @@ void SYMBOL_EDIT_FRAME::ShowChangedLanguage() m_treePane->GetLibTree()->ShowChangedLanguage(); + m_propertiesPanel->LanguageChanged(); + // status bar UpdateMsgPanel(); diff --git a/eeschema/widgets/sch_properties_panel.cpp b/eeschema/widgets/sch_properties_panel.cpp index 9edccc404c..a15b2c7cdb 100644 --- a/eeschema/widgets/sch_properties_panel.cpp +++ b/eeschema/widgets/sch_properties_panel.cpp @@ -87,6 +87,8 @@ SCH_PROPERTIES_PANEL::SCH_PROPERTIES_PANEL( wxWindow* aParent, SCH_BASE_FRAME* a { m_colorEditorInstance = static_cast( it->second ); } + + updateFontList(); } @@ -102,10 +104,6 @@ void SCH_PROPERTIES_PANEL::UpdateData() EE_SELECTION_TOOL* selectionTool = m_frame->GetToolManager()->GetTool(); const SELECTION& selection = selectionTool->GetSelection(); - // TODO perhaps it could be called less often? use PROPERTIES_TOOL and catch MODEL_RELOAD? - if( SCH_EDIT_FRAME* schFrame = dynamic_cast( m_frame ) ) - updateLists( schFrame->Schematic() ); - // Will actually just be updatePropertyValues() if selection hasn't changed rebuildProperties( selection ); } @@ -209,7 +207,13 @@ void SCH_PROPERTIES_PANEL::valueChanged( wxPropertyGridEvent& aEvent ) } -void SCH_PROPERTIES_PANEL::updateLists( const SCHEMATIC& aSchematic ) +void SCH_PROPERTIES_PANEL::LanguageChanged() +{ + updateFontList(); +} + + +void SCH_PROPERTIES_PANEL::updateFontList() { wxPGChoices fonts; diff --git a/eeschema/widgets/sch_properties_panel.h b/eeschema/widgets/sch_properties_panel.h index 3f6d8f9846..87b9a083ee 100644 --- a/eeschema/widgets/sch_properties_panel.h +++ b/eeschema/widgets/sch_properties_panel.h @@ -43,6 +43,8 @@ public: void AfterCommit() override; + void LanguageChanged() override; + protected: wxPGProperty* createPGProperty( const PROPERTY_BASE* aProperty ) const override; @@ -51,8 +53,8 @@ protected: void valueChanging( wxPropertyGridEvent& aEvent ) override; void valueChanged( wxPropertyGridEvent& aEvent ) override; - ///< Regenerates caches of list properties - void updateLists( const SCHEMATIC& aSchematic ); + ///< Regenerates caches of font list property + void updateFontList(); SCH_BASE_FRAME* m_frame; PROPERTY_MANAGER& m_propMgr;