From d0f2c2023519cd41cc7efc378fde092347605d47 Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Thu, 13 Jan 2022 14:31:00 +0100 Subject: [PATCH] Define our kicad font name only once, and do not translate it. Especially using a translated name breaks kicad config and files because in non English languages both translated and not translated names were used in code. --- common/font/font.cpp | 7 +++-- common/font/stroke_font.cpp | 5 +++- common/widgets/font_choice.cpp | 18 ++++++++++++- .../panel_eeschema_display_options.cpp | 7 ++++- include/font/kicad_font_name.h | 27 +++++++++++++++++++ 5 files changed, 59 insertions(+), 5 deletions(-) create mode 100644 include/font/kicad_font_name.h diff --git a/common/font/font.cpp b/common/font/font.cpp index 60a94a6e79..35404547ed 100644 --- a/common/font/font.cpp +++ b/common/font/font.cpp @@ -32,6 +32,9 @@ #include #include +// The "official" name of the building Kicad stroke font (always existing) +#include + // markup_parser.h includes pegtl.hpp which includes windows.h... which leaks #define DrawText #undef DrawText @@ -66,7 +69,7 @@ FONT* FONT::getDefaultFont() FONT* FONT::GetFont( const wxString& aFontName, bool aBold, bool aItalic ) { - if( aFontName.empty() || aFontName.StartsWith( wxT( "KiCad Font" ) ) ) + if( aFontName.empty() || aFontName.StartsWith( KICAD_FONT_NAME ) ) return getDefaultFont(); std::tuple key = { aFontName, aBold, aItalic }; @@ -89,7 +92,7 @@ bool FONT::IsStroke( const wxString& aFontName ) { // This would need a more complex implementation if we ever support more stroke fonts // than the KiCad Font. - return aFontName == _( "Default Font" ) || aFontName == wxT( "KiCad Font" ); + return aFontName == _( "Default Font" ) || aFontName == KICAD_FONT_NAME; } diff --git a/common/font/stroke_font.cpp b/common/font/stroke_font.cpp index 7d9e82bb78..7084325ebb 100644 --- a/common/font/stroke_font.cpp +++ b/common/font/stroke_font.cpp @@ -35,6 +35,9 @@ #include #include +// The "official" name of the building Kicad stroke font (always existing) +#include + using namespace KIFONT; @@ -185,7 +188,7 @@ void STROKE_FONT::loadNewStrokeFont( const char* const aNewStrokeFont[], int aNe m_glyphs = &g_defaultFontGlyphs; m_glyphBoundingBoxes = g_defaultFontGlyphBoundingBoxes; - m_fontName = wxT( "KiCad Font" ); + m_fontName = KICAD_FONT_NAME; m_fontFileName = wxEmptyString; } diff --git a/common/widgets/font_choice.cpp b/common/widgets/font_choice.cpp index 44171f9151..4dea77fe2b 100644 --- a/common/widgets/font_choice.cpp +++ b/common/widgets/font_choice.cpp @@ -21,6 +21,9 @@ #include #include +// The "official" name of the building Kicad stroke font (always existing) +#include + FONT_CHOICE::FONT_CHOICE( wxWindow* aParent, int aId, wxPoint aPosition, wxSize aSize, int nChoices, wxString* aChoices, int aStyle ) : @@ -33,6 +36,19 @@ FONT_CHOICE::FONT_CHOICE( wxWindow* aParent, int aId, wxPoint aPosition, wxSize wxArrayString menuList; + // The initial list of fonts has on top 1 or 2 options + // only "KiCad Font" (KICAD_FONT_NAME) + // "Default Font" and "KiCad Font" (KICAD_FONT_NAME) + // "KiCad Font" is also a keyword, and cannot be translated. + // So rebuilt the starting list + wxChoice::Clear(); + + if( m_systemFontCount > 1 ) + Append( _( "Default Font" ) ); + + Append( KICAD_FONT_NAME ); + m_systemFontCount = wxChoice::GetCount(); + for( const std::string& name : fontNames ) menuList.Add( wxString( name ) ); @@ -88,7 +104,7 @@ KIFONT::FONT* FONT_CHOICE::GetFontSelection( bool aBold, bool aItalic ) const if( GetSelection() <= 0 ) return nullptr; else if( GetSelection() == 1 && m_systemFontCount == 2 ) - return KIFONT::FONT::GetFont( "KiCad Font", aBold, aItalic ); + return KIFONT::FONT::GetFont( KICAD_FONT_NAME, aBold, aItalic ); else return KIFONT::FONT::GetFont( GetStringSelection(), aBold, aItalic ); } diff --git a/eeschema/dialogs/panel_eeschema_display_options.cpp b/eeschema/dialogs/panel_eeschema_display_options.cpp index 4098346949..24aa21ed6e 100644 --- a/eeschema/dialogs/panel_eeschema_display_options.cpp +++ b/eeschema/dialogs/panel_eeschema_display_options.cpp @@ -30,6 +30,9 @@ #include #include +// The "official" name of the building Kicad stroke font (always existing) +#include + PANEL_EESCHEMA_DISPLAY_OPTIONS::PANEL_EESCHEMA_DISPLAY_OPTIONS( wxWindow* aParent, APP_SETTINGS_BASE* aAppSettings ) : @@ -87,7 +90,9 @@ bool PANEL_EESCHEMA_DISPLAY_OPTIONS::TransferDataFromWindow() SETTINGS_MANAGER& mgr = Pgm().GetSettingsManager(); EESCHEMA_SETTINGS* cfg = mgr.GetAppSettings(); - cfg->m_Appearance.default_font = m_defaultFontCtrl->GetStringSelection(); + cfg->m_Appearance.default_font = m_defaultFontCtrl->GetSelection() <= 0 + ? KICAD_FONT_NAME // This is a keyword. Do not translate + : m_defaultFontCtrl->GetStringSelection(); cfg->m_Appearance.show_hidden_pins = m_checkShowHiddenPins->GetValue(); cfg->m_Appearance.show_hidden_fields = m_checkShowHiddenFields->GetValue(); cfg->m_Appearance.show_erc_warnings = m_checkShowERCWarnings->GetValue(); diff --git a/include/font/kicad_font_name.h b/include/font/kicad_font_name.h new file mode 100644 index 0000000000..dfd9687fa7 --- /dev/null +++ b/include/font/kicad_font_name.h @@ -0,0 +1,27 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2022 KiCad Developers, see AUTHORS.txt for contributors. + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation, either version 3 of the License, or (at your + * option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ + +#ifndef KICAD_FONT_NAME_H +#define KICAD_FONT_NAME_H + +// The "official" name of the building Kicad stroke font (always existing) +// This is also a keyword, that cannot be translated +#define KICAD_FONT_NAME wxT( "KiCad Font" ) + +#endif //KICAD_FONT_NAME_H