[Libreoffice-commits] core.git: Branch 'libreoffice-4-1' - sw/qa writerfilter/source

Miklos Vajna vmiklos at suse.cz
Fri Sep 6 04:31:46 PDT 2013


 sw/qa/extras/ooxmlimport/data/table-style-parprop.docx   |binary
 sw/qa/extras/ooxmlimport/ooxmlimport.cxx                 |   11 ++++
 writerfilter/source/dmapper/DomainMapperTableHandler.cxx |   38 +++++++++++++++
 3 files changed, 49 insertions(+)

New commits:
commit 124b2e26797726851116646b478f056583213d5b
Author: Miklos Vajna <vmiklos at suse.cz>
Date:   Thu Aug 29 14:17:09 2013 +0200

    bnc#816593 DOCX filter: import paragraph spacing from table style
    
    (cherry picked from commit 17e904ed66c3caf87e658b9d3a18d7b13f4a0b52)
    
    Change-Id: I9dce59ecd8a2d2bfadb8c7273cd46c6c0cf17774
    Reviewed-on: https://gerrit.libreoffice.org/5786
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>
    Tested-by: Caolán McNamara <caolanm at redhat.com>

diff --git a/sw/qa/extras/ooxmlimport/data/table-style-parprop.docx b/sw/qa/extras/ooxmlimport/data/table-style-parprop.docx
new file mode 100755
index 0000000..1c68c70
Binary files /dev/null and b/sw/qa/extras/ooxmlimport/data/table-style-parprop.docx differ
diff --git a/sw/qa/extras/ooxmlimport/ooxmlimport.cxx b/sw/qa/extras/ooxmlimport/ooxmlimport.cxx
index 0c066df..090b5d8 100644
--- a/sw/qa/extras/ooxmlimport/ooxmlimport.cxx
+++ b/sw/qa/extras/ooxmlimport/ooxmlimport.cxx
@@ -129,6 +129,7 @@ public:
     void testTableAutoColumnFixedSize();
     void testTableFloating();
     void testTableAutoNested();
+    void testTableStyleParprop();
 
     CPPUNIT_TEST_SUITE(Test);
 #if !defined(MACOSX) && !defined(WNT)
@@ -223,6 +224,7 @@ void Test::run()
         {"table-auto-column-fixed-size.docx", &Test::testTableAutoColumnFixedSize},
         {"table-floating.docx", &Test::testTableFloating},
         {"table-auto-nested.docx", &Test::testTableAutoNested},
+        {"table-style-parprop.docx", &Test::testTableStyleParprop},
     };
     header();
     for (unsigned int i = 0; i < SAL_N_ELEMENTS(aMethods); ++i)
@@ -1583,6 +1585,15 @@ void Test::testTableAutoNested()
     CPPUNIT_ASSERT_EQUAL(sal_Int32(23051), getProperty<sal_Int32>(xTables->getByIndex(1), "Width"));
 }
 
+void Test::testTableStyleParprop()
+{
+    // The problem was that w:spacing's w:after=0 (a paragraph property) wasn't imported from table style.
+    uno::Reference<text::XTextTable> xTable(getParagraphOrTable(1), uno::UNO_QUERY);
+    uno::Reference<text::XTextRange> xCell(xTable->getCellByName("A1"), uno::UNO_QUERY);
+    // This was 353, the document default, i.e. paragraph property from table style had no effect.
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(0), getProperty<sal_Int32>(getParagraphOfText(1, xCell->getText()), "ParaBottomMargin"));
+}
+
 CPPUNIT_TEST_SUITE_REGISTRATION(Test);
 
 CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/writerfilter/source/dmapper/DomainMapperTableHandler.cxx b/writerfilter/source/dmapper/DomainMapperTableHandler.cxx
index 8cbf48c..d7d498a 100644
--- a/writerfilter/source/dmapper/DomainMapperTableHandler.cxx
+++ b/writerfilter/source/dmapper/DomainMapperTableHandler.cxx
@@ -19,9 +19,12 @@
 #include <DomainMapperTableHandler.hxx>
 #include <DomainMapper_Impl.hxx>
 #include <StyleSheetTable.hxx>
+#include <com/sun/star/beans/XPropertyState.hpp>
+#include <com/sun/star/container/XEnumerationAccess.hpp>
 #include <com/sun/star/table/TableBorderDistances.hpp>
 #include <com/sun/star/table/TableBorder.hpp>
 #include <com/sun/star/table/BorderLine2.hpp>
+#include <com/sun/star/table/XCellRange.hpp>
 #include <com/sun/star/text/HoriOrientation.hpp>
 #include <com/sun/star/text/RelOrientation.hpp>
 #include <com/sun/star/text/SizeType.hpp>
@@ -772,6 +775,22 @@ RowPropertyValuesSeq_t DomainMapperTableHandler::endTableGetRowProperties()
     return aRowProperties;
 }
 
+// Apply paragraph property to each paragraph within a cell.
+static void lcl_ApplyCellParaProps(uno::Reference<table::XCell> xCell, uno::Any aBottomMargin)
+{
+    uno::Reference<container::XEnumerationAccess> xEnumerationAccess(xCell, uno::UNO_QUERY);
+    uno::Reference<container::XEnumeration> xEnumeration = xEnumerationAccess->createEnumeration();
+    while (xEnumeration->hasMoreElements())
+    {
+        uno::Reference<beans::XPropertySet> xParagraph(xEnumeration->nextElement(), uno::UNO_QUERY);
+        uno::Reference<beans::XPropertyState> xPropertyState(xParagraph, uno::UNO_QUERY);
+        // Don't apply in case direct formatting is already present.
+        // TODO: probably paragraph style has priority over table style here.
+        if (xPropertyState.is() && xPropertyState->getPropertyState("ParaBottomMargin") == beans::PropertyState_DEFAULT_VALUE)
+            xParagraph->setPropertyValue("ParaBottomMargin", aBottomMargin);
+    }
+}
+
 void DomainMapperTableHandler::endTable(unsigned int nestedTableLevel)
 {
 #ifdef DEBUG_DMAPPER_TABLE_HANDLER
@@ -818,6 +837,25 @@ void DomainMapperTableHandler::endTable(unsigned int nestedTableLevel)
 
                 if (xTable.is())
                     m_xTableRange = xTable->getAnchor( );
+
+                // OOXML table style may container paragraph properties, apply these now.
+                for (int i = 0; i < aTableInfo.aTableProperties.getLength(); ++i)
+                {
+                    if (aTableInfo.aTableProperties[i].Name == "ParaBottomMargin")
+                    {
+                        uno::Reference<table::XCellRange> xCellRange(xTable, uno::UNO_QUERY);
+                        uno::Any aBottomMargin = aTableInfo.aTableProperties[i].Value;
+                        sal_Int32 nRows = aCellProperties.getLength();
+                        for (sal_Int32 nRow = 0; nRow < nRows; ++nRow)
+                        {
+                            const uno::Sequence< beans::PropertyValues > aCurrentRow = aCellProperties[nRow];
+                            sal_Int32 nCells = aCurrentRow.getLength();
+                            for (sal_Int32 nCell = 0; nCell < nCells; ++nCell)
+                                lcl_ApplyCellParaProps(xCellRange->getCellByPosition(nCell, nRow), aBottomMargin);
+                        }
+                        break;
+                    }
+                }
             }
         }
         catch ( const lang::IllegalArgumentException &e )


More information about the Libreoffice-commits mailing list