summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTünde Tóth <toth.tunde@nisz.hu>2023-01-24 15:02:09 +0100
committerLászló Németh <nemeth@numbertext.org>2023-01-30 11:25:32 +0000
commitf589d7e769bee4b82826a944fed3cf2382d84fb2 (patch)
tree6ca4ac02b86fa43e7f258158082ba0f03d5b306c
parent9c9a711ac5d8f32ac318d0e4ecab7b3a26bc2150 (diff)
tdf#153185 PPTX: fix export of linked OLE objects
Linked OLE objects were not exported. Change-Id: If6e8c6e0d0c9917e8ec476ad14dcaa1602c74b29 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/146073 Tested-by: Jenkins Tested-by: László Németh <nemeth@numbertext.org> Reviewed-by: László Németh <nemeth@numbertext.org>
-rw-r--r--oox/source/export/shapes.cxx64
-rw-r--r--sd/qa/unit/data/odp/linked_ole.odpbin0 -> 15351 bytes
-rw-r--r--sd/qa/unit/export-tests-ooxml3.cxx18
3 files changed, 57 insertions, 25 deletions
diff --git a/oox/source/export/shapes.cxx b/oox/source/export/shapes.cxx
index d6b3a9e9ef99..1c828d438653 100644
--- a/oox/source/export/shapes.cxx
+++ b/oox/source/export/shapes.cxx
@@ -2602,49 +2602,60 @@ ShapeExport& ShapeExport::WriteOLE2Shape( const Reference< XShape >& xShape )
OUString sRelationType;
OUString sSuffix;
const char * pProgID(nullptr);
+ OString anotherProgID;
uno::Reference<io::XInputStream> const xInStream =
oox::GetOLEObjectStream(
mpFB->getComponentContext(), xObj, progID,
sMediaType, sRelationType, sSuffix, pProgID);
+ OUString sURL;
+ OUString sRelId;
if (!xInStream.is())
{
- return *this;
- }
+ xPropSet->getPropertyValue("LinkURL") >>= sURL;
+ if (sURL.isEmpty())
+ return *this;
- OString anotherProgID;
- if (!pProgID && !progID.isEmpty())
- {
- anotherProgID = OUStringToOString(progID, RTL_TEXTENCODING_UTF8);
- pProgID = anotherProgID.getStr();
+ sRelId = mpFB->addRelation(mpFS->getOutputStream(),
+ oox::getRelationship(Relationship::OLEOBJECT), sURL, true);
}
+ else
+ {
+ if (!pProgID && !progID.isEmpty())
+ {
+ anotherProgID = OUStringToOString(progID, RTL_TEXTENCODING_UTF8);
+ pProgID = anotherProgID.getStr();
+ }
+
+ assert(!sMediaType.isEmpty());
+ assert(!sRelationType.isEmpty());
+ assert(!sSuffix.isEmpty());
- assert(!sMediaType.isEmpty());
- assert(!sRelationType.isEmpty());
- assert(!sSuffix.isEmpty());
+ OUString sFileName
+ = "embeddings/oleObject" + OUString::number(++m_nEmbeddedObjects) + "." + sSuffix;
+ uno::Reference<io::XOutputStream> const xOutStream(mpFB->openFragmentStream(
+ OUString::createFromAscii(GetComponentDir()) + "/" + sFileName, sMediaType));
+ assert(xOutStream.is()); // no reason why that could fail
- OUString sFileName = "embeddings/oleObject" + OUString::number(++m_nEmbeddedObjects) + "." + sSuffix;
- uno::Reference<io::XOutputStream> const xOutStream(
- mpFB->openFragmentStream(
- OUString::createFromAscii(GetComponentDir()) + "/" + sFileName,
- sMediaType));
- assert(xOutStream.is()); // no reason why that could fail
+ try
+ {
+ ::comphelper::OStorageHelper::CopyInputToOutput(xInStream, xOutStream);
+ }
+ catch (uno::Exception const&)
+ {
+ TOOLS_WARN_EXCEPTION("oox.shape", "ShapeExport::WriteOLEObject");
+ }
- try {
- ::comphelper::OStorageHelper::CopyInputToOutput(xInStream, xOutStream);
- } catch (uno::Exception const&) {
- TOOLS_WARN_EXCEPTION("oox.shape", "ShapeExport::WriteOLEObject");
+ sRelId = mpFB->addRelation(
+ mpFS->getOutputStream(), sRelationType,
+ Concat2View(OUString::createFromAscii(GetRelationCompPrefix()) + sFileName));
}
sal_Int64 nAspect;
bool bShowAsIcon = (xPropSet->getPropertyValue("Aspect") >>= nAspect)
&& nAspect == embed::Aspects::MSOLE_ICON;
- OUString const sRelId = mpFB->addRelation(
- mpFS->getOutputStream(), sRelationType,
- Concat2View(OUString::createFromAscii(GetRelationCompPrefix()) + sFileName));
-
mpFS->startElementNS(mnXmlNamespace, XML_graphicFrame);
mpFS->startElementNS(mnXmlNamespace, XML_nvGraphicFramePr);
@@ -2682,7 +2693,10 @@ ShapeExport& ShapeExport::WriteOLE2Shape( const Reference< XShape >& xShape )
XML_spid, "" );
}
- mpFS->singleElementNS( mnXmlNamespace, XML_embed );
+ if (sURL.isEmpty())
+ mpFS->singleElementNS(mnXmlNamespace, XML_embed);
+ else
+ mpFS->singleElementNS(mnXmlNamespace, XML_link, XML_updateAutomatic, "1");
// pic element
SdrObject* pSdrOLE2(SdrObject::getSdrObjectFromXShape(xShape));
diff --git a/sd/qa/unit/data/odp/linked_ole.odp b/sd/qa/unit/data/odp/linked_ole.odp
new file mode 100644
index 000000000000..13fb0a845a13
--- /dev/null
+++ b/sd/qa/unit/data/odp/linked_ole.odp
Binary files differ
diff --git a/sd/qa/unit/export-tests-ooxml3.cxx b/sd/qa/unit/export-tests-ooxml3.cxx
index 7753abe651ee..2bbb68875760 100644
--- a/sd/qa/unit/export-tests-ooxml3.cxx
+++ b/sd/qa/unit/export-tests-ooxml3.cxx
@@ -131,6 +131,7 @@ public:
void testAutofittedTextboxIndent();
void testTdf151622_oleIcon();
void testTdf152436();
+ void testLinkedOLE();
CPPUNIT_TEST_SUITE(SdOOXMLExportTest3);
@@ -223,6 +224,7 @@ public:
CPPUNIT_TEST(testAutofittedTextboxIndent);
CPPUNIT_TEST(testTdf151622_oleIcon);
CPPUNIT_TEST(testTdf152436);
+ CPPUNIT_TEST(testLinkedOLE);
CPPUNIT_TEST_SUITE_END();
virtual void registerNamespaces(xmlXPathContextPtr& pXmlXPathCtx) override
@@ -2121,6 +2123,22 @@ void SdOOXMLExportTest3::testTdf152436()
CPPUNIT_ASSERT_EQUAL(sal_Int32(1), getPage(0)->getCount());
}
+void SdOOXMLExportTest3::testLinkedOLE()
+{
+ createSdImpressDoc("odp/linked_ole.odp");
+
+ save("Impress Office Open XML");
+
+ xmlDocUniquePtr pXml = parseExport("ppt/slides/slide1.xml");
+
+ // Without the accompanying fix in place, this test would have failed with:
+ // - Expected: 1
+ // - Actual : 0
+ // - In<>, XPath '//p:oleObj' number of nodes is incorrect
+ // i.e. the linked ole object wasn't exported.
+ assertXPath(pXml, "//p:oleObj", 1);
+}
+
CPPUNIT_TEST_SUITE_REGISTRATION(SdOOXMLExportTest3);
CPPUNIT_PLUGIN_IMPLEMENT();