[Libreoffice-commits] core.git: Branch 'libreoffice-4-2' - sw/qa writerfilter/source
Miklos Vajna
vmiklos at collabora.co.uk
Mon Mar 17 06:56:15 PDT 2014
sw/qa/extras/rtfimport/data/do-dhgt-old.rtf | 10 ++++++++
sw/qa/extras/rtfimport/data/dprect-anchor.rtf | 4 +++
sw/qa/extras/rtfimport/data/dptxbx-relation.rtf | 5 ++++
sw/qa/extras/rtfimport/rtfimport.cxx | 29 ++++++++++++++++++++++++
writerfilter/source/dmapper/GraphicHelpers.cxx | 10 +++++---
writerfilter/source/dmapper/GraphicHelpers.hxx | 2 -
writerfilter/source/rtftok/rtfdocumentimpl.cxx | 22 ++++++++++++++++--
writerfilter/source/rtftok/rtfsdrimport.cxx | 8 +++---
writerfilter/source/rtftok/rtfsdrimport.hxx | 2 -
9 files changed, 81 insertions(+), 11 deletions(-)
New commits:
commit e6006b5c91c8f6852a1b8b1b7ed1c5e7b4975a68
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date: Fri Mar 14 12:11:13 2014 +0100
RTF import: 3 drawing-object fixes:
This bring back the fdo#fdo42407 bugdoc to the state where it was around
4.0.
- fix dobxpage before dptxbx
The problem was that dobxpage arrived first, set HoriOrientRelation to
FRAME, then dptxbx tried to apply defaults, which overwrote the already
set HoriOrientRelation. Fix this by only applying properties which are
not set yet.
(cherry picked from commit 7c53577f325e5260c538f9ca42cda54ca1a24b7a)
- anchor drawing objects at-character by default
(cherry picked from commit d05b67a7b9448c67c3a923ecb33dac74b52dd192)
- 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.
(cherry picked from commit e4fe3610eb17c441217c80536f0acf4123abd683)
Change-Id: Ib2d284cefc3c0dce40ac2e516ba260d6cd04ce43
Reviewed-on: https://gerrit.libreoffice.org/8621
Reviewed-by: Andras Timar <andras.timar at collabora.com>
Tested-by: Andras Timar <andras.timar at collabora.com>
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/data/dprect-anchor.rtf b/sw/qa/extras/rtfimport/data/dprect-anchor.rtf
new file mode 100644
index 0000000..ac5675e
--- /dev/null
+++ b/sw/qa/extras/rtfimport/data/dprect-anchor.rtf
@@ -0,0 +1,4 @@
+{\rtf1
+{\colortbl\red255\green255\blue255; \red0\green0\blue0; }
+{\*\do\dobxpage\dobypara\dodhgt8192\dprect\dproundr\dpx9807\dpy3968\dpxsize1644\dpysize566\dplinecor255\dplinecog255\dplinecob255\dpfillbgcr0\dpfillbgcg0\dpfillbgcb0\dpfillpat1\dplinehollow0}
+}
diff --git a/sw/qa/extras/rtfimport/data/dptxbx-relation.rtf b/sw/qa/extras/rtfimport/data/dptxbx-relation.rtf
new file mode 100644
index 0000000..82f0741
--- /dev/null
+++ b/sw/qa/extras/rtfimport/data/dptxbx-relation.rtf
@@ -0,0 +1,5 @@
+{\rtf1
+{\*\do\dobxpage\dobypara\dodhgt8192\dptxbx\dptxbxmar0
+{\dptxbxtext\ltrpar\f4\fs20\cf1\vertalc\qc\ltrch To:\par}
+\dpx941\dpy2114\dpxsize1349\dpysize221\dplinehollow0}
+}
diff --git a/sw/qa/extras/rtfimport/rtfimport.cxx b/sw/qa/extras/rtfimport/rtfimport.cxx
index a8d8fd7..8d24829 100644
--- a/sw/qa/extras/rtfimport/rtfimport.cxx
+++ b/sw/qa/extras/rtfimport/rtfimport.cxx
@@ -1007,6 +1007,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);
@@ -1576,6 +1593,18 @@ DECLARE_RTFIMPORT_TEST(testFdo69289, "fdo69289.rtf")
CPPUNIT_ASSERT_EQUAL(sal_Int32(2), getProperty< uno::Sequence<text::TableColumnSeparator> >(xTableRows->getByIndex(0), "TableColumnSeparators").getLength());
}
+DECLARE_RTFIMPORT_TEST(testDptxbxRelation, "dptxbx-relation.rtf")
+{
+ // This was FRAME, not PAGE_FRAME, even if dobxpage is in the document.
+ CPPUNIT_ASSERT_EQUAL(text::RelOrientation::PAGE_FRAME, getProperty<sal_Int16>(getShape(1), "HoriOrientRelation"));
+}
+
+DECLARE_RTFIMPORT_TEST(testDprectAnchor, "dprect-anchor.rtf")
+{
+ // This was at-page, which is not something Word supports, so clearly an import error.
+ CPPUNIT_ASSERT_EQUAL(text::TextContentAnchorType_AT_CHARACTER, getProperty<text::TextContentAnchorType>(getShape(1), "AnchorType"));
+}
+
CPPUNIT_PLUGIN_IMPLEMENT();
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/writerfilter/source/dmapper/GraphicHelpers.cxx b/writerfilter/source/dmapper/GraphicHelpers.cxx
index d2e64d2..98afc62 100644
--- a/writerfilter/source/dmapper/GraphicHelpers.cxx
+++ b/writerfilter/source/dmapper/GraphicHelpers.cxx
@@ -268,14 +268,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 e3e4be6..e977404 100644
--- a/writerfilter/source/dmapper/GraphicHelpers.hxx
+++ b/writerfilter/source/dmapper/GraphicHelpers.hxx
@@ -74,7 +74,7 @@ class WRITERFILTER_DLLPRIVATE 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 87071f0..54b6927 100644
--- a/writerfilter/source/rtftok/rtfdocumentimpl.cxx
+++ b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
@@ -19,6 +19,7 @@
#include <com/sun/star/text/VertOrientation.hpp>
#include <com/sun/star/text/RelOrientation.hpp>
#include <com/sun/star/text/WrapTextMode.hpp>
+#include <com/sun/star/text/TextContentAnchorType.hpp>
#include <rtl/tencinfo.h>
#include <svl/lngmisc.hxx>
#include <unotools/ucbstreamhelper.hxx>
@@ -2184,6 +2185,17 @@ int RTFDocumentImpl::dispatchSymbol(RTFKeyword nKeyword)
return 0;
}
+// Checks if rName is contained at least once in rProperties as a key.
+bool lcl_findPropertyName(const std::vector<beans::PropertyValue>& rProperties, const OUString& rName)
+{
+ for (std::vector<beans::PropertyValue>::const_iterator it = rProperties.begin(); it != rProperties.end(); ++it)
+ {
+ if (it->Name == rName)
+ return true;
+ }
+ return false;
+}
+
int RTFDocumentImpl::dispatchFlag(RTFKeyword nKeyword)
{
setNeedSect();
@@ -2798,7 +2810,10 @@ int RTFDocumentImpl::dispatchFlag(RTFKeyword nKeyword)
m_aStates.top().aDrawingObject.xShape.set(getModelFactory()->createInstance("com.sun.star.text.TextFrame"), uno::UNO_QUERY);
std::vector<beans::PropertyValue> aDefaults = m_pSdrImport->getTextFrameDefaults(false);
for (size_t i = 0; i < aDefaults.size(); ++i)
- m_aStates.top().aDrawingObject.aPendingProperties.push_back(aDefaults[i]);
+ {
+ if (!lcl_findPropertyName(m_aStates.top().aDrawingObject.aPendingProperties, aDefaults[i].Name))
+ m_aStates.top().aDrawingObject.aPendingProperties.push_back(aDefaults[i]);
+ }
checkFirstRun();
Mapper().startShape(m_aStates.top().aDrawingObject.xShape);
m_aStates.top().aDrawingObject.bHadShapeText = true;
@@ -2825,7 +2840,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:
@@ -4467,6 +4482,9 @@ int RTFDocumentImpl::popState()
uno::Reference<lang::XServiceInfo> xServiceInfo(xShape, uno::UNO_QUERY);
bool bTextFrame = xServiceInfo->supportsService("com.sun.star.text.TextFrame");
+ // The default is certainly not inline, but then what Word supports is just at-character.
+ xPropertySet->setPropertyValue("AnchorType", uno::makeAny(text::TextContentAnchorType_AT_CHARACTER));
+
if (bTextFrame)
{
xPropertySet->setPropertyValue("HoriOrientPosition", uno::makeAny((sal_Int32)rDrawing.nLeft));
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.
More information about the Libreoffice-commits
mailing list