Kaydet (Commit) 825265f0 authored tarafından umeshkadam's avatar umeshkadam Kaydeden (comit) Miklos Vajna

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/9121Reviewed-by: 's avatarMiklos Vajna <vmiklos@collabora.co.uk>
Tested-by: 's avatarMiklos Vajna <vmiklos@collabora.co.uk>
üst dfbaef22
......@@ -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<io::XInputStream> 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<packages::zip::XZipFileAccess2> 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<io::XInputStream> 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<io::XInputStream> xInputStream2(xNameAccess->getByName( sImageFile2 ), uno::UNO_QUERY);
CPPUNIT_ASSERT( xInputStream2.is() );
}
DECLARE_OOXMLEXPORT_TEST(testTableCurruption, "tableCurrupt.docx")
{
xmlDocPtr pXmlDoc = parseExport("word/header4.xml");
......
......@@ -807,7 +807,8 @@ void DocxSdrExport::writeDMLEffectLst(const SwFrmFmt& rFrmFmt)
void DocxSdrExport::writeDiagramRels(uno::Reference<xml::dom::XDocument> 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<xml::dom::XDocument> xDom,
uno::Reference<io::XInputStream> 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);
}
}
......
......@@ -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.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment