summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/svx/svdotext.hxx2
-rw-r--r--oox/source/export/drawingml.cxx5
-rw-r--r--sd/qa/unit/export-tests-ooxml2.cxx5
-rw-r--r--svx/source/svdraw/svdotext.cxx65
-rw-r--r--svx/source/unodraw/unoshape.cxx9
5 files changed, 12 insertions, 74 deletions
diff --git a/include/svx/svdotext.hxx b/include/svx/svdotext.hxx
index 61a63f660950..a3ff2e1fda50 100644
--- a/include/svx/svdotext.hxx
+++ b/include/svx/svdotext.hxx
@@ -392,7 +392,7 @@ public:
// FitToSize and Fontwork are not taken into account in GetTextSize()!
virtual const Size& GetTextSize() const;
void FitFrameToTextSize();
- double GetFontScaleY() const;
+ sal_uInt16 GetFontScaleY() const;
// Simultaneously sets the text into the Outliner (possibly
// the one of the EditOutliner) and sets the PaperSize.
diff --git a/oox/source/export/drawingml.cxx b/oox/source/export/drawingml.cxx
index 6805c1bd3a49..684623a41813 100644
--- a/oox/source/export/drawingml.cxx
+++ b/oox/source/export/drawingml.cxx
@@ -3302,10 +3302,7 @@ void DrawingML::WriteText(const Reference<XInterface>& rXIface, bool bBodyPr, bo
{
SdrTextObj* pTextObject = dynamic_cast<SdrTextObj*>(pTextShape->GetSdrObject());
if (pTextObject)
- {
- double fScaleY = pTextObject->GetFontScaleY();
- nFontScale = static_cast<sal_uInt32>(fScaleY * 100) * 1000;
- }
+ nFontScale = pTextObject->GetFontScaleY() * 1000;
}
mpFS->singleElementNS(XML_a, XML_normAutofit, XML_fontScale,
diff --git a/sd/qa/unit/export-tests-ooxml2.cxx b/sd/qa/unit/export-tests-ooxml2.cxx
index af1fb0e7d99a..abf469788695 100644
--- a/sd/qa/unit/export-tests-ooxml2.cxx
+++ b/sd/qa/unit/export-tests-ooxml2.cxx
@@ -1899,10 +1899,9 @@ void SdOOXMLExportTest2::testFontScale()
xDocShRef = saveAndReload(xDocShRef.get(), PPTX, &tempFile);
xmlDocUniquePtr pXmlDocContent = parseExport(tempFile, "ppt/slides/slide1.xml");
- // Rounding errors possible, approximate value
+ // Rounding errors possible, approximate value (+/- 1%)
OUString sScale = getXPath(pXmlDocContent, "/p:sld/p:cSld/p:spTree/p:sp/p:txBody/a:bodyPr/a:normAutofit", "fontScale");
- if (sScale != "73000" && sScale != "72000" && sScale != "74000")
- CPPUNIT_ASSERT_EQUAL(OUString("73000"), sScale);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(sal_Int32(76000), sScale.toInt32(), 1000);
xDocShRef->DoClose();
}
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();
}
}