oox/source/drawingml/shape.cxx | 30 ++++++++++++++++++++++++ oox/source/token/properties.txt | 1 sd/qa/unit/data/pptx/tdfpictureplaceholder.pptx |binary sd/qa/unit/export-tests-ooxml3.cxx | 20 ++++++++++++++++ 4 files changed, 51 insertions(+)
New commits: commit 2be6b90cfa201b894cc893c51ca8e29577e33aa1 Author: gulsahkose <gulsah.k...@collabora.com> AuthorDate: Wed Dec 1 10:46:41 2021 +0300 Commit: Miklos Vajna <vmik...@collabora.com> CommitDate: Fri Dec 3 09:30:18 2021 +0100 tdf#140912 Better handling of the picture placeholders. To see icon and placeholder text at the center of picture placeholder shape, we set the TextContourFrame and GraphicCrop properties. Change-Id: I49e3d08c9020e593232c60c97af3f45fb620075e Reviewed-on: https://gerrit.libreoffice.org/c/core/+/126165 Tested-by: Jenkins Reviewed-by: Miklos Vajna <vmik...@collabora.com> (cherry picked from commit 7b3be7f6f3d800e2ad86f5a043e6e9b21ed4409f) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/126138 diff --git a/oox/source/drawingml/shape.cxx b/oox/source/drawingml/shape.cxx index 8ec9eb43a691..3b0c34e68e52 100644 --- a/oox/source/drawingml/shape.cxx +++ b/oox/source/drawingml/shape.cxx @@ -88,6 +88,7 @@ #include <basegfx/matrix/b2dhommatrixtools.hxx> #include <com/sun/star/document/XActionLockable.hpp> #include <com/sun/star/chart2/data/XDataReceiver.hpp> +#include <com/sun/star/text/GraphicCrop.hpp> #include <svx/svdtrans.hxx> #include <tools/stream.hxx> #include <unotools/streamwrap.hxx> @@ -1347,6 +1348,35 @@ Reference< XShape > const & Shape::createAndInsert( propertySet->setPropertyValue("InteropGrabBag",uno::makeAny(aGrabBag)); } + // If the shape is a picture placeholder. + if (aServiceName == "com.sun.star.presentation.GraphicObjectShape" && !bClearText) + { + // Placeholder text should be in center of the shape. + aShapeProps.setProperty(PROP_TextContourFrame, false); + + /* Placeholder icon should be at the center of the parent shape. + * We use negative graphic crop property because of that we don't + * have padding support. + */ + uno::Reference<beans::XPropertySet> xGraphic(xSet->getPropertyValue("Graphic"), uno::UNO_QUERY); + if (xGraphic.is()) + { + awt::Size aBitmapSize; + xGraphic->getPropertyValue("Size100thMM") >>= aBitmapSize; + sal_Int32 nXMargin = (aShapeRectHmm.Width - aBitmapSize.Width) / 2; + sal_Int32 nYMargin = (aShapeRectHmm.Height - aBitmapSize.Height) / 2; + if (nXMargin > 0 && nYMargin > 0) + { + text::GraphicCrop aGraphicCrop; + aGraphicCrop.Top = nYMargin * -1; + aGraphicCrop.Bottom = nYMargin * -1; + aGraphicCrop.Left = nXMargin * -1; + aGraphicCrop.Right = nXMargin * -1; + aShapeProps.setProperty(PROP_GraphicCrop, aGraphicCrop); + } + } + } + PropertySet( xSet ).setProperties( aShapeProps ); if (mbLockedCanvas) { diff --git a/oox/source/token/properties.txt b/oox/source/token/properties.txt index 68b5e2d14af5..562f26c36f33 100644 --- a/oox/source/token/properties.txt +++ b/oox/source/token/properties.txt @@ -533,6 +533,7 @@ TextBreak TextCameraZRotateAngle TextColor TextColumns +TextContourFrame TextFitToSize TextFrames TextHorizontalAdjust diff --git a/sd/qa/unit/data/pptx/tdfpictureplaceholder.pptx b/sd/qa/unit/data/pptx/tdfpictureplaceholder.pptx new file mode 100644 index 000000000000..d681c749cab0 Binary files /dev/null and b/sd/qa/unit/data/pptx/tdfpictureplaceholder.pptx differ diff --git a/sd/qa/unit/export-tests-ooxml3.cxx b/sd/qa/unit/export-tests-ooxml3.cxx index f842e4b97717..623761f25786 100644 --- a/sd/qa/unit/export-tests-ooxml3.cxx +++ b/sd/qa/unit/export-tests-ooxml3.cxx @@ -37,6 +37,7 @@ #include <com/sun/star/style/LineSpacing.hpp> #include <com/sun/star/style/LineSpacingMode.hpp> #include <com/sun/star/frame/XLoadable.hpp> +#include <com/sun/star/text/GraphicCrop.hpp> #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp> @@ -118,6 +119,7 @@ public: void testTdf96061_textHighlight(); void testTdf142235_TestPlaceholderTextAlignment(); void testTdf143315(); + void testTdf140912_PicturePlaceholder(); CPPUNIT_TEST_SUITE(SdOOXMLExportTest3); @@ -188,6 +190,7 @@ public: CPPUNIT_TEST(testTdf96061_textHighlight); CPPUNIT_TEST(testTdf142235_TestPlaceholderTextAlignment); CPPUNIT_TEST(testTdf143315); + CPPUNIT_TEST(testTdf140912_PicturePlaceholder); CPPUNIT_TEST_SUITE_END(); virtual void registerNamespaces(xmlXPathContextPtr& pXmlXPathCtx) override @@ -1770,6 +1773,23 @@ void SdOOXMLExportTest3::testTdf143315() assertXPath(pXml, "/p:sld/p:cSld/p:spTree/p:sp/p:txBody/a:p/a:pPr/a:buChar", 0); } +void SdOOXMLExportTest3::testTdf140912_PicturePlaceholder() +{ + ::sd::DrawDocShellRef xDocShRef = loadURL( + m_directories.getURLFromSrc(u"/sd/qa/unit/data/pptx/tdfpictureplaceholder.pptx"), PPTX); + + uno::Reference<beans::XPropertySet> xShapeProps(getShapeFromPage(0, 0, xDocShRef)); + bool bTextContourFrame = true; + xShapeProps->getPropertyValue("TextContourFrame") >>= bTextContourFrame; + CPPUNIT_ASSERT_EQUAL(false, bTextContourFrame); + + text::GraphicCrop aGraphicCrop; + xShapeProps->getPropertyValue("GraphicCrop") >>= aGraphicCrop; + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(-8490), aGraphicCrop.Top); + + xDocShRef->DoClose(); +} + CPPUNIT_TEST_SUITE_REGISTRATION(SdOOXMLExportTest3); CPPUNIT_PLUGIN_IMPLEMENT();