diff options
author | Mike Kaganski <mike.kaganski@collabora.com> | 2021-06-06 21:50:53 +0300 |
---|---|---|
committer | Mike Kaganski <mike.kaganski@collabora.com> | 2021-06-06 21:58:09 +0200 |
commit | a1ae30166e92a0a40dff06740f0bb8e9ee63f70a (patch) | |
tree | f5020467afb9bd47282817b29605ea2dc483db2d /svx | |
parent | 2671476e7c8acc6569840e66e6d306b890b431fd (diff) |
Fix and unify the two methods that get scaled text size
GetTextFitToSizeScale and SdrTextObj::GetFontScaleY both didn't
initialize outliners properly, and thus returned wrong results.
Change-Id: I6fe63c51ed838a0d0fafdfa03597cac97ce29831
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/116765
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'svx')
-rw-r--r-- | svx/source/svdraw/svdotext.cxx | 65 | ||||
-rw-r--r-- | svx/source/unodraw/unoshape.cxx | 9 |
2 files changed, 8 insertions, 66 deletions
diff --git a/svx/source/svdraw/svdotext.cxx b/svx/source/svdraw/svdotext.cxx index ef9cedaeedb5..090ffc901dfe 100644 --- a/svx/source/svdraw/svdotext.cxx +++ b/svx/source/svdraw/svdotext.cxx @@ -51,6 +51,7 @@ #include <vcl/virdev.hxx> #include <basegfx/matrix/b2dhommatrixtools.hxx> #include <sal/log.hxx> +#include <o3tl/temporary.hxx> using namespace com::sun::star; @@ -1186,67 +1187,15 @@ void SdrTextObj::ImpSetupDrawOutlinerForPaint( bool bContourFrame, } } -double SdrTextObj::GetFontScaleY() const +sal_uInt16 SdrTextObj::GetFontScaleY() const { - SdrText* pText = getActiveText(); - if (pText == nullptr || !pText->GetOutlinerParaObject()) - return 1.0; - SdrOutliner& rOutliner = ImpGetDrawOutliner(); - const Size aShapeSize = GetSnapRect().GetSize(); - const Size aSize(aShapeSize.Width() - GetTextLeftDistance() - GetTextRightDistance(), - aShapeSize.Height() - GetTextUpperDistance() - GetTextLowerDistance()); - - rOutliner.SetPaperSize(aSize); - rOutliner.SetUpdateMode(true); - rOutliner.SetText(*pText->GetOutlinerParaObject()); - bool bIsVerticalWriting = IsVerticalWriting(); - - // Algorithm from SdrTextObj::ImpAutoFitText - - sal_uInt16 nMinStretchX = 0, nMinStretchY = 0; - sal_uInt16 nCurrStretchX = 100, nCurrStretchY = 100; - sal_uInt16 aOldStretchXVals[] = { 0,0,0 }; - const size_t aStretchArySize = SAL_N_ELEMENTS(aOldStretchXVals); - for (unsigned int i = 0; i<aStretchArySize; ++i) - { - const Size aCurrTextSize = rOutliner.CalcTextSizeNTP(); - double fFactor(1.0); - if (bIsVerticalWriting) - { - if (aCurrTextSize.Width() != 0) - { - fFactor = double(aSize.Width()) / aCurrTextSize.Width(); - } - } - else if (aCurrTextSize.Height() != 0) - { - fFactor = double(aSize.Height()) / aCurrTextSize.Height(); - } - fFactor = std::sqrt(fFactor); - - rOutliner.GetGlobalCharStretching(nCurrStretchX, nCurrStretchY); - - if (fFactor >= 1.0) - { - nMinStretchX = std::max(nMinStretchX, nCurrStretchX); - nMinStretchY = std::max(nMinStretchY, nCurrStretchY); - } - - aOldStretchXVals[i] = nCurrStretchX; - if (std::find(aOldStretchXVals, aOldStretchXVals + i, nCurrStretchX) != aOldStretchXVals + i) - break; // same value already attained once; algo is looping, exit - - if (fFactor < 1.0 || nCurrStretchX != 100) - { - nCurrStretchX = sal::static_int_cast<sal_uInt16>(nCurrStretchX*fFactor); - nCurrStretchY = sal::static_int_cast<sal_uInt16>(nCurrStretchY*fFactor); - rOutliner.SetGlobalCharStretching(std::min(sal_uInt16(100), nCurrStretchX), - std::min(sal_uInt16(100), nCurrStretchY)); - } - } + // This eventually calls ImpAutoFitText + UpdateOutlinerFormatting(rOutliner, o3tl::temporary(tools::Rectangle())); - return std::min(sal_uInt16(100), nCurrStretchY) / 100.0; + sal_uInt16 nStretchY; + rOutliner.GetGlobalCharStretching(o3tl::temporary(sal_uInt16()), nStretchY); + return nStretchY; } void SdrTextObj::ImpAutoFitText( SdrOutliner& rOutliner ) const diff --git a/svx/source/unodraw/unoshape.cxx b/svx/source/unodraw/unoshape.cxx index 1c6d3c9c451c..984356691261 100644 --- a/svx/source/unodraw/unoshape.cxx +++ b/svx/source/unodraw/unoshape.cxx @@ -186,14 +186,7 @@ sal_Int16 GetTextFitToSizeScale(SdrObject* pObject) return 0; } - std::unique_ptr<SdrOutliner> pOutliner - = pTextObj->getSdrModelFromSdrObject().createOutliner(OutlinerMode::TextObject); - tools::Rectangle aBoundRect(pTextObj->GetCurrentBoundRect()); - pTextObj->SetupOutlinerFormatting(*pOutliner, aBoundRect); - sal_uInt16 nX = 0; - sal_uInt16 nY = 0; - pOutliner->GetGlobalCharStretching(nX, nY); - return nY; + return pTextObj->GetFontScaleY(); } } |