sw/qa/writerfilter/dmapper/DomainMapper.cxx                  |   24 +++++++++++
 sw/qa/writerfilter/dmapper/data/table-style-para-border.docx |binary
 sw/source/writerfilter/dmapper/DomainMapper.cxx              |    9 ++++
 3 files changed, 33 insertions(+)

New commits:
commit 39c54c0ef837e0e23a676a4d1fa5da667e18939c
Author:     Miklos Vajna <vmik...@collabora.com>
AuthorDate: Fri Jun 7 09:14:21 2024 +0200
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Fri Jun 7 10:20:05 2024 +0200

    tdf#161443 DOCX import, table style: fix para border leaking into cell 
border
    
    Open the document with a single table, notice that start of the text in
    A1 cell is missing.
    
    Seems what happens is that the cell has some positive border distance,
    then the para has the same negative left margin, so in total there is 0
    left margin for the text, which makes this readable in Word. On our
    side, we map the paragraph border from the table style to the
    LeftBorderDistance property, then throw this on the cell object, which
    gives us 0 border distance, so the negative para left margin results in
    an unwanted shift of text towards the left: the start of the text is
    hidden by clipping to make sure the painted text is inside the cell
    frame. (Both paragraphs and cells have a LeftBorderDistance property, by
    accident.)
    
    Given that a visible paragraph border from table style is not actually
    imported, first just do the minimal fix and make sure we don't import
    paragraph borders from table style at all: this solves the problem of
    unwanted 0 cell border distances and the full text is now readable.
    
    In case the paragraph border in the table style would be actually
    visible, that would be useful to route to the paragraphs in the cell,
    that's not yet done here.
    
    Change-Id: I79907a2487c48659effcc55253b9d9881550284d
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/168516
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>
    Tested-by: Jenkins

diff --git a/sw/qa/writerfilter/dmapper/DomainMapper.cxx 
b/sw/qa/writerfilter/dmapper/DomainMapper.cxx
index 5c6b429bc9f6..851ab20412e8 100644
--- a/sw/qa/writerfilter/dmapper/DomainMapper.cxx
+++ b/sw/qa/writerfilter/dmapper/DomainMapper.cxx
@@ -13,6 +13,7 @@
 #include <com/sun/star/beans/XPropertySet.hpp>
 #include <com/sun/star/beans/PropertyValues.hpp>
 #include <com/sun/star/drawing/XDrawPageSupplier.hpp>
+#include <com/sun/star/text/XTextTable.hpp>
 
 #include <tools/UnitConversion.hxx>
 
@@ -161,6 +162,29 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf158360)
     // just test that doc with annotation in TOC doesn't crash/assert
     loadFromFile(u"tdf158360.docx");
 }
+
+CPPUNIT_TEST_FIXTURE(Test, testTableStyleParaBorder)
+{
+    // Given a document with a table, table style defines 115 twips left cell 
margin and an empty
+    // paragraph border:
+    // When importing that file:
+    loadFromFile(u"table-style-para-border.docx");
+
+    // Then make sure the cell margin is not lost:
+    uno::Reference<text::XTextDocument> xTextDocument(mxComponent, 
uno::UNO_QUERY);
+    uno::Reference<container::XEnumerationAccess> 
xParaEnumAccess(xTextDocument->getText(),
+                                                                  
uno::UNO_QUERY);
+    uno::Reference<container::XEnumeration> xParaEnum = 
xParaEnumAccess->createEnumeration();
+    uno::Reference<text::XTextTable> xPara(xParaEnum->nextElement(), 
uno::UNO_QUERY);
+    uno::Reference<beans::XPropertySet> xCell(xPara->getCellByName("A1"), 
uno::UNO_QUERY);
+    sal_Int32 nLeftBorderDistance{};
+    xCell->getPropertyValue("LeftBorderDistance") >>= nLeftBorderDistance;
+    // Without the accompanying fix in place, this test would have failed with:
+    // - Expected: 203
+    // - Actual  : 0
+    // i.e. the 0 para border distance was applied on the cell instead.
+    CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(203), nLeftBorderDistance);
+}
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/qa/writerfilter/dmapper/data/table-style-para-border.docx 
b/sw/qa/writerfilter/dmapper/data/table-style-para-border.docx
new file mode 100644
index 000000000000..0d7154eade1f
Binary files /dev/null and 
b/sw/qa/writerfilter/dmapper/data/table-style-para-border.docx differ
diff --git a/sw/source/writerfilter/dmapper/DomainMapper.cxx 
b/sw/source/writerfilter/dmapper/DomainMapper.cxx
index 72f88fc2a1a3..30c5f02fb693 100644
--- a/sw/source/writerfilter/dmapper/DomainMapper.cxx
+++ b/sw/source/writerfilter/dmapper/DomainMapper.cxx
@@ -1654,6 +1654,15 @@ void DomainMapper::sprmWithProps( Sprm& rSprm, const 
PropertyMapPtr& rContext )
             PropertyIds eBorderId = PropertyIds::INVALID;
             PropertyIds eBorderComplexColorId = PropertyIds::INVALID;
             PropertyIds eBorderDistId = PropertyIds::INVALID;
+
+            const StyleSheetEntryPtr& pEntry = 
GetStyleSheetTable()->GetCurrentEntry();
+            if (pEntry && pEntry->m_nStyleTypeCode == STYLE_TYPE_TABLE)
+            {
+                // This would map para borders in table style to cell borders, 
avoid that till we
+                // have separate property names for these.
+                break;
+            }
+
             switch( nSprmId )
             {
             case NS_ooxml::LN_CT_PBdr_top:

Reply via email to