sw/qa/extras/ooxmlexport/ooxmlexport.cxx                 |   14 +++++++++++++-
 sw/source/filter/ww8/docxattributeoutput.cxx             |    8 ++++++--
 writerfilter/source/dmapper/DomainMapperTableHandler.cxx |    4 ++--
 3 files changed, 21 insertions(+), 5 deletions(-)

New commits:
commit 7fb8b73ad320e32af130ceddec80a9ff08407eab
Author:     Miklos Vajna <vmik...@collabora.com>
AuthorDate: Wed Feb 15 08:28:27 2023 +0100
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Wed Feb 15 08:28:30 2023 +0000

    DOCX filter: fix horizontal pos of floattables with compat mode >= 15
    
    The floating table in the bugdoc has a small negative horizontal indent,
    which carefully aligns it so that the contained paragraph lines up with
    the text above the table.
    
    It turns out that compatibilityMode >= 15 doesn't do this anymore in
    Word, so we should at least avoid this tweak on import/export when we
    know the compat mode.
    
    Fix the problem by avoiding the <w:tblpPr w:tblpX="..."> decrease during
    import and the matching increase on export. This is similar to what
    commit 9a31d1c83e08600507689dc18f6f0973bc7e4389 (tdf#106742: OOXML
    import/export: treat "tblInd" properly., 2017-04-04) did for
    non-floating tables.
    
    I discovered this while working on multi-page sw floattables, but this
    is relevant for single-page sw floattables as well. Next to the modified
    testcase, sw/qa/core/layout/data/floattable.docx is also a good test
    file, which shows how the left border now lines up with the body frame,
    and there used to be a noticeable gap there. Now
    sw/qa/core/layout/data/floattable.docx gets rendered ~perfectly (with
    SW_FORCE_FLY_SPLIT=1).
    
    Change-Id: Ia52202f1bc3274f4ce2b7ee02c85d07589454ae9
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/147037
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>
    Tested-by: Jenkins

diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport.cxx 
b/sw/qa/extras/ooxmlexport/ooxmlexport.cxx
index 04b7c3c5fd45..101fe99027a9 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport.cxx
@@ -31,6 +31,7 @@
 #include <comphelper/sequenceashashmap.hxx>
 #include <comphelper/processfactory.hxx>
 #include <tools/UnitConversion.hxx>
+#include <frameformats.hxx>
 
 class Test : public SwModelTestBase
 {
@@ -1105,7 +1106,18 @@ DECLARE_OOXMLEXPORT_TEST(testTdf106953, "tdf106953.docx")
 
 CPPUNIT_TEST_FIXTURE(Test, testTdf115094v3)
 {
-    loadAndSave("tdf115094v3.docx");
+    createSwDoc("tdf115094v3.docx");
+    {
+        SwDoc* pDoc = getSwDoc();
+        SwFrameFormats& rSpzFormats = *pDoc->GetSpzFrameFormats();
+        SwFrameFormat* pFormat = rSpzFormats[0];
+        // Without the fix, this has failed with:
+        // - Expected: 1991
+        // - Actual  : 1883
+        // i.e. some unwanted ~-2mm left margin appeared.
+        CPPUNIT_ASSERT_EQUAL(static_cast<SwTwips>(1991), 
pFormat->GetHoriOrient().GetPos());
+    }
+    save(OUString::createFromAscii(mpFilter));
     // floating table is now exported directly without surrounding frame
     xmlDocUniquePtr pXmlDoc = parseExport("word/document.xml");
 
diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx 
b/sw/source/filter/ww8/docxattributeoutput.cxx
index e40d6c0b3db3..6d1c94868917 100644
--- a/sw/source/filter/ww8/docxattributeoutput.cxx
+++ b/sw/source/filter/ww8/docxattributeoutput.cxx
@@ -4769,8 +4769,12 @@ void DocxAttributeOutput::TableDefinition( 
ww8::WW8TableNodeInfoInner::Pointer_t
                     const SwTableBox * pTabBox = 
pTableTextNodeInfoInner->getTableBox();
                     const SwFrameFormat * pFrameFormat = 
pTabBox->GetFrameFormat();
                     const SvxBoxItem& rBox = pFrameFormat->GetBox( );
-                    sal_uInt16 nLeftDistance = 
rBox.GetDistance(SvxBoxItemLine::LEFT);
-                    nValue += nLeftDistance;
+                    sal_Int32 nMode = lcl_getWordCompatibilityMode(m_rExport);
+                    if (nMode < 15)
+                    {
+                        sal_uInt16 nLeftDistance = 
rBox.GetDistance(SvxBoxItemLine::LEFT);
+                        nValue += nLeftDistance;
+                    }
 
                     // 2nd: if a left border is given, revert the shift by 
half the width
                     // from lcl_DecrementHoriOrientPosition() in writerfilter
diff --git a/writerfilter/source/dmapper/DomainMapperTableHandler.cxx 
b/writerfilter/source/dmapper/DomainMapperTableHandler.cxx
index 58d96a9cd8f5..042cc142c71d 100644
--- a/writerfilter/source/dmapper/DomainMapperTableHandler.cxx
+++ b/writerfilter/source/dmapper/DomainMapperTableHandler.cxx
@@ -536,7 +536,8 @@ TableStyleSheetEntry * 
DomainMapperTableHandler::endTableGetTableStyle(TableInfo
 
         m_aTableProperties->Insert( PROP_TABLE_BORDER_DISTANCES, uno::Any( 
aDistances ) );
 
-        if (!rFrameProperties.empty())
+        sal_Int32 nMode = 
m_rDMapper_Impl.GetSettingsTable()->GetWordCompatibilityMode();
+        if (!rFrameProperties.empty() && nMode < 15)
             lcl_DecrementHoriOrientPosition(rFrameProperties, 
rInfo.nLeftBorderDistance);
 
         // Set table above/bottom spacing to 0.
@@ -613,7 +614,6 @@ TableStyleSheetEntry * 
DomainMapperTableHandler::endTableGetTableStyle(TableInfo
 
         // tdf#106742: since MS Word 2013 (compatibilityMode >= 15), top-level 
tables are handled the same as nested tables;
         // the default behavior when DOCX doesn't define "compatibilityMode" 
option is to add the cell spacing
-        sal_Int32 nMode = 
m_rDMapper_Impl.GetSettingsTable()->GetWordCompatibilityMode();
 
         if (0 < nMode && nMode <= 14 && rInfo.nNestLevel == 1)
         {

Reply via email to