sw/qa/extras/rtfimport/data/do-dhgt-old.rtf | 10 ++++++++++ sw/qa/extras/rtfimport/rtfimport.cxx | 17 +++++++++++++++++ writerfilter/source/dmapper/GraphicHelpers.cxx | 10 +++++++--- writerfilter/source/dmapper/GraphicHelpers.hxx | 2 +- writerfilter/source/rtftok/rtfdocumentimpl.cxx | 2 +- writerfilter/source/rtftok/rtfsdrimport.cxx | 8 ++++---- writerfilter/source/rtftok/rtfsdrimport.hxx | 2 +- 7 files changed, 41 insertions(+), 10 deletions(-)
New commits: commit e4fe3610eb17c441217c80536f0acf4123abd683 Author: Miklos Vajna <vmik...@collabora.co.uk> Date: Fri Mar 14 16:48:17 2014 +0100 RTF import: fix ordering of old-style dhght in case of equal values Commit 1eaab77c718ffa254068ae6032862dfb5a03db67 (fdo#60722 import RTF_SHPZ, 2013-03-06) changed how we handle z-order, in case two shapes have the same value. Turns out for drawing-objects the order is the opposite in this situation. So fix this by adding a new mode, that keeps the original testcase happy without breaking older documents. Change-Id: Ib2d284cefc3c0dce40ac2e516ba260d6cd04ce43 diff --git a/sw/qa/extras/rtfimport/data/do-dhgt-old.rtf b/sw/qa/extras/rtfimport/data/do-dhgt-old.rtf new file mode 100644 index 0000000..07da38f --- /dev/null +++ b/sw/qa/extras/rtfimport/data/do-dhgt-old.rtf @@ -0,0 +1,10 @@ +{\rtf1 +{\colortbl\red255\green255\blue255; \red0\green0\blue0; } +{\*\do\dobxpage\dobypara\dodhgt8192\dptxbx\dptxbxmar0 +{\dptxbxtext\ltrpar\f4\fs20\cf1\vertalc\qc\ltrch a\par} +\dpx8594\dpy3486\dpxsize1179\dpysize221\dplinehollow0} +{\*\do\dobxpage\dobypara\dodhgt8192\dprect\dproundr\dpx9807\dpy3968\dpxsize1644\dpysize566\dplinecor255\dplinecog255\dplinecob255\dpfillbgcr0\dpfillbgcg0\dpfillbgcb0\dpfillpat1\dplinehollow0} +{\*\do\dobxpage\dobypara\dodhgt8192\dptxbx\dptxbxmar0 +{\dptxbxtext\ltrpar\f2\fs20\cf0\vertalc\i\b\qc\ltrch b\par} +\dpx9864\dpy4138\dpxsize1530\dpysize226\dplinehollow0} +} diff --git a/sw/qa/extras/rtfimport/rtfimport.cxx b/sw/qa/extras/rtfimport/rtfimport.cxx index 0be7aff..a48f976 100644 --- a/sw/qa/extras/rtfimport/rtfimport.cxx +++ b/sw/qa/extras/rtfimport/rtfimport.cxx @@ -1009,6 +1009,23 @@ DECLARE_RTFIMPORT_TEST(testFdo60722, "fdo60722.rtf") CPPUNIT_ASSERT_EQUAL(sal_uInt32(0), getProperty<sal_uInt32>(xShape, "LineColor")); } +DECLARE_RTFIMPORT_TEST(testDoDhgtOld, "do-dhgt-old.rtf") +{ + // The file contains 3 shapes which have the same dhgt (z-order). + // Test that the order is 1) a 2) black rectangle 3) b, and not something else + uno::Reference<text::XText> xShape(getShape(1), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(sal_Int32(0), getProperty<sal_Int32>(xShape, "ZOrder")); + CPPUNIT_ASSERT_EQUAL(OUString("a"), xShape->getString()); + + xShape.set(getShape(2), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(sal_Int32(1), getProperty<sal_Int32>(xShape, "ZOrder")); + CPPUNIT_ASSERT_EQUAL(COL_BLACK, getProperty<sal_uInt32>(xShape, "FillColor")); + + xShape.set(getShape(3), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(sal_Int32(2), getProperty<sal_Int32>(xShape, "ZOrder")); + CPPUNIT_ASSERT_EQUAL(OUString("b"), xShape->getString()); +} + DECLARE_RTFIMPORT_TEST(testFdo61909, "fdo61909.rtf") { uno::Reference<text::XTextRange> xTextRange = getRun(getParagraph(1), 1); diff --git a/writerfilter/source/dmapper/GraphicHelpers.cxx b/writerfilter/source/dmapper/GraphicHelpers.cxx index 433e30e..da93450 100644 --- a/writerfilter/source/dmapper/GraphicHelpers.cxx +++ b/writerfilter/source/dmapper/GraphicHelpers.cxx @@ -276,14 +276,18 @@ void GraphicZOrderHelper::addItem( uno::Reference< beans::XPropertySet > props, // The relativeHeight value in .docx is an arbitrary number, where only the relative ordering matters. // But in Writer, the z-order is index in 0..(numitems-1) range, so whenever a new item needs to be // added in the proper z-order, it is necessary to find the proper index. -sal_Int32 GraphicZOrderHelper::findZOrder( sal_Int32 relativeHeight ) +sal_Int32 GraphicZOrderHelper::findZOrder( sal_Int32 relativeHeight, bool bOldStyle ) { Items::const_iterator it = items.begin(); while( it != items.end()) { // std::map is iterated sorted by key - // if there is an item that has the same z-order, we belong under it - if( it->first >= relativeHeight ) + + // Old-style ordering differs in what should happen when there is already an item with the same z-order: + // we belong under it in case of new-style, but we belong below it in case of old-style. + bool bCond = bOldStyle ? (it->first > relativeHeight) : (it->first >= relativeHeight); + + if( bCond ) break; // this is the first one higher, we belong right before it else ++it; diff --git a/writerfilter/source/dmapper/GraphicHelpers.hxx b/writerfilter/source/dmapper/GraphicHelpers.hxx index 88d09de..adaba62 100644 --- a/writerfilter/source/dmapper/GraphicHelpers.hxx +++ b/writerfilter/source/dmapper/GraphicHelpers.hxx @@ -75,7 +75,7 @@ class GraphicZOrderHelper { public: void addItem( uno::Reference< beans::XPropertySet > props, sal_Int32 relativeHeight ); - sal_Int32 findZOrder( sal_Int32 relativeHeight ); + sal_Int32 findZOrder( sal_Int32 relativeHeight, bool bOldStyle = false ); private: typedef std::map< sal_Int32, uno::Reference< beans::XPropertySet > > Items; Items items; diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.cxx b/writerfilter/source/rtftok/rtfdocumentimpl.cxx index 4eef7ea..0e21515 100644 --- a/writerfilter/source/rtftok/rtfdocumentimpl.cxx +++ b/writerfilter/source/rtftok/rtfdocumentimpl.cxx @@ -2890,7 +2890,7 @@ int RTFDocumentImpl::dispatchFlag(RTFKeyword nKeyword) std::vector<beans::PropertyValue>& rPendingProperties = m_aStates.top().aDrawingObject.aPendingProperties; for (std::vector<beans::PropertyValue>::iterator i = rPendingProperties.begin(); i != rPendingProperties.end(); ++i) m_aStates.top().aDrawingObject.xPropertySet->setPropertyValue(i->Name, i->Value); - m_pSdrImport->resolveDhgt(m_aStates.top().aDrawingObject.xPropertySet, m_aStates.top().aDrawingObject.nDhgt); + m_pSdrImport->resolveDhgt(m_aStates.top().aDrawingObject.xPropertySet, m_aStates.top().aDrawingObject.nDhgt, /*bOldStyle=*/true); } break; case RTF_DOBXMARGIN: diff --git a/writerfilter/source/rtftok/rtfsdrimport.cxx b/writerfilter/source/rtftok/rtfsdrimport.cxx index 14e2df2..fa147d7 100644 --- a/writerfilter/source/rtftok/rtfsdrimport.cxx +++ b/writerfilter/source/rtftok/rtfsdrimport.cxx @@ -119,12 +119,12 @@ void RTFSdrImport::popParent() m_aParents.pop(); } -void RTFSdrImport::resolveDhgt(uno::Reference<beans::XPropertySet> xPropertySet, sal_Int32 nZOrder) +void RTFSdrImport::resolveDhgt(uno::Reference<beans::XPropertySet> xPropertySet, sal_Int32 nZOrder, bool bOldStyle) { writerfilter::dmapper::DomainMapper& rMapper = dynamic_cast<writerfilter::dmapper::DomainMapper&>(m_rImport.Mapper()); writerfilter::dmapper::GraphicZOrderHelper* pHelper = rMapper.graphicZOrderHelper(); - xPropertySet->setPropertyValue("ZOrder", uno::makeAny(pHelper->findZOrder(nZOrder))); + xPropertySet->setPropertyValue("ZOrder", uno::makeAny(pHelper->findZOrder(nZOrder, bOldStyle))); pHelper->addItem(xPropertySet, nZOrder); } @@ -455,7 +455,7 @@ void RTFSdrImport::resolve(RTFShape& rShape, bool bClose) { // dhgt is Word 2007, \shpz is Word 97-2003, the later has priority. if (!rShape.oZ) - resolveDhgt(xPropertySet, i->second.toInt32()); + resolveDhgt(xPropertySet, i->second.toInt32(), /*bOldStyle=*/false); } // These are in EMU, convert to mm100. else if (i->first == "dxTextLeft") @@ -565,7 +565,7 @@ void RTFSdrImport::resolve(RTFShape& rShape, bool bClose) } } if (rShape.oZ) - resolveDhgt(xPropertySet, *rShape.oZ); + resolveDhgt(xPropertySet, *rShape.oZ, /*bOldStyle=*/false); if (m_bTextFrame) // Writer textframes implement text::WritingMode2, which is a different data type. xPropertySet->setPropertyValue("WritingMode", uno::makeAny(sal_Int16(eWritingMode))); diff --git a/writerfilter/source/rtftok/rtfsdrimport.hxx b/writerfilter/source/rtftok/rtfsdrimport.hxx index 333927d..31d08b4 100644 --- a/writerfilter/source/rtftok/rtfsdrimport.hxx +++ b/writerfilter/source/rtftok/rtfsdrimport.hxx @@ -28,7 +28,7 @@ namespace writerfilter { void append(OUString aKey, OUString aValue); /// Append property on the current parent. void appendGroupProperty(OUString aKey, OUString aValue); - void resolveDhgt(uno::Reference<beans::XPropertySet> xPropertySet, sal_Int32 nZOrder); + void resolveDhgt(uno::Reference<beans::XPropertySet> xPropertySet, sal_Int32 nZOrder, bool bOldStyle); void resolveFLine(uno::Reference<beans::XPropertySet> xPropertySet, sal_Int32 nFLine); /** * These are the default in Word, but not in Writer. _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits