sw/qa/extras/htmlexport/data/table_cell_padding.fodt | 34 +++++++++++++++++++ sw/qa/extras/htmlexport/htmlexport.cxx | 32 +++++++++++++++++ sw/source/filter/html/htmltab.cxx | 27 +++++++++++++-- 3 files changed, 91 insertions(+), 2 deletions(-)
New commits: commit 97a6e3f22185b26745dbe27949a9b283937f98da Author: Mike Kaganski <mike.kagan...@collabora.com> AuthorDate: Mon Aug 7 09:22:00 2023 +0300 Commit: Mike Kaganski <mike.kagan...@collabora.com> CommitDate: Mon Aug 7 09:50:04 2023 +0200 tdf#156647: restore the explicitly set properties after applying defaults Since commit 63c91b9cb3f73b66a915875721b0efd65b8aebac (sw HTML import: apply default table autoformat on cells in reqif mode, 2018-08-08), defaults are applied to imported-from-ReqIF tables. This resets the padding correctly imported from the markup. This change saves the previous box item, and restores the non-default line and distance settings from it after the defaults application. Change-Id: Ibcd8868875905fa93ab2e0443b2a8900ce1441a4 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/155410 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com> diff --git a/sw/qa/extras/htmlexport/data/table_cell_padding.fodt b/sw/qa/extras/htmlexport/data/table_cell_padding.fodt new file mode 100644 index 000000000000..059a37b9dab7 --- /dev/null +++ b/sw/qa/extras/htmlexport/data/table_cell_padding.fodt @@ -0,0 +1,34 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<office:document xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" office:version="1.3" office:mimetype="application/vnd.oasis.opendocument.text"> + <office:automatic-styles> + <style:style style:name="TableCell" style:family="table-cell"> + <style:table-cell-properties fo:padding="1.27cm" fo:border="none"/> + </style:style> + </office:automatic-styles> + <office:body> + <office:text> + <table:table table:name="Table1"> + <table:table-column/> + <table:table-column/> + <table:table-row> + <table:table-cell table:style-name="TableCell" office:value-type="string"> + <text:p>A</text:p> + </table:table-cell> + <table:table-cell table:style-name="TableCell" office:value-type="string"> + <text:p>B</text:p> + </table:table-cell> + </table:table-row> + <table:table-row> + <table:table-cell table:style-name="TableCell" office:value-type="string"> + <text:p>C</text:p> + </table:table-cell> + <table:table-cell table:style-name="TableCell" office:value-type="string"> + <text:p>D</text:p> + </table:table-cell> + </table:table-row> + </table:table> + <text:p/> + </office:text> + </office:body> +</office:document> diff --git a/sw/qa/extras/htmlexport/htmlexport.cxx b/sw/qa/extras/htmlexport/htmlexport.cxx index becda28a832a..9cd104f77292 100644 --- a/sw/qa/extras/htmlexport/htmlexport.cxx +++ b/sw/qa/extras/htmlexport/htmlexport.cxx @@ -18,6 +18,7 @@ #include <com/sun/star/io/XSeekable.hpp> #include <com/sun/star/style/ParagraphAdjust.hpp> #include <com/sun/star/awt/FontUnderline.hpp> +#include <com/sun/star/table/TableBorder2.hpp> #include <com/sun/star/text/XTextTablesSupplier.hpp> #include <com/sun/star/text/XTextTable.hpp> #include <com/sun/star/text/XTextEmbeddedObjectsSupplier.hpp> @@ -2714,6 +2715,37 @@ CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testReqIF_Tdf156602) assertXPathContent(pDoc, "/reqif-xhtml:html/reqif-xhtml:div/reqif-xhtml:p", "Following text"); } +CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testTdf156647_CellPaddingRoundtrip) +{ + // Given a document with a table with cell padding: + createSwDoc("table_cell_padding.fodt"); + { + auto xTable = getParagraphOrTable(1); + auto aTableBorder = getProperty<css::table::TableBorder2>(xTable, "TableBorder2"); + CPPUNIT_ASSERT_EQUAL(sal_Int16(1270), aTableBorder.Distance); + CPPUNIT_ASSERT(aTableBorder.IsDistanceValid); + } + // When exporting to reqif-xhtml: + ExportToReqif(); + // Make sure that we export it: + xmlDocUniquePtr pXmlDoc = WrapReqifFromTempFile(); + assertXPath(pXmlDoc, "//reqif-xhtml:table", "cellpadding", "48"); // px + // Now import it + mxComponent->dispose(); + ImportFromReqif(maTempFile.GetURL()); + // Then make sure that padding is not lost: + { + auto xTable = getParagraphOrTable(1); + auto aTableBorder = getProperty<css::table::TableBorder2>(xTable, "TableBorder2"); + // Without the accompanying fix in place, this test would have failed: + // - Expected: 1270 + // - Actual : 97 + // as the padding was lost, and the default 55 twip padding was used. + CPPUNIT_ASSERT_EQUAL(sal_Int16(1270), aTableBorder.Distance); + CPPUNIT_ASSERT(aTableBorder.IsDistanceValid); + } +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/filter/html/htmltab.cxx b/sw/source/filter/html/htmltab.cxx index 861152083455..e1e50865f624 100644 --- a/sw/source/filter/html/htmltab.cxx +++ b/sw/source/filter/html/htmltab.cxx @@ -1486,11 +1486,34 @@ void HTMLTable::FixFrameFormat( SwTableBox *pBox, if (pTableFormat) { sal_uInt8 nPos = SwTableAutoFormat::CountPos(nCol, m_nCols, nRow, m_nRows); + const SfxItemSet& rAttrSet = pFrameFormat->GetAttrSet(); + std::unique_ptr<SvxBoxItem> pOldBoxItem; + if (const SvxBoxItem* pBoxItem2 = rAttrSet.GetItemIfSet(RES_BOX)) + pOldBoxItem.reset(pBoxItem2->Clone()); pTableFormat->UpdateToSet(nPos, m_nRows==1, m_nCols==1, - const_cast<SfxItemSet&>(static_cast<SfxItemSet const&>( - pFrameFormat->GetAttrSet())), + const_cast<SfxItemSet&>(rAttrSet), SwTableAutoFormatUpdateFlags::Box, pFrameFormat->GetDoc()->GetNumberFormatter()); + if (pOldBoxItem) + { + // There was an old item, so it's guaranteed that there's a new item + const SvxBoxItem* pBoxItem2(rAttrSet.GetItem(RES_BOX)); + if (*pBoxItem2 != *pOldBoxItem) + { + std::unique_ptr<SvxBoxItem> pNewBoxItem(pBoxItem2->Clone()); + // Restore the box elements that could have been already set + for (auto eLine : { SvxBoxItemLine::TOP, SvxBoxItemLine::BOTTOM, + SvxBoxItemLine::LEFT, SvxBoxItemLine::RIGHT }) + { + if (auto pLine = pOldBoxItem->GetLine(eLine)) + pNewBoxItem->SetLine(pLine, eLine); + if (auto nDistance = pOldBoxItem->GetDistance(eLine, true)) + pNewBoxItem->SetDistance(nDistance, eLine); + } + + pFrameFormat->SetFormatAttr(*pNewBoxItem); + } + } } } }