[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-4.1' - 3 commits - sw/qa writerfilter/source

Miklos Vajna vmiklos at collabora.co.uk
Mon Mar 17 04:36:00 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 c2c7a9837cf0cf2c46d06f5c62bf5379d37f2782
Author: Miklos Vajna <vmiklos at 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.
    
    (cherry picked from commit e4fe3610eb17c441217c80536f0acf4123abd683)
    
    Conflicts:
    	sw/qa/extras/rtfimport/rtfimport.cxx
    	writerfilter/source/rtftok/rtfsdrimport.cxx
    	writerfilter/source/rtftok/rtfsdrimport.hxx
    
    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 d36fcc7..f33a47d 100644
--- a/sw/qa/extras/rtfimport/rtfimport.cxx
+++ b/sw/qa/extras/rtfimport/rtfimport.cxx
@@ -1576,8 +1576,6 @@ DECLARE_RTFIMPORT_TEST(testCharColor, "char-color.rtf")
     CPPUNIT_ASSERT_EQUAL(sal_Int32(0x365F91), getProperty<sal_Int32>(getParagraph(1), "CharColor"));
 }
 
-#endif
-
 DECLARE_RTFIMPORT_TEST(testDptxbxRelation, "dptxbx-relation.rtf")
 {
     // This was FRAME, not PAGE_FRAME, even if dobxpage is in the document.
@@ -1590,6 +1588,25 @@ DECLARE_RTFIMPORT_TEST(testDprectAnchor, "dprect-anchor.rtf")
     CPPUNIT_ASSERT_EQUAL(text::TextContentAnchorType_AT_CHARACTER, getProperty<text::TextContentAnchorType>(getShape(1), "AnchorType"));
 }
 
+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());
+}
+
+#endif
+
 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 9a259b9..ec3b9c6 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 03a933e..4589a4a 100644
--- a/writerfilter/source/rtftok/rtfdocumentimpl.cxx
+++ b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
@@ -2629,7 +2629,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 765ea71..c23c00b 100644
--- a/writerfilter/source/rtftok/rtfsdrimport.cxx
+++ b/writerfilter/source/rtftok/rtfsdrimport.cxx
@@ -102,11 +102,11 @@ std::vector<beans::PropertyValue> RTFSdrImport::getTextFrameDefaults(bool bNew)
     return aRet;
 }
 
-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 = (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);
 }
 
@@ -418,7 +418,7 @@ void RTFSdrImport::resolve(RTFShape& rShape, bool bClose)
             aViewBox.Height = i->second.toInt32();
         else if ( i->first == "dhgt" )
         {
-            resolveDhgt(xPropertySet, i->second.toInt32());
+            resolveDhgt(xPropertySet, i->second.toInt32(), /*bOldStyle=*/false);
             // dhgt is Word 2007, \shpz is Word 97-2003, the previous has priority.
             rShape.oZ.reset();
         }
@@ -512,7 +512,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 f177e44..a778362 100644
--- a/writerfilter/source/rtftok/rtfsdrimport.hxx
+++ b/writerfilter/source/rtftok/rtfsdrimport.hxx
@@ -24,7 +24,7 @@ namespace writerfilter {
                 void resolve(RTFShape& rShape, bool bClose);
                 void close();
                 void append(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.
commit 1a60cdca29d532e80a5eee7e32a99fdc237315ec
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Fri Mar 14 15:51:25 2014 +0100

    RTF import: anchor drawing objects at-character by default
    
    Change-Id: I292ab1a6f12a9372b1cfdd4e8e59fbae57c6ceca
    (cherry picked from commit d05b67a7b9448c67c3a923ecb33dac74b52dd192)

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/rtfimport.cxx b/sw/qa/extras/rtfimport/rtfimport.cxx
index 091cf86..d36fcc7 100644
--- a/sw/qa/extras/rtfimport/rtfimport.cxx
+++ b/sw/qa/extras/rtfimport/rtfimport.cxx
@@ -1584,6 +1584,12 @@ DECLARE_RTFIMPORT_TEST(testDptxbxRelation, "dptxbx-relation.rtf")
     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/rtftok/rtfdocumentimpl.cxx b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
index d7bbf5d..03a933e 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>
@@ -4187,6 +4188,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));
commit d885c8cfc365a8e1c14f2cbb744758b4d13bd31b
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Fri Mar 14 12:11:13 2014 +0100

    RTF import: 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.
    
    Change-Id: I108f3363a2758eee0242533fe92e511e8c522b68
    (cherry picked from commit 7c53577f325e5260c538f9ca42cda54ca1a24b7a)

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 828ddcc..091cf86 100644
--- a/sw/qa/extras/rtfimport/rtfimport.cxx
+++ b/sw/qa/extras/rtfimport/rtfimport.cxx
@@ -1578,6 +1578,12 @@ DECLARE_RTFIMPORT_TEST(testCharColor, "char-color.rtf")
 
 #endif
 
+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"));
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.cxx b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
index 86ab26d..d7bbf5d 100644
--- a/writerfilter/source/rtftok/rtfdocumentimpl.cxx
+++ b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
@@ -1987,6 +1987,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)
 {
     checkUnicode();
@@ -2587,7 +2598,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;


More information about the Libreoffice-commits mailing list