include/svx/svdobj.hxx | 1 svx/source/svdraw/svdobj.cxx | 140 ++++++++++++++++------------------------- svx/source/svdraw/svdotxdr.cxx | 62 +++++++++++++++++- 3 files changed, 119 insertions(+), 84 deletions(-)
New commits: commit 183941f9e0668b0963e0157f2d9c414b58741fd6 Author: Laurent Balland <laurent.ball...@mailo.fr> AuthorDate: Tue Sep 16 19:16:03 2025 +0200 Commit: Laurent Balland <laurent.ball...@mailo.fr> CommitDate: Tue Sep 16 22:48:25 2025 +0200 tdf#168318 Revert "Rezing SdrObject: Remove duplicate code" This reverts commit edd0991c3cc1c5ae439e33873c2567ee62d0e710. Reason for revert: unexpected behavior for rotated object (see tdf#168318) Change-Id: Ie83c8d35dba12ff7eca7429efb0ff195eacd205b Reviewed-on: https://gerrit.libreoffice.org/c/core/+/191041 Tested-by: Jenkins Reviewed-by: Laurent Balland <laurent.ball...@mailo.fr> diff --git a/include/svx/svdobj.hxx b/include/svx/svdobj.hxx index 93f4cff8fda9..f9dac6e810bb 100644 --- a/include/svx/svdobj.hxx +++ b/include/svx/svdobj.hxx @@ -917,7 +917,6 @@ protected: virtual std::unique_ptr<sdr::contact::ViewContact> CreateObjectSpecificViewContact(); - static void ImpCommonDragCalcRect(const SdrDragStat& rDrag, tools::Rectangle& rTmpRect); tools::Rectangle ImpDragCalcRect(const SdrDragStat& rDrag) const; // for GetDragComment diff --git a/svx/source/svdraw/svdobj.cxx b/svx/source/svdraw/svdobj.cxx index c945d3ee7362..90e310d14254 100644 --- a/svx/source/svdraw/svdobj.cxx +++ b/svx/source/svdraw/svdobj.cxx @@ -1249,95 +1249,71 @@ void SdrObject::addCropHandles(SdrHdlList& /*rTarget*/) const // SdrGrafObj and SwVirtFlyDrawObj } -void SdrObject::ImpCommonDragCalcRect(const SdrDragStat& rDrag, tools::Rectangle& rTmpRect) +tools::Rectangle SdrObject::ImpDragCalcRect(const SdrDragStat& rDrag) const { - 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(); + 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) - rTmpRect.SetLeft(aPos.X() ); - else if (bRgt) - rTmpRect.SetRight(aPos.X() ); - if (bTop) - rTmpRect.SetTop(aPos.Y() ); - else if (bBtm) - rTmpRect.SetBottom(aPos.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 ); + 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 ); } - 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 ); + } 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 // 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 ); + 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 ); } } } -} - -tools::Rectangle SdrObject::ImpDragCalcRect(const SdrDragStat& rDrag) const -{ - tools::Rectangle aTmpRect(GetSnapRect()); - ImpCommonDragCalcRect( rDrag, aTmpRect ); aTmpRect.Normalize(); return aTmpRect; } diff --git a/svx/source/svdraw/svdotxdr.cxx b/svx/source/svdraw/svdotxdr.cxx index 208302d473d3..b5348094a295 100644 --- a/svx/source/svdraw/svdotxdr.cxx +++ b/svx/source/svdraw/svdotxdr.cxx @@ -74,12 +74,72 @@ 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 ); + + 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;