include/svx/svdobj.hxx | 1 svx/source/svdraw/svdobj.cxx | 142 +++++++++++++++++++++++------------------ svx/source/svdraw/svdotxdr.cxx | 61 ----------------- 3 files changed, 85 insertions(+), 119 deletions(-)
New commits: commit e9424085769f6143ba7be9a9abb6e7b57e34bf9b Author: Laurent Balland <[email protected]> AuthorDate: Sun Sep 21 16:06:25 2025 +0200 Commit: Miklos Vajna <[email protected]> CommitDate: Mon Sep 22 08:45:15 2025 +0200 follow-up tdf#168318 Remove duplicate code Removing duplicate code in resizing SdrObject was not incorrect in https://gerrit.libreoffice.org/184931 After reverting it, this commit fix the problem to avoid tdf#168318 by using correted position point after rotating and shearing Change-Id: I908918213141fc911c5e709d3301d83ff0652ad7 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/191294 Tested-by: Jenkins Reviewed-by: Miklos Vajna <[email protected]> diff --git a/include/svx/svdobj.hxx b/include/svx/svdobj.hxx index f9dac6e810bb..4c249b8a1048 100644 --- a/include/svx/svdobj.hxx +++ b/include/svx/svdobj.hxx @@ -917,6 +917,7 @@ protected: virtual std::unique_ptr<sdr::contact::ViewContact> CreateObjectSpecificViewContact(); + static void ImpCommonDragCalcRect(const SdrDragStat& rDrag, tools::Rectangle& rTmpRect, const Point& rPos); tools::Rectangle ImpDragCalcRect(const SdrDragStat& rDrag) const; // for GetDragComment diff --git a/svx/source/svdraw/svdobj.cxx b/svx/source/svdraw/svdobj.cxx index 90e310d14254..32067bb33d47 100644 --- a/svx/source/svdraw/svdobj.cxx +++ b/svx/source/svdraw/svdobj.cxx @@ -1249,71 +1249,95 @@ void SdrObject::addCropHandles(SdrHdlList& /*rTarget*/) const // SdrGrafObj and SwVirtFlyDrawObj } -tools::Rectangle SdrObject::ImpDragCalcRect(const SdrDragStat& rDrag) const +void SdrObject::ImpCommonDragCalcRect(const SdrDragStat& rDrag, tools::Rectangle& rTmpRect, const Point& rPos) { - tools::Rectangle aTmpRect(GetSnapRect()); - tools::Rectangle aRect(aTmpRect); - const SdrHdl* pHdl=rDrag.GetHdl(); - SdrHdlKind eHdl=pHdl==nullptr ? SdrHdlKind::Move : pHdl->GetKind(); - bool bEcke=(eHdl==SdrHdlKind::UpperLeft || eHdl==SdrHdlKind::UpperRight || eHdl==SdrHdlKind::LowerLeft || eHdl==SdrHdlKind::LowerRight); - bool bOrtho=rDrag.GetView()!=nullptr && rDrag.GetView()->IsOrtho(); - bool bBigOrtho=bEcke && bOrtho && rDrag.GetView()->IsBigOrtho(); - Point aPos(rDrag.GetNow()); - bool bLft=(eHdl==SdrHdlKind::UpperLeft || eHdl==SdrHdlKind::Left || eHdl==SdrHdlKind::LowerLeft); - bool bRgt=(eHdl==SdrHdlKind::UpperRight || eHdl==SdrHdlKind::Right || eHdl==SdrHdlKind::LowerRight); - bool bTop=(eHdl==SdrHdlKind::UpperRight || eHdl==SdrHdlKind::Upper || eHdl==SdrHdlKind::UpperLeft); - bool bBtm=(eHdl==SdrHdlKind::LowerRight || eHdl==SdrHdlKind::Lower || eHdl==SdrHdlKind::LowerLeft); - if (bLft) aTmpRect.SetLeft(aPos.X() ); - if (bRgt) aTmpRect.SetRight(aPos.X() ); - if (bTop) aTmpRect.SetTop(aPos.Y() ); - if (bBtm) aTmpRect.SetBottom(aPos.Y() ); - if (bOrtho) { // Ortho - tools::Long nWdt0=aRect.Right() -aRect.Left(); - tools::Long nHgt0=aRect.Bottom()-aRect.Top(); - tools::Long nXMul=aTmpRect.Right() -aTmpRect.Left(); - tools::Long nYMul=aTmpRect.Bottom()-aTmpRect.Top(); - tools::Long nXDiv=nWdt0; - tools::Long nYDiv=nHgt0; - bool bXNeg=(nXMul<0)!=(nXDiv<0); - bool bYNeg=(nYMul<0)!=(nYDiv<0); - nXMul=std::abs(nXMul); - nYMul=std::abs(nYMul); - nXDiv=std::abs(nXDiv); - nYDiv=std::abs(nYDiv); - Fraction aXFact(nXMul,nXDiv); // fractions for canceling - Fraction aYFact(nYMul,nYDiv); // and for comparing - nXMul=aXFact.GetNumerator(); - nYMul=aYFact.GetNumerator(); - nXDiv=aXFact.GetDenominator(); - nYDiv=aYFact.GetDenominator(); - if (bEcke) { // corner point handles - bool bUseX=(aXFact<aYFact) != bBigOrtho; - if (bUseX) { - tools::Long nNeed=tools::Long(BigInt(nHgt0)*BigInt(nXMul)/BigInt(nXDiv)); - if (bYNeg) nNeed=-nNeed; - if (bTop) aTmpRect.SetTop(aTmpRect.Bottom()-nNeed ); - if (bBtm) aTmpRect.SetBottom(aTmpRect.Top()+nNeed ); - } else { - tools::Long nNeed=tools::Long(BigInt(nWdt0)*BigInt(nYMul)/BigInt(nYDiv)); - if (bXNeg) nNeed=-nNeed; - if (bLft) aTmpRect.SetLeft(aTmpRect.Right()-nNeed ); - if (bRgt) aTmpRect.SetRight(aTmpRect.Left()+nNeed ); + const tools::Rectangle aRect(rTmpRect); + const SdrHdl* pHdl = rDrag.GetHdl(); + SdrHdlKind eHdl = (pHdl==nullptr ? SdrHdlKind::Move : pHdl->GetKind()); + bool bCorner = (eHdl==SdrHdlKind::UpperLeft || eHdl==SdrHdlKind::UpperRight || eHdl==SdrHdlKind::LowerLeft || eHdl==SdrHdlKind::LowerRight); + bool bOrtho = rDrag.GetView()!=nullptr && rDrag.GetView()->IsOrtho(); + bool bBigOrtho = bCorner && bOrtho && rDrag.GetView()->IsBigOrtho(); + bool bLft = (eHdl==SdrHdlKind::UpperLeft || eHdl==SdrHdlKind::Left || eHdl==SdrHdlKind::LowerLeft); + bool bRgt = (eHdl==SdrHdlKind::UpperRight || eHdl==SdrHdlKind::Right || eHdl==SdrHdlKind::LowerRight); + bool bTop = (eHdl==SdrHdlKind::UpperRight || eHdl==SdrHdlKind::Upper || eHdl==SdrHdlKind::UpperLeft); + bool bBtm = (eHdl==SdrHdlKind::LowerRight || eHdl==SdrHdlKind::Lower || eHdl==SdrHdlKind::LowerLeft); + if (bLft) + rTmpRect.SetLeft( rPos.X() ); + else if (bRgt) + rTmpRect.SetRight( rPos.X() ); + if (bTop) + rTmpRect.SetTop( rPos.Y() ); + else if (bBtm) + rTmpRect.SetBottom( rPos.Y() ); + if (bOrtho) // Ortho + { + tools::Long nWdt0 = aRect.Right() - aRect.Left(); + tools::Long nHgt0 = aRect.Bottom()- aRect.Top(); + tools::Long nXMul = rTmpRect.Right() - rTmpRect.Left(); + tools::Long nYMul = rTmpRect.Bottom()- rTmpRect.Top(); + tools::Long nXDiv = nWdt0; + tools::Long nYDiv = nHgt0; + bool bXNeg = ((nXMul<0) != (nXDiv<0)); + bool bYNeg = ((nYMul<0) != (nYDiv<0)); + nXMul = std::abs(nXMul); + nYMul = std::abs(nYMul); + nXDiv = std::abs(nXDiv); + nYDiv = std::abs(nYDiv); + Fraction aXFact(nXMul, nXDiv); // fractions for canceling + Fraction aYFact(nYMul, nYDiv); // and for comparing + nXMul = aXFact.GetNumerator(); + nYMul = aYFact.GetNumerator(); + nXDiv = aXFact.GetDenominator(); + nYDiv = aYFact.GetDenominator(); + if (bCorner) // corner point handles + { + bool bUseX = ((aXFact<aYFact) != bBigOrtho); + if (bUseX) + { + tools::Long nNeed = tools::Long( BigInt(nHgt0) * BigInt(nXMul) / BigInt(nXDiv) ); + if (bYNeg) + nNeed = -nNeed; + if (bTop) + rTmpRect.SetTop( rTmpRect.Bottom() - nNeed ); + else if (bBtm) + rTmpRect.SetBottom( rTmpRect.Top() + nNeed ); } - } else { // apex handles - if ((bLft || bRgt) && nXDiv!=0) { - tools::Long nHgt0b=aRect.Bottom()-aRect.Top(); - tools::Long nNeed=tools::Long(BigInt(nHgt0b)*BigInt(nXMul)/BigInt(nXDiv)); - aTmpRect.AdjustTop( -((nNeed-nHgt0b)/2) ); - aTmpRect.SetBottom(aTmpRect.Top()+nNeed ); + else + { + tools::Long nNeed = tools::Long( BigInt(nWdt0) * BigInt(nYMul) / BigInt(nYDiv) ); + if (bXNeg) + nNeed = -nNeed; + if (bLft) + rTmpRect.SetLeft(rTmpRect.Right()-nNeed ); + else if (bRgt) + rTmpRect.SetRight(rTmpRect.Left()+nNeed ); } - if ((bTop || bBtm) && nYDiv!=0) { - tools::Long nWdt0b=aRect.Right()-aRect.Left(); - tools::Long nNeed=tools::Long(BigInt(nWdt0b)*BigInt(nYMul)/BigInt(nYDiv)); - aTmpRect.AdjustLeft( -((nNeed-nWdt0b)/2) ); - aTmpRect.SetRight(aTmpRect.Left()+nNeed ); + } + else // apex handles + { + if ((bLft || bRgt) && nXDiv!=0) + { + tools::Long nHgt0b = aRect.Bottom() - aRect.Top(); + tools::Long nNeed = tools::Long( BigInt(nHgt0b) * BigInt(nXMul) / BigInt(nXDiv) ) ; + rTmpRect.AdjustTop( -((nNeed-nHgt0b)/2) ); + rTmpRect.SetBottom( rTmpRect.Top() + nNeed ); + } + else if ((bTop || bBtm) && nYDiv!=0) + { + tools::Long nWdt0b = aRect.Right() - aRect.Left(); + tools::Long nNeed = tools::Long( BigInt(nWdt0b) * BigInt(nYMul) / BigInt(nYDiv) ); + rTmpRect.AdjustLeft( -((nNeed-nWdt0b)/2) ); + rTmpRect.SetRight( rTmpRect.Left() + nNeed ); } } } +} + +tools::Rectangle SdrObject::ImpDragCalcRect(const SdrDragStat& rDrag) const +{ + tools::Rectangle aTmpRect(GetSnapRect()); + Point aPos(rDrag.GetNow()); + ImpCommonDragCalcRect( rDrag, aTmpRect, aPos ); aTmpRect.Normalize(); return aTmpRect; } diff --git a/svx/source/svdraw/svdotxdr.cxx b/svx/source/svdraw/svdotxdr.cxx index b5348094a295..ebf8c3e484ed 100644 --- a/svx/source/svdraw/svdotxdr.cxx +++ b/svx/source/svdraw/svdotxdr.cxx @@ -74,72 +74,13 @@ bool SdrTextObj::hasSpecialDrag() const tools::Rectangle SdrTextObj::ImpDragCalcRect(const SdrDragStat& rDrag) const { tools::Rectangle aTmpRect(getRectangle()); - const SdrHdl* pHdl=rDrag.GetHdl(); - SdrHdlKind eHdl=pHdl==nullptr ? SdrHdlKind::Move : pHdl->GetKind(); - bool bEcke=(eHdl==SdrHdlKind::UpperLeft || eHdl==SdrHdlKind::UpperRight || eHdl==SdrHdlKind::LowerLeft || eHdl==SdrHdlKind::LowerRight); - bool bOrtho=rDrag.GetView()!=nullptr && rDrag.GetView()->IsOrtho(); - bool bBigOrtho=bEcke && bOrtho && rDrag.GetView()->IsBigOrtho(); Point aPos(rDrag.GetNow()); // Unrotate: if (maGeo.m_nRotationAngle) RotatePoint(aPos,aTmpRect.TopLeft(),-maGeo.mfSinRotationAngle,maGeo.mfCosRotationAngle); // Unshear: if (maGeo.m_nShearAngle) ShearPoint(aPos,aTmpRect.TopLeft(),-maGeo.mfTanShearAngle); + ImpCommonDragCalcRect( rDrag, aTmpRect, aPos ); - bool bLft=(eHdl==SdrHdlKind::UpperLeft || eHdl==SdrHdlKind::Left || eHdl==SdrHdlKind::LowerLeft); - bool bRgt=(eHdl==SdrHdlKind::UpperRight || eHdl==SdrHdlKind::Right || eHdl==SdrHdlKind::LowerRight); - bool bTop=(eHdl==SdrHdlKind::UpperRight || eHdl==SdrHdlKind::Upper || eHdl==SdrHdlKind::UpperLeft); - bool bBtm=(eHdl==SdrHdlKind::LowerRight || eHdl==SdrHdlKind::Lower || eHdl==SdrHdlKind::LowerLeft); - if (bLft) aTmpRect.SetLeft(aPos.X() ); - if (bRgt) aTmpRect.SetRight(aPos.X() ); - if (bTop) aTmpRect.SetTop(aPos.Y() ); - if (bBtm) aTmpRect.SetBottom(aPos.Y() ); - if (bOrtho) { // Ortho - tools::Long nWdt0=getRectangle().Right() - getRectangle().Left(); - tools::Long nHgt0=getRectangle().Bottom() - getRectangle().Top(); - tools::Long nXMul=aTmpRect.Right() -aTmpRect.Left(); - tools::Long nYMul=aTmpRect.Bottom()-aTmpRect.Top(); - tools::Long nXDiv=nWdt0; - tools::Long nYDiv=nHgt0; - bool bXNeg=(nXMul<0)!=(nXDiv<0); - bool bYNeg=(nYMul<0)!=(nYDiv<0); - nXMul=std::abs(nXMul); - nYMul=std::abs(nYMul); - nXDiv=std::abs(nXDiv); - nYDiv=std::abs(nYDiv); - Fraction aXFact(nXMul,nXDiv); // fractions for canceling - Fraction aYFact(nYMul,nYDiv); // and for comparing - nXMul=aXFact.GetNumerator(); - nYMul=aYFact.GetNumerator(); - nXDiv=aXFact.GetDenominator(); - nYDiv=aYFact.GetDenominator(); - if (bEcke) { // corner point handles - bool bUseX=(aXFact<aYFact) != bBigOrtho; - if (bUseX) { - tools::Long nNeed=tools::Long(BigInt(nHgt0)*BigInt(nXMul)/BigInt(nXDiv)); - if (bYNeg) nNeed=-nNeed; - if (bTop) aTmpRect.SetTop(aTmpRect.Bottom()-nNeed ); - if (bBtm) aTmpRect.SetBottom(aTmpRect.Top()+nNeed ); - } else { - tools::Long nNeed=tools::Long(BigInt(nWdt0)*BigInt(nYMul)/BigInt(nYDiv)); - if (bXNeg) nNeed=-nNeed; - if (bLft) aTmpRect.SetLeft(aTmpRect.Right()-nNeed ); - if (bRgt) aTmpRect.SetRight(aTmpRect.Left()+nNeed ); - } - } else { // apex handles - if ((bLft || bRgt) && nXDiv!=0) { - tools::Long nHgt0b=getRectangle().Bottom() - getRectangle().Top(); - tools::Long nNeed=tools::Long(BigInt(nHgt0b)*BigInt(nXMul)/BigInt(nXDiv)); - aTmpRect.AdjustTop( -((nNeed-nHgt0b)/2) ); - aTmpRect.SetBottom(aTmpRect.Top()+nNeed ); - } - if ((bTop || bBtm) && nYDiv!=0) { - tools::Long nWdt0b=getRectangle().Right() - getRectangle().Left(); - tools::Long nNeed=tools::Long(BigInt(nWdt0b)*BigInt(nYMul)/BigInt(nYDiv)); - aTmpRect.AdjustLeft( -((nNeed-nWdt0b)/2) ); - aTmpRect.SetRight(aTmpRect.Left()+nNeed ); - } - } - } if (dynamic_cast<const SdrObjCustomShape*>(this) == nullptr) // not justifying when in CustomShapes, to be able to detect if a shape has to be mirrored ImpJustifyRect(aTmpRect); return aTmpRect;
