sw/inc/node.hxx | 2 ++ sw/qa/extras/htmlexport/htmlexport.cxx | 8 +++++++- sw/source/core/docnode/ndtbl.cxx | 26 ++++++++++++++++++++++++++ sw/source/core/docnode/node.cxx | 8 +------- sw/source/filter/html/css1atr.cxx | 21 +++++++++++++++++++-- 5 files changed, 55 insertions(+), 10 deletions(-)
New commits: commit 04cc6e079e3122c183054fde046c054ed6c7b737 Author: Miklos Vajna <vmik...@collabora.com> AuthorDate: Fri Jun 10 09:12:33 2022 +0200 Commit: Miklos Vajna <vmik...@collabora.com> CommitDate: Fri Jun 10 14:28:11 2022 +0200 sw XHTML export: avoid writing default transparent background for ReqIF We started writing properties of tables and rows since commit c3c3303516c3da9372dce3f05f38f15a104e961c (sw XHTML export: output table / table row background format using CSS, 2022-05-10). In case the SwTableLine has an explicit SvxBrushItem with its color set to COL_TRANSPARENT, we turn that into a "background: transparent" CSS by default. This is a 1:1 mapping from the doc model, but HTML defaults to this already, so this is considered as noise. Extend IgnorePropertyForReqIF() to filter out these unwanted defaults, and fix SwHTMLWriter::OutCSS1_Property(), because it used to not pass the CSS value for the filter function. The behavior for table cells is unchanged, we continue to not export cell properties (in the ReqIF case) at all. Change-Id: Idbcd07809e159def694f4de017eebc7ad4104575 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/135576 Tested-by: Jenkins Reviewed-by: Miklos Vajna <vmik...@collabora.com> diff --git a/sw/qa/extras/htmlexport/htmlexport.cxx b/sw/qa/extras/htmlexport/htmlexport.cxx index 6ca8c80699ea..bc0af92e93c0 100644 --- a/sw/qa/extras/htmlexport/htmlexport.cxx +++ b/sw/qa/extras/htmlexport/htmlexport.cxx @@ -2266,10 +2266,14 @@ CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testTableBackground) pWrtShell->SetTabBackground(aBrush); pWrtShell->Down(/*bSelect=*/false); pWrtShell->SplitNode(); - pWrtShell->InsertTable(aInsertTableOptions, /*nRows=*/1, /*nCols=*/1); + pWrtShell->InsertTable(aInsertTableOptions, /*nRows=*/2, /*nCols=*/1); pWrtShell->MoveTable(GotoPrevTable, fnTableStart); aBrush.SetColor(0x00ff00); pWrtShell->SetRowBackground(aBrush); + pWrtShell->Down(/*bSelect=*/false); + // Second row has an explicit transparent background. + aBrush.SetColor(COL_TRANSPARENT); + pWrtShell->SetRowBackground(aBrush); // When exporting to reqif-xhtml: ExportToReqif(); @@ -2286,6 +2290,8 @@ CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testTableBackground) assertXPath(pXmlDoc, "//reqif-xhtml:table[2]/reqif-xhtml:tr[1]", "style", "background: #00ff00"); assertXPathNoAttribute(pXmlDoc, "//reqif-xhtml:table[2]/reqif-xhtml:tr[1]", "bgcolor"); + // Second row has no explicit style, the default is not written. + assertXPathNoAttribute(pXmlDoc, "//reqif-xhtml:table[2]/reqif-xhtml:tr[2]", "style"); } CPPUNIT_TEST_FIXTURE(HtmlExportTest, testImageKeepRatio) diff --git a/sw/source/filter/html/css1atr.cxx b/sw/source/filter/html/css1atr.cxx index 9619002314af..bc2449b865cc 100644 --- a/sw/source/filter/html/css1atr.cxx +++ b/sw/source/filter/html/css1atr.cxx @@ -185,9 +185,21 @@ OString lclConvToHex(sal_uInt16 nHex) bool IgnorePropertyForReqIF(bool bReqIF, std::string_view rProperty, std::string_view rValue, std::optional<sw::Css1Background> oMode) { - if (!bReqIF || (oMode.has_value() && *oMode != sw::Css1Background::TableCell)) + if (!bReqIF) return false; + if (oMode.has_value() && *oMode != sw::Css1Background::TableCell) + { + // Table or row. + if (rProperty == sCSS1_P_background && rValue == "transparent") + { + // This is the default already. + return true; + } + + return false; + } + // Only allow these two keys, nothing else in ReqIF mode. if (rProperty == sCSS1_P_text_decoration) { @@ -244,7 +256,12 @@ void SwHTMLWriter::OutCSS1_Property( const char *pProp, const OUString *pSVal, std::optional<sw::Css1Background> oMode ) { - if (IgnorePropertyForReqIF(mbReqIF, pProp, sVal, oMode)) + OString aPropertyValue(sVal); + if (aPropertyValue.isEmpty() && pSVal) + { + aPropertyValue = pSVal->toUtf8(); + } + if (IgnorePropertyForReqIF(mbReqIF, pProp, aPropertyValue, oMode)) return; OStringBuffer sOut; commit af3c766cb5ddb1959fb659e3c316e42f832d8de3 Author: Miklos Vajna <vmik...@collabora.com> AuthorDate: Fri Jun 10 09:11:55 2022 +0200 Commit: Miklos Vajna <vmik...@collabora.com> CommitDate: Fri Jun 10 14:27:55 2022 +0200 sw doc model xml dump: show table row properties Also extract SwTableNode::dumpAsXml() from SwStartNode::dumpAsXml(), ideally dumpAsXml() should only dump own members, not members of other classes. Change-Id: I5ef3e90d0cdd23ba44c192de1802844acad64cc4 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/135575 Tested-by: Jenkins Reviewed-by: Miklos Vajna <vmik...@collabora.com> diff --git a/sw/inc/node.hxx b/sw/inc/node.hxx index 4706e090290e..cf9ebc80bee7 100644 --- a/sw/inc/node.hxx +++ b/sw/inc/node.hxx @@ -524,6 +524,8 @@ public: // Removes redline objects that relate to this table from the 'Extra Redlines' table void RemoveRedlines(); + void dumpAsXml(xmlTextWriterPtr pWriter) const override; + private: SwTableNode( const SwTableNode & rNode ) = delete; SwTableNode & operator= ( const SwTableNode & rNode ) = delete; diff --git a/sw/source/core/docnode/ndtbl.cxx b/sw/source/core/docnode/ndtbl.cxx index 1c1fc32d16a3..38f8034d0681 100644 --- a/sw/source/core/docnode/ndtbl.cxx +++ b/sw/source/core/docnode/ndtbl.cxx @@ -17,6 +17,8 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ +#include <libxml/xmlwriter.h> + #include <config_wasm_strip.h> #include <memory> @@ -2499,6 +2501,30 @@ void SwTableNode::RemoveRedlines() rDoc.getIDocumentRedlineAccess().GetExtraRedlineTable().DeleteAllTableRedlines(rDoc, rTable, true, RedlineType::Any); } +void SwTableNode::dumpAsXml(xmlTextWriterPtr pWriter) const +{ + (void)xmlTextWriterStartElement(pWriter, BAD_CAST("SwTableNode")); + (void)xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST("ptr"), "%p", this); + (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("index"), BAD_CAST(OString::number(sal_Int32(GetIndex())).getStr())); + + if (m_pTable) + { + (void)xmlTextWriterStartElement(pWriter, BAD_CAST("SwTable")); + (void)xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST("ptr"), "%p", m_pTable.get()); + m_pTable->GetFrameFormat()->dumpAsXml(pWriter); + for (const auto& pLine : m_pTable->GetTabLines()) + { + (void)xmlTextWriterStartElement(pWriter, BAD_CAST("SwTableLine")); + (void)xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST("ptr"), "%p", pLine); + pLine->GetFrameFormat()->dumpAsXml(pWriter); + (void)xmlTextWriterEndElement(pWriter); + } + (void)xmlTextWriterEndElement(pWriter); + } + + // (void)xmlTextWriterEndElement(pWriter); - it is a start node, so don't end, will make xml better nested +} + void SwDoc::GetTabCols( SwTabCols &rFill, const SwCellFrame* pBoxFrame ) { OSL_ENSURE( pBoxFrame, "pBoxFrame needs to be specified!" ); diff --git a/sw/source/core/docnode/node.cxx b/sw/source/core/docnode/node.cxx index df2ffc3b4095..444e6dda6613 100644 --- a/sw/source/core/docnode/node.cxx +++ b/sw/source/core/docnode/node.cxx @@ -1022,13 +1022,7 @@ void SwStartNode::dumpAsXml(xmlTextWriterPtr pWriter) const (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("type"), BAD_CAST(OString::number(static_cast<sal_uInt8>(GetNodeType())).getStr())); (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("index"), BAD_CAST(OString::number(sal_Int32(GetIndex())).getStr())); - if (IsTableNode()) - { - (void)xmlTextWriterStartElement(pWriter, BAD_CAST("attrset")); - GetTableNode()->GetTable().GetFrameFormat()->GetAttrSet().dumpAsXml(pWriter); - (void)xmlTextWriterEndElement(pWriter); - } - else if (GetStartNodeType() == SwTableBoxStartNode) + if (GetStartNodeType() == SwTableBoxStartNode) { if (SwTableBox* pBox = GetTableBox()) (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("rowspan"), BAD_CAST(OString::number(pBox->getRowSpan()).getStr()));