summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@suse.cz>2013-08-29 14:17:09 +0200
committerMiklos Vajna <vmiklos@suse.cz>2013-09-03 17:04:24 +0200
commitfc01e55ded5b517307a28a9ac8c438ce9ea5f967 (patch)
tree4f77b7771075cbe4aff1fc2717b67fd1da91edaa
parentd74f44882336226990a290eaaf37f7b477c98777 (diff)
bnc#816593 DOCX filter: import paragraph spacing from table style
(cherry picked from commit 17e904ed66c3caf87e658b9d3a18d7b13f4a0b52) Change-Id: I9dce59ecd8a2d2bfadb8c7273cd46c6c0cf17774
-rwxr-xr-xsw/qa/extras/ooxmlimport/data/table-style-parprop.docxbin0 -> 10098 bytes
-rw-r--r--sw/qa/extras/ooxmlimport/ooxmlimport.cxx11
-rw-r--r--writerfilter/source/dmapper/DomainMapperTableHandler.cxx38
3 files changed, 49 insertions, 0 deletions
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 000000000000..1c68c704e7fb
--- /dev/null
+++ b/sw/qa/extras/ooxmlimport/data/table-style-parprop.docx
Binary files differ
diff --git a/sw/qa/extras/ooxmlimport/ooxmlimport.cxx b/sw/qa/extras/ooxmlimport/ooxmlimport.cxx
index bbdb706b4751..e85a2286b735 100644
--- a/sw/qa/extras/ooxmlimport/ooxmlimport.cxx
+++ b/sw/qa/extras/ooxmlimport/ooxmlimport.cxx
@@ -132,6 +132,7 @@ public:
void testBnc780044Spacing();
void testTableFloating();
void testTableAutoNested();
+ void testTableStyleParprop();
CPPUNIT_TEST_SUITE(Test);
#if !defined(MACOSX) && !defined(WNT)
@@ -213,6 +214,7 @@ void Test::run()
{"bnc780044_spacing.docx", &Test::testBnc780044Spacing},
{"table-floating.docx", &Test::testTableFloating},
{"table-auto-nested.docx", &Test::testTableAutoNested},
+ {"table-style-parprop.docx", &Test::testTableStyleParprop},
};
for (unsigned int i = 0; i < SAL_N_ELEMENTS(aMethods); ++i)
{
@@ -1338,6 +1340,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 6647408251ab..546ff2028d31 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>
@@ -720,6 +723,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
@@ -766,6 +785,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 )