oox/source/drawingml/shape.cxx | 37 +++++++------------------------------ sd/qa/unit/export-tests-ooxml4.cxx | 22 +++++++++------------- 2 files changed, 16 insertions(+), 43 deletions(-)
New commits: commit 0d88061459c0d5200d7f87acc63babdac30e4d43 Author: Mike Kaganski <mike.kagan...@collabora.com> AuthorDate: Wed Jan 17 21:21:24 2024 +0600 Commit: Xisco Fauli <xiscofa...@libreoffice.org> CommitDate: Thu Jan 25 11:04:33 2024 +0100 tdf#140912, tdf#159219: fix import of graphic placeholder with custom prompt Importing the text marks the object as not empty. Then, the object would behave as an outliner object. This includes showing in slide show; allowing text esiting; stretching the placeholder image, which required a workaround implemented in commit 7b3be7f6f3d800e2ad86f5a043e6e9b21ed4409f (tdf#140912 Better handling of the picture placeholders, 2021-12-01). Instead, drop the custom prompt. More correct solution would be making sure to mark the object as empty after setting the text; but this doesn't round- trip to ODF; and it crashes export to PPTX. Proper support for the sustom placeholder prompt feature should be done separately. The new workaround (dropping the text) makes previous workaround (special handling of the placeholder graphic) unnecessary. The unit test is updated. Change-Id: Ic7f42493af8d1d725ffa39ffab58f1ff033351cc Reviewed-on: https://gerrit.libreoffice.org/c/core/+/162202 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com> Signed-off-by: Xisco Fauli <xiscofa...@libreoffice.org> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/162239 diff --git a/oox/source/drawingml/shape.cxx b/oox/source/drawingml/shape.cxx index c42a9f7820a3..22cc551ed6b2 100644 --- a/oox/source/drawingml/shape.cxx +++ b/oox/source/drawingml/shape.cxx @@ -95,7 +95,6 @@ #include <basegfx/matrix/b2dhommatrix.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/svdobj.hxx> #include <svx/svdotable.hxx> #include <svx/svdtrans.hxx> @@ -1539,35 +1538,6 @@ Reference< XShape > const & Shape::createAndInsert( propertySet->setPropertyValue("InteropGrabBag",uno::Any(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 (mpTablePropertiesPtr && aServiceName == "com.sun.star.drawing.TableShape") @@ -1873,6 +1843,13 @@ Reference< XShape > const & Shape::createAndInsert( aPropertySet.setAnyProperty( PROP_VertOrientPosition, Any( maPosition.Y ) ); } + // Make sure to not set text to placeholders. Doing it here would eventually call + // SvxTextEditSourceImpl::UpdateData, SdrObject::SetEmptyPresObj(false), and that + // would make the object behave like a standard outline object. + // TODO/FIXME: support custom prompt text in placeholders. + if (rServiceName == "com.sun.star.presentation.GraphicObjectShape") + mpTextBody.reset(); + // in some cases, we don't have any text body. if( mpTextBody && ( !bDoNotInsertEmptyTextBody || !mpTextBody->isEmpty() ) ) { diff --git a/sd/qa/unit/export-tests-ooxml4.cxx b/sd/qa/unit/export-tests-ooxml4.cxx index b09614454df9..c4c061c50d2d 100644 --- a/sd/qa/unit/export-tests-ooxml4.cxx +++ b/sd/qa/unit/export-tests-ooxml4.cxx @@ -751,22 +751,18 @@ CPPUNIT_TEST_FIXTURE(SdOOXMLExportTest4, testTdf147121) CPPUNIT_TEST_FIXTURE(SdOOXMLExportTest4, testTdf140912_PicturePlaceholder) { - // FIXME: the DPI check should be removed when either (1) the test is fixed to work with - // non-default DPI; or (2) unit tests on Windows are made to use svp VCL plugin. - // -8490 in the test below turns into -8014 on my Windows box with 150% scaling. - if (!IsDefaultDPI()) - return; - + // Given a graphic placeholder with a custom prompt: createSdImpressDoc("pptx/tdfpictureplaceholder.pptx"); uno::Reference<beans::XPropertySet> xShapeProps(getShapeFromPage(0, 0)); - 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); + bool isEmptyPresentationObject = false; + // Without the fix, it would not be imported as empty presentation object; + // the text would be treated as its content. + xShapeProps->getPropertyValue("IsEmptyPresentationObject") >>= isEmptyPresentationObject; + CPPUNIT_ASSERT(isEmptyPresentationObject); + + // If we supported custom prompt text, here we would also test "String" property, + // which would be equal to "Insert Image". } CPPUNIT_TEST_FIXTURE(SdOOXMLExportTest4, testEnhancedPathViewBox)