summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2022-11-23 11:00:13 +0900
committerTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2022-12-29 16:04:40 +0900
commited5100f96c63ec49a53969c0694ac77645175533 (patch)
tree640f26ffca649b1ef5deccb5955f4703740c3a5f
parent44c5c59d5a596e3bbbfcf779ad0f6af5623fdfa3 (diff)
svx: convert SdrTextObj rotate and move to use gfx::Lengthprivate/tvajngerl/staging
Change-Id: I82f10f82db8ac9d5653f4902276ee58fc18c52d6
-rw-r--r--include/basegfx/utils/RectangleWrapper.hxx5
-rw-r--r--svx/source/svdraw/svdotxtr.cxx73
2 files changed, 62 insertions, 16 deletions
diff --git a/include/basegfx/utils/RectangleWrapper.hxx b/include/basegfx/utils/RectangleWrapper.hxx
index 00586d6eae71..4f5dbe851f66 100644
--- a/include/basegfx/utils/RectangleWrapper.hxx
+++ b/include/basegfx/utils/RectangleWrapper.hxx
@@ -55,6 +55,11 @@ public:
m_aRange.setSize(width, height);
}
+ void shift(gfx::Length const& rXDelta, gfx::Length const& rYDelta)
+ {
+ m_aRange.shift(rXDelta, rYDelta);
+ }
+
void move(sal_Int32 nXDelta, sal_Int32 nYDelta)
{
auto deltaX = gfx::Length::hmm(nXDelta);
diff --git a/svx/source/svdraw/svdotxtr.cxx b/svx/source/svdraw/svdotxtr.cxx
index e2a050c99dba..1ac82bc3db47 100644
--- a/svx/source/svdraw/svdotxtr.cxx
+++ b/svx/source/svdraw/svdotxtr.cxx
@@ -39,6 +39,35 @@
using namespace com::sun::star;
+namespace
+{
+gfx::Tuple2DL rotatePoint(gfx::Tuple2DL const& rPoint, gfx::Tuple2DL const& rReference, double sinAngle, double cosAngle)
+{
+ gfx::Length dx = rPoint.getX() - rReference.getX();
+ gfx::Length dy = rPoint.getY() - rReference.getY();
+
+ auto x = rReference.getX() + gfx::Length::emu(basegfx::fround(dx.raw() * cosAngle + dy.raw() * sinAngle));
+ auto y = rReference.getY() + gfx::Length::emu(basegfx::fround(dy.raw() * cosAngle - dx.raw() * sinAngle));
+
+ return gfx::Tuple2DL(x, y);
+}
+
+gfx::Tuple2DL toTuple(Point const& rPointHmm)
+{
+ auto x = gfx::Length::hmm(rPointHmm.X());
+ auto y = gfx::Length::hmm(rPointHmm.Y());
+ return {x, y};
+}
+
+gfx::Size2DL toSize2D(Size const& rSizeHmm)
+{
+ auto x = gfx::Length::hmm(rSizeHmm.Width());
+ auto y = gfx::Length::hmm(rSizeHmm.Height());
+ return {x, y};
+}
+
+} // end anonymous ns
+
void SdrTextObj::NbcSetSnapRect(const tools::Rectangle& rRect)
{
if (maGeo.nRotationAngle || maGeo.nShearAngle)
@@ -91,7 +120,9 @@ Degree100 SdrTextObj::GetShearAngle(bool /*bVertical*/) const
void SdrTextObj::NbcMove(const Size& rSize)
{
- moveRectangle(rSize.Width(), rSize.Height());
+ gfx::Size2DL aSize2D = toSize2D(rSize);
+ maRectangle.shift(aSize2D.getWidth(), aSize2D.getHeight());
+
moveOutRectangle(rSize.Width(), rSize.Height());
maSnapRect.Move(rSize);
SetBoundAndSnapRectsDirty(true);
@@ -182,27 +213,37 @@ void SdrTextObj::NbcResize(const Point& rRef, const Fraction& xFact, const Fract
SetBoundAndSnapRectsDirty();
}
-void SdrTextObj::NbcRotate(const Point& rRef, Degree100 nAngle, double sn, double cs)
+void SdrTextObj::NbcRotate(const Point& rRef, Degree100 nAngle, double sinAngle, double cosAngle)
{
+ auto aReference = toTuple(rRef);
+
SetGlueReallyAbsolute(true);
- tools::Long dx = getRectangle().Right() - getRectangle().Left();
- tools::Long dy = getRectangle().Bottom() - getRectangle().Top();
- Point aPoint1(getRectangle().TopLeft());
- RotatePoint(aPoint1, rRef, sn, cs);
- Point aPoint2(aPoint1.X() + dx, aPoint1.Y() + dy);
- tools::Rectangle aRectangle(aPoint1, aPoint2);
- setRectangle(aRectangle);
+ auto const& rRange = maRectangle.getRange();
+
+ auto nWidth = rRange.getWidth();
+ auto nHeight = rRange.getHeight();
+
+ gfx::Tuple2DL aPoint1(rRange.getMinX(), rRange.getMinY());
+ aPoint1 = rotatePoint(aPoint1, aReference, sinAngle, cosAngle);
- if (maGeo.nRotationAngle==0_deg100) {
- maGeo.nRotationAngle=NormAngle36000(nAngle);
- maGeo.mfSinRotationAngle=sn;
- maGeo.mfCosRotationAngle=cs;
- } else {
- maGeo.nRotationAngle=NormAngle36000(maGeo.nRotationAngle+nAngle);
+ gfx::Tuple2DL aPoint2(aPoint1.getX() + nWidth, aPoint1.getY() + nHeight);
+
+ gfx::Range2DL aRange{aPoint1, aPoint2};
+ maRectangle.setRange(aRange);
+
+ if (maGeo.nRotationAngle == 0_deg100)
+ {
+ maGeo.nRotationAngle = NormAngle36000(nAngle);
+ maGeo.mfSinRotationAngle = sinAngle;
+ maGeo.mfCosRotationAngle = cosAngle;
+ }
+ else
+ {
+ maGeo.nRotationAngle = NormAngle36000(maGeo.nRotationAngle + nAngle);
maGeo.RecalcSinCos();
}
SetBoundAndSnapRectsDirty();
- NbcRotateGluePoints(rRef,nAngle,sn,cs);
+ NbcRotateGluePoints(rRef, nAngle, sinAngle, cosAngle);
SetGlueReallyAbsolute(false);
}