summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2025-05-14 08:35:56 +0200
committerCaolán McNamara <caolan.mcnamara@collabora.com>2025-05-14 10:55:46 +0200
commit4d24374bf686d7637148355f6d9a9165469f062d (patch)
tree5aeec1a02298abfdfa32c8c0c3ad3c7eef686b68
parentfb3aee8468a7bf34cfb7900c8392111988dfff52 (diff)
tdf#166319 sw interdependent redlines: fix DOCX export of delete under format cp-25.04.2-1
The bugdoc has <del>AA<format>BB</format>CC</del> in it, DOCX import works fine, but exporting back to DOCX results in a document Word can't open. It seems that the problem is: this is a "format on top of a delete" redline, so we kept writing <w:t> for the format redline content, while Word considers "format on top of a delete" essentially a type of delete, so it requires <w:delText> instead. Fix the problem by extending DocxAttributeOutput::RunText() to consider both "delete" and "delete, then something on top of it" as a delete redline, that results in the correct markup. Keep our own DOCX import unchanged to still accept both <w:t> and <w:delText> for text inside a delete redline. Change-Id: Id64fcad322bc58dc0ef3e453445f83248d6f3cff Reviewed-on: https://gerrit.libreoffice.org/c/core/+/185293 Tested-by: Caolán McNamara <caolan.mcnamara@collabora.com> Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com> Reviewed-by: Caolán McNamara <caolan.mcnamara@collabora.com>
-rw-r--r--sw/qa/extras/ooxmlexport/data/del-then-format.docxbin0 -> 14457 bytes
-rw-r--r--sw/qa/extras/ooxmlexport/ooxmlexport22.cxx14
-rw-r--r--sw/source/filter/ww8/docxattributeoutput.cxx32
3 files changed, 45 insertions, 1 deletions
diff --git a/sw/qa/extras/ooxmlexport/data/del-then-format.docx b/sw/qa/extras/ooxmlexport/data/del-then-format.docx
new file mode 100644
index 000000000000..866201f7fb18
--- /dev/null
+++ b/sw/qa/extras/ooxmlexport/data/del-then-format.docx
Binary files differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport22.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport22.cxx
index 2d77c7155ed5..01f0220cd676 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport22.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport22.cxx
@@ -199,6 +199,20 @@ CPPUNIT_TEST_FIXTURE(Test, testBadFormulaResult)
assertXPathContent(pXmlDoc, "/w:document/w:body/w:tbl/w:tr[4]/w:tc/w:p/w:r[4]/w:t", u"6");
}
+CPPUNIT_TEST_FIXTURE(Test, testDelThenFormatDocxExport)
+{
+ // Given a document with <del>A<format>B</format>C</del> style redlines:
+ // When exporting that document:
+ loadAndSave("del-then-format.docx");
+
+ // Then make sure delete "under" format uses the <w:delText> markup:
+ // Without the accompanying fix in place, this test would have failed with:
+ // - In <>, XPath '/w:document/w:body/w:p/w:del[2]/w:r/w:delText' not found
+ // i.e. <w:t> was used, not <w:delText>.
+ xmlDocUniquePtr pXmlDoc = parseExport(u"word/document.xml"_ustr);
+ assertXPathContent(pXmlDoc, "/w:document/w:body/w:p/w:del[2]/w:r/w:delText", u"BBB");
+}
+
DECLARE_OOXMLEXPORT_TEST(testTdf139418, "tdf139418.docx")
{
uno::Reference<beans::XPropertySet> xPropertySet(
diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx b/sw/source/filter/ww8/docxattributeoutput.cxx
index 3498494aac8a..702f2d7f8b26 100644
--- a/sw/source/filter/ww8/docxattributeoutput.cxx
+++ b/sw/source/filter/ww8/docxattributeoutput.cxx
@@ -3852,6 +3852,36 @@ static bool impl_WriteRunText( FSHelperPtr const & pSerializer, sal_Int32 nTextT
return true;
}
+namespace
+{
+/// Decides if pRedlineData is a delete or is something on a delete.
+RedlineType GetRedlineTypeForTextToken(const SwRedlineData* pRedlineData)
+{
+ if (!pRedlineData)
+ {
+ return RedlineType::None;
+ }
+
+ if (pRedlineData->GetType() == RedlineType::Delete)
+ {
+ return RedlineType::Delete;
+ }
+
+ const SwRedlineData* pNext = pRedlineData->Next();
+ if (!pNext)
+ {
+ return RedlineType::None;
+ }
+
+ if (pNext->GetType() == RedlineType::Delete)
+ {
+ return RedlineType::Delete;
+ }
+
+ return RedlineType::None;
+}
+}
+
void DocxAttributeOutput::RunText( const OUString& rText, rtl_TextEncoding /*eCharSet*/, const OUString& rSymbolFont )
{
if( m_closeHyperlinkInThisRun )
@@ -3888,7 +3918,7 @@ void DocxAttributeOutput::RunText( const OUString& rText, rtl_TextEncoding /*eCh
// tdf#150166 save tracked moving around TOC as w:ins, w:del
SwDoc::GetCurTOX(*m_rExport.m_pCurPam->GetPoint()) == nullptr;
- if ( m_pRedlineData && m_pRedlineData->GetType() == RedlineType::Delete && !bMoved )
+ if (GetRedlineTypeForTextToken(m_pRedlineData) == RedlineType::Delete && !bMoved)
{
nTextToken = XML_delText;
}