From f0956e48f20e6c51a275267f66a8d64d8de08d2c Mon Sep 17 00:00:00 2001 From: Marek Roszko Date: Sun, 28 Aug 2022 09:44:31 -0400 Subject: [PATCH] Make EDA_TEXT common Since EDA_TEXT is a base class, we can just force the child classes to pass the correct iu scaled size ALLOW_BOLD_THICKNESS removed because it's a pre-custom font holdover --- common/CMakeLists.txt | 2 +- common/eda_text.cpp | 10 ++++------ eeschema/CMakeLists.txt | 1 - eeschema/lib_field.cpp | 9 ++++++--- eeschema/lib_text.cpp | 2 +- eeschema/lib_textbox.cpp | 2 +- eeschema/sch_field.cpp | 2 +- eeschema/sch_plugins/kicad/sch_sexpr_parser.cpp | 4 ++-- eeschema/sch_text.cpp | 2 +- eeschema/sch_textbox.cpp | 2 +- gerbview/CMakeLists.txt | 1 - include/base_units.h | 9 --------- include/drawing_sheet/ds_draw_item.h | 4 ++-- include/eda_text.h | 2 +- pagelayout_editor/CMakeLists.txt | 1 - pcbnew/fp_text.cpp | 2 +- pcbnew/fp_textbox.cpp | 2 +- pcbnew/pcb_text.cpp | 2 +- pcbnew/pcb_textbox.cpp | 2 +- 19 files changed, 25 insertions(+), 36 deletions(-) diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index 3676de0321..d903283fe9 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -307,6 +307,7 @@ set( COMMON_SRCS eda_pattern_match.cpp eda_rect.cpp eda_shape.cpp + eda_text.cpp eda_units.cpp env_paths.cpp env_vars.cpp @@ -506,7 +507,6 @@ target_include_directories( common SYSTEM PUBLIC set( PCB_COMMON_SRCS - eda_text.cpp fp_lib_table.cpp hash_eda.cpp pg_properties.cpp diff --git a/common/eda_text.cpp b/common/eda_text.cpp index f7d80fcede..3929900828 100644 --- a/common/eda_text.cpp +++ b/common/eda_text.cpp @@ -35,7 +35,6 @@ #include #include #include -#include // for Mils2iu #include #include // for EDA_TEXT, TEXT_EFFECTS, GR_TEXT_VJUSTIF... #include // for COLOR4D, COLOR4D::BLACK @@ -89,14 +88,13 @@ GR_TEXT_V_ALIGN_T EDA_TEXT::MapVertJustify( int aVertJustify ) } -EDA_TEXT::EDA_TEXT( const wxString& text ) : - m_text( text ), +EDA_TEXT::EDA_TEXT( int aDefaultSizeIu, const wxString& aText ) : + m_text( aText ), m_bounding_box_cache_valid( false ), m_bounding_box_cache_line( -1 ), m_bounding_box_cache_inverted( false ) { - int sz = Mils2iu( DEFAULT_SIZE_TEXT ); - SetTextSize( wxSize( sz, sz ) ); + SetTextSize( VECTOR2I( aDefaultSizeIu, aDefaultSizeIu ) ); cacheShownText(); } @@ -309,7 +307,7 @@ int EDA_TEXT::GetEffectiveTextPenWidth( int aDefaultPenWidth ) const } // Clip pen size for small texts: - penWidth = Clamp_Text_PenSize( penWidth, GetTextSize(), ALLOW_BOLD_THICKNESS ); + penWidth = Clamp_Text_PenSize( penWidth, GetTextSize(), IsBold() ); return penWidth; } diff --git a/eeschema/CMakeLists.txt b/eeschema/CMakeLists.txt index 75c6d6aeae..ada74cad28 100644 --- a/eeschema/CMakeLists.txt +++ b/eeschema/CMakeLists.txt @@ -320,7 +320,6 @@ set( EESCHEMA_COMMON_SRCS ${CMAKE_SOURCE_DIR}/common/dialogs/panel_gal_display_options.cpp ${CMAKE_SOURCE_DIR}/common/base_units.cpp - ${CMAKE_SOURCE_DIR}/common/eda_text.cpp ) diff --git a/eeschema/lib_field.cpp b/eeschema/lib_field.cpp index f78f97a21a..63029ccfc1 100644 --- a/eeschema/lib_field.cpp +++ b/eeschema/lib_field.cpp @@ -40,21 +40,24 @@ LIB_FIELD::LIB_FIELD( LIB_SYMBOL* aParent, int aId ) : - LIB_ITEM( LIB_FIELD_T, aParent ) + LIB_ITEM( LIB_FIELD_T, aParent ), + EDA_TEXT( Mils2iu( DEFAULT_SIZE_TEXT ) ) { Init( aId ); } LIB_FIELD::LIB_FIELD( int aId ) : - LIB_ITEM( LIB_FIELD_T, nullptr ) + LIB_ITEM( LIB_FIELD_T, nullptr ), + EDA_TEXT( Mils2iu( DEFAULT_SIZE_TEXT ) ) { Init( aId ); } LIB_FIELD::LIB_FIELD( int aId, const wxString& aName ) : - LIB_ITEM( LIB_FIELD_T, nullptr ) + LIB_ITEM( LIB_FIELD_T, nullptr ), + EDA_TEXT( Mils2iu( DEFAULT_SIZE_TEXT ) ) { Init( aId ); m_name = aName; diff --git a/eeschema/lib_text.cpp b/eeschema/lib_text.cpp index 51f729ce40..33a2a1754f 100644 --- a/eeschema/lib_text.cpp +++ b/eeschema/lib_text.cpp @@ -39,7 +39,7 @@ LIB_TEXT::LIB_TEXT( LIB_SYMBOL* aParent ) : LIB_ITEM( LIB_TEXT_T, aParent ), - EDA_TEXT( wxEmptyString ) + EDA_TEXT( Mils2iu( DEFAULT_SIZE_TEXT ), wxEmptyString ) { SetTextSize( wxSize( Mils2iu( DEFAULT_TEXT_SIZE ), Mils2iu( DEFAULT_TEXT_SIZE ) ) ); } diff --git a/eeschema/lib_textbox.cpp b/eeschema/lib_textbox.cpp index 6cd148fee3..751405c463 100644 --- a/eeschema/lib_textbox.cpp +++ b/eeschema/lib_textbox.cpp @@ -45,7 +45,7 @@ using KIGFX::SCH_RENDER_SETTINGS; LIB_TEXTBOX::LIB_TEXTBOX( LIB_SYMBOL* aParent, int aLineWidth, FILL_T aFillType, const wxString& text ) : LIB_SHAPE( aParent, SHAPE_T::RECT, aLineWidth, aFillType, LIB_TEXTBOX_T ), - EDA_TEXT( text ) + EDA_TEXT( Mils2iu( DEFAULT_SIZE_TEXT ), text ) { SetTextSize( wxSize( Mils2iu( DEFAULT_TEXT_SIZE ), Mils2iu( DEFAULT_TEXT_SIZE ) ) ); SetHorizJustify( GR_TEXT_H_ALIGN_LEFT ); diff --git a/eeschema/sch_field.cpp b/eeschema/sch_field.cpp index ea07ca8034..544ff2c12b 100644 --- a/eeschema/sch_field.cpp +++ b/eeschema/sch_field.cpp @@ -59,7 +59,7 @@ SCH_FIELD::SCH_FIELD( const VECTOR2I& aPos, int aFieldId, SCH_ITEM* aParent, const wxString& aName ) : SCH_ITEM( aParent, SCH_FIELD_T ), - EDA_TEXT( wxEmptyString ), + EDA_TEXT( Mils2iu( DEFAULT_SIZE_TEXT ), wxEmptyString ), m_id( 0 ), m_name( aName ), m_renderCacheValid( false ) diff --git a/eeschema/sch_plugins/kicad/sch_sexpr_parser.cpp b/eeschema/sch_plugins/kicad/sch_sexpr_parser.cpp index 70bf6aa24d..c0af921bf7 100644 --- a/eeschema/sch_plugins/kicad/sch_sexpr_parser.cpp +++ b/eeschema/sch_plugins/kicad/sch_sexpr_parser.cpp @@ -1322,7 +1322,7 @@ LIB_PIN* SCH_SEXPR_PARSER::parsePin() { // The EDA_TEXT font effects formatting is used so use and EDA_TEXT object // so duplicate parsing is not required. - EDA_TEXT text; + EDA_TEXT text( Mils2iu( DEFAULT_SIZE_TEXT ) ); parseEDA_TEXT( &text, true ); pin->SetNameTextSize( text.GetTextHeight() ); @@ -1356,7 +1356,7 @@ LIB_PIN* SCH_SEXPR_PARSER::parsePin() { // The EDA_TEXT font effects formatting is used so use and EDA_TEXT object // so duplicate parsing is not required. - EDA_TEXT text; + EDA_TEXT text( Mils2iu( DEFAULT_SIZE_TEXT ) ); parseEDA_TEXT( &text, false ); pin->SetNumberTextSize( text.GetTextHeight() ); diff --git a/eeschema/sch_text.cpp b/eeschema/sch_text.cpp index e7685afab1..71fdb32dae 100644 --- a/eeschema/sch_text.cpp +++ b/eeschema/sch_text.cpp @@ -114,7 +114,7 @@ TEXT_SPIN_STYLE TEXT_SPIN_STYLE::MirrorY() SCH_TEXT::SCH_TEXT( const VECTOR2I& pos, const wxString& text, KICAD_T aType ) : SCH_ITEM( nullptr, aType ), - EDA_TEXT( text ) + EDA_TEXT( Mils2iu( DEFAULT_SIZE_TEXT ), text ) { m_layer = LAYER_NOTES; diff --git a/eeschema/sch_textbox.cpp b/eeschema/sch_textbox.cpp index 2f88350718..30ee7d2323 100644 --- a/eeschema/sch_textbox.cpp +++ b/eeschema/sch_textbox.cpp @@ -45,7 +45,7 @@ using KIGFX::SCH_RENDER_SETTINGS; SCH_TEXTBOX::SCH_TEXTBOX( int aLineWidth, FILL_T aFillType, const wxString& text ) : SCH_SHAPE( SHAPE_T::RECT, aLineWidth, aFillType, SCH_TEXTBOX_T ), - EDA_TEXT( text ) + EDA_TEXT( Mils2iu( DEFAULT_SIZE_TEXT ), text ) { m_layer = LAYER_NOTES; diff --git a/gerbview/CMakeLists.txt b/gerbview/CMakeLists.txt index 891bf28774..354077325c 100644 --- a/gerbview/CMakeLists.txt +++ b/gerbview/CMakeLists.txt @@ -73,7 +73,6 @@ set( GERBVIEW_SRCS set( GERBVIEW_EXTRA_SRCS ${CMAKE_SOURCE_DIR}/common/base_units.cpp - ${CMAKE_SOURCE_DIR}/common/eda_text.cpp ${CMAKE_SOURCE_DIR}/common/widgets/layer_box_selector.cpp ${CMAKE_SOURCE_DIR}/common/lset.cpp ) diff --git a/include/base_units.h b/include/base_units.h index b99c5fcfa8..ee9f182d0e 100644 --- a/include/base_units.h +++ b/include/base_units.h @@ -48,15 +48,6 @@ #define INDETERMINATE_STATE _( "-- mixed values --" ) #define INDETERMINATE_ACTION _( "-- leave unchanged --" ) - -// PCBNew doesn't support a bold style so we want to allow text thicknesses -// that achieve the same effect -#if defined( PCBNEW ) -#define ALLOW_BOLD_THICKNESS true -#else -#define ALLOW_BOLD_THICKNESS IsBold() -#endif - /** * Convert mm to mils. */ diff --git a/include/drawing_sheet/ds_draw_item.h b/include/drawing_sheet/ds_draw_item.h index 64c1748233..81d21f979d 100644 --- a/include/drawing_sheet/ds_draw_item.h +++ b/include/drawing_sheet/ds_draw_item.h @@ -306,10 +306,10 @@ public: bool aItalic = false, bool aBold = false, const KIGFX::COLOR4D& aColor = KIGFX::COLOR4D::UNSPECIFIED ) : DS_DRAW_ITEM_BASE( aPeer, aIndex, WSG_TEXT_T), - EDA_TEXT( aText ) + EDA_TEXT( 0, aText ) { SetTextPos( aPos ); - SetTextSize( (wxSize) aSize ); + SetTextSize( aSize ); SetTextThickness( aPenWidth ); SetFont( aFont ); SetItalic( aItalic ); diff --git a/include/eda_text.h b/include/eda_text.h index 9a3e779567..27298c635b 100644 --- a/include/eda_text.h +++ b/include/eda_text.h @@ -72,7 +72,7 @@ using KIGFX::COLOR4D; class EDA_TEXT { public: - EDA_TEXT( const wxString& text = wxEmptyString ); + EDA_TEXT( int aDefaultSizeIu, const wxString& aText = wxEmptyString ); EDA_TEXT( const EDA_TEXT& aText ); diff --git a/pagelayout_editor/CMakeLists.txt b/pagelayout_editor/CMakeLists.txt index 66bf688830..d898f33b0a 100644 --- a/pagelayout_editor/CMakeLists.txt +++ b/pagelayout_editor/CMakeLists.txt @@ -46,7 +46,6 @@ set( PL_EDITOR_SRCS set( PL_EDITOR_EXTRA_SRCS ${CMAKE_SOURCE_DIR}/common/base_units.cpp - ${CMAKE_SOURCE_DIR}/common/eda_text.cpp ${CMAKE_SOURCE_DIR}/common/dialogs/panel_gal_display_options.cpp ) diff --git a/pcbnew/fp_text.cpp b/pcbnew/fp_text.cpp index 40e858e47b..817faf0c86 100644 --- a/pcbnew/fp_text.cpp +++ b/pcbnew/fp_text.cpp @@ -40,7 +40,7 @@ FP_TEXT::FP_TEXT( FOOTPRINT* aParentFootprint, TEXT_TYPE text_type ) : BOARD_ITEM( aParentFootprint, PCB_FP_TEXT_T ), - EDA_TEXT() + EDA_TEXT( Mils2iu( DEFAULT_SIZE_TEXT ) ) { FOOTPRINT* parentFootprint = static_cast( m_parent ); diff --git a/pcbnew/fp_textbox.cpp b/pcbnew/fp_textbox.cpp index fdb1c3f335..033e080e36 100644 --- a/pcbnew/fp_textbox.cpp +++ b/pcbnew/fp_textbox.cpp @@ -39,7 +39,7 @@ FP_TEXTBOX::FP_TEXTBOX( FOOTPRINT* aParentFootprint ) : FP_SHAPE( aParentFootprint, SHAPE_T::RECT, PCB_FP_TEXTBOX_T ), - EDA_TEXT() + EDA_TEXT( Mils2iu( DEFAULT_SIZE_TEXT ) ) { SetHorizJustify( GR_TEXT_H_ALIGN_LEFT ); SetVertJustify( GR_TEXT_V_ALIGN_TOP ); diff --git a/pcbnew/pcb_text.cpp b/pcbnew/pcb_text.cpp index f9582dc1ca..70cb8eda61 100644 --- a/pcbnew/pcb_text.cpp +++ b/pcbnew/pcb_text.cpp @@ -41,7 +41,7 @@ PCB_TEXT::PCB_TEXT( BOARD_ITEM* parent ) : BOARD_ITEM( parent, PCB_TEXT_T ), - EDA_TEXT() + EDA_TEXT( Mils2iu( DEFAULT_SIZE_TEXT ) ) { SetMultilineAllowed( true ); } diff --git a/pcbnew/pcb_textbox.cpp b/pcbnew/pcb_textbox.cpp index ff83aa20e2..883d2f775d 100644 --- a/pcbnew/pcb_textbox.cpp +++ b/pcbnew/pcb_textbox.cpp @@ -39,7 +39,7 @@ PCB_TEXTBOX::PCB_TEXTBOX( BOARD_ITEM* parent ) : PCB_SHAPE( parent, PCB_TEXTBOX_T, SHAPE_T::RECT ), - EDA_TEXT() + EDA_TEXT( Mils2iu( DEFAULT_SIZE_TEXT ) ) { SetHorizJustify( GR_TEXT_H_ALIGN_LEFT ); SetVertJustify( GR_TEXT_V_ALIGN_TOP );