summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.co.uk>2014-03-14 16:48:17 +0100
committerMiklos Vajna <vmiklos@collabora.co.uk>2014-03-14 21:20:19 +0100
commite4fe3610eb17c441217c80536f0acf4123abd683 (patch)
tree4bf5c748135cf4d4240c6ce2bf1911e3900236fd
parent62c2fa48de6e2a77f42568b6378c4cc9aa4605a7 (diff)
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
-rw-r--r--sw/qa/extras/rtfimport/data/do-dhgt-old.rtf10
-rw-r--r--sw/qa/extras/rtfimport/rtfimport.cxx17
-rw-r--r--writerfilter/source/dmapper/GraphicHelpers.cxx10
-rw-r--r--writerfilter/source/dmapper/GraphicHelpers.hxx2
-rw-r--r--writerfilter/source/rtftok/rtfdocumentimpl.cxx2
-rw-r--r--writerfilter/source/rtftok/rtfsdrimport.cxx8
-rw-r--r--writerfilter/source/rtftok/rtfsdrimport.hxx2
7 files changed, 41 insertions, 10 deletions
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 000000000000..07da38ff0ef8
--- /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 0be7aff4a017..a48f976a02d8 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 433e30e37eeb..da93450c69d9 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 88d09dede652..adaba624bc81 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 4eef7ea5d0b9..0e215158b1ee 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 14e2df2dfa56..fa147d77445c 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 333927dd827c..31d08b4bba5b 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.