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.
This commit is contained in:
jean-pierre charras 2022-01-13 14:31:00 +01:00
parent 15dc1b3a38
commit d0f2c20235
5 changed files with 59 additions and 5 deletions

View File

@ -32,6 +32,9 @@
#include <trigo.h>
#include <markup_parser.h>
// The "official" name of the building Kicad stroke font (always existing)
#include <font/kicad_font_name.h>
// 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<wxString, bool, bool> 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;
}

View File

@ -35,6 +35,9 @@
#include <geometry/shape_line_chain.h>
#include <trigo.h>
// The "official" name of the building Kicad stroke font (always existing)
#include <font/kicad_font_name.h>
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;
}

View File

@ -21,6 +21,9 @@
#include <wx/fontenum.h>
#include <font/fontconfig.h>
// The "official" name of the building Kicad stroke font (always existing)
#include <font/kicad_font_name.h>
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 );
}

View File

@ -30,6 +30,9 @@
#include <widgets/ui_common.h>
#include <widgets/font_choice.h>
// The "official" name of the building Kicad stroke font (always existing)
#include <font/kicad_font_name.h>
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<EESCHEMA_SETTINGS>();
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();

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
#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