LIB_FIELD: fix incorrect text thickness for small sized texts.

Also remove duplicate code.
This commit is contained in:
jean-pierre charras 2018-11-02 11:27:57 +01:00
parent b7b9cccffc
commit d465af65a7
2 changed files with 21 additions and 29 deletions

View File

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

View File

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