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
This commit is contained in:
Marek Roszko 2022-08-28 09:44:31 -04:00
parent 1a7157fe37
commit f0956e48f2
19 changed files with 25 additions and 36 deletions

View File

@ -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

View File

@ -35,7 +35,6 @@
#include <eda_item.h>
#include <base_units.h>
#include <callback_gal.h>
#include <convert_to_biu.h> // for Mils2iu
#include <eda_rect.h>
#include <eda_text.h> // for EDA_TEXT, TEXT_EFFECTS, GR_TEXT_VJUSTIF...
#include <gal/color4d.h> // 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;
}

View File

@ -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
)

View File

@ -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;

View File

@ -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 ) ) );
}

View File

@ -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 );

View File

@ -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 )

View File

@ -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() );

View File

@ -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;

View File

@ -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;

View File

@ -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
)

View File

@ -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.
*/

View File

@ -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 );

View File

@ -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 );

View File

@ -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
)

View File

@ -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<FOOTPRINT*>( m_parent );

View File

@ -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 );

View File

@ -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 );
}

View File

@ -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 );