From 67067c3fd017bd0d5cb91218c4ee4befd0f824ba Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Wed, 14 Apr 2021 15:04:43 +0200 Subject: avoid creating an SfxItemSet here Change-Id: I9bd65c5938c5a500acc026a95de186fdae33e2fe Reviewed-on: https://gerrit.libreoffice.org/c/core/+/114093 Tested-by: Jenkins Reviewed-by: Noel Grandin --- svx/source/svdraw/svdoashp.cxx | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/svx/source/svdraw/svdoashp.cxx b/svx/source/svdraw/svdoashp.cxx index 855d6e0e12ec..409915bc1c8a 100644 --- a/svx/source/svdraw/svdoashp.cxx +++ b/svx/source/svdraw/svdoashp.cxx @@ -1376,12 +1376,21 @@ void SdrObjCustomShape::AdaptTextMinSize() if (getSdrModelFromSdrObject().IsCreatingDataObj() || getSdrModelFromSdrObject().IsPasteResize()) return; + // check if we need to change anything before creating an SfxItemSet, because that is expensive const bool bResizeShapeToFitText(GetObjectItem(SDRATTR_TEXT_AUTOGROWHEIGHT).GetValue()); + tools::Rectangle aTextBound(maRect); + bool bChanged(false); + if(bResizeShapeToFitText) + bChanged = true; + else if(GetTextBounds(aTextBound)) + bChanged = true; + if (!bChanged) + return; + SfxItemSet aSet( *GetObjectItemSet().GetPool(), svl::Items{}); // contains SDRATTR_TEXT_MAXFRAMEWIDTH - bool bChanged(false); if(bResizeShapeToFitText) { @@ -1389,28 +1398,20 @@ void SdrObjCustomShape::AdaptTextMinSize() // to allow resizing being completely dependent on text size only aSet.Put(makeSdrTextMinFrameWidthItem(0)); aSet.Put(makeSdrTextMinFrameHeightItem(0)); - bChanged = true; } else { // recreate from CustomShape-specific TextBounds - tools::Rectangle aTextBound(maRect); + const tools::Long nHDist(GetTextLeftDistance() + GetTextRightDistance()); + const tools::Long nVDist(GetTextUpperDistance() + GetTextLowerDistance()); + const tools::Long nTWdt(std::max(tools::Long(0), static_cast(aTextBound.GetWidth() - 1 - nHDist))); + const tools::Long nTHgt(std::max(tools::Long(0), static_cast(aTextBound.GetHeight() - 1 - nVDist))); - if(GetTextBounds(aTextBound)) - { - const tools::Long nHDist(GetTextLeftDistance() + GetTextRightDistance()); - const tools::Long nVDist(GetTextUpperDistance() + GetTextLowerDistance()); - const tools::Long nTWdt(std::max(tools::Long(0), static_cast(aTextBound.GetWidth() - 1 - nHDist))); - const tools::Long nTHgt(std::max(tools::Long(0), static_cast(aTextBound.GetHeight() - 1 - nVDist))); - - aSet.Put(makeSdrTextMinFrameWidthItem(nTWdt)); - aSet.Put(makeSdrTextMinFrameHeightItem(nTHgt)); - bChanged = true; - } + aSet.Put(makeSdrTextMinFrameWidthItem(nTWdt)); + aSet.Put(makeSdrTextMinFrameHeightItem(nTHgt)); } - if(bChanged) - SetObjectItemSet(aSet); + SetObjectItemSet(aSet); } void SdrObjCustomShape::NbcSetSnapRect( const tools::Rectangle& rRect ) -- cgit