Adjust justified text for mirroring and rotation.

Fixes https://gitlab.com/kicad/code/kicad/issues/3737
This commit is contained in:
Jeff Young 2020-02-04 20:57:39 +00:00
parent 134a7ba85d
commit 2507f985ad
2 changed files with 96 additions and 1 deletions

View File

@ -134,39 +134,132 @@ void LIB_TEXT::MoveTo( const wxPoint& newPosition )
} }
void LIB_TEXT::NormalizeJustification( bool inverse )
{
wxPoint delta( 0, 0 );
EDA_RECT bbox = GetTextBox( -1 );
if( GetTextAngle() == 0.0 )
{
if( GetHorizJustify() == GR_TEXT_HJUSTIFY_LEFT )
delta.x = bbox.GetWidth() / 2;
else if( GetHorizJustify() == GR_TEXT_HJUSTIFY_RIGHT )
delta.x = - bbox.GetWidth() / 2;
if( GetVertJustify() == GR_TEXT_VJUSTIFY_TOP )
delta.y = - bbox.GetHeight() / 2;
else if( GetVertJustify() == GR_TEXT_VJUSTIFY_BOTTOM )
delta.y = bbox.GetHeight() / 2;
}
else
{
if( GetHorizJustify() == GR_TEXT_HJUSTIFY_LEFT )
delta.y = bbox.GetWidth() / 2;
else if( GetHorizJustify() == GR_TEXT_HJUSTIFY_RIGHT )
delta.y = - bbox.GetWidth() / 2;
if( GetVertJustify() == GR_TEXT_VJUSTIFY_TOP )
delta.x = + bbox.GetHeight() / 2;
else if( GetVertJustify() == GR_TEXT_VJUSTIFY_BOTTOM )
delta.x = - bbox.GetHeight() / 2;
}
if( inverse )
SetTextPos( GetTextPos() - delta );
else
SetTextPos( GetTextPos() + delta );
}
void LIB_TEXT::MirrorHorizontal( const wxPoint& center ) void LIB_TEXT::MirrorHorizontal( const wxPoint& center )
{ {
NormalizeJustification( false );
int x = GetTextPos().x; int x = GetTextPos().x;
x -= center.x; x -= center.x;
x *= -1; x *= -1;
x += center.x; x += center.x;
if( GetTextAngle() == 0.0 )
{
if( GetHorizJustify() == GR_TEXT_HJUSTIFY_LEFT )
SetHorizJustify( GR_TEXT_HJUSTIFY_RIGHT );
else if( GetHorizJustify() == GR_TEXT_HJUSTIFY_RIGHT )
SetHorizJustify( GR_TEXT_HJUSTIFY_LEFT );
}
else
{
if( GetVertJustify() == GR_TEXT_VJUSTIFY_TOP )
SetVertJustify( GR_TEXT_VJUSTIFY_BOTTOM );
else if( GetVertJustify() == GR_TEXT_VJUSTIFY_BOTTOM )
SetVertJustify( GR_TEXT_VJUSTIFY_TOP );
}
SetTextX( x ); SetTextX( x );
NormalizeJustification( true );
} }
void LIB_TEXT::MirrorVertical( const wxPoint& center ) void LIB_TEXT::MirrorVertical( const wxPoint& center )
{ {
NormalizeJustification( false );
int y = GetTextPos().y; int y = GetTextPos().y;
y -= center.y; y -= center.y;
y *= -1; y *= -1;
y += center.y; y += center.y;
if( GetTextAngle() == 0.0 )
{
if( GetVertJustify() == GR_TEXT_VJUSTIFY_TOP )
SetVertJustify( GR_TEXT_VJUSTIFY_BOTTOM );
else if( GetVertJustify() == GR_TEXT_VJUSTIFY_BOTTOM )
SetVertJustify( GR_TEXT_VJUSTIFY_TOP );
}
else
{
if( GetHorizJustify() == GR_TEXT_HJUSTIFY_LEFT )
SetHorizJustify( GR_TEXT_HJUSTIFY_RIGHT );
else if( GetHorizJustify() == GR_TEXT_HJUSTIFY_RIGHT )
SetHorizJustify( GR_TEXT_HJUSTIFY_LEFT );
}
SetTextY( y ); SetTextY( y );
NormalizeJustification( true );
} }
void LIB_TEXT::Rotate( const wxPoint& center, bool aRotateCCW ) void LIB_TEXT::Rotate( const wxPoint& center, bool aRotateCCW )
{ {
NormalizeJustification( false );
int rot_angle = aRotateCCW ? -900 : 900; int rot_angle = aRotateCCW ? -900 : 900;
wxPoint pt = GetTextPos(); wxPoint pt = GetTextPos();
RotatePoint( &pt, center, rot_angle ); RotatePoint( &pt, center, rot_angle );
SetTextPos( pt ); SetTextPos( pt );
SetTextAngle( GetTextAngle() != 0.0 ? 0 : 900 ); if( GetTextAngle() == 0.0 )
{
SetTextAngle( 900 );
}
else
{
// 180º of rotation is a mirror
if( GetHorizJustify() == GR_TEXT_HJUSTIFY_LEFT )
SetHorizJustify( GR_TEXT_HJUSTIFY_RIGHT );
else if( GetHorizJustify() == GR_TEXT_HJUSTIFY_RIGHT )
SetHorizJustify( GR_TEXT_HJUSTIFY_LEFT );
if( GetVertJustify() == GR_TEXT_VJUSTIFY_TOP )
SetVertJustify( GR_TEXT_VJUSTIFY_BOTTOM );
else if( GetVertJustify() == GR_TEXT_VJUSTIFY_BOTTOM )
SetVertJustify( GR_TEXT_VJUSTIFY_TOP );
SetTextAngle( 0 );
}
NormalizeJustification( true );
} }

View File

@ -89,6 +89,8 @@ public:
void MirrorVertical( const wxPoint& aCenter ) override; void MirrorVertical( const wxPoint& aCenter ) override;
void Rotate( const wxPoint& aCenter, bool aRotateCCW = true ) override; void Rotate( const wxPoint& aCenter, bool aRotateCCW = true ) override;
void NormalizeJustification( bool inverse );
void Plot( PLOTTER* aPlotter, const wxPoint& aOffset, bool aFill, void Plot( PLOTTER* aPlotter, const wxPoint& aOffset, bool aFill,
const TRANSFORM& aTransform ) override; const TRANSFORM& aTransform ) override;