Make sure users don't run into min text size.

Fixes https://gitlab.com/kicad/code/kicad/-/issues/17543

(cherry picked from commit fc572bfbc6)
This commit is contained in:
Jeff Young 2024-03-23 13:15:31 +00:00
parent f3621496fb
commit 4bea619855
12 changed files with 32 additions and 30 deletions

View File

@ -364,8 +364,8 @@ void EDA_TEXT::SetTextSize( VECTOR2I aNewSize, bool aEnforceMinTextSize )
if( aEnforceMinTextSize ) if( aEnforceMinTextSize )
{ {
int min = m_IuScale.get().MilsToIU( TEXT_MIN_SIZE_MILS ); int min = m_IuScale.get().mmToIU( TEXT_MIN_SIZE_MM );
int max = m_IuScale.get().MilsToIU( TEXT_MAX_SIZE_MILS ); int max = m_IuScale.get().mmToIU( TEXT_MAX_SIZE_MM );
aNewSize = VECTOR2I( alg::clamp( min, aNewSize.x, max ), aNewSize = VECTOR2I( alg::clamp( min, aNewSize.x, max ),
alg::clamp( min, aNewSize.y, max ) ); alg::clamp( min, aNewSize.y, max ) );
@ -380,8 +380,8 @@ void EDA_TEXT::SetTextSize( VECTOR2I aNewSize, bool aEnforceMinTextSize )
void EDA_TEXT::SetTextWidth( int aWidth ) void EDA_TEXT::SetTextWidth( int aWidth )
{ {
int min = m_IuScale.get().MilsToIU( TEXT_MIN_SIZE_MILS ); int min = m_IuScale.get().mmToIU( TEXT_MIN_SIZE_MM );
int max = m_IuScale.get().MilsToIU( TEXT_MAX_SIZE_MILS ); int max = m_IuScale.get().mmToIU( TEXT_MAX_SIZE_MM );
m_attributes.m_Size.x = alg::clamp( min, aWidth, max ); m_attributes.m_Size.x = alg::clamp( min, aWidth, max );
ClearRenderCache(); ClearRenderCache();
@ -391,8 +391,8 @@ void EDA_TEXT::SetTextWidth( int aWidth )
void EDA_TEXT::SetTextHeight( int aHeight ) void EDA_TEXT::SetTextHeight( int aHeight )
{ {
int min = m_IuScale.get().MilsToIU( TEXT_MIN_SIZE_MILS ); int min = m_IuScale.get().mmToIU( TEXT_MIN_SIZE_MM );
int max = m_IuScale.get().MilsToIU( TEXT_MAX_SIZE_MILS ); int max = m_IuScale.get().mmToIU( TEXT_MAX_SIZE_MM );
m_attributes.m_Size.y = alg::clamp( min, aHeight, max ); m_attributes.m_Size.y = alg::clamp( min, aHeight, max );
ClearRenderCache(); ClearRenderCache();

View File

@ -62,9 +62,8 @@
*/ */
/** /**
* @brief some define and functions to convert a value in mils, decimils or mm * @brief some macros and functions to convert a value in mils, decimils or mm to the internal
* to the internal unit used in pcbnew, cvpcb or gerbview (nanometer or deci-mil) * unit used in pcbnew, cvpcb or gerbview (nanometer or deci-mil) depending on compile time option
* depending on compile time option
*/ */
constexpr double GERB_IU_PER_MM = 1e5; // Gerbview IU is 10 nanometers. constexpr double GERB_IU_PER_MM = 1e5; // Gerbview IU is 10 nanometers.

View File

@ -38,9 +38,12 @@ class SHAPE_COMPOUND;
class SHAPE_POLY_SET; class SHAPE_POLY_SET;
// These are only here for algorithmic safety, not to tell the user what to do // These are only here for algorithmic safety, not to tell the user what to do.
#define TEXT_MIN_SIZE_MILS 1 ///< Minimum text size in mils // PL_EDITOR has the least resolution (its internal units are microns), so the min size is chosen
#define TEXT_MAX_SIZE_MILS 10000 ///< Maximum text size in mils (10 inches) // to yield 1 in PL_EDITOR.
// The max size chosen is somewhat arbitrary, but no one has complained yet.
#define TEXT_MIN_SIZE_MM 0.001 ///< Minimum text size (1 micron).
#define TEXT_MAX_SIZE_MM 250.0 ///< Maximum text size in mm (~10 inches)
namespace KIGFX namespace KIGFX

View File

@ -670,8 +670,8 @@ BOARD_DESIGN_SETTINGS::BOARD_DESIGN_SETTINGS( JSON_SETTINGS* aParent, const std:
}, },
{} ) ); {} ) );
int minTextSize = pcbIUScale.MilsToIU( TEXT_MIN_SIZE_MILS ); int minTextSize = pcbIUScale.mmToIU( TEXT_MIN_SIZE_MM );
int maxTextSize = pcbIUScale.MilsToIU( TEXT_MAX_SIZE_MILS ); int maxTextSize = pcbIUScale.mmToIU( TEXT_MAX_SIZE_MM );
int minStroke = 1; int minStroke = 1;
int maxStroke = pcbIUScale.mmToIU( 100 ); int maxStroke = pcbIUScale.mmToIU( 100 );

View File

@ -377,8 +377,8 @@ bool DIALOG_FOOTPRINT_PROPERTIES::Validate()
return false; return false;
} }
int minSize = pcbIUScale.MilsToIU( TEXT_MIN_SIZE_MILS ); int minSize = pcbIUScale.mmToIU( TEXT_MIN_SIZE_MM );
int maxSize = pcbIUScale.MilsToIU( TEXT_MAX_SIZE_MILS ); int maxSize = pcbIUScale.mmToIU( TEXT_MAX_SIZE_MM );
int width = m_frame->ValueFromString( m_itemsGrid->GetCellValue( i, FPT_WIDTH ) ); int width = m_frame->ValueFromString( m_itemsGrid->GetCellValue( i, FPT_WIDTH ) );
int height = m_frame->ValueFromString( m_itemsGrid->GetCellValue( i, FPT_HEIGHT ) ); int height = m_frame->ValueFromString( m_itemsGrid->GetCellValue( i, FPT_HEIGHT ) );

View File

@ -425,8 +425,8 @@ bool DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR::Validate()
return false; return false;
} }
int minSize = pcbIUScale.MilsToIU( TEXT_MIN_SIZE_MILS ); int minSize = pcbIUScale.mmToIU( TEXT_MIN_SIZE_MM );
int maxSize = pcbIUScale.MilsToIU( TEXT_MAX_SIZE_MILS ); int maxSize = pcbIUScale.mmToIU( TEXT_MAX_SIZE_MM );
if( field.GetTextWidth() < minSize || field.GetTextWidth() > maxSize ) if( field.GetTextWidth() < minSize || field.GetTextWidth() > maxSize )
{ {

View File

@ -511,8 +511,8 @@ void DIALOG_GLOBAL_EDIT_TEXT_AND_GRAPHICS::visitItem( BOARD_COMMIT& aCommit, BOA
bool DIALOG_GLOBAL_EDIT_TEXT_AND_GRAPHICS::TransferDataFromWindow() bool DIALOG_GLOBAL_EDIT_TEXT_AND_GRAPHICS::TransferDataFromWindow()
{ {
int minTextSize = pcbIUScale.MilsToIU( TEXT_MIN_SIZE_MILS ); int minTextSize = pcbIUScale.mmToIU( TEXT_MIN_SIZE_MM );
int maxTextSize = pcbIUScale.MilsToIU( TEXT_MAX_SIZE_MILS ); int maxTextSize = pcbIUScale.mmToIU( TEXT_MAX_SIZE_MM );
if( !m_textWidth.Validate( minTextSize, maxTextSize ) if( !m_textWidth.Validate( minTextSize, maxTextSize )
|| !m_textHeight.Validate( minTextSize, maxTextSize ) ) || !m_textHeight.Validate( minTextSize, maxTextSize ) )

View File

@ -428,8 +428,8 @@ bool DIALOG_TEXT_PROPERTIES::TransferDataFromWindow()
if( !DIALOG_TEXT_PROPERTIES_BASE::TransferDataFromWindow() ) if( !DIALOG_TEXT_PROPERTIES_BASE::TransferDataFromWindow() )
return false; return false;
int minSize = pcbIUScale.MilsToIU( TEXT_MIN_SIZE_MILS ); int minSize = pcbIUScale.mmToIU( TEXT_MIN_SIZE_MM );
int maxSize = pcbIUScale.MilsToIU( TEXT_MAX_SIZE_MILS ); int maxSize = pcbIUScale.mmToIU( TEXT_MAX_SIZE_MM );
if( !m_textWidth.Validate( minSize, maxSize ) || !m_textHeight.Validate( minSize, maxSize ) ) if( !m_textWidth.Validate( minSize, maxSize ) || !m_textHeight.Validate( minSize, maxSize ) )
return false; return false;

View File

@ -290,8 +290,8 @@ bool DIALOG_TEXTBOX_PROPERTIES::TransferDataFromWindow()
if( !DIALOG_TEXTBOX_PROPERTIES_BASE::TransferDataFromWindow() ) if( !DIALOG_TEXTBOX_PROPERTIES_BASE::TransferDataFromWindow() )
return false; return false;
int minSize = pcbIUScale.MilsToIU( TEXT_MIN_SIZE_MILS ); int minSize = pcbIUScale.mmToIU( TEXT_MIN_SIZE_MM );
int maxSize = pcbIUScale.MilsToIU( TEXT_MAX_SIZE_MILS ); int maxSize = pcbIUScale.mmToIU( TEXT_MAX_SIZE_MM );
if( !m_textWidth.Validate( minSize, maxSize ) || !m_textHeight.Validate( minSize, maxSize ) ) if( !m_textWidth.Validate( minSize, maxSize ) || !m_textHeight.Validate( minSize, maxSize ) )
return false; return false;

View File

@ -361,8 +361,8 @@ bool PANEL_FP_EDITOR_DEFAULTS::TransferDataFromWindow()
// A minimal value for sizes and thickness: // A minimal value for sizes and thickness:
const int minWidth = pcbIUScale.mmToIU( MINIMUM_LINE_WIDTH_MM ); const int minWidth = pcbIUScale.mmToIU( MINIMUM_LINE_WIDTH_MM );
const int maxWidth = pcbIUScale.mmToIU( MAXIMUM_LINE_WIDTH_MM ); const int maxWidth = pcbIUScale.mmToIU( MAXIMUM_LINE_WIDTH_MM );
const int minSize = pcbIUScale.MilsToIU( TEXT_MIN_SIZE_MILS ); const int minSize = pcbIUScale.mmToIU( TEXT_MIN_SIZE_MM );
const int maxSize = pcbIUScale.MilsToIU( TEXT_MAX_SIZE_MILS ); const int maxSize = pcbIUScale.mmToIU( TEXT_MAX_SIZE_MM );
wxString errorsMsg; wxString errorsMsg;
for( int i = 0; i < ROW_COUNT; ++i ) for( int i = 0; i < ROW_COUNT; ++i )

View File

@ -205,8 +205,8 @@ bool PANEL_SETUP_TEXT_AND_GRAPHICS::TransferDataFromWindow()
// A minimal value for sizes and thickness // A minimal value for sizes and thickness
const int minWidth = pcbIUScale.mmToIU( MINIMUM_LINE_WIDTH_MM ); const int minWidth = pcbIUScale.mmToIU( MINIMUM_LINE_WIDTH_MM );
const int maxWidth = pcbIUScale.mmToIU( MAXIMUM_LINE_WIDTH_MM ); const int maxWidth = pcbIUScale.mmToIU( MAXIMUM_LINE_WIDTH_MM );
const int minSize = pcbIUScale.MilsToIU( TEXT_MIN_SIZE_MILS ); const int minSize = pcbIUScale.mmToIU( TEXT_MIN_SIZE_MM );
const int maxSize = pcbIUScale.MilsToIU( TEXT_MAX_SIZE_MILS ); const int maxSize = pcbIUScale.mmToIU( TEXT_MAX_SIZE_MM );
wxString errorsMsg; wxString errorsMsg;
UNITS_PROVIDER* unitProvider = m_Frame; UNITS_PROVIDER* unitProvider = m_Frame;

View File

@ -184,8 +184,8 @@ FOOTPRINT_EDITOR_SETTINGS::FOOTPRINT_EDITOR_SETTINGS() :
{ "${REFERENCE}", true, F_Fab } { "${REFERENCE}", true, F_Fab }
} ) ) ); } ) ) );
int minTextSize = pcbIUScale.MilsToIU( TEXT_MIN_SIZE_MILS ); int minTextSize = pcbIUScale.mmToIU( TEXT_MIN_SIZE_MM );
int maxTextSize = pcbIUScale.MilsToIU( TEXT_MAX_SIZE_MILS ); int maxTextSize = pcbIUScale.mmToIU( TEXT_MAX_SIZE_MM );
int minStroke = 1; int minStroke = 1;
int maxStroke = pcbIUScale.mmToIU( 100 ); int maxStroke = pcbIUScale.mmToIU( 100 );