From 687c2f3e82dad539b590e469118b67a0a5d566f2 Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Thu, 30 Apr 2020 08:59:43 +0200 Subject: [PATCH] eeschema: fix a readability issue for small texts. Texts were drawn with a minimal line thickness = GetDefaultPenWidth(). The default pen width can be to large for small texts. So the actual text thickness is now always clamped. --- common/eda_text.cpp | 10 +++++++--- eeschema/sch_field.cpp | 6 +++--- eeschema/sch_painter.cpp | 6 ++---- eeschema/sch_text.cpp | 3 +-- include/eda_text.h | 7 ++++++- 5 files changed, 19 insertions(+), 13 deletions(-) diff --git a/common/eda_text.cpp b/common/eda_text.cpp index 4c406b7d90..7a7ae767da 100644 --- a/common/eda_text.cpp +++ b/common/eda_text.cpp @@ -149,15 +149,19 @@ void EDA_TEXT::SwapEffects( EDA_TEXT& aTradingPartner ) } -int EDA_TEXT::GetEffectiveTextPenWidth() const +int EDA_TEXT::GetEffectiveTextPenWidth( int aDefaultWidth ) const { int width = GetTextThickness(); - if( width <= 0 ) + if( width <= 1 ) { + width = aDefaultWidth; + if( IsBold() ) width = GetPenSizeForBold( GetTextWidth() ); - else + + // Avoid using a 0 width for text: it can create issues when drawing it + if( width <= 1 ) width = 1; } diff --git a/eeschema/sch_field.cpp b/eeschema/sch_field.cpp index 5a0964664d..e56007b387 100644 --- a/eeschema/sch_field.cpp +++ b/eeschema/sch_field.cpp @@ -146,7 +146,7 @@ void SCH_FIELD::Print( RENDER_SETTINGS* aSettings, const wxPoint& aOffset ) COLOR4D color = aSettings->GetLayerColor( IsForceVisible() ? LAYER_HIDDEN : m_Layer ); int orient; wxPoint textpos; - int penWidth = std::max( GetEffectiveTextPenWidth(), aSettings->GetDefaultPenWidth() ); + int penWidth = GetEffectiveTextPenWidth( aSettings->GetDefaultPenWidth() ); if( ( !IsVisible() && !IsForceVisible() ) || IsVoid() ) return; @@ -483,8 +483,8 @@ bool SCH_FIELD::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy ) void SCH_FIELD::Plot( PLOTTER* aPlotter ) { COLOR4D color = aPlotter->RenderSettings()->GetLayerColor( GetLayer() ); - int penWidth = std::max( GetEffectiveTextPenWidth(), - aPlotter->RenderSettings()->GetDefaultPenWidth() ); + int penWidth = GetEffectiveTextPenWidth( + aPlotter->RenderSettings()->GetDefaultPenWidth() ); if( !IsVisible() ) return; diff --git a/eeschema/sch_painter.cpp b/eeschema/sch_painter.cpp index f0fc7dba2e..6087f60019 100644 --- a/eeschema/sch_painter.cpp +++ b/eeschema/sch_painter.cpp @@ -325,8 +325,7 @@ float SCH_PAINTER::getLineWidth( const SCH_ITEM* aItem, bool aDrawingShadows ) float SCH_PAINTER::getTextThickness( const SCH_TEXT* aItem, bool aDrawingShadows ) { - float width = (float) std::max( aItem->GetEffectiveTextPenWidth(), - m_schSettings.GetDefaultPenWidth() ); + float width = (float) aItem->GetEffectiveTextPenWidth( m_schSettings.GetDefaultPenWidth() ); if( aItem->IsSelected() && aDrawingShadows ) width += getShadowWidth(); @@ -337,8 +336,7 @@ float SCH_PAINTER::getTextThickness( const SCH_TEXT* aItem, bool aDrawingShadows float SCH_PAINTER::getTextThickness( const SCH_FIELD* aItem, bool aDrawingShadows ) { - float width = (float) std::max( aItem->GetEffectiveTextPenWidth(), - m_schSettings.GetDefaultPenWidth() ); + float width = (float) aItem->GetEffectiveTextPenWidth( m_schSettings.GetDefaultPenWidth() ); if( aItem->IsSelected() && aDrawingShadows ) width += getShadowWidth(); diff --git a/eeschema/sch_text.cpp b/eeschema/sch_text.cpp index b608cd40c1..8090bfa68c 100644 --- a/eeschema/sch_text.cpp +++ b/eeschema/sch_text.cpp @@ -592,8 +592,7 @@ void SCH_TEXT::Plot( PLOTTER* aPlotter ) { static std::vector Poly; COLOR4D color = aPlotter->RenderSettings()->GetLayerColor( GetLayer() ); - int penWidth = std::max( GetEffectiveTextPenWidth(), - aPlotter->RenderSettings()->GetDefaultPenWidth() ); + int penWidth = GetEffectiveTextPenWidth( aPlotter->RenderSettings()->GetDefaultPenWidth() ); aPlotter->SetCurrentLineWidth( penWidth ); diff --git a/include/eda_text.h b/include/eda_text.h index 6b36755c39..e7a968aecb 100644 --- a/include/eda_text.h +++ b/include/eda_text.h @@ -156,7 +156,12 @@ public: */ void SetTextThickness( int aWidth ) { m_e.penwidth = aWidth; }; int GetTextThickness() const { return m_e.penwidth; }; - int GetEffectiveTextPenWidth() const; + + /** + * The EffectiveTextPenWidth uses the text thickness if > 1 or + * aDefaultWidth. + */ + int GetEffectiveTextPenWidth( int aDefaultWidth = 0 ) const; virtual void SetTextAngle( double aAngle ) {