KiCad PCB EDA Suite
Loading...
Searching...
No Matches
font_choice.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2021-2022 KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation, either version 3 of the License, or (at your
9 * option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#include <widgets/font_choice.h>
21#include <kiplatform/ui.h>
22#include <wx/fontenum.h>
23#include <font/fontconfig.h>
24#include <pgm_base.h>
25
26// The "official" name of the building Kicad stroke font (always existing)
28
29
30FONT_CHOICE::FONT_CHOICE( wxWindow* aParent, int aId, wxPoint aPosition, wxSize aSize,
31 int nChoices, wxString* aChoices, int aStyle ) :
32 wxChoice( aParent, aId, aPosition, aSize, nChoices, aChoices, aStyle )
33{
34 m_systemFontCount = wxChoice::GetCount();
35
36 std::vector<std::string> fontNames;
37 Fontconfig()->ListFonts( fontNames, std::string( Pgm().GetLanguageTag().utf8_str() ) );
38
39 wxArrayString menuList;
40
41 // The initial list of fonts has on top 1 or 2 options
42 // only "KiCad Font" (KICAD_FONT_NAME)
43 // "Default Font" and "KiCad Font" (KICAD_FONT_NAME)
44 // "KiCad Font" is also a keyword, and cannot be translated.
45 // So rebuilt the starting list
46 wxChoice::Clear();
47
48 if( m_systemFontCount > 1 )
49 Append( _( "Default Font" ) );
50
51 Append( KICAD_FONT_NAME );
52 m_systemFontCount = wxChoice::GetCount();
53
54 for( const std::string& name : fontNames )
55 menuList.Add( wxString( name ) );
56
57 menuList.Sort();
58
59 Freeze();
60 Append( menuList );
62 Thaw();
63
64 m_notFound = wxS( " " ) + _( "<not found>" );
65}
66
67
69{
70}
71
72
74{
75 if( !aFont )
76 {
77 SetSelection( 0 );
78 }
79 else
80 {
81 SetStringSelection( aFont->GetName() );
82
83 if( GetSelection() == wxNOT_FOUND )
84 {
85 Append( aFont->GetName() + m_notFound );
86 SetSelection( GetCount() );
87 }
88 }
89
90 SendSelectionChangedEvent( wxEVT_CHOICE );
91}
92
93
95{
96 int sel = GetSelection();
97
98 if( sel < 0 )
99 return false;
100
101 if( GetString( sel ).EndsWith( m_notFound ) )
102 return false;
103
104 return true;
105}
106
107
108KIFONT::FONT* FONT_CHOICE::GetFontSelection( bool aBold, bool aItalic ) const
109{
110 if( GetSelection() <= 0 )
111 return nullptr;
112 else if( GetSelection() == 1 && m_systemFontCount == 2 )
113 return KIFONT::FONT::GetFont( KICAD_FONT_NAME, aBold, aItalic );
114 else
115 return KIFONT::FONT::GetFont( GetStringSelection(), aBold, aItalic );
116}
117
const char * name
Definition: DXF_plotter.cpp:57
bool HaveFontSelection() const
Definition: font_choice.cpp:94
FONT_CHOICE(wxWindow *aParent, int aId, wxPoint aPosition, wxSize aSize, int nChoices, wxString *aChoices, int aStyle)
Definition: font_choice.cpp:30
int m_systemFontCount
Definition: font_choice.h:43
void SetFontSelection(KIFONT::FONT *aFont)
Definition: font_choice.cpp:73
virtual ~FONT_CHOICE()
Definition: font_choice.cpp:68
wxString m_notFound
Definition: font_choice.h:44
KIFONT::FONT * GetFontSelection(bool aBold, bool aItalic) const
FONT is an abstract base class for both outline and stroke fonts.
Definition: font.h:131
static FONT * GetFont(const wxString &aFontName=wxEmptyString, bool aBold=false, bool aItalic=false)
Definition: font.cpp:146
const wxString & GetName() const
Definition: font.h:147
#define _(s)
FONTCONFIG * Fontconfig()
Definition: fontconfig.cpp:90
#define KICAD_FONT_NAME
void LargeChoiceBoxHack(wxChoice *aChoice)
Configure a wxChoice control to support a lot of entries by disabling functionality that makes adding...
Definition: gtk/ui.cpp:136
PGM_BASE & Pgm()
The global Program "get" accessor.
Definition: pgm_base.cpp:1059
see class PGM_BASE