From bb08ef2f419b1dfbbc00c4f155d7dd7448a97f0a Mon Sep 17 00:00:00 2001 From: Mikolaj Wielgus Date: Thu, 2 Dec 2021 16:33:49 +0100 Subject: [PATCH] Fix SCH_TEXT rotation around a reference point Fixes https://gitlab.com/kicad/code/kicad/issues/9690 --- eeschema/sch_text.cpp | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/eeschema/sch_text.cpp b/eeschema/sch_text.cpp index 7c6fb092d5..85c9085d51 100644 --- a/eeschema/sch_text.cpp +++ b/eeschema/sch_text.cpp @@ -299,13 +299,21 @@ void SCH_TEXT::MirrorVertically( int aCenter ) void SCH_TEXT::Rotate( const wxPoint& aCenter ) { - wxPoint pt = GetTextPos(); - RotatePoint( &pt, aCenter, 900 ); + wxPoint pt = GetBoundingBox().GetCenter(); wxPoint offset = pt - GetTextPos(); + RotatePoint( &pt, aCenter, 900 ); + + // `offset` compensates for `GetTextPos()` not being the item center. + SetTextPos( pt - offset ); + + + pt = GetBoundingBox().GetCenter(); Rotate90( false ); - SetTextPos( GetTextPos() + offset ); + // Compensate for `Rotate90()` shifting the item center. + offset = GetBoundingBox().GetCenter() - pt; + SetTextPos( GetTextPos() - offset ); } @@ -556,7 +564,7 @@ const EDA_RECT SCH_TEXT::GetBoundingBox() const { EDA_RECT rect = GetTextBox(); - if( GetTextAngle() != 0 ) // Rotate rect + if( GetTextAngle() != 0 ) { wxPoint pos = rect.GetOrigin(); wxPoint end = rect.GetEnd(); @@ -566,9 +574,10 @@ const EDA_RECT SCH_TEXT::GetBoundingBox() const rect.SetOrigin( pos ); rect.SetEnd( end ); + + rect.Normalize(); } - rect.Normalize(); return rect; }