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

New commits:
commit c15531dd24101c78ec41345685cbda7c2a8eaef4
Author:     Miklos Vajna <vmik...@collabora.com>
AuthorDate: Fri Jun 7 09:14:21 2024 +0200
Commit:     Michael Stahl <michael.st...@allotropia.de>
CommitDate: Tue Jun 11 11:20:09 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.
    
    (cherry picked from commit 39c54c0ef837e0e23a676a4d1fa5da667e18939c)
    
    Change-Id: I79907a2487c48659effcc55253b9d9881550284d
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/168621
    Tested-by: Jenkins
    Reviewed-by: Michael Stahl <michael.st...@allotropia.de>

diff --git a/writerfilter/qa/cppunittests/dmapper/DomainMapper.cxx 
b/writerfilter/qa/cppunittests/dmapper/DomainMapper.cxx
index 885443c5a210..6029806e171d 100644
--- a/writerfilter/qa/cppunittests/dmapper/DomainMapper.cxx
+++ b/writerfilter/qa/cppunittests/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/writerfilter/qa/cppunittests/dmapper/data/table-style-para-border.docx 
b/writerfilter/qa/cppunittests/dmapper/data/table-style-para-border.docx
new file mode 100644
index 000000000000..0d7154eade1f
Binary files /dev/null and 
b/writerfilter/qa/cppunittests/dmapper/data/table-style-para-border.docx differ
diff --git a/writerfilter/source/dmapper/DomainMapper.cxx 
b/writerfilter/source/dmapper/DomainMapper.cxx
index 344a36cf9520..0c2cb13a3185 100644
--- a/writerfilter/source/dmapper/DomainMapper.cxx
+++ b/writerfilter/source/dmapper/DomainMapper.cxx
@@ -1608,6 +1608,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