Browse Source

Take text height into account as well as thickness for knockout margin.

Also centralizes calculation so all clients will get the same answer.

Fixes https://gitlab.com/kicad/code/kicad/issues/11636
7.0
Jeff Young 3 years ago
parent
commit
fa11e1c097
  1. 3
      3d-viewer/3d_canvas/create_3Dgraphic_brd_items.cpp
  2. 13
      include/gr_text.h
  3. 6
      pcbnew/pcb_painter.cpp
  4. 3
      pcbnew/plot_brditems_plotter.cpp
  5. 41
      pcbnew/zone_filler.cpp

3
3d-viewer/3d_canvas/create_3Dgraphic_brd_items.cpp

@ -91,7 +91,8 @@ void BOARD_ADAPTER::addText( const EDA_TEXT* aText, CONTAINER_2D_BASE* aContaine
font->Draw( &callback_gal, aText->GetShownText(), aText->GetDrawPos(), attrs );
SHAPE_POLY_SET finalPoly;
int margin = attrs.m_StrokeWidth * 1.5;
int margin = attrs.m_StrokeWidth * 1.5 +
GetKnockoutTextMargin( attrs.m_Size, attrs.m_StrokeWidth );
aText->TransformBoundingBoxWithClearanceToPolygon( &finalPoly, margin );
finalPoly.BooleanSubtract( knockouts, SHAPE_POLY_SET::PM_FAST );

13
include/gr_text.h

@ -79,6 +79,19 @@ int GetPenSizeForBold( const wxSize& aTextSize );
int GetPenSizeForNormal( int aTextSize );
int GetPenSizeForNormal( const wxSize& aTextSize );
/**
* Returns the margin for knockout text.
*
* Note that this is not a perfect calculation as fonts (especially outline fonts) vary greatly
* in how well ascender and descender heights are enforced.
*/
inline int GetKnockoutTextMargin( const VECTOR2I& aSize, int aThickness )
{
return std::max( aThickness, KiROUND( aSize.y / 4.0 ) );
}
/**
* The full X size is GraphicTextWidth + the thickness of graphic lines.
*

6
pcbnew/pcb_painter.cpp

@ -1681,7 +1681,8 @@ void PCB_PAINTER::draw( const PCB_TEXT* aText, int aLayer )
font->Draw( &callback_gal, resolvedText, aText->GetDrawPos(), attrs );
SHAPE_POLY_SET finalPoly;
int margin = attrs.m_StrokeWidth * 2.5;
int margin = attrs.m_StrokeWidth * 1.5
+ GetKnockoutTextMargin( attrs.m_Size, attrs.m_StrokeWidth );
aText->TransformBoundingBoxWithClearanceToPolygon( &finalPoly, margin );
finalPoly.BooleanSubtract( knockouts, SHAPE_POLY_SET::PM_FAST );
@ -1835,7 +1836,8 @@ void PCB_PAINTER::draw( const FP_TEXT* aText, int aLayer )
font->Draw( &callback_gal, resolvedText, aText->GetDrawPos(), attrs );
SHAPE_POLY_SET finalPoly;
int margin = attrs.m_StrokeWidth * 1.5;
int margin = attrs.m_StrokeWidth * 1.5
+ GetKnockoutTextMargin( attrs.m_Size, attrs.m_StrokeWidth );
aText->TransformBoundingBoxWithClearanceToPolygon( &finalPoly, margin );
finalPoly.BooleanSubtract( knockouts, SHAPE_POLY_SET::PM_FAST );

3
pcbnew/plot_brditems_plotter.cpp

@ -825,7 +825,8 @@ void BRDITEMS_PLOTTER::PlotPcbText( const EDA_TEXT* aText, PCB_LAYER_ID aLayer,
font->Draw( &callback_gal, shownText, aText->GetDrawPos(), attrs );
SHAPE_POLY_SET finalPoly;
int margin = attrs.m_StrokeWidth * 1.5;
int margin = attrs.m_StrokeWidth * 1.5
+ GetKnockoutTextMargin( attrs.m_Size, attrs.m_StrokeWidth );
aText->TransformBoundingBoxWithClearanceToPolygon( &finalPoly, margin );
finalPoly.BooleanSubtract( knockouts, SHAPE_POLY_SET::PM_FAST );

41
pcbnew/zone_filler.cpp

@ -521,33 +521,20 @@ void ZONE_FILLER::addHoleKnockout( PAD* aPad, int aGap, SHAPE_POLY_SET& aHoles )
void ZONE_FILLER::addKnockout( BOARD_ITEM* aItem, PCB_LAYER_ID aLayer, int aGap,
bool aIgnoreLineWidth, SHAPE_POLY_SET& aHoles )
{
// Text has a complicated relationship with its boudingBox due to ascenders, descenders,
// diacriticals, etc. Some things want a fairly tight bounding box, and some things don't.
// Since there's no uniformly "correct" answer, we pad the bounding box here to limit
// shorting as much as possible. (Note, however, that it will be caught by DRC either way,
// as it's not reliant on the bounding box.)
EDA_TEXT* text = nullptr;
switch( aItem->Type() )
{
case PCB_TEXT_T:
aGap += static_cast<PCB_TEXT*>( aItem )->GetTextThickness();
break;
case PCB_TEXTBOX_T:
aGap += static_cast<PCB_TEXTBOX*>( aItem )->GetTextThickness();
break;
case PCB_FP_TEXT_T:
aGap += static_cast<FP_TEXT*>( aItem )->GetTextThickness();
break;
case PCB_FP_TEXTBOX_T:
aGap += static_cast<FP_TEXTBOX*>( aItem )->GetTextThickness();
break;
default:
break;
case PCB_TEXT_T: text = static_cast<PCB_TEXT*>( aItem ); break;
case PCB_TEXTBOX_T: text = static_cast<PCB_TEXTBOX*>( aItem ); break;
case PCB_FP_TEXT_T: text = static_cast<FP_TEXT*>( aItem ); break;
case PCB_FP_TEXTBOX_T: text = static_cast<FP_TEXTBOX*>( aItem ); break;
default: break;
}
if( text )
aGap += GetKnockoutTextMargin( text->GetTextSize(), text->GetTextThickness() );
switch( aItem->Type() )
{
case PCB_SHAPE_T:
@ -561,17 +548,13 @@ void ZONE_FILLER::addKnockout( BOARD_ITEM* aItem, PCB_LAYER_ID aLayer, int aGap,
break;
case PCB_FP_TEXT_T:
{
FP_TEXT* text = static_cast<FP_TEXT*>( aItem );
if( text->IsVisible() )
{
text->TransformShapeWithClearanceToPolygon( aHoles, aLayer, aGap, m_maxError,
ERROR_OUTSIDE, aIgnoreLineWidth );
aItem->TransformShapeWithClearanceToPolygon( aHoles, aLayer, aGap, m_maxError,
ERROR_OUTSIDE, aIgnoreLineWidth );
}
break;
}
default:
break;

Loading…
Cancel
Save