Use same text positioning algorithm in LibEdit and Eeschema.

Also fixes some uninitialized variables in PCB painter.

Fixes https://gitlab.com/kicad/code/kicad/issues/8947
This commit is contained in:
Jeff Young 2021-09-07 12:32:25 +01:00
parent 2ac03e2cdb
commit 9cf7c7800b
2 changed files with 16 additions and 20 deletions

View File

@ -650,31 +650,26 @@ void SCH_PAINTER::draw( const LIB_FIELD *aField, int aLayer )
m_gal->SetIsStroke( true ); m_gal->SetIsStroke( true );
m_gal->SetStrokeColor( color ); m_gal->SetStrokeColor( color );
auto pos = mapCoords( aField->GetPosition() ); EDA_RECT bbox = aField->GetBoundingBox();
wxPoint textpos = bbox.Centre();
if( drawingShadows && eeconfig()->m_Selection.text_as_box ) if( drawingShadows && eeconfig()->m_Selection.text_as_box )
{ {
EDA_RECT boundaryBox = aField->GetBoundingBox();
m_gal->SetIsFill( true ); m_gal->SetIsFill( true );
m_gal->SetFillColor( color ); m_gal->SetFillColor( color );
m_gal->SetLineWidth( m_gal->GetLineWidth() * 0.5 ); m_gal->SetLineWidth( m_gal->GetLineWidth() * 0.5 );
boundaryBox.RevertYAxis(); bbox.RevertYAxis();
m_gal->DrawRectangle( mapCoords( boundaryBox.GetPosition() ), m_gal->DrawRectangle( mapCoords( bbox.GetPosition() ), mapCoords( bbox.GetEnd() ) );
mapCoords( boundaryBox.GetEnd() ) );
} }
else else
{ {
m_gal->SetHorizontalJustify( GR_TEXT_HJUSTIFY_CENTER );
m_gal->SetVerticalJustify( GR_TEXT_VJUSTIFY_CENTER );
m_gal->SetGlyphSize( VECTOR2D( aField->GetTextSize() ) ); m_gal->SetGlyphSize( VECTOR2D( aField->GetTextSize() ) );
m_gal->SetFontItalic( aField->IsItalic() ); m_gal->SetFontItalic( aField->IsItalic() );
m_gal->SetHorizontalJustify( aField->GetHorizJustify() ); strokeText( UnescapeString( aField->GetText() ), textpos, aField->GetTextAngleRadians() );
m_gal->SetVerticalJustify( aField->GetVertJustify() );
double orient = aField->GetTextAngleRadians();
strokeText( UnescapeString( aField->GetText() ), pos, orient );
} }
// Draw the umbilical line // Draw the umbilical line
@ -682,7 +677,7 @@ void SCH_PAINTER::draw( const LIB_FIELD *aField, int aLayer )
{ {
m_gal->SetLineWidth( m_schSettings.m_outlineWidth ); m_gal->SetLineWidth( m_schSettings.m_outlineWidth );
m_gal->SetStrokeColor( COLOR4D( 0.0, 0.0, 1.0, 1.0 ) ); m_gal->SetStrokeColor( COLOR4D( 0.0, 0.0, 1.0, 1.0 ) );
m_gal->DrawLine( pos, wxPoint( 0, 0 ) ); m_gal->DrawLine( textpos, wxPoint( 0, 0 ) );
} }
} }
@ -1554,8 +1549,8 @@ void SCH_PAINTER::draw( const SCH_FIELD *aField, int aLayer )
* to calculate so the easier way is to use no justifications (centered text) and use * to calculate so the easier way is to use no justifications (centered text) and use
* GetBoundingBox to know the text coordinate considered as centered * GetBoundingBox to know the text coordinate considered as centered
*/ */
EDA_RECT boundaryBox = aField->GetBoundingBox(); EDA_RECT bbox = aField->GetBoundingBox();
wxPoint textpos = boundaryBox.Centre(); wxPoint textpos = bbox.Centre();
m_gal->SetStrokeColor( color ); m_gal->SetStrokeColor( color );
m_gal->SetIsStroke( true ); m_gal->SetIsStroke( true );
@ -1565,10 +1560,9 @@ void SCH_PAINTER::draw( const SCH_FIELD *aField, int aLayer )
m_gal->SetIsFill( true ); m_gal->SetIsFill( true );
m_gal->SetFillColor( color ); m_gal->SetFillColor( color );
m_gal->SetLineWidth( m_gal->GetLineWidth() * 0.5 ); m_gal->SetLineWidth( m_gal->GetLineWidth() * 0.5 );
boundaryBox.RevertYAxis(); bbox.RevertYAxis();
m_gal->DrawRectangle( mapCoords( boundaryBox.GetPosition() ), m_gal->DrawRectangle( mapCoords( bbox.GetPosition() ), mapCoords( bbox.GetEnd() ) );
mapCoords( boundaryBox.GetEnd() ) );
} }
else else
{ {

View File

@ -414,13 +414,15 @@ COLOR4D PCB_RENDER_SETTINGS::GetColor( const VIEW_ITEM* aItem, int aLayer ) cons
else if( item->Type() == PCB_ZONE_T || item->Type() == PCB_FP_ZONE_T ) else if( item->Type() == PCB_ZONE_T || item->Type() == PCB_FP_ZONE_T )
color.a *= m_zoneOpacity; color.a *= m_zoneOpacity;
// No special modificators enabled // No special modifiers enabled
return color; return color;
} }
PCB_PAINTER::PCB_PAINTER( GAL* aGal ) : PCB_PAINTER::PCB_PAINTER( GAL* aGal ) :
PAINTER( aGal ) PAINTER( aGal ),
m_maxError( ARC_HIGH_DEF ),
m_holePlatingThickness( 0 )
{ {
} }