From d465af65a713eb49cd23a06e5761040016aef0f8 Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Fri, 2 Nov 2018 11:27:57 +0100 Subject: [PATCH] LIB_FIELD: fix incorrect text thickness for small sized texts. Also remove duplicate code. --- eeschema/lib_field.cpp | 23 +++++++++++++++-------- eeschema/sch_painter.cpp | 27 ++++++--------------------- 2 files changed, 21 insertions(+), 29 deletions(-) diff --git a/eeschema/lib_field.cpp b/eeschema/lib_field.cpp index e4d2c03006..e0d3f43966 100644 --- a/eeschema/lib_field.cpp +++ b/eeschema/lib_field.cpp @@ -1,8 +1,8 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 2012 Jean-Pierre Charras, jp.charras at wanadoo.fr - * Copyright (C) 2004-2017 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2018 Jean-Pierre Charras, jp.charras at wanadoo.fr + * Copyright (C) 2004-2018 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -109,7 +109,19 @@ void LIB_FIELD::Init( int id ) int LIB_FIELD::GetPenSize() const { - return GetThickness() == 0 ? GetDefaultLineThickness() : GetThickness(); + int pensize = GetThickness(); + + if( pensize == 0 ) // Use default values for pen size + { + if( IsBold() ) + pensize = GetPenSizeForBold( GetTextWidth() ); + else + pensize = GetDefaultLineThickness(); + } + + // Clip pen size for small texts: + pensize = Clamp_Text_PenSize( pensize, GetTextSize(), IsBold() ); + return pensize; } @@ -121,11 +133,6 @@ void LIB_FIELD::drawGraphic( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& a COLOR4D color = COLOR4D::UNSPECIFIED; int linewidth = GetPenSize(); - if( IsBold() ) - linewidth = GetPenSizeForBold( GetTextWidth() ); - else - linewidth = Clamp_Text_PenSize( linewidth, GetTextSize(), IsBold() ); - if( !IsVisible() && ( aColor == COLOR4D::UNSPECIFIED ) ) { color = GetInvisibleItemColor(); diff --git a/eeschema/sch_painter.cpp b/eeschema/sch_painter.cpp index 15d0c37e66..e2f29256d7 100644 --- a/eeschema/sch_painter.cpp +++ b/eeschema/sch_painter.cpp @@ -391,11 +391,6 @@ void SCH_PAINTER::draw( LIB_FIELD *aField, int aLayer ) int linewidth = aField->GetPenSize(); - if( aField->IsBold() ) - linewidth = GetPenSizeForBold( aField->GetTextWidth() ); - - Clamp_Text_PenSize( linewidth, aField->GetTextSize(), aField->IsBold() ); - m_gal->SetLineWidth( linewidth ); m_gal->SetIsFill( false ); m_gal->SetIsStroke( true ); @@ -438,7 +433,7 @@ void SCH_PAINTER::draw( LIB_TEXT *aText, int aLayer ) return; } - int w = aText->GetPenSize(); + int linewidth = aText->GetPenSize(); EDA_RECT bBox = aText->GetBoundingBox(); bBox.RevertYAxis(); VECTOR2D pos = mapCoords( bBox.Centre() ); @@ -446,7 +441,7 @@ void SCH_PAINTER::draw( LIB_TEXT *aText, int aLayer ) m_gal->SetHorizontalJustify( GR_TEXT_HJUSTIFY_CENTER ); m_gal->SetVerticalJustify( GR_TEXT_VJUSTIFY_CENTER ); - m_gal->SetLineWidth( w ); + m_gal->SetLineWidth( linewidth ); m_gal->SetIsFill( false ); m_gal->SetIsStroke( true ); m_gal->SetStrokeColor( color ); @@ -976,11 +971,9 @@ void SCH_PAINTER::draw( SCH_TEXT *aText, int aLayer ) drawDanglingSymbol( m_gal, aText->GetTextPos() ); wxPoint text_offset = aText->GetTextPos() + aText->GetSchematicTextOffset(); - int linewidth = aText->GetThickness() ? aText->GetThickness() : GetDefaultLineThickness(); + int linewidth = aText->GetPenSize(); wxString shownText( aText->GetShownText() ); - linewidth = Clamp_Text_PenSize( linewidth, aText->GetTextSize(), aText->IsBold() ); - if( !shownText.IsEmpty() ) { m_gal->SetIsFill( false ); @@ -1081,11 +1074,8 @@ void SCH_PAINTER::draw( SCH_COMPONENT *aComp, int aLayer ) void SCH_PAINTER::draw( SCH_FIELD *aField, int aLayer ) { - int orient; COLOR4D color; - wxPoint textpos; SCH_COMPONENT* parentComponent = (SCH_COMPONENT*) aField->GetParent(); - int lineWidth = aField->GetPenSize(); switch( aField->GetId() ) { @@ -1108,14 +1098,8 @@ void SCH_PAINTER::draw( SCH_FIELD *aField, int aLayer ) if( aField->IsVoid() ) return; - if( aField->IsBold() ) - lineWidth = GetPenSizeForBold( aField->GetTextWidth() ); - - // Clip pen size for small texts: - lineWidth = Clamp_Text_PenSize( lineWidth, aField->GetTextSize(), aField->IsBold() ); - // Calculate the text orientation according to the component orientation. - orient = (int) aField->GetTextAngle(); + int orient = (int) aField->GetTextAngle(); if( parentComponent->GetTransform().y1 ) // Rotate component 90 degrees. { @@ -1137,7 +1121,8 @@ void SCH_PAINTER::draw( SCH_FIELD *aField, int aLayer ) * and use GetBoundaryBox to know the text coordinate considered as centered */ EDA_RECT boundaryBox = aField->GetBoundingBox(); - textpos = boundaryBox.Centre(); + wxPoint textpos = boundaryBox.Centre(); + int lineWidth = aField->GetPenSize(); m_gal->SetHorizontalJustify( GR_TEXT_HJUSTIFY_CENTER ); m_gal->SetVerticalJustify( GR_TEXT_VJUSTIFY_CENTER );