diff options
author | Szymon Kłos <szymon.klos@collabora.com> | 2018-02-13 17:47:23 +0100 |
---|---|---|
committer | Szymon Kłos <szymon.klos@collabora.com> | 2018-02-16 17:27:27 +0100 |
commit | 2c2919cb591d88b11bb2e25e45d6f75923821457 (patch) | |
tree | d77e2de6e306b2c48d6953fb391369417f94036b /svx/source/svdraw | |
parent | 168c5e4994e1b9e742911273ecb0b959396d5bf0 (diff) |
PPTX export scale for TextFitToSize
MSO requires to save fontScale attribute to have
all the text shown properly (with FitToSize property)
Values are approximated, after any modification in MSO
scale is recalculated.
Change-Id: I73657fdd663b540b436747cfeeef3c76e8fe388c
Reviewed-on: https://gerrit.libreoffice.org/49742
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Szymon Kłos <szymon.klos@collabora.com>
Diffstat (limited to 'svx/source/svdraw')
-rw-r--r-- | svx/source/svdraw/svdotext.cxx | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/svx/source/svdraw/svdotext.cxx b/svx/source/svdraw/svdotext.cxx index a0cf962a7671..4a9f69d1afe3 100644 --- a/svx/source/svdraw/svdotext.cxx +++ b/svx/source/svdraw/svdotext.cxx @@ -1259,6 +1259,69 @@ void SdrTextObj::ImpSetupDrawOutlinerForPaint( bool bContourFrame, } } +double SdrTextObj::GetFontScaleY() const +{ + SdrText* pText = getActiveText(); + if (pText == nullptr || !pText->GetOutlinerParaObject() || pModel == nullptr) + return 1.0; + + SdrOutliner& rOutliner = ImpGetDrawOutliner(); + const Size aShapeSize = GetSnapRect().GetSize(); + const Size aSize = Size(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)); + } + } + + return std::min(sal_uInt16(100), nCurrStretchY) / 100.0; +} + void SdrTextObj::ImpAutoFitText( SdrOutliner& rOutliner ) const { const Size aShapeSize=GetSnapRect().GetSize(); |