[PATCH libreoffice-4-0] fdo#60722 RTF filter: shape import fixes

Miklos Vajna (via Code Review) gerrit at gerrit.libreoffice.org
Wed Mar 6 08:31:24 PST 2013


Hi,

I have submitted a patch for review:

    https://gerrit.libreoffice.org/2569

To pull it, you can do:

    git pull ssh://gerrit.libreoffice.org:29418/core refs/changes/69/2569/1

fdo#60722 RTF filter: shape import fixes

- fix line color default
- fix line width default
- fix z-order of shapes

(cherry picked from commits 9c7dbd9e1d2a131402a80e377630fe1ab5381a47,
cf2a1277acd4a29492f056a626b13e903d391027,
1eaab77c718ffa254068ae6032862dfb5a03db67 and
ea66024d4da38a619f44c941b65e6a28b74214b9)

Change-Id: Ib6097c844b2bc929c6ece31bcec62f27bfbf386c
---
A sw/qa/extras/rtfimport/data/fdo60722.rtf
M sw/qa/extras/rtfimport/rtfimport.cxx
M writerfilter/source/dmapper/GraphicHelpers.cxx
M writerfilter/source/rtftok/rtfdocumentimpl.cxx
M writerfilter/source/rtftok/rtfdocumentimpl.hxx
M writerfilter/source/rtftok/rtfsdrimport.cxx
6 files changed, 57 insertions(+), 12 deletions(-)



diff --git a/sw/qa/extras/rtfimport/data/fdo60722.rtf b/sw/qa/extras/rtfimport/data/fdo60722.rtf
new file mode 100644
index 0000000..498df01
--- /dev/null
+++ b/sw/qa/extras/rtfimport/data/fdo60722.rtf
@@ -0,0 +1,13 @@
+{\rtf1\ansi\deff0
+{\fonttbl
+{\f0\fnil\fcharset204\fprq0\cpg1251 Arial;}
+{\f1\fnil\fcharset204\fprq0\cpg1251 Times New Roman;}
+{\f2\fnil\fcharset204\fprq0\cpg1251 Courier New;}
+}
+{\*\viewkind1}{\*\viewscale100}\margl0\margr0\margt0\margb0
+\paperw11905\paperh16837
+{\shp{\*\shpinst\shpleft10480\shptop840\shpright11320\shpbottom840\shpfhdr0\shpbxpage\shpbypage\shpwr3\shpwrk0\shpfblwtxt1\shpz0{\sp{\sn shapeType}{\sv 20}}}}
+{\shp{\*\shpinst\shpleft8900\shptop11940\shpright10360\shpbottom12320\shpfhdr0\shpbxpage\shpbypage\shpwr3\shpwrk0\shpfblwtxt1\shpz0{\sp{\sn shapeType}{\sv 1}}{\sp{\sn fFilled}{\sv 0}}{\sp{\sn wzDescription}{\sv smaller}}}}
+{\shp{\*\shpinst\shpleft7920\shptop11040\shpright11320\shpbottom13440\shpfhdr0\shpbxpage\shpbypage\shpwr3\shpwrk0\shpfblwtxt1\shpz0{\sp{\sn shapeType}{\sv 1}}{\sp{\sn fFilled}{\sv 0}}{\sp{\sn wzDescription}{\sv larger}}}}
+{\par\plain\par
+}}
diff --git a/sw/qa/extras/rtfimport/rtfimport.cxx b/sw/qa/extras/rtfimport/rtfimport.cxx
index b55aad9..3d3cbe6 100644
--- a/sw/qa/extras/rtfimport/rtfimport.cxx
+++ b/sw/qa/extras/rtfimport/rtfimport.cxx
@@ -140,6 +140,7 @@
     void testFdo58646line();
     void testFdo59953();
     void testFdo59638();
+    void testFdo60722();
 
     CPPUNIT_TEST_SUITE(Test);
 #if !defined(MACOSX) && !defined(WNT)
@@ -230,6 +231,7 @@
         {"fdo58646line.rtf", &Test::testFdo58646line},
         {"fdo59953.rtf", &Test::testFdo59953},
         {"fdo59638.rtf", &Test::testFdo59638},
+        {"fdo60722.rtf", &Test::testFdo60722},
     };
     for (unsigned int i = 0; i < SAL_N_ELEMENTS(aMethods); ++i)
     {
@@ -1110,6 +1112,25 @@
     CPPUNIT_FAIL("no BulletChar property");
 }
 
+void Test::testFdo60722()
+{
+    // The problem was that the larger shape was over the smaller one, and not the other way around.
+    uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(mxComponent, uno::UNO_QUERY);
+    uno::Reference<container::XIndexAccess> xDraws(xDrawPageSupplier->getDrawPage(), uno::UNO_QUERY);
+    uno::Reference<beans::XPropertySet> xShape(xDraws->getByIndex(0), uno::UNO_QUERY);
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(0), getProperty<sal_Int32>(xShape, "ZOrder"));
+    CPPUNIT_ASSERT_EQUAL(OUString("larger"), getProperty<OUString>(xShape, "Description"));
+
+    xShape.set(xDraws->getByIndex(1), uno::UNO_QUERY);
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(1), getProperty<sal_Int32>(xShape, "ZOrder"));
+    CPPUNIT_ASSERT_EQUAL(OUString("smaller"), getProperty<OUString>(xShape, "Description"));
+
+    // Color of the line was blue, and it had zero width.
+    xShape.set(xDraws->getByIndex(2), uno::UNO_QUERY);
+    CPPUNIT_ASSERT_EQUAL(sal_uInt32(26), getProperty<sal_uInt32>(xShape, "LineWidth"));
+    CPPUNIT_ASSERT_EQUAL(sal_uInt32(0), getProperty<sal_uInt32>(xShape, "LineColor"));
+}
+
 CPPUNIT_TEST_SUITE_REGISTRATION(Test);
 
 CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/writerfilter/source/dmapper/GraphicHelpers.cxx b/writerfilter/source/dmapper/GraphicHelpers.cxx
index 4d190e5..4564f3a 100644
--- a/writerfilter/source/dmapper/GraphicHelpers.cxx
+++ b/writerfilter/source/dmapper/GraphicHelpers.cxx
@@ -251,7 +251,8 @@
     while( it != items.end())
     {
         // std::map is iterated sorted by key
-        if( it->first > relativeHeight )
+        // if there is an item that has the same z-order, we belong under it
+        if( it->first >= relativeHeight )
             break; // this is the first one higher, we belong right before it
         else
             ++it;
diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.cxx b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
index c35b0d9..401ebb7 100644
--- a/writerfilter/source/rtftok/rtfdocumentimpl.cxx
+++ b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
@@ -3186,6 +3186,9 @@
         case RTF_SHPBOTTOM:
             m_aStates.top().aShape.nBottom = TWIP_TO_MM100(nParam);
             break;
+        case RTF_SHPZ:
+            m_aStates.top().aShape.oZ.reset(nParam);
+            break;
         case RTF_FFTYPE:
             switch (nParam)
             {
diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.hxx b/writerfilter/source/rtftok/rtfdocumentimpl.hxx
index c7affd7..5ced019 100644
--- a/writerfilter/source/rtftok/rtfdocumentimpl.hxx
+++ b/writerfilter/source/rtftok/rtfdocumentimpl.hxx
@@ -31,6 +31,7 @@
 
 #include <stack>
 #include <queue>
+#include <boost/optional.hpp>
 
 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
 #include <com/sun/star/beans/XPropertySet.hpp>
@@ -259,6 +260,7 @@
                 sal_Int32 nTop;
                 sal_Int32 nRight;
                 sal_Int32 nBottom;
+                boost::optional<sal_Int32> oZ; ///< Z-Order of the shape.
                 sal_Int16 nHoriOrientRelation;
                 sal_Int16 nVertOrientRelation;
                 int nWrap;
diff --git a/writerfilter/source/rtftok/rtfsdrimport.cxx b/writerfilter/source/rtftok/rtfsdrimport.cxx
index 641fa973..864a8bd 100644
--- a/writerfilter/source/rtftok/rtfsdrimport.cxx
+++ b/writerfilter/source/rtftok/rtfsdrimport.cxx
@@ -100,6 +100,10 @@
     beans::PropertyValue aPropertyValue;
     awt::Rectangle aViewBox;
     std::vector<beans::PropertyValue> aPathPropVec;
+    // Default line color is black in Word, blue in Writer.
+    uno::Any aLineColor = uno::makeAny(COL_BLACK);
+    // Default line width is 0.75 pt (26 mm100) in Word, 0 in Writer.
+    uno::Any aLineWidth = uno::makeAny(sal_Int32(26));
 
     for (std::vector< std::pair<rtl::OUString, rtl::OUString> >::iterator i = rShape.aProperties.begin();
             i != rShape.aProperties.end(); ++i)
@@ -138,11 +142,8 @@
         }
         else if ( i->first == "fillBackColor" )
             ; // Ignore: complementer of fillColor
-        else if (i->first == "lineColor" && xPropertySet.is())
-        {
-            aAny <<= msfilter::util::BGRToRGB(i->second.toInt32());
-            xPropertySet->setPropertyValue("LineColor", aAny);
-        }
+        else if (i->first == "lineColor")
+            aLineColor <<= msfilter::util::BGRToRGB(i->second.toInt32());
         else if ( i->first == "lineBackColor" )
             ; // Ignore: complementer of lineColor
         else if (i->first == "txflTextFlow" && xPropertySet.is())
@@ -166,12 +167,8 @@
             aAny <<= i->second.toInt32()*100/65536;
             xPropertySet->setPropertyValue("RotateAngle", aAny);
         }
-        else if (i->first == "lineWidth" && xPropertySet.is())
-        {
-
-            aAny <<= i->second.toInt32()/360;
-            xPropertySet->setPropertyValue("LineWidth", aAny);
-        }
+        else if (i->first == "lineWidth")
+            aLineWidth <<= i->second.toInt32()/360;
         else if ( i->first == "pVerticies" )
         {
             uno::Sequence<drawing::EnhancedCustomShapeParameterPair> aCoordinates;
@@ -297,6 +294,14 @@
                     OUStringToOString( i->second, RTL_TEXTENCODING_UTF8 ).getStr() << "'");
     }
 
+    if (xPropertySet.is())
+    {
+        xPropertySet->setPropertyValue("LineColor", aLineColor);
+        xPropertySet->setPropertyValue("LineWidth", aLineWidth);
+        if (rShape.oZ)
+            resolveDhgt(xPropertySet, *rShape.oZ);
+    }
+
     if (nType == ESCHER_ShpInst_PictureFrame) // picture frame
     {
         if (bPib)

-- 
To view, visit https://gerrit.libreoffice.org/2569
To unsubscribe, visit https://gerrit.libreoffice.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib6097c844b2bc929c6ece31bcec62f27bfbf386c
Gerrit-PatchSet: 1
Gerrit-Project: core
Gerrit-Branch: libreoffice-4-0
Gerrit-Owner: Miklos Vajna <vmiklos at suse.cz>



More information about the LibreOffice mailing list