sw/qa/extras/ooxmlexport/ooxmlexport10.cxx   |    4 ++++
 sw/qa/extras/ww8export/ww8export3.cxx        |   11 ++++++++++-
 sw/source/filter/ww8/docxattributeoutput.cxx |   10 ++++++++++
 sw/source/filter/ww8/wrtww8.cxx              |    5 +++++
 4 files changed, 29 insertions(+), 1 deletion(-)

New commits:
commit f629dc8dc8b9620508b5bd8e55ddb298438c447f
Author:     Justin Luth <justin_l...@sil.org>
AuthorDate: Wed Oct 6 07:38:44 2021 +0200
Commit:     Justin Luth <justin_l...@sil.org>
CommitDate: Thu Oct 7 07:21:17 2021 +0200

    tdf#143982 doc/x export: save automatic table as 100% relative
    
    Currently, the automatic mode is just being saved as
    "determine width from cell size" or absolute size.
    But a better match would be 100% of the available space,
    so that changing the page or margin size would automatically
    increase the table size (which is what automatic implies).
    
    It doesn't appear that MS formats really have a
    similar automatic. Their automatic just seems to
    say that the width isn't specified at the table level.
    So a percent-size seems to be the best match.
    
    RTF currently does not even round-trip relative tables,
    so I ignored that format.
    
    Change-Id: I5bfc066864ab630755046b881e98503491cfb1ee
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/123128
    Tested-by: Jenkins
    Reviewed-by: Justin Luth <justin_l...@sil.org>

diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport10.cxx 
b/sw/qa/extras/ooxmlexport/ooxmlexport10.cxx
index 31dba7b98385..b364d1314278 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport10.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport10.cxx
@@ -1214,6 +1214,10 @@ DECLARE_OOXMLEXPORT_TEST(testTableMarginAdjustment, 
"table.fodt")
 
     assertXPath(pXmlDoc, "//w:tbl[1]/w:tblPr[1]/w:tblInd[1]", "type", "dxa");
     assertXPath(pXmlDoc, "//w:tbl[1]/w:tblPr[1]/w:tblInd[1]", "w", "0");
+
+
+    // tdf#143982: automatic tables should export as something better than 
just left-and-size
+    CPPUNIT_ASSERT_EQUAL(sal_Int16(100), getProperty<sal_Int16>(xTable, 
"RelativeWidth"));
 }
 
 DECLARE_OOXMLEXPORT_TEST(testTdf119760_tableInTablePosition, 
"tdf119760_tableInTablePosition.docx")
diff --git a/sw/qa/extras/ww8export/ww8export3.cxx 
b/sw/qa/extras/ww8export/ww8export3.cxx
index a0df68658947..01ddaf60016e 100644
--- a/sw/qa/extras/ww8export/ww8export3.cxx
+++ b/sw/qa/extras/ww8export/ww8export3.cxx
@@ -268,11 +268,20 @@ DECLARE_WW8EXPORT_TEST(testdf79553_lineNumbers, 
"tdf79553_lineNumbers.doc")
     CPPUNIT_ASSERT_MESSAGE("automatic distance", nValue > 0);
 }
 
-DECLARE_WW8EXPORT_TEST(tesTdf138302_restartNumbering, 
"tdf138302_restartNumbering.odt")
+DECLARE_WW8EXPORT_TEST(testTdf138302_restartNumbering, 
"tdf138302_restartNumbering.odt")
 {
     CPPUNIT_ASSERT_EQUAL(1, getPages());
     uno::Reference<beans::XPropertySet> xPara(getParagraph(8), uno::UNO_QUERY);
     CPPUNIT_ASSERT_EQUAL(OUString("1."), getProperty<OUString>(xPara, 
"ListLabelString"));
+
+
+    // tdf#143982: automatic tables should export as something better than 
just left-and-size
+    uno::Reference<text::XTextTablesSupplier> xTextTablesSupplier(mxComponent, 
uno::UNO_QUERY);
+    uno::Reference<container::XIndexAccess> 
xTables(xTextTablesSupplier->getTextTables(), uno::UNO_QUERY);
+    uno::Reference<text::XTextTable> xTable(xTables->getByIndex(0), 
uno::UNO_QUERY);
+
+    CPPUNIT_ASSERT(getProperty<bool>(xTable, "IsWidthRelative"));
+    CPPUNIT_ASSERT_EQUAL(sal_Int16(100), getProperty<sal_Int16>(xTable, 
"RelativeWidth"));
 }
 
 DECLARE_WW8EXPORT_TEST(testTdf122429_header, "tdf122429_header.doc")
diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx 
b/sw/source/filter/ww8/docxattributeoutput.cxx
index 81180f5ec3f9..868196d654e0 100644
--- a/sw/source/filter/ww8/docxattributeoutput.cxx
+++ b/sw/source/filter/ww8/docxattributeoutput.cxx
@@ -3947,9 +3947,19 @@ void DocxAttributeOutput::TableDefinition( 
ww8::WW8TableNodeInfoInner::Pointer_t
         const SwFormatFrameSize &rFrameSize = 
pFloatingTableFrame->GetFrameFormat().GetFrameSize();
         nWidthPercent = rFrameSize.GetWidthPercent();
     }
+
     uno::Reference<beans::XPropertySet> 
xPropertySet(SwXTextTables::GetObject(*pTable->GetFrameFormat( 
)),uno::UNO_QUERY);
     bool isWidthRelative = false;
     xPropertySet->getPropertyValue("IsWidthRelative") >>= isWidthRelative;
+    if (!isWidthRelative && !nWidthPercent)
+    {
+        // The best fit for "automatic" table placement is relative 100%
+        short nHoriOrient = -1;
+        xPropertySet->getPropertyValue("HoriOrient") >>= nHoriOrient;
+        isWidthRelative = nHoriOrient == text::HoriOrientation::FULL;
+        if (isWidthRelative)
+            nWidthPercent = 100;
+    }
 
     if(isWidthRelative)
     {
diff --git a/sw/source/filter/ww8/wrtww8.cxx b/sw/source/filter/ww8/wrtww8.cxx
index 6c5a5a927eda..7db1fb50386e 100644
--- a/sw/source/filter/ww8/wrtww8.cxx
+++ b/sw/source/filter/ww8/wrtww8.cxx
@@ -2415,6 +2415,11 @@ void WW8AttributeOutput::TableDefinition( 
ww8::WW8TableNodeInfoInner::Pointer_t
     }
 
     int nWidthPercent = pFormat->GetFrameSize().GetWidthPercent();
+
+    // The best fit for "automatic" table placement is relative 100%
+    if (!nWidthPercent && rHori.GetHoriOrient() == text::HoriOrientation::FULL)
+        nWidthPercent = 100;
+
     // Width is in fiftieths of a percent. For sprmTTableWidth, must be 
non-negative and 600% max
     if ( nWidthPercent > 0 && nWidthPercent <= 600 )
     {

Reply via email to