3D viewer: Fix broken handling of text thickness, thus creating erroneous item positions

Especially, texts having a not centered justification were shown with artifacts.
This commit is contained in:
jean-pierre charras 2021-05-15 13:18:06 +02:00
parent ccaf9e11df
commit d1061b9683
2 changed files with 17 additions and 57 deletions

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2015-2016 Mario Luzeiro <mrluzeiro@ua.pt> * Copyright (C) 2015-2016 Mario Luzeiro <mrluzeiro@ua.pt>
* Copyright (C) 1992-2020 KiCad Developers, see AUTHORS.txt for contributors. * Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -96,33 +96,16 @@ void BOARD_ADAPTER::addShapeWithClearance( const PCB_TEXT* aText, CONTAINER_2D_B
s_biuTo3Dunits = m_biuTo3Dunits; s_biuTo3Dunits = m_biuTo3Dunits;
// not actually used, but needed by GRText // not actually used, but needed by GRText
const COLOR4D dummy_color = COLOR4D::BLACK; const COLOR4D dummy_color;
bool forceBold = true;
int penWidth = 0; // force max width for bold
if( aText->IsMultilineAllowed() ) // Use the actual text width to generate segments. The segment position depend on
{ // text thickness and justification
wxArrayString strings_list; bool isBold = aText->IsBold();
wxStringSplit( aText->GetShownText(), strings_list, '\n' ); int penWidth = aText->GetEffectiveTextPenWidth();
std::vector<wxPoint> positions;
positions.reserve( strings_list.Count() );
aText->GetLinePositions( positions, strings_list.Count() );
for( unsigned ii = 0; ii < strings_list.Count(); ++ii ) GRText( nullptr, aText->GetTextPos(), dummy_color, aText->GetShownText(),
{ aText->GetTextAngle(), size, aText->GetHorizJustify(), aText->GetVertJustify(),
wxString txt = strings_list.Item( ii ); penWidth, aText->IsItalic(), isBold, addTextSegmToContainer );
GRText( nullptr, positions[ii], dummy_color, txt, aText->GetTextAngle(), size,
aText->GetHorizJustify(), aText->GetVertJustify(), penWidth,
aText->IsItalic(), forceBold, addTextSegmToContainer );
}
}
else
{
GRText( nullptr, aText->GetTextPos(), dummy_color, aText->GetShownText(),
aText->GetTextAngle(), size, aText->GetHorizJustify(), aText->GetVertJustify(),
penWidth, aText->IsItalic(), forceBold, addTextSegmToContainer );
}
} }
@ -229,15 +212,15 @@ void BOARD_ADAPTER::addFootprintShapesWithClearance( const FOOTPRINT* aFootprint
{ {
s_textWidth = text->GetEffectiveTextPenWidth() + ( 2 * aInflateValue ); s_textWidth = text->GetEffectiveTextPenWidth() + ( 2 * aInflateValue );
wxSize size = text->GetTextSize(); wxSize size = text->GetTextSize();
bool forceBold = true; bool isBold = text->IsBold();
int penWidth = 0; // force max width for bold int penWidth = text->GetEffectiveTextPenWidth();
if( text->IsMirrored() ) if( text->IsMirrored() )
size.x = -size.x; size.x = -size.x;
GRText( nullptr, text->GetTextPos(), BLACK, text->GetShownText(), text->GetDrawRotation(), GRText( nullptr, text->GetTextPos(), BLACK, text->GetShownText(), text->GetDrawRotation(),
size, text->GetHorizJustify(), text->GetVertJustify(), penWidth, text->IsItalic(), size, text->GetHorizJustify(), text->GetVertJustify(), penWidth, text->IsItalic(),
forceBold, addTextSegmToContainer ); isBold, addTextSegmToContainer );
} }
} }

View File

@ -283,7 +283,6 @@ void FOOTPRINT::TransformFPShapesWithClearanceToPolygon( SHAPE_POLY_SET& aCorner
/** /**
* Function TransformTextShapeWithClearanceToPolygon
* Convert the text to a polygonSet describing the actual character strokes (one per segment). * Convert the text to a polygonSet describing the actual character strokes (one per segment).
* @aCornerBuffer = SHAPE_POLY_SET to store the polygon corners * @aCornerBuffer = SHAPE_POLY_SET to store the polygon corners
* @aClearanceValue = the clearance around the text * @aClearanceValue = the clearance around the text
@ -293,19 +292,17 @@ void FP_TEXT::TransformTextShapeWithClearanceToPolygon( SHAPE_POLY_SET& aCornerB
PCB_LAYER_ID aLayer, int aClearance, PCB_LAYER_ID aLayer, int aClearance,
int aError, ERROR_LOC aErrorLoc ) const int aError, ERROR_LOC aErrorLoc ) const
{ {
bool forceBold = true;
int penWidth = 0; // force max width for bold text
prms.m_cornerBuffer = &aCornerBuffer; prms.m_cornerBuffer = &aCornerBuffer;
prms.m_textWidth = GetEffectiveTextPenWidth() + ( 2 * aClearance ); prms.m_textWidth = GetEffectiveTextPenWidth() + ( 2 * aClearance );
prms.m_error = aError; prms.m_error = aError;
wxSize size = GetTextSize(); wxSize size = GetTextSize();
int penWidth = GetEffectiveTextPenWidth();
if( IsMirrored() ) if( IsMirrored() )
size.x = -size.x; size.x = -size.x;
GRText( NULL, GetTextPos(), BLACK, GetShownText(), GetDrawRotation(), size, GetHorizJustify(), GRText( NULL, GetTextPos(), BLACK, GetShownText(), GetDrawRotation(), size, GetHorizJustify(),
GetVertJustify(), penWidth, IsItalic(), forceBold, addTextSegmToPoly, &prms ); GetVertJustify(), penWidth, IsItalic(), IsBold(), addTextSegmToPoly, &prms );
} }
@ -381,7 +378,6 @@ void EDA_TEXT::TransformBoundingBoxWithClearanceToPolygon( SHAPE_POLY_SET* aCorn
/** /**
* Function TransformTextShapeWithClearanceToPolygon
* Convert the text to a polygonSet describing the actual character strokes (one per segment). * Convert the text to a polygonSet describing the actual character strokes (one per segment).
* @aCornerBuffer = SHAPE_POLY_SET to store the polygon corners * @aCornerBuffer = SHAPE_POLY_SET to store the polygon corners
* @aClearanceValue = the clearance around the text * @aClearanceValue = the clearance around the text
@ -396,34 +392,15 @@ void PCB_TEXT::TransformTextShapeWithClearanceToPolygon( SHAPE_POLY_SET& aCorner
if( IsMirrored() ) if( IsMirrored() )
size.x = -size.x; size.x = -size.x;
bool forceBold = true;
int penWidth = GetEffectiveTextPenWidth(); int penWidth = GetEffectiveTextPenWidth();
prms.m_cornerBuffer = &aCornerBuffer; prms.m_cornerBuffer = &aCornerBuffer;
prms.m_textWidth = GetEffectiveTextPenWidth() + ( 2 * aClearanceValue ); prms.m_textWidth = GetEffectiveTextPenWidth() + ( 2 * aClearanceValue );
prms.m_error = aError; prms.m_error = aError;
COLOR4D color = COLOR4D::BLACK; // not actually used, but needed by GRText COLOR4D color; // not actually used, but needed by GRText
if( IsMultilineAllowed() ) GRText( NULL, GetTextPos(), color, GetShownText(), GetTextAngle(), size, GetHorizJustify(),
{ GetVertJustify(), penWidth, IsItalic(), IsBold(), addTextSegmToPoly, &prms );
wxArrayString strings_list;
wxStringSplit( GetShownText(), strings_list, '\n' );
std::vector<wxPoint> positions;
positions.reserve( strings_list.Count() );
GetLinePositions( positions, strings_list.Count() );
for( unsigned ii = 0; ii < strings_list.Count(); ii++ )
{
wxString txt = strings_list.Item( ii );
GRText( NULL, positions[ii], color, txt, GetTextAngle(), size, GetHorizJustify(),
GetVertJustify(), penWidth, IsItalic(), forceBold, addTextSegmToPoly, &prms );
}
}
else
{
GRText( NULL, GetTextPos(), color, GetShownText(), GetTextAngle(), size, GetHorizJustify(),
GetVertJustify(), penWidth, IsItalic(), forceBold, addTextSegmToPoly, &prms );
}
} }