diff options
author | Grzegorz Araminowicz <grzegorz.araminowicz@collabora.com> | 2019-05-27 20:00:42 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2019-05-28 14:09:42 +0200 |
commit | 14c4e6155271d04f0a86029635d0a4c0b460146a (patch) | |
tree | 7a5ff528a8858ba5cdf1fd5c1acb766f691cb0b4 | |
parent | a2179fb76bb1e1da43e8185130866ea334537b13 (diff) |
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@collabora.com>
-rw-r--r-- | oox/source/drawingml/diagram/diagramlayoutatoms.cxx | 15 | ||||
-rw-r--r-- | sd/qa/unit/data/pptx/smartart-font-size.pptx | bin | 0 -> 63915 bytes | |||
-rw-r--r-- | sd/qa/unit/import-tests-smartart.cxx | 33 |
3 files changed, 47 insertions, 1 deletions
diff --git a/oox/source/drawingml/diagram/diagramlayoutatoms.cxx b/oox/source/drawingml/diagram/diagramlayoutatoms.cxx index dcd19a61c9e4..a9b2f0c1c5a1 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; @@ -1127,6 +1128,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) @@ -1146,9 +1148,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() || @@ -1157,6 +1160,16 @@ 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; sal_Int32 nShapeRot = rShape->getRotation(); diff --git a/sd/qa/unit/data/pptx/smartart-font-size.pptx b/sd/qa/unit/data/pptx/smartart-font-size.pptx Binary files differnew file mode 100644 index 000000000000..253cd4c73b65 --- /dev/null +++ b/sd/qa/unit/data/pptx/smartart-font-size.pptx diff --git a/sd/qa/unit/import-tests-smartart.cxx b/sd/qa/unit/import-tests-smartart.cxx index 1e726a5d1339..f07cca532e1b 100644 --- a/sd/qa/unit/import-tests-smartart.cxx +++ b/sd/qa/unit/import-tests-smartart.cxx @@ -11,6 +11,7 @@ #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> @@ -75,6 +76,7 @@ public: void testBackground(); void testBackgroundDrawingmlFallback(); void testCenterCycle(); + void testFontSize(); CPPUNIT_TEST_SUITE(SdImportTestSmartArt); @@ -112,6 +114,7 @@ public: CPPUNIT_TEST(testBackground); CPPUNIT_TEST(testBackgroundDrawingmlFallback); CPPUNIT_TEST(testCenterCycle); + CPPUNIT_TEST(testFontSize); CPPUNIT_TEST_SUITE_END(); }; @@ -1166,6 +1169,36 @@ void SdImportTestSmartArt::testCenterCycle() 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(); |