[Libreoffice-commits] core.git: Branch 'libreoffice-6-2' - oox/source sd/qa
Grzegorz Araminowicz (via logerrit)
logerrit at kemper.freedesktop.org
Mon Jun 3 07:48:40 UTC 2019
oox/source/drawingml/diagram/diagramlayoutatoms.cxx | 16 ++++++++-
sd/qa/unit/data/pptx/smartart-font-size.pptx |binary
sd/qa/unit/import-tests-smartart.cxx | 34 ++++++++++++++++++++
3 files changed, 49 insertions(+), 1 deletion(-)
New commits:
commit 9b4cb15e41618fb1943c6c2cb150582dccc5c96c
Author: Grzegorz Araminowicz <grzegorz.araminowicz at collabora.com>
AuthorDate: Mon May 27 20:00:42 2019 +0200
Commit: Miklos Vajna <vmiklos at collabora.com>
CommitDate: Mon Jun 3 09:48:01 2019 +0200
SmartArt: adjust text size to fit shapes
up to maximal size of primFontSz constraint.
Do not override text size changed by user.
Change-Id: If7ea6bbb96cb839831d877edc274a1b0eefdaf21
Reviewed-on: https://gerrit.libreoffice.org/73050
Tested-by: Jenkins
Reviewed-by: Miklos Vajna <vmiklos at collabora.com>
Reviewed-on: https://gerrit.libreoffice.org/73251
diff --git a/oox/source/drawingml/diagram/diagramlayoutatoms.cxx b/oox/source/drawingml/diagram/diagramlayoutatoms.cxx
index bc30ec38e219..808960093f29 100644
--- a/oox/source/drawingml/diagram/diagramlayoutatoms.cxx
+++ b/oox/source/drawingml/diagram/diagramlayoutatoms.cxx
@@ -31,6 +31,7 @@
#include <drawingml/textrun.hxx>
#include <drawingml/customshapeproperties.hxx>
#include <tools/gen.hxx>
+#include <com/sun/star/drawing/TextFitToSizeType.hpp>
using namespace ::com::sun::star;
using namespace ::com::sun::star::uno;
@@ -1105,6 +1106,7 @@ void AlgAtom::layoutShape( const ShapePtr& rShape,
// adjust text alignment
// Parse constraints, only self margins as a start.
+ double fFontSize = 0;
for (const auto& rConstr : rConstraints)
{
if (rConstr.mnRefType == XML_w)
@@ -1124,9 +1126,10 @@ void AlgAtom::layoutShape( const ShapePtr& rShape,
rShape->getShapeProperties().setProperty(nProperty, nValue);
}
+ if (rConstr.mnType == XML_primFontSz)
+ fFontSize = rConstr.mfValue;
}
- // TODO: adjust text size to fit shape
TextBodyPtr pTextBody = rShape->getTextBody();
if (!pTextBody ||
pTextBody->getParagraphs().empty() ||
@@ -1135,6 +1138,17 @@ void AlgAtom::layoutShape( const ShapePtr& rShape,
break;
}
+ // adjust text size to fit shape
+ if (fFontSize != 0)
+ {
+ for (auto& aParagraph : pTextBody->getParagraphs())
+ for (auto& aRun : aParagraph->getRuns())
+ if (!aRun->getTextCharacterProperties().moHeight.has())
+ aRun->getTextCharacterProperties().moHeight = fFontSize * 100;
+ }
+ pTextBody->getTextProperties().maPropertyMap.setProperty(PROP_TextFitToSize, drawing::TextFitToSizeType_AUTOFIT);
+
+ // ECMA-376-1:2016 21.4.7.5 ST_AutoTextRotation (Auto Text Rotation)
const sal_Int32 nautoTxRot = maMap.count(XML_autoTxRot) ? maMap.find(XML_autoTxRot)->second : XML_upr;
switch(nautoTxRot)
diff --git a/sd/qa/unit/data/pptx/smartart-font-size.pptx b/sd/qa/unit/data/pptx/smartart-font-size.pptx
new file mode 100644
index 000000000000..253cd4c73b65
Binary files /dev/null and b/sd/qa/unit/data/pptx/smartart-font-size.pptx differ
diff --git a/sd/qa/unit/import-tests-smartart.cxx b/sd/qa/unit/import-tests-smartart.cxx
index 682c775b80fe..624205c5380a 100644
--- a/sd/qa/unit/import-tests-smartart.cxx
+++ b/sd/qa/unit/import-tests-smartart.cxx
@@ -10,6 +10,8 @@
#include "sdmodeltestbase.hxx"
#include <com/sun/star/beans/XPropertySet.hpp>
+#include <com/sun/star/drawing/FillStyle.hpp>
+#include <com/sun/star/drawing/TextFitToSizeType.hpp>
#include <com/sun/star/drawing/XShape.hpp>
#include <com/sun/star/style/ParagraphAdjust.hpp>
#include <com/sun/star/text/XText.hpp>
@@ -71,6 +73,7 @@ public:
void testInteropGrabBag();
void testBackground();
void testBackgroundDrawingmlFallback();
+ void testFontSize();
CPPUNIT_TEST_SUITE(SdImportTestSmartArt);
@@ -106,6 +109,7 @@ public:
CPPUNIT_TEST(testInteropGrabBag);
CPPUNIT_TEST(testBackground);
CPPUNIT_TEST(testBackgroundDrawingmlFallback);
+ CPPUNIT_TEST(testFontSize);
CPPUNIT_TEST_SUITE_END();
};
@@ -997,6 +1001,36 @@ void SdImportTestSmartArt::testBackgroundDrawingmlFallback()
xDocShRef->DoClose();
}
+void SdImportTestSmartArt::testFontSize()
+{
+ sd::DrawDocShellRef xDocShRef = loadURL(
+ m_directories.getURLFromSrc("/sd/qa/unit/data/pptx/smartart-font-size.pptx"), PPTX);
+
+ uno::Reference<drawing::XShapes> xGroup1(getShapeFromPage(0, 0, xDocShRef), uno::UNO_QUERY);
+ uno::Reference<beans::XPropertySet> xShape1(xGroup1->getByIndex(1), uno::UNO_QUERY);
+ uno::Reference<text::XTextRange> xParagraph1(getParagraphFromShape(0, xShape1));
+ uno::Reference<text::XTextRange> xRun1(getRunFromParagraph(0, xParagraph1));
+ uno::Reference<beans::XPropertySet> xPropSet1(xRun1, uno::UNO_QUERY);
+ double fFontSize1 = xPropSet1->getPropertyValue("CharHeight").get<double>();
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(65.0, fFontSize1, 0.01);
+
+ uno::Reference<drawing::XShapes> xGroup2(getShapeFromPage(1, 0, xDocShRef), uno::UNO_QUERY);
+ uno::Reference<beans::XPropertySet> xShape2(xGroup2->getByIndex(1), uno::UNO_QUERY);
+ uno::Reference<text::XTextRange> xParagraph2(getParagraphFromShape(0, xShape2));
+ uno::Reference<text::XTextRange> xRun2(getRunFromParagraph(0, xParagraph2));
+ uno::Reference<beans::XPropertySet> xPropSet2(xRun2, uno::UNO_QUERY);
+ double fFontSize2 = xPropSet2->getPropertyValue("CharHeight").get<double>();
+ CPPUNIT_ASSERT_EQUAL(32.0, fFontSize2);
+
+ uno::Reference<drawing::XShapes> xGroup3(getShapeFromPage(2, 0, xDocShRef), uno::UNO_QUERY);
+ uno::Reference<beans::XPropertySet> xShape3(xGroup3->getByIndex(1), uno::UNO_QUERY);
+ drawing::TextFitToSizeType eTextFitToSize = drawing::TextFitToSizeType_NONE;
+ xShape3->getPropertyValue("TextFitToSize") >>= eTextFitToSize;
+ CPPUNIT_ASSERT_EQUAL(drawing::TextFitToSizeType_AUTOFIT, eTextFitToSize);
+
+ xDocShRef->DoClose();
+}
+
CPPUNIT_TEST_SUITE_REGISTRATION(SdImportTestSmartArt);
CPPUNIT_PLUGIN_IMPLEMENT();
More information about the Libreoffice-commits
mailing list