From aef2a3fca4012d1cb466bca67ac5dc941ecfaa1d Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Fri, 7 Jan 2022 00:47:23 +0000 Subject: [PATCH] Default font for eeschema. --- .../3d_canvas/create_3Dgraphic_brd_items.cpp | 4 +- common/eda_text.cpp | 30 ++-- .../panel_eeschema_display_options.cpp | 8 + .../panel_eeschema_display_options_base.cpp | 20 ++- .../panel_eeschema_display_options_base.fbp | 138 +++++++++++++++++- .../panel_eeschema_display_options_base.h | 9 +- eeschema/eeschema_settings.cpp | 3 + eeschema/eeschema_settings.h | 1 + eeschema/lib_field.cpp | 13 +- eeschema/lib_field.h | 2 + eeschema/lib_item.cpp | 11 ++ eeschema/lib_item.h | 2 + eeschema/lib_pin.cpp | 64 ++++---- eeschema/lib_pin.h | 2 + eeschema/lib_text.cpp | 13 +- eeschema/lib_text.h | 2 + eeschema/sch_field.cpp | 13 +- eeschema/sch_field.h | 2 + eeschema/sch_item.cpp | 15 +- eeschema/sch_item.h | 2 + eeschema/sch_painter.cpp | 10 +- eeschema/sch_text.cpp | 14 +- eeschema/sch_text.h | 2 + include/eda_text.h | 1 + .../dialogs/dialog_text_properties_base.cpp | 2 +- .../dialogs/dialog_text_properties_base.fbp | 2 +- pcbnew/fp_text.cpp | 2 +- pcbnew/pcb_text.cpp | 6 +- pcbnew/plot_brditems_plotter.cpp | 11 +- 29 files changed, 338 insertions(+), 66 deletions(-) diff --git a/3d-viewer/3d_canvas/create_3Dgraphic_brd_items.cpp b/3d-viewer/3d_canvas/create_3Dgraphic_brd_items.cpp index f30a367500..d9c4a598dd 100644 --- a/3d-viewer/3d_canvas/create_3Dgraphic_brd_items.cpp +++ b/3d-viewer/3d_canvas/create_3Dgraphic_brd_items.cpp @@ -115,7 +115,7 @@ void BOARD_ADAPTER::addShapeWithClearance( const PCB_TEXT* aText, CONTAINER_2D_B GRText( nullptr, aText->GetTextPos(), dummy_color, aText->GetShownText(), aText->GetTextAngle(), size, aText->GetHorizJustify(), aText->GetVertJustify(), penWidth, aText->IsItalic(), - isBold, aText->GetFont(), addTextSegmToContainer, &callbackData ); + isBold, aText->GetDrawFont(), addTextSegmToContainer, &callbackData ); } @@ -243,7 +243,7 @@ void BOARD_ADAPTER::addFootprintShapesWithClearance( const FOOTPRINT* aFootprint GRText( nullptr, text->GetTextPos(), BLACK, text->GetShownText(), text->GetDrawRotation(), size, text->GetHorizJustify(), text->GetVertJustify(), penWidth, text->IsItalic(), - isBold, text->GetFont(), addTextSegmToContainer, &callbackData ); + isBold, text->GetDrawFont(), addTextSegmToContainer, &callbackData ); } } diff --git a/common/eda_text.cpp b/common/eda_text.cpp index c329746f55..9d9f1e1262 100644 --- a/common/eda_text.cpp +++ b/common/eda_text.cpp @@ -399,6 +399,17 @@ void EDA_TEXT::cacheShownText() } +KIFONT::FONT* EDA_TEXT::GetDrawFont() const +{ + KIFONT::FONT* font = GetFont(); + + if( !font ) + font = KIFONT::FONT::GetFont( wxEmptyString, IsBold(), IsItalic() ); + + return font; +} + + std::vector>* EDA_TEXT::GetRenderCache( const wxString& forResolvedText ) const { @@ -457,12 +468,7 @@ wxString EDA_TEXT::ShortenedShownText() const int EDA_TEXT::GetInterline() const { - KIFONT::FONT* font = GetFont(); - - if( !font ) - font = KIFONT::FONT::GetFont( wxEmptyString, m_attributes.m_Bold, m_attributes.m_Italic ); - - return KiROUND( font->GetInterline( GetTextHeight() ) ); + return KiROUND( GetDrawFont()->GetInterline( GetTextHeight() ) ); } @@ -502,7 +508,7 @@ EDA_RECT EDA_TEXT::GetTextBox( int aLine, bool aInvertY ) const } // calculate the H and V size - KIFONT::FONT* font = KIFONT::FONT::GetFont(); + KIFONT::FONT* font = GetDrawFont(); VECTOR2D fontSize( GetTextSize() ); double penWidth( thickness ); int dx = KiROUND( font->StringBoundaryLimits( text, fontSize, penWidth ).x ); @@ -626,6 +632,7 @@ void EDA_TEXT::Print( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset, GetLinePositions( positions, strings.Count() ); + // FONT TODO: this is going to use the KiCad font because it doesn't know any better... for( unsigned ii = 0; ii < strings.Count(); ii++ ) printOneLineOfText( aSettings, aOffset, aColor, aFillMode, strings[ii], positions[ii] ); } @@ -692,7 +699,7 @@ void EDA_TEXT::printOneLineOfText( const RENDER_SETTINGS* aSettings, const VECTO size.x = -size.x; GRText( DC, aOffset + aPos, aColor, aText, GetTextAngle(), size, GetHorizJustify(), - GetVertJustify(), penWidth, IsItalic(), IsBold(), GetFont() ); + GetVertJustify(), penWidth, IsItalic(), IsBold(), GetDrawFont() ); } @@ -808,8 +815,9 @@ void EDA_TEXT::Format( OUTPUTFORMATTER* aFormatter, int aNestLevel, int aControl std::shared_ptr EDA_TEXT::GetEffectiveTextShape( ) const { std::shared_ptr shape = std::make_shared(); + KIFONT::FONT* font = GetDrawFont(); - if( GetFont() && GetFont()->IsOutline() ) + if( font->IsOutline() ) { // Make sure the cache is up-to-date before using it (void) GetRenderCache( m_render_cache_text ); @@ -864,14 +872,14 @@ std::shared_ptr EDA_TEXT::GetEffectiveTextShape( ) const { GRText( nullptr, positions[ii], COLOR4D::BLACK, strings_list.Item( ii ), GetDrawRotation(), size, GetDrawHorizJustify(), GetDrawVertJustify(), - penWidth, IsItalic(), forceBold, GetFont(), addTextSegmToShape, &prms ); + penWidth, IsItalic(), forceBold, font, addTextSegmToShape, &prms ); } } else { GRText( nullptr, GetDrawPos(), COLOR4D::BLACK, GetShownText(), GetDrawRotation(), size, GetDrawHorizJustify(), GetDrawVertJustify(), - penWidth, IsItalic(), forceBold, GetFont(), addTextSegmToShape, &prms ); + penWidth, IsItalic(), forceBold, font, addTextSegmToShape, &prms ); } } diff --git a/eeschema/dialogs/panel_eeschema_display_options.cpp b/eeschema/dialogs/panel_eeschema_display_options.cpp index 5249f007b7..4098346949 100644 --- a/eeschema/dialogs/panel_eeschema_display_options.cpp +++ b/eeschema/dialogs/panel_eeschema_display_options.cpp @@ -28,6 +28,8 @@ #include #include #include +#include + PANEL_EESCHEMA_DISPLAY_OPTIONS::PANEL_EESCHEMA_DISPLAY_OPTIONS( wxWindow* aParent, APP_SETTINGS_BASE* aAppSettings ) : @@ -43,6 +45,11 @@ PANEL_EESCHEMA_DISPLAY_OPTIONS::PANEL_EESCHEMA_DISPLAY_OPTIONS( wxWindow* aParen void PANEL_EESCHEMA_DISPLAY_OPTIONS::loadEEschemaSettings( EESCHEMA_SETTINGS* cfg ) { + m_defaultFontCtrl->SetStringSelection( cfg->m_Appearance.default_font ); + + if( m_defaultFontCtrl->GetSelection() < 0 ) + m_defaultFontCtrl->SetSelection( 0 ); + m_checkShowHiddenPins->SetValue( cfg->m_Appearance.show_hidden_pins ); m_checkShowHiddenFields->SetValue( cfg->m_Appearance.show_hidden_fields ); m_checkShowERCErrors->SetValue( cfg->m_Appearance.show_erc_errors ); @@ -80,6 +87,7 @@ 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.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/eeschema/dialogs/panel_eeschema_display_options_base.cpp b/eeschema/dialogs/panel_eeschema_display_options_base.cpp index 7768b3fb87..66e877d870 100644 --- a/eeschema/dialogs/panel_eeschema_display_options_base.cpp +++ b/eeschema/dialogs/panel_eeschema_display_options_base.cpp @@ -5,6 +5,8 @@ // PLEASE DO *NOT* EDIT THIS FILE! /////////////////////////////////////////////////////////////////////////// +#include "widgets/font_choice.h" + #include "panel_eeschema_display_options_base.h" /////////////////////////////////////////////////////////////////////////// @@ -25,8 +27,24 @@ PANEL_EESCHEMA_DISPLAY_OPTIONS_BASE::PANEL_EESCHEMA_DISPLAY_OPTIONS_BASE( wxWind wxStaticBoxSizer* sbSizer1; sbSizer1 = new wxStaticBoxSizer( new wxStaticBox( this, wxID_ANY, _("Appearance") ), wxVERTICAL ); + wxBoxSizer* bSizer4; + bSizer4 = new wxBoxSizer( wxHORIZONTAL ); + + m_defaultFontLabel = new wxStaticText( sbSizer1->GetStaticBox(), wxID_ANY, _("Default font:"), wxDefaultPosition, wxDefaultSize, 0 ); + m_defaultFontLabel->Wrap( -1 ); + bSizer4->Add( m_defaultFontLabel, 0, wxRIGHT|wxLEFT|wxALIGN_CENTER_VERTICAL, 5 ); + + wxString m_defaultFontCtrlChoices[] = { _("KiCad Font") }; + int m_defaultFontCtrlNChoices = sizeof( m_defaultFontCtrlChoices ) / sizeof( wxString ); + m_defaultFontCtrl = new FONT_CHOICE( sbSizer1->GetStaticBox(), wxID_ANY, wxDefaultPosition, wxDefaultSize, m_defaultFontCtrlNChoices, m_defaultFontCtrlChoices, 0 ); + m_defaultFontCtrl->SetSelection( 0 ); + bSizer4->Add( m_defaultFontCtrl, 0, wxALIGN_CENTER_VERTICAL, 5 ); + + + sbSizer1->Add( bSizer4, 1, wxEXPAND, 5 ); + m_checkShowHiddenPins = new wxCheckBox( sbSizer1->GetStaticBox(), wxID_ANY, _("S&how hidden pins"), wxDefaultPosition, wxDefaultSize, 0 ); - sbSizer1->Add( m_checkShowHiddenPins, 0, wxEXPAND|wxBOTTOM|wxRIGHT|wxLEFT, 5 ); + sbSizer1->Add( m_checkShowHiddenPins, 0, wxEXPAND|wxALL, 5 ); m_checkShowHiddenFields = new wxCheckBox( sbSizer1->GetStaticBox(), wxID_ANY, _("Show hidden fields"), wxDefaultPosition, wxDefaultSize, 0 ); sbSizer1->Add( m_checkShowHiddenFields, 0, wxBOTTOM|wxRIGHT|wxLEFT|wxEXPAND, 5 ); diff --git a/eeschema/dialogs/panel_eeschema_display_options_base.fbp b/eeschema/dialogs/panel_eeschema_display_options_base.fbp index be6523044d..a5bee52063 100644 --- a/eeschema/dialogs/panel_eeschema_display_options_base.fbp +++ b/eeschema/dialogs/panel_eeschema_display_options_base.fbp @@ -86,9 +86,145 @@ wxVERTICAL 1 none + + 5 + wxEXPAND + 1 + + + bSizer4 + wxHORIZONTAL + none + + 5 + wxRIGHT|wxLEFT|wxALIGN_CENTER_VERTICAL + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + Default font: + 0 + + 0 + + + 0 + + 1 + m_defaultFontLabel + 1 + + + protected + 1 + + Resizable + 1 + + + ; ; forward_declare + 0 + + + + + -1 + + + + 5 + wxALIGN_CENTER_VERTICAL + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + "KiCad Font" + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + + 0 + + + 0 + + 1 + m_defaultFontCtrl + 1 + + + protected + 1 + + Resizable + 0 + 1 + + + FONT_CHOICE; widgets/font_choice.h; forward_declare + 0 + + + wxFILTER_NONE + wxDefaultValidator + + + + + + + + 5 - wxEXPAND|wxBOTTOM|wxRIGHT|wxLEFT + wxEXPAND|wxALL 0 1 diff --git a/eeschema/dialogs/panel_eeschema_display_options_base.h b/eeschema/dialogs/panel_eeschema_display_options_base.h index 586fd8daff..749bd7f211 100644 --- a/eeschema/dialogs/panel_eeschema_display_options_base.h +++ b/eeschema/dialogs/panel_eeschema_display_options_base.h @@ -10,16 +10,19 @@ #include #include #include +class FONT_CHOICE; + #include "widgets/resettable_panel.h" #include #include #include -#include +#include #include #include #include +#include +#include #include -#include #include #include #include @@ -35,6 +38,8 @@ class PANEL_EESCHEMA_DISPLAY_OPTIONS_BASE : public RESETTABLE_PANEL protected: wxBoxSizer* m_galOptionsSizer; + wxStaticText* m_defaultFontLabel; + FONT_CHOICE* m_defaultFontCtrl; wxCheckBox* m_checkShowHiddenPins; wxCheckBox* m_checkShowHiddenFields; wxCheckBox* m_checkShowERCErrors; diff --git a/eeschema/eeschema_settings.cpp b/eeschema/eeschema_settings.cpp index 336bae9daa..a4eac78a12 100644 --- a/eeschema/eeschema_settings.cpp +++ b/eeschema/eeschema_settings.cpp @@ -94,6 +94,9 @@ EESCHEMA_SETTINGS::EESCHEMA_SETTINGS() : m_params.emplace_back( new PARAM( "appearance.print_sheet_reference", &m_Appearance.print_sheet_reference, true ) ); + m_params.emplace_back( new PARAM( "appearance.default_font", + &m_Appearance.default_font, "KiCad Font" ) ); + m_params.emplace_back( new PARAM( "appearance.show_hidden_pins", &m_Appearance.show_hidden_pins, false ) ); diff --git a/eeschema/eeschema_settings.h b/eeschema/eeschema_settings.h index ad78c17fde..5c82814f53 100644 --- a/eeschema/eeschema_settings.h +++ b/eeschema/eeschema_settings.h @@ -42,6 +42,7 @@ public: bool footprint_preview; bool navigator_stays_open; bool print_sheet_reference; + wxString default_font; bool show_hidden_pins; bool show_hidden_fields; bool show_erc_warnings; diff --git a/eeschema/lib_field.cpp b/eeschema/lib_field.cpp index 68bcbd1453..5ec9561cf1 100644 --- a/eeschema/lib_field.cpp +++ b/eeschema/lib_field.cpp @@ -111,6 +111,17 @@ int LIB_FIELD::GetPenWidth() const } +KIFONT::FONT* LIB_FIELD::GetDrawFont() const +{ + KIFONT::FONT* font = EDA_TEXT::GetFont(); + + if( !font ) + font = KIFONT::FONT::GetFont( GetDefaultFont(), IsBold(), IsItalic() ); + + return font; +} + + void LIB_FIELD::print( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset, void* aData, const TRANSFORM& aTransform ) { @@ -121,7 +132,7 @@ void LIB_FIELD::print( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset wxString text = aData ? *static_cast( aData ) : GetText(); GRText( DC, text_pos, color, text, GetTextAngle(), GetTextSize(), GetHorizJustify(), - GetVertJustify(), penWidth, IsItalic(), IsBold(), GetFont() ); + GetVertJustify(), penWidth, IsItalic(), IsBold(), GetDrawFont() ); } diff --git a/eeschema/lib_field.h b/eeschema/lib_field.h index 948e383327..892341e2a6 100644 --- a/eeschema/lib_field.h +++ b/eeschema/lib_field.h @@ -117,6 +117,8 @@ public: int GetPenWidth() const override; + KIFONT::FONT* GetDrawFont() const override; + /** * Copy parameters of this field to another field. Pointers are not copied. * diff --git a/eeschema/lib_item.cpp b/eeschema/lib_item.cpp index 0036c81950..b20f9ce6e5 100644 --- a/eeschema/lib_item.cpp +++ b/eeschema/lib_item.cpp @@ -23,6 +23,9 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ +#include +#include +#include #include #include #include @@ -115,6 +118,14 @@ bool LIB_ITEM::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy ) } +const wxString& LIB_ITEM::GetDefaultFont() const +{ + EESCHEMA_SETTINGS* cfg = Pgm().GetSettingsManager().GetAppSettings(); + + return cfg->m_Appearance.default_font; +} + + void LIB_ITEM::Print( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset, void* aData, const TRANSFORM& aTransform ) { diff --git a/eeschema/lib_item.h b/eeschema/lib_item.h index 19748d7578..0924f759e0 100644 --- a/eeschema/lib_item.h +++ b/eeschema/lib_item.h @@ -142,6 +142,8 @@ public: virtual int GetPenWidth() const = 0; + const wxString& GetDefaultFont() const; + virtual int GetEffectivePenWidth( const RENDER_SETTINGS* aSettings ) const { // For historical reasons, a stored value of 0 means "default width" and negative diff --git a/eeschema/lib_pin.cpp b/eeschema/lib_pin.cpp index 224d64c453..f19c5593cb 100644 --- a/eeschema/lib_pin.cpp +++ b/eeschema/lib_pin.cpp @@ -170,6 +170,12 @@ int LIB_PIN::GetPenWidth() const } +KIFONT::FONT* LIB_PIN::GetDrawFont() const +{ + return KIFONT::FONT::GetFont( GetDefaultFont(), false, false ); +} + + wxString LIB_PIN::GetShownName() const { if( m_name == "~" ) @@ -348,10 +354,12 @@ void LIB_PIN::printPinTexts( const RENDER_SETTINGS* aSettings, VECTOR2I& aPinPos if( !aDrawPinName && !aDrawPinNum ) return; - int x, y; - wxDC* DC = aSettings->GetPrintDC(); - wxSize PinNameSize( m_nameTextSize, m_nameTextSize ); - wxSize PinNumSize( m_numTextSize, m_numTextSize ); + int x, y; + wxDC* DC = aSettings->GetPrintDC(); + KIFONT::FONT* font = GetDrawFont(); + + wxSize pinNameSize( m_nameTextSize, m_nameTextSize ); + wxSize pinNumSize( m_numTextSize, m_numTextSize ); int namePenWidth = std::max( Clamp_Text_PenSize( GetPenWidth(), m_nameTextSize, false ), aSettings->GetDefaultPenWidth() ); @@ -396,23 +404,23 @@ void LIB_PIN::printPinTexts( const RENDER_SETTINGS* aSettings, VECTOR2I& aPinPos { x = x1 + aTextInside; GRText( DC, VECTOR2I( x, y1 ), NameColor, name, EDA_ANGLE::HORIZONTAL, - PinNameSize, GR_TEXT_H_ALIGN_LEFT, GR_TEXT_V_ALIGN_CENTER, namePenWidth, - false, false, nullptr ); + pinNameSize, GR_TEXT_H_ALIGN_LEFT, GR_TEXT_V_ALIGN_CENTER, namePenWidth, + false, false, font ); } else // Orient == PIN_LEFT { x = x1 - aTextInside; GRText( DC, VECTOR2I( x, y1 ), NameColor, name, EDA_ANGLE::HORIZONTAL, - PinNameSize, GR_TEXT_H_ALIGN_RIGHT, GR_TEXT_V_ALIGN_CENTER, namePenWidth, - false, false, nullptr ); + pinNameSize, GR_TEXT_H_ALIGN_RIGHT, GR_TEXT_V_ALIGN_CENTER, namePenWidth, + false, false, font ); } } if( aDrawPinNum ) { GRText( DC, VECTOR2I(( x1 + aPinPos.x) / 2, y1 - num_offset ), NumColor, number, - EDA_ANGLE::HORIZONTAL, PinNumSize, GR_TEXT_H_ALIGN_CENTER, - GR_TEXT_V_ALIGN_BOTTOM, numPenWidth, false, false, nullptr ); + EDA_ANGLE::HORIZONTAL, pinNumSize, GR_TEXT_H_ALIGN_CENTER, + GR_TEXT_V_ALIGN_BOTTOM, numPenWidth, false, false, font ); } } else /* Its a vertical line. */ @@ -424,16 +432,16 @@ void LIB_PIN::printPinTexts( const RENDER_SETTINGS* aSettings, VECTOR2I& aPinPos if( aDrawPinName ) { - GRText( DC, VECTOR2I( x1, y ), NameColor, name, EDA_ANGLE::VERTICAL, PinNameSize, + GRText( DC, VECTOR2I( x1, y ), NameColor, name, EDA_ANGLE::VERTICAL, pinNameSize, GR_TEXT_H_ALIGN_RIGHT, GR_TEXT_V_ALIGN_CENTER, namePenWidth, false, - false, nullptr ); + false, font ); } if( aDrawPinNum ) { GRText( DC, VECTOR2I( x1 - num_offset, ( y1 + aPinPos.y) / 2 ), NumColor, - number, EDA_ANGLE::VERTICAL, PinNumSize, GR_TEXT_H_ALIGN_CENTER, - GR_TEXT_V_ALIGN_BOTTOM, numPenWidth, false, false, nullptr ); + number, EDA_ANGLE::VERTICAL, pinNumSize, GR_TEXT_H_ALIGN_CENTER, + GR_TEXT_V_ALIGN_BOTTOM, numPenWidth, false, false, font ); } } else /* PIN_UP */ @@ -442,16 +450,16 @@ void LIB_PIN::printPinTexts( const RENDER_SETTINGS* aSettings, VECTOR2I& aPinPos if( aDrawPinName ) { - GRText( DC, VECTOR2I( x1, y ), NameColor, name, EDA_ANGLE::VERTICAL, PinNameSize, + GRText( DC, VECTOR2I( x1, y ), NameColor, name, EDA_ANGLE::VERTICAL, pinNameSize, GR_TEXT_H_ALIGN_LEFT, GR_TEXT_V_ALIGN_CENTER, namePenWidth, false, - false, nullptr ); + false, font ); } if( aDrawPinNum ) { GRText( DC, VECTOR2I( x1 - num_offset, ( y1 + aPinPos.y) / 2 ), NumColor, - number, EDA_ANGLE::VERTICAL, PinNumSize, GR_TEXT_H_ALIGN_CENTER, - GR_TEXT_V_ALIGN_BOTTOM, numPenWidth, false, false, nullptr ); + number, EDA_ANGLE::VERTICAL, pinNumSize, GR_TEXT_H_ALIGN_CENTER, + GR_TEXT_V_ALIGN_BOTTOM, numPenWidth, false, false, font ); } } } @@ -465,15 +473,15 @@ void LIB_PIN::printPinTexts( const RENDER_SETTINGS* aSettings, VECTOR2I& aPinPos { x = ( x1 + aPinPos.x) / 2; GRText( DC, VECTOR2I( x, y1 - name_offset ), NameColor, name, EDA_ANGLE::HORIZONTAL, - PinNameSize, GR_TEXT_H_ALIGN_CENTER, GR_TEXT_V_ALIGN_BOTTOM, - namePenWidth, false, false, nullptr ); + pinNameSize, GR_TEXT_H_ALIGN_CENTER, GR_TEXT_V_ALIGN_BOTTOM, + namePenWidth, false, false, font ); } if( aDrawPinNum ) { x = ( x1 + aPinPos.x) / 2; GRText( DC, VECTOR2I( x, y1 + num_offset ), NumColor, number, EDA_ANGLE::HORIZONTAL, - PinNumSize, GR_TEXT_H_ALIGN_CENTER, GR_TEXT_V_ALIGN_TOP, numPenWidth, - false, false, nullptr ); + pinNumSize, GR_TEXT_H_ALIGN_CENTER, GR_TEXT_V_ALIGN_TOP, numPenWidth, + false, false, font ); } } else /* Its a vertical line. */ @@ -482,15 +490,15 @@ void LIB_PIN::printPinTexts( const RENDER_SETTINGS* aSettings, VECTOR2I& aPinPos { y = ( y1 + aPinPos.y) / 2; GRText( DC, VECTOR2I( x1 - name_offset, y ), NameColor, name, EDA_ANGLE::VERTICAL, - PinNameSize, GR_TEXT_H_ALIGN_CENTER, GR_TEXT_V_ALIGN_BOTTOM, - namePenWidth, false, false, nullptr ); + pinNameSize, GR_TEXT_H_ALIGN_CENTER, GR_TEXT_V_ALIGN_BOTTOM, + namePenWidth, false, false, font ); } if( aDrawPinNum ) { GRText( DC, VECTOR2I( x1 + num_offset, ( y1 + aPinPos.y) / 2 ), NumColor, number, - EDA_ANGLE::VERTICAL, PinNumSize, GR_TEXT_H_ALIGN_CENTER, GR_TEXT_V_ALIGN_TOP, - numPenWidth, false, false, nullptr ); + EDA_ANGLE::VERTICAL, pinNumSize, GR_TEXT_H_ALIGN_CENTER, GR_TEXT_V_ALIGN_TOP, + numPenWidth, false, false, font ); } } } @@ -547,7 +555,7 @@ void LIB_PIN::printPinElectricalTypeName( const RENDER_SETTINGS* aSettings, VECT } GRText( DC, txtpos, color, typeName, orient, wxSize( textSize, textSize ), hjustify, - GR_TEXT_V_ALIGN_CENTER, pensize, false, false, nullptr ); + GR_TEXT_V_ALIGN_CENTER, pensize, false, false, GetDrawFont() ); } @@ -1069,7 +1077,7 @@ void LIB_PIN::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector()->m_Appearance.default_font ); EDA_RECT bbox; VECTOR2I begin; diff --git a/eeschema/lib_pin.h b/eeschema/lib_pin.h index f9462e9c88..f842fc9d97 100644 --- a/eeschema/lib_pin.h +++ b/eeschema/lib_pin.h @@ -191,6 +191,8 @@ public: int GetPenWidth() const override; + KIFONT::FONT* GetDrawFont() const; + /** * Plot the pin number and pin text info, given the pin line coordinates. * Same as DrawPinTexts((), but output is the plotter diff --git a/eeschema/lib_text.cpp b/eeschema/lib_text.cpp index 92e501c7fb..356dca4408 100644 --- a/eeschema/lib_text.cpp +++ b/eeschema/lib_text.cpp @@ -296,6 +296,17 @@ int LIB_TEXT::GetPenWidth() const } +KIFONT::FONT* LIB_TEXT::GetDrawFont() const +{ + KIFONT::FONT* font = EDA_TEXT::GetFont(); + + if( !font ) + font = KIFONT::FONT::GetFont( GetDefaultFont(), IsBold(), IsItalic() ); + + return font; +} + + void LIB_TEXT::print( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset, void* aData, const TRANSFORM& aTransform ) { @@ -335,7 +346,7 @@ void LIB_TEXT::print( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset, txtpos = aTransform.TransformCoordinate( txtpos ) + aOffset; GRText( DC, txtpos, color, GetShownText(), orient, GetTextSize(), GR_TEXT_H_ALIGN_CENTER, - GR_TEXT_V_ALIGN_CENTER, penWidth, IsItalic(), IsBold(), GetFont() ); + GR_TEXT_V_ALIGN_CENTER, penWidth, IsItalic(), IsBold(), GetDrawFont() ); } diff --git a/eeschema/lib_text.h b/eeschema/lib_text.h index 51437a8b16..7e96685e21 100644 --- a/eeschema/lib_text.h +++ b/eeschema/lib_text.h @@ -79,6 +79,8 @@ public: int GetPenWidth() const override; + KIFONT::FONT* GetDrawFont() const override; + const EDA_RECT GetBoundingBox() const override; void BeginEdit( const VECTOR2I& aStartPoint ) override; diff --git a/eeschema/sch_field.cpp b/eeschema/sch_field.cpp index aa64be89d0..46bed51079 100644 --- a/eeschema/sch_field.cpp +++ b/eeschema/sch_field.cpp @@ -215,6 +215,17 @@ int SCH_FIELD::GetPenWidth() const } +KIFONT::FONT* SCH_FIELD::GetDrawFont() const +{ + KIFONT::FONT* font = EDA_TEXT::GetFont(); + + if( !font ) + font = KIFONT::FONT::GetFont( GetDefaultFont(), IsBold(), IsItalic() ); + + return font; +} + + void SCH_FIELD::Print( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset ) { wxDC* DC = aSettings->GetPrintDC(); @@ -254,7 +265,7 @@ void SCH_FIELD::Print( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset textpos = GetBoundingBox().Centre() + aOffset; GRText( DC, textpos, color, GetShownText(), orient, GetTextSize(), GR_TEXT_H_ALIGN_CENTER, - GR_TEXT_V_ALIGN_CENTER, penWidth, IsItalic(), IsBold(), GetFont() ); + GR_TEXT_V_ALIGN_CENTER, penWidth, IsItalic(), IsBold(), GetDrawFont() ); } diff --git a/eeschema/sch_field.h b/eeschema/sch_field.h index 8dfeb0bbdc..6e63b38f9b 100644 --- a/eeschema/sch_field.h +++ b/eeschema/sch_field.h @@ -154,6 +154,8 @@ public: int GetPenWidth() const override; + KIFONT::FONT* GetDrawFont() const override; + void Print( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset ) override; void Move( const VECTOR2I& aMoveVector ) override diff --git a/eeschema/sch_item.cpp b/eeschema/sch_item.cpp index 4c36ce4755..7333a19b3a 100644 --- a/eeschema/sch_item.cpp +++ b/eeschema/sch_item.cpp @@ -22,6 +22,9 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ +#include +#include +#include #include #include #include @@ -37,9 +40,7 @@ /* Constructor and destructor for SCH_ITEM */ -/* They are not inline because this creates problems with gcc at linking time - * in debug mode - */ +/* They are not inline because this creates problems with gcc at linking time in debug mode */ SCH_ITEM::SCH_ITEM( EDA_ITEM* aParent, KICAD_T aType ) : EDA_ITEM( aParent, aType ) @@ -244,6 +245,14 @@ bool SCH_ITEM::operator < ( const SCH_ITEM& aItem ) const } +const wxString& SCH_ITEM::GetDefaultFont() const +{ + EESCHEMA_SETTINGS* cfg = Pgm().GetSettingsManager().GetAppSettings(); + + return cfg->m_Appearance.default_font; +} + + void SCH_ITEM::Plot( PLOTTER* aPlotter ) const { wxFAIL_MSG( wxT( "Plot() method not implemented for class " ) + GetClass() ); diff --git a/eeschema/sch_item.h b/eeschema/sch_item.h index 45981ed5cc..ac75ef5329 100644 --- a/eeschema/sch_item.h +++ b/eeschema/sch_item.h @@ -259,6 +259,8 @@ public: */ virtual int GetPenWidth() const { return 0; } + const wxString& GetDefaultFont() const; + /** * Print a schematic item. * diff --git a/eeschema/sch_painter.cpp b/eeschema/sch_painter.cpp index b498f6555d..e545292219 100644 --- a/eeschema/sch_painter.cpp +++ b/eeschema/sch_painter.cpp @@ -441,7 +441,10 @@ void SCH_PAINTER::strokeText( const wxString& aText, const VECTOR2D& aPosition, KIFONT::FONT* font = aAttrs.m_Font; if( !font ) - font = KIFONT::FONT::GetFont( wxEmptyString, aAttrs.m_Bold, aAttrs.m_Italic ); + { + font = KIFONT::FONT::GetFont( eeconfig()->m_Appearance.default_font, aAttrs.m_Bold, + aAttrs.m_Italic ); + } m_gal->SetIsFill( font->IsOutline() ); m_gal->SetIsStroke( font->IsStroke() ); @@ -456,7 +459,10 @@ void SCH_PAINTER::boxText( const wxString& aText, const VECTOR2D& aPosition, KIFONT::FONT* font = aAttrs.m_Font; if( !font ) - font = KIFONT::FONT::GetFont( wxEmptyString, aAttrs.m_Bold, aAttrs.m_Italic ); + { + font = KIFONT::FONT::GetFont( eeconfig()->m_Appearance.default_font, aAttrs.m_Bold, + aAttrs.m_Italic ); + } VECTOR2D extents = font->StringBoundaryLimits( aText, aAttrs.m_Size, aAttrs.m_StrokeWidth ); EDA_RECT box( (VECTOR2I) aPosition, wxSize( extents.x, aAttrs.m_Size.y ) ); diff --git a/eeschema/sch_text.cpp b/eeschema/sch_text.cpp index dcfbc500ec..86a6a30265 100644 --- a/eeschema/sch_text.cpp +++ b/eeschema/sch_text.cpp @@ -403,6 +403,17 @@ int SCH_TEXT::GetPenWidth() const } +KIFONT::FONT* SCH_TEXT::GetDrawFont() const +{ + KIFONT::FONT* font = EDA_TEXT::GetFont(); + + if( !font ) + font = KIFONT::FONT::GetFont( GetDefaultFont(), IsBold(), IsItalic() ); + + return font; +} + + void SCH_TEXT::Print( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset ) { COLOR4D color = aSettings->GetLayerColor( m_layer ); @@ -545,6 +556,7 @@ void SCH_TEXT::Plot( PLOTTER* aPlotter ) const int layer = ( connection && connection->IsBus() ) ? LAYER_BUS : m_layer; COLOR4D color = settings->GetLayerColor( layer ); int penWidth = GetEffectiveTextPenWidth( settings->GetDefaultPenWidth() ); + KIFONT::FONT* font = GetDrawFont(); penWidth = std::max( penWidth, settings->GetMinPenWidth() ); aPlotter->SetCurrentLineWidth( penWidth ); @@ -561,7 +573,7 @@ void SCH_TEXT::Plot( PLOTTER* aPlotter ) const VECTOR2I textpos = positions[ii] + GetSchematicTextOffset( aPlotter->RenderSettings() ); wxString& txt = strings_list.Item( ii ); aPlotter->Text( textpos, color, txt, GetTextAngle(), GetTextSize(), GetHorizJustify(), - GetVertJustify(), penWidth, IsItalic(), IsBold() ); + GetVertJustify(), penWidth, IsItalic(), IsBold(), false, font ); } } diff --git a/eeschema/sch_text.h b/eeschema/sch_text.h index b7421c6a4e..e3a38c6375 100644 --- a/eeschema/sch_text.h +++ b/eeschema/sch_text.h @@ -173,6 +173,8 @@ public: int GetPenWidth() const override; + KIFONT::FONT* GetDrawFont() const override; + void Move( const VECTOR2I& aMoveVector ) override { EDA_TEXT::Offset( aMoveVector ); diff --git a/include/eda_text.h b/include/eda_text.h index b11f8b625f..c351ff28c9 100644 --- a/include/eda_text.h +++ b/include/eda_text.h @@ -336,6 +336,7 @@ public: */ virtual void Format( OUTPUTFORMATTER* aFormatter, int aNestLevel, int aControlBits ) const; + virtual KIFONT::FONT* GetDrawFont() const; virtual EDA_ANGLE GetDrawRotation() const { return GetTextAngle(); } virtual VECTOR2I GetDrawPos() const { return GetTextPos(); } virtual GR_TEXT_H_ALIGN_T GetDrawHorizJustify() const { return GetHorizJustify(); }; diff --git a/pcbnew/dialogs/dialog_text_properties_base.cpp b/pcbnew/dialogs/dialog_text_properties_base.cpp index 88907245d2..ec4c8a4b58 100644 --- a/pcbnew/dialogs/dialog_text_properties_base.cpp +++ b/pcbnew/dialogs/dialog_text_properties_base.cpp @@ -109,7 +109,7 @@ DIALOG_TEXT_PROPERTIES_BASE::DIALOG_TEXT_PROPERTIES_BASE( wxWindow* parent, wxWi m_fontLabel->Wrap( -1 ); gbSizer1->Add( m_fontLabel, wxGBPosition( 2, 0 ), wxGBSpan( 1, 1 ), wxALIGN_CENTER_VERTICAL|wxALL, 5 ); - wxString m_fontCtrlChoices[] = { _("Default Font"), _("KiCad Font") }; + wxString m_fontCtrlChoices[] = { _("KiCad Font") }; int m_fontCtrlNChoices = sizeof( m_fontCtrlChoices ) / sizeof( wxString ); m_fontCtrl = new FONT_CHOICE( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, m_fontCtrlNChoices, m_fontCtrlChoices, 0 ); m_fontCtrl->SetSelection( 0 ); diff --git a/pcbnew/dialogs/dialog_text_properties_base.fbp b/pcbnew/dialogs/dialog_text_properties_base.fbp index 0c1725b477..c154fb807a 100644 --- a/pcbnew/dialogs/dialog_text_properties_base.fbp +++ b/pcbnew/dialogs/dialog_text_properties_base.fbp @@ -777,7 +777,7 @@ 1 0 - "Default Font" "KiCad Font" + "KiCad Font" 1 1 diff --git a/pcbnew/fp_text.cpp b/pcbnew/fp_text.cpp index 9ef6f195ba..a30abf1b0e 100644 --- a/pcbnew/fp_text.cpp +++ b/pcbnew/fp_text.cpp @@ -476,7 +476,7 @@ void FP_TEXT::TransformTextShapeWithClearanceToPolygon( SHAPE_POLY_SET& aCornerB size.x = -size.x; GRText( nullptr, GetTextPos(), BLACK, GetShownText(), GetDrawRotation(), size, - GetHorizJustify(), GetVertJustify(), penWidth, IsItalic(), IsBold(), GetFont(), + GetHorizJustify(), GetVertJustify(), penWidth, IsItalic(), IsBold(), GetDrawFont(), addTextSegmToPoly, &prms ); } diff --git a/pcbnew/pcb_text.cpp b/pcbnew/pcb_text.cpp index 53e496e67f..84dd5f34cf 100644 --- a/pcbnew/pcb_text.cpp +++ b/pcbnew/pcb_text.cpp @@ -241,10 +241,10 @@ void PCB_TEXT::TransformTextShapeWithClearanceToPolygon( SHAPE_POLY_SET& aCorner prms.m_cornerBuffer = &aCornerBuffer; prms.m_textWidth = GetEffectiveTextPenWidth() + ( 2 * aClearanceValue ); prms.m_error = aError; - COLOR4D color; // not actually used, but needed by GRText - GRText( nullptr, GetTextPos(), color, GetShownText(), GetTextAngle(), size, GetHorizJustify(), - GetVertJustify(), penWidth, IsItalic(), IsBold(), GetFont(), addTextSegmToPoly, &prms ); + GRText( nullptr, GetTextPos(), COLOR4D::BLACK, GetShownText(), GetTextAngle(), size, + GetHorizJustify(), GetVertJustify(), penWidth, IsItalic(), IsBold(), GetDrawFont(), + addTextSegmToPoly, &prms ); } diff --git a/pcbnew/plot_brditems_plotter.cpp b/pcbnew/plot_brditems_plotter.cpp index 02680e43d8..e2abae75fe 100644 --- a/pcbnew/plot_brditems_plotter.cpp +++ b/pcbnew/plot_brditems_plotter.cpp @@ -412,7 +412,7 @@ void BRDITEMS_PLOTTER::PlotFootprintTextItem( const FP_TEXT* aText, const COLOR4 m_plotter->Text( pos, aColor, aText->GetShownText(), aText->GetDrawRotation(), size, aText->GetHorizJustify(), aText->GetVertJustify(), thickness, - aText->IsItalic(), allow_bold, false, aText->GetFont(), &gbr_metadata ); + aText->IsItalic(), allow_bold, false, aText->GetDrawFont(), &gbr_metadata ); } @@ -736,7 +736,8 @@ void BRDITEMS_PLOTTER::PlotFootprintGraphicItem( const FP_SHAPE* aShape ) void BRDITEMS_PLOTTER::PlotPcbText( const PCB_TEXT* aText ) { - wxString shownText( aText->GetShownText() ); + wxString shownText( aText->GetShownText() ); + KIFONT::FONT* font = aText->GetDrawFont(); if( shownText.IsEmpty() ) return; @@ -781,16 +782,14 @@ void BRDITEMS_PLOTTER::PlotPcbText( const PCB_TEXT* aText ) wxString& txt = strings_list.Item( ii ); m_plotter->Text( positions[ii], color, txt, aText->GetTextAngle(), size, aText->GetHorizJustify(), aText->GetVertJustify(), thickness, - aText->IsItalic(), allow_bold, false, aText->GetFont(), - &gbr_metadata ); + aText->IsItalic(), allow_bold, false, font, &gbr_metadata ); } } else { m_plotter->Text( pos, color, shownText, aText->GetTextAngle(), size, aText->GetHorizJustify(), aText->GetVertJustify(), thickness, - aText->IsItalic(), allow_bold, false, aText->GetFont(), - &gbr_metadata ); + aText->IsItalic(), allow_bold, false, font, &gbr_metadata ); } }