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.
*
* 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
* 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;
// not actually used, but needed by GRText
const COLOR4D dummy_color = COLOR4D::BLACK;
bool forceBold = true;
int penWidth = 0; // force max width for bold
const COLOR4D dummy_color;
if( aText->IsMultilineAllowed() )
{
wxArrayString strings_list;
wxStringSplit( aText->GetShownText(), strings_list, '\n' );
std::vector<wxPoint> positions;
positions.reserve( strings_list.Count() );
aText->GetLinePositions( positions, strings_list.Count() );
// Use the actual text width to generate segments. The segment position depend on
// text thickness and justification
bool isBold = aText->IsBold();
int penWidth = aText->GetEffectiveTextPenWidth();
for( unsigned ii = 0; ii < strings_list.Count(); ++ii )
{
wxString txt = strings_list.Item( ii );
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 );
}
penWidth, aText->IsItalic(), isBold, addTextSegmToContainer );
}
@ -229,15 +212,15 @@ void BOARD_ADAPTER::addFootprintShapesWithClearance( const FOOTPRINT* aFootprint
{
s_textWidth = text->GetEffectiveTextPenWidth() + ( 2 * aInflateValue );
wxSize size = text->GetTextSize();
bool forceBold = true;
int penWidth = 0; // force max width for bold
bool isBold = text->IsBold();
int penWidth = text->GetEffectiveTextPenWidth();
if( text->IsMirrored() )
size.x = -size.x;
GRText( nullptr, text->GetTextPos(), BLACK, text->GetShownText(), text->GetDrawRotation(),
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).
* @aCornerBuffer = SHAPE_POLY_SET to store the polygon corners
* @aClearanceValue = the clearance around the text
@ -293,19 +292,17 @@ void FP_TEXT::TransformTextShapeWithClearanceToPolygon( SHAPE_POLY_SET& aCornerB
PCB_LAYER_ID aLayer, int aClearance,
int aError, ERROR_LOC aErrorLoc ) const
{
bool forceBold = true;
int penWidth = 0; // force max width for bold text
prms.m_cornerBuffer = &aCornerBuffer;
prms.m_textWidth = GetEffectiveTextPenWidth() + ( 2 * aClearance );
prms.m_error = aError;
wxSize size = GetTextSize();
int penWidth = GetEffectiveTextPenWidth();
if( IsMirrored() )
size.x = -size.x;
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).
* @aCornerBuffer = SHAPE_POLY_SET to store the polygon corners
* @aClearanceValue = the clearance around the text
@ -396,34 +392,15 @@ void PCB_TEXT::TransformTextShapeWithClearanceToPolygon( SHAPE_POLY_SET& aCorner
if( IsMirrored() )
size.x = -size.x;
bool forceBold = true;
int penWidth = GetEffectiveTextPenWidth();
prms.m_cornerBuffer = &aCornerBuffer;
prms.m_textWidth = GetEffectiveTextPenWidth() + ( 2 * aClearanceValue );
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() )
{
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 );
}
GetVertJustify(), penWidth, IsItalic(), IsBold(), addTextSegmToPoly, &prms );
}