From 825265f093a844f952d0dd64e5b4de9a1aba3185 Mon Sep 17 00:00:00 2001 From: umeshkadam Date: Mon, 21 Apr 2014 19:46:00 +0530 Subject: fdo#77718: Picture inside SmartArt changes after RT - The image data stream for the targets of relId's were getting overwritten, therefore the data was getting loss. - Added anchor id as part of computing a unique name for images. - Added UT for the same. Change-Id: I999ba1b3701ef357641dd0365403a5d7ad8d18aa Reviewed-on: https://gerrit.libreoffice.org/9121 Reviewed-by: Miklos Vajna Tested-by: Miklos Vajna --- sw/qa/extras/ooxmlexport/data/fdo77718.docx | Bin 0 -> 554994 bytes sw/qa/extras/ooxmlexport/ooxmlexport.cxx | 34 +++++++++++++++++++++++++++- sw/source/filter/ww8/docxsdrexport.cxx | 10 ++++---- sw/source/filter/ww8/docxsdrexport.hxx | 3 ++- 4 files changed, 41 insertions(+), 6 deletions(-) create mode 100644 sw/qa/extras/ooxmlexport/data/fdo77718.docx (limited to 'sw') diff --git a/sw/qa/extras/ooxmlexport/data/fdo77718.docx b/sw/qa/extras/ooxmlexport/data/fdo77718.docx new file mode 100644 index 000000000000..7a22485f7644 Binary files /dev/null and b/sw/qa/extras/ooxmlexport/data/fdo77718.docx differ diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport.cxx index 631f415d2c86..31fd36badc1e 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport.cxx @@ -2748,11 +2748,43 @@ DECLARE_OOXMLEXPORT_TEST(testFdo74792, "fdo74792.docx") comphelper::getComponentContext(m_xSFactory), m_aTempFile.GetURL()); //check that images are also saved - OUString sImageFile( "word/media/OOXDiagramDataRels0.jpeg" ); + OUString sImageFile( "word/media/OOXDiagramDataRels1_0.jpeg" ); //added anchor id to form a uniqe name uno::Reference xInputStream(xNameAccess->getByName( sImageFile ), uno::UNO_QUERY); CPPUNIT_ASSERT( xInputStream.is() ); } +DECLARE_OOXMLEXPORT_TEST(testFdo77718, "fdo77718.docx") +{ + //in case of multiple smart arts the names for images were getting + //repeated and thereby causing a data loss as the binary stream was + //getting over written. This test case ensures that unique names are + //given for images in different smart arts. + xmlDocPtr pXmlDataRels1 = parseExport("word/diagrams/_rels/data1.xml.rels"); + if( !pXmlDataRels1 ) + return; + + xmlDocPtr pXmlDataRels2 = parseExport("word/diagrams/_rels/data2.xml.rels"); + if( !pXmlDataRels2 ) + return; + + //ensure that the rels file is present. + assertXPath(pXmlDataRels1,"/rels:Relationships/rels:Relationship", 4); + assertXPath(pXmlDataRels2,"/rels:Relationships/rels:Relationship", 4); + + uno::Reference xNameAccess = packages::zip::ZipFileAccess::createWithURL( + comphelper::getComponentContext(m_xSFactory), m_aTempFile.GetURL()); + + //check that images are also saved + OUString sImageFile1( "word/media/OOXDiagramDataRels1_0.jpeg" ); //added anchor id to form a uniqe name + uno::Reference xInputStream1(xNameAccess->getByName( sImageFile1 ), uno::UNO_QUERY); + CPPUNIT_ASSERT( xInputStream1.is() ); + + //check that images are saved for other smart-arts as well. + OUString sImageFile2( "word/media/OOXDiagramDataRels2_0.jpeg" ); //added anchor id to form a uniqe name + uno::Reference xInputStream2(xNameAccess->getByName( sImageFile2 ), uno::UNO_QUERY); + CPPUNIT_ASSERT( xInputStream2.is() ); +} + DECLARE_OOXMLEXPORT_TEST(testTableCurruption, "tableCurrupt.docx") { xmlDocPtr pXmlDoc = parseExport("word/header4.xml"); diff --git a/sw/source/filter/ww8/docxsdrexport.cxx b/sw/source/filter/ww8/docxsdrexport.cxx index da3c9e92769d..5c5d5a233dcb 100644 --- a/sw/source/filter/ww8/docxsdrexport.cxx +++ b/sw/source/filter/ww8/docxsdrexport.cxx @@ -807,7 +807,8 @@ void DocxSdrExport::writeDMLEffectLst(const SwFrmFmt& rFrmFmt) void DocxSdrExport::writeDiagramRels(uno::Reference xDom, uno::Sequence< uno::Sequence< uno::Any > > xRelSeq, - uno::Reference< io::XOutputStream > xOutStream, const OUString& sGrabBagProperyName) + uno::Reference< io::XOutputStream > xOutStream, const OUString& sGrabBagProperyName, + int nAnchorId) { // add image relationships of OOXData, OOXDiagram OUString sType("http://schemas.openxmlformats.org/officeDocument/2006/relationships/image"); @@ -838,7 +839,8 @@ void DocxSdrExport::writeDiagramRels(uno::Reference xDom, uno::Reference dataImagebin(new ::comphelper::SequenceInputStream(dataSeq)); OUString sFragment("../media/"); - sFragment += sGrabBagProperyName + OUString::number(j) + sExtension; + //nAnchorId is used to make the name unique irrespective of the number of smart arts. + sFragment += sGrabBagProperyName + OUString::number(nAnchorId) + "_" + OUString::number(j) + sExtension; PropertySet aProps(xOutStream); aProps.setAnyProperty(PROP_RelId, uno::makeAny(sal_Int32(sRelId.toInt32()))); @@ -1021,7 +1023,7 @@ void DocxSdrExport::writeDiagram(const SdrObject* sdrObject, const SwFrmFmt& rFr uno::Sequence< beans::StringPair >()); // write the associated Images and rels for data file - writeDiagramRels(dataDom, xDataRelSeq, xDataOutputStream, OUString("OOXDiagramDataRels")); + writeDiagramRels(dataDom, xDataRelSeq, xDataOutputStream, OUString("OOXDiagramDataRels"), nAnchorId); // write layout file serializer.set(layoutDom, uno::UNO_QUERY); @@ -1058,7 +1060,7 @@ void DocxSdrExport::writeDiagram(const SdrObject* sdrObject, const SwFrmFmt& rFr // write the associated Images and rels for drawing file uno::Sequence< uno::Sequence< uno::Any > > xDrawingRelSeq; diagramDrawing[1] >>= xDrawingRelSeq; - writeDiagramRels(drawingDom, xDrawingRelSeq, xDrawingOutputStream, OUString("OOXDiagramDrawingRels")); + writeDiagramRels(drawingDom, xDrawingRelSeq, xDrawingOutputStream, OUString("OOXDiagramDrawingRels"), nAnchorId); } } diff --git a/sw/source/filter/ww8/docxsdrexport.hxx b/sw/source/filter/ww8/docxsdrexport.hxx index dced28cdcae6..32a5644701ef 100644 --- a/sw/source/filter/ww8/docxsdrexport.hxx +++ b/sw/source/filter/ww8/docxsdrexport.hxx @@ -87,7 +87,8 @@ public: void writeDiagram(const SdrObject* sdrObject, const SwFrmFmt& rFrmFmt, int nAnchorId); void writeDiagramRels(com::sun::star::uno::Reference< com::sun::star::xml::dom::XDocument> xDom, com::sun::star::uno::Sequence< com::sun::star::uno::Sequence< com::sun::star::uno::Any > > xRelSeq, - com::sun::star::uno::Reference< com::sun::star::io::XOutputStream > xOutStream, const OUString& sGrabBagProperyName); + com::sun::star::uno::Reference< com::sun::star::io::XOutputStream > xOutStream, const OUString& sGrabBagProperyName, + int nAnchorId); /// Writes text frame in DML format. void writeDMLTextFrame(sw::Frame* pParentFrame, int nAnchorId); /// Writes text frame in VML format. -- cgit