Separate text-thickness clamping into strict and lenient modes.
We used to use the bold setting, but since PCBNew allows you to directly define the width you end up with settings in between normal and bold that get clamped to the normal max. Fixes https://gitlab.com/kicad/code/kicad/issues/12367
This commit is contained in:
parent
b874aaac5e
commit
6f5281258e
|
@ -306,7 +306,7 @@ int EDA_TEXT::GetEffectiveTextPenWidth( int aDefaultPenWidth ) const
|
|||
}
|
||||
|
||||
// Clip pen size for small texts:
|
||||
penWidth = Clamp_Text_PenSize( penWidth, GetTextSize(), IsBold() );
|
||||
penWidth = Clamp_Text_PenSize( penWidth, GetTextSize() );
|
||||
|
||||
return penWidth;
|
||||
}
|
||||
|
|
|
@ -62,37 +62,39 @@ int GetPenSizeForNormal( const wxSize& aTextSize )
|
|||
|
||||
|
||||
/**
|
||||
* Don't allow text to become cluttered up in its own fatness. Bold fonts are generally around
|
||||
* aSize/5 in width, so we limit them to aSize/4, and normal text to aSize/6.
|
||||
* Pen width should not allow characters to become cluttered up in their own fatness. Normal
|
||||
* text is normally around 15% the fontsize, and bold text around 20%. So we set a hard limit
|
||||
* at 25%, and a secondary limit for non-decorative text that must be readable at small sizes
|
||||
* at 18%.
|
||||
*
|
||||
* @param aPenSize is the pen size to clamp.
|
||||
* @param aSize is the character size (height or width).
|
||||
* @param aBold use true if text accept bold pen size.
|
||||
* @return the max pen size allowed.
|
||||
*/
|
||||
int Clamp_Text_PenSize( int aPenSize, int aSize, bool aBold )
|
||||
int Clamp_Text_PenSize( int aPenSize, int aSize, bool aStrict )
|
||||
{
|
||||
double scale = aBold ? 4.0 : 6.0;
|
||||
int maxWidth = KiROUND( (double) aSize / scale );
|
||||
double scale = aStrict ? 0.18 : 0.25;
|
||||
int maxWidth = KiROUND( (double) aSize * scale );
|
||||
|
||||
return std::min( aPenSize, maxWidth );
|
||||
}
|
||||
|
||||
|
||||
float Clamp_Text_PenSize( float aPenSize, int aSize, bool aBold )
|
||||
float Clamp_Text_PenSize( float aPenSize, int aSize, bool aStrict )
|
||||
{
|
||||
float scale = aBold ? 4.0 : 6.0;
|
||||
float maxWidth = (float) aSize / scale;
|
||||
double scale = aStrict ? 0.18 : 0.25;
|
||||
float maxWidth = (float) aSize * scale;
|
||||
|
||||
return std::min( aPenSize, maxWidth );
|
||||
}
|
||||
|
||||
|
||||
int Clamp_Text_PenSize( int aPenSize, const VECTOR2I& aSize, bool aBold )
|
||||
int Clamp_Text_PenSize( int aPenSize, const VECTOR2I& aSize, bool aStrict )
|
||||
{
|
||||
int size = std::min( std::abs( aSize.x ), std::abs( aSize.y ) );
|
||||
|
||||
return Clamp_Text_PenSize( aPenSize, size, aBold );
|
||||
return Clamp_Text_PenSize( aPenSize, size, aStrict );
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -363,9 +363,9 @@ void LIB_PIN::printPinTexts( const RENDER_SETTINGS* aSettings, VECTOR2I& aPinPos
|
|||
wxSize pinNameSize( m_nameTextSize, m_nameTextSize );
|
||||
wxSize pinNumSize( m_numTextSize, m_numTextSize );
|
||||
|
||||
int namePenWidth = std::max( Clamp_Text_PenSize( GetPenWidth(), m_nameTextSize, false ),
|
||||
int namePenWidth = std::max( Clamp_Text_PenSize( GetPenWidth(), m_nameTextSize, true ),
|
||||
aSettings->GetDefaultPenWidth() );
|
||||
int numPenWidth = std::max( Clamp_Text_PenSize( GetPenWidth(), m_numTextSize, false ),
|
||||
int numPenWidth = std::max( Clamp_Text_PenSize( GetPenWidth(), m_numTextSize, true ),
|
||||
aSettings->GetDefaultPenWidth() );
|
||||
|
||||
int name_offset = Mils2iu( PIN_TEXT_MARGIN ) + namePenWidth;
|
||||
|
@ -710,9 +710,9 @@ void LIB_PIN::PlotPinTexts( PLOTTER* aPlotter, const VECTOR2I& aPinPos, int aPin
|
|||
return;
|
||||
|
||||
int x, y;
|
||||
int namePenWidth = std::max( Clamp_Text_PenSize( GetPenWidth(), m_nameTextSize, false ),
|
||||
int namePenWidth = std::max( Clamp_Text_PenSize( GetPenWidth(), m_nameTextSize, true ),
|
||||
aPlotter->RenderSettings()->GetDefaultPenWidth() );
|
||||
int numPenWidth = std::max( Clamp_Text_PenSize( GetPenWidth(), m_numTextSize, false ),
|
||||
int numPenWidth = std::max( Clamp_Text_PenSize( GetPenWidth(), m_numTextSize, true ),
|
||||
aPlotter->RenderSettings()->GetDefaultPenWidth() );
|
||||
int name_offset = Mils2iu( PIN_TEXT_MARGIN ) + namePenWidth;
|
||||
int num_offset = Mils2iu( PIN_TEXT_MARGIN ) + numPenWidth;
|
||||
|
|
|
@ -1327,8 +1327,8 @@ void SCH_PAINTER::draw( LIB_PIN *aPin, int aLayer )
|
|||
bool showPinNames = libEntry->ShowPinNames();
|
||||
bool showPinNumbers = m_schSettings.m_ShowPinNumbers || libEntry->ShowPinNumbers();
|
||||
|
||||
nameStrokeWidth = Clamp_Text_PenSize( nameStrokeWidth, aPin->GetNameTextSize(), false );
|
||||
numStrokeWidth = Clamp_Text_PenSize( numStrokeWidth, aPin->GetNumberTextSize(), false );
|
||||
nameStrokeWidth = Clamp_Text_PenSize( nameStrokeWidth, aPin->GetNameTextSize(), true );
|
||||
numStrokeWidth = Clamp_Text_PenSize( numStrokeWidth, aPin->GetNumberTextSize(), true );
|
||||
|
||||
int PIN_TEXT_MARGIN = KiROUND( 24 * m_schSettings.m_TextOffsetRatio );
|
||||
|
||||
|
|
|
@ -50,20 +50,19 @@ namespace KIGFX
|
|||
class PLOTTER;
|
||||
|
||||
/**
|
||||
* As a rule, pen width should not be >1/4em, otherwise the character will be cluttered up in
|
||||
* its own fatness.
|
||||
*
|
||||
* The pen width max is aSize/4 for bold texts, and aSize/6 for normal texts. The "best" pen
|
||||
* width is aSize/5 for bold texts so the clamp is consistent with bold option.
|
||||
* Pen width should not allow characters to become cluttered up in their own fatness. Normal
|
||||
* text is normally around 15% the fontsize, and bold text around 20%. So we set a hard limit
|
||||
* at 25%, and a secondary limit for non-decorative text that must be readable at small sizes
|
||||
* at 18%.
|
||||
*
|
||||
* @param aPenSize the pen size to clamp.
|
||||
* @param aSize the char size (height or width, or its wxSize).
|
||||
* @param aBold true if text accept bold pen size.
|
||||
* @return the max pen size allowed.
|
||||
*/
|
||||
int Clamp_Text_PenSize( int aPenSize, int aSize, bool aBold = true );
|
||||
float Clamp_Text_PenSize( float aPenSize, int aSize, bool aBold = true );
|
||||
int Clamp_Text_PenSize( int aPenSize, const VECTOR2I& aSize, bool aBold = true );
|
||||
int Clamp_Text_PenSize( int aPenSize, int aSize, bool aStrict = false );
|
||||
float Clamp_Text_PenSize( float aPenSize, int aSize, bool aStrict = false );
|
||||
int Clamp_Text_PenSize( int aPenSize, const VECTOR2I& aSize, bool aStrict = false );
|
||||
|
||||
/**
|
||||
* @param aTextSize the char size (height or width).
|
||||
|
|
Loading…
Reference in New Issue