oox/source/export/shapes.cxx       |   14 ++++++++++++--
 sd/qa/unit/data/pptx/n90223RT.pptx |binary
 sd/qa/unit/export-tests-ooxml1.cxx |    8 ++++++++
 3 files changed, 20 insertions(+), 2 deletions(-)

New commits:
commit a2c58edd20f243697a0790d323816094e319b2a7
Author:     Justin Luth <justin.l...@collabora.com>
AuthorDate: Mon Mar 31 17:25:24 2025 -0400
Commit:     Justin Luth <jl...@mail.com>
CommitDate: Tue Apr 1 03:55:44 2025 +0200

    tdf#165995 pptx export: table cell margins weren't exported
    
    Although some left/right margins have been exported since
    5.0 commit 636c5a63d67b52b0d2f9f21a863c45eca6ac9ff7
    Author: yogesh.bharate001 on Thu Mar 26 10:48:15 2015 +0530
        tdf#90223:PPTX table cell left  and right margin is not exported.
    
    zero left/right margins weren't exported,
    and nothing was done for top/bottom border padding from table cells.
    (That's a bit weird, because I am using Yogesh's unit test to
     test for a round-tripped zero bottom border.
     It was the only existing unit test with non-default border spacing.)
    
    [The default (if not specified during import) L/R margins are 0.25cm
     (so definitely a zero margin needs to be exported and not ignored),
     and the import default for T/B margins is 0.127cm.
     However, none of that is documented of course.]
    
    make CppunitTest_sd_export_tests-ooxml1 \
        CPPUNIT_TEST_NAME=testCellLeftAndRightMargin
    
    Change-Id: I12a8a785ddb784cacd4abf10e8e19df7cd50ec64
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/183564
    Tested-by: Jenkins
    Reviewed-by: Justin Luth <jl...@mail.com>

diff --git a/oox/source/export/shapes.cxx b/oox/source/export/shapes.cxx
index f05e9212a952..d8c396382217 100644
--- a/oox/source/export/shapes.cxx
+++ b/oox/source/export/shapes.cxx
@@ -2468,6 +2468,8 @@ void ShapeExport::WriteTable( const Reference< XShape >& 
rXShape  )
 void ShapeExport::WriteTableCellProperties(const Reference< XPropertySet>& 
xCellPropSet)
 {
     sal_Int32 nLeftMargin(0), nRightMargin(0);
+    sal_Int32 nTopMargin(0);
+    sal_Int32 nBottomMargin(0);
     TextVerticalAdjust eVerticalAlignment;
     const char* sVerticalAlignment;
 
@@ -2477,6 +2479,12 @@ void ShapeExport::WriteTableCellProperties(const 
Reference< XPropertySet>& xCell
     Any aRightMargin = 
xCellPropSet->getPropertyValue(u"TextRightDistance"_ustr);
     aRightMargin >>= nRightMargin;
 
+    Any aTopMargin = xCellPropSet->getPropertyValue(u"TextUpperDistance"_ustr);
+    aTopMargin >>= nTopMargin;
+
+    Any aBottomMargin = 
xCellPropSet->getPropertyValue(u"TextLowerDistance"_ustr);
+    aBottomMargin >>= nBottomMargin;
+
     Any aVerticalAlignment = 
xCellPropSet->getPropertyValue(u"TextVerticalAdjust"_ustr);
     aVerticalAlignment >>= eVerticalAlignment;
     sVerticalAlignment = GetTextVerticalAdjust(eVerticalAlignment);
@@ -2502,8 +2510,10 @@ void ShapeExport::WriteTableCellProperties(const 
Reference< XPropertySet>& xCell
 
     mpFS->startElementNS(XML_a, XML_tcPr, XML_anchor, sVerticalAlignment,
     XML_vert, aTextVerticalValue,
-    XML_marL, 
sax_fastparser::UseIf(OString::number(oox::drawingml::convertHmmToEmu(nLeftMargin)),
 nLeftMargin > 0),
-    XML_marR, 
sax_fastparser::UseIf(OString::number(oox::drawingml::convertHmmToEmu(nRightMargin)),
 nRightMargin > 0));
+    XML_marL, OString::number(oox::drawingml::convertHmmToEmu(nLeftMargin)),
+    XML_marR, OString::number(oox::drawingml::convertHmmToEmu(nRightMargin)),
+    XML_marT, OString::number(oox::drawingml::convertHmmToEmu(nTopMargin)),
+    XML_marB, OString::number(oox::drawingml::convertHmmToEmu(nBottomMargin)));
 
     // Write background fill for table cell.
     // TODO
diff --git a/sd/qa/unit/data/pptx/n90223RT.pptx 
b/sd/qa/unit/data/pptx/n90223RT.pptx
new file mode 100644
index 000000000000..3d33ebdb9236
Binary files /dev/null and b/sd/qa/unit/data/pptx/n90223RT.pptx differ
diff --git a/sd/qa/unit/export-tests-ooxml1.cxx 
b/sd/qa/unit/export-tests-ooxml1.cxx
index 32aa1ac088a2..59d46c235375 100644
--- a/sd/qa/unit/export-tests-ooxml1.cxx
+++ b/sd/qa/unit/export-tests-ooxml1.cxx
@@ -1054,6 +1054,14 @@ CPPUNIT_TEST_FIXTURE(SdOOXMLExportTest1, 
testCellLeftAndRightMargin)
 
     CPPUNIT_ASSERT_EQUAL(sal_Int32(45720), nLeftMargin);
     CPPUNIT_ASSERT_EQUAL(sal_Int32(45720), nRightMargin);
+
+    // tdf#165995: also export top/bottom margins, including zero margins 
(since default is not 0)
+    xCell.set(xTable->getCellByPosition(1, 0), uno::UNO_QUERY_THROW); // B1 - 
the synerzip cell
+    xCellPropSet.set(xCell, uno::UNO_QUERY_THROW);
+    sal_Int32 nBottomMargin(-1);
+    xCellPropSet->getPropertyValue(u"TextLowerDistance"_ustr) >>= 
nBottomMargin;
+    // Without the accompanying patch, this was 127 (0.127 cm), not zero
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(0), nBottomMargin);
 }
 
 CPPUNIT_TEST_FIXTURE(SdOOXMLExportTest1, testMergedCells)

Reply via email to