From d1d23f01ed321b088c26217e9be367c0fe8121af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A1szl=C3=B3=20N=C3=A9meth?= Date: Wed, 27 Apr 2022 12:18:22 +0200 Subject: [PATCH] tdf#85610 sw: show tracked footnote insertion/deletion MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit also in the footnote area by formatting the footnote number there as the footnote index number in the main text (i.e. as anchor of the footnote). Previously deleted footnotes were shown as not deleted footnotes in Show Changes mode, also inserted footnotes lost their footnote number formatting (i.e. author color of the tracked change, and e.g. the default underline) after file saving. Note: for a working test, fix also MetafileXmlDump by removing the bad 0x01 from the XML dump, which resulted by the not expanded footnote index placeholder character. Change-Id: Ie003f4e19d2e2cee6f09d3b195db69fe5c10e405 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/133503 Tested-by: Jenkins Reviewed-by: László Németh --- sw/qa/extras/layout/data/tdf85610.fodt | 56 ++++++++++++++++++++++++++ sw/qa/extras/layout/layout2.cxx | 18 +++++++++ sw/source/core/text/txtftn.cxx | 37 +++++++++++++++++ vcl/source/gdi/mtfxmldump.cxx | 10 ++++- 4 files changed, 120 insertions(+), 1 deletion(-) create mode 100644 sw/qa/extras/layout/data/tdf85610.fodt diff --git a/sw/qa/extras/layout/data/tdf85610.fodt b/sw/qa/extras/layout/data/tdf85610.fodt new file mode 100644 index 000000000000..17c51096db12 --- /dev/null +++ b/sw/qa/extras/layout/data/tdf85610.fodt @@ -0,0 +1,56 @@ + + + + + + + + + + + + + + + + + + + + + + C + 2022-04-27T11:06:53 + + + + + + + C + 2022-04-27T11:07:06 + + + + + + + C + 2022-04-27T11:06:51 + + + + + + + + + + + Lorem.1 + Ipsum. + Dolor sit.2 + Amet. + + + diff --git a/sw/qa/extras/layout/layout2.cxx b/sw/qa/extras/layout/layout2.cxx index 6c059f0f57c4..02b40c21b5ef 100644 --- a/sw/qa/extras/layout/layout2.cxx +++ b/sw/qa/extras/layout/layout2.cxx @@ -302,6 +302,24 @@ CPPUNIT_TEST_FIXTURE(SwLayoutWriter2, testRedlineNumberInNumbering) assertXPath(pXmlDoc, "/metafile/push/push/push/font[4][@color='#000000']", 0); } +CPPUNIT_TEST_FIXTURE(SwLayoutWriter2, testRedlineNumberInFootnote) +{ + SwDoc* pDoc = createSwDoc(DATA_DIRECTORY, "tdf85610.fodt"); + SwDocShell* pShell = pDoc->GetDocShell(); + + // Dump the rendering of the first page as an XML file. + std::shared_ptr xMetaFile = pShell->GetPreviewMetaFile(); + MetafileXmlDump dumper; + + xmlDocUniquePtr pXmlDoc = dumpAndParse(dumper, *xMetaFile); + CPPUNIT_ASSERT(pXmlDoc); + + // changed color of numbers of footnote 1 (deleted footnote) and footnote 2 (inserted footnote) + // decreased the black elements by 2: + // This was 7 + assertXPath(pXmlDoc, "/metafile/push/push/push/font[@color='#000000']", 5); +} + CPPUNIT_TEST_FIXTURE(SwLayoutWriter2, testRedlineMoving) { SwDoc* pDoc = createSwDoc(DATA_DIRECTORY, "tdf42748.fodt"); diff --git a/sw/source/core/text/txtftn.cxx b/sw/source/core/text/txtftn.cxx index ce7756c23a45..64d0f0418286 100644 --- a/sw/source/core/text/txtftn.cxx +++ b/sw/source/core/text/txtftn.cxx @@ -53,6 +53,13 @@ #include #include #include +#include +#include +#include +#include +#include +#include +#include #include #include @@ -990,6 +997,36 @@ SwNumberPortion *SwTextFormatter::NewFootnoteNumPortion( SwTextFormatInfo const pNumFnt->SetDiffFnt(&rSet, pIDSA ); pNumFnt->SetVertical( pNumFnt->GetOrientation(), m_pFrame->IsVertical() ); + // tdf#85610 apply redline coloring to the footnote numbering in the footnote area + SwUnoInternalPaM aPam(*pDoc); + if ( ::sw::XTextRangeToSwPaM(aPam, xAnchor) ) + { + SwRedlineTable::size_type nRedlinePos = 0; + const SwRedlineTable& rTable = pDoc->getIDocumentRedlineAccess().GetRedlineTable(); + const SwRangeRedline* pRedline = rTable.FindAtPosition( *aPam.Start(), nRedlinePos ); + if (pRedline) + { + SwAttrPool& rPool = pDoc->GetAttrPool(); + SfxItemSetFixed aSet(rPool); + + std::size_t aAuthor = (1 < pRedline->GetStackCount()) + ? pRedline->GetAuthor( 1 ) + : pRedline->GetAuthor(); + + if ( RedlineType::Delete == pRedline->GetType() ) + SW_MOD()->GetDeletedAuthorAttr(aAuthor, aSet); + else + SW_MOD()->GetInsertAuthorAttr(aAuthor, aSet); + + if (const SvxColorItem* pItem = aSet.GetItemIfSet(RES_CHRATR_COLOR)) + pNumFnt->SetColor(pItem->GetValue()); + if (const SvxUnderlineItem* pItem = aSet.GetItemIfSet(RES_CHRATR_UNDERLINE)) + pNumFnt->SetUnderline(pItem->GetLineStyle()); + if (const SvxCrossedOutItem* pItem = aSet.GetItemIfSet(RES_CHRATR_CROSSEDOUT)) + pNumFnt->SetStrikeout( pItem->GetStrikeout() ); + } + } + SwFootnoteNumPortion* pNewPor = new SwFootnoteNumPortion( aFootnoteText, std::move(pNumFnt) ); pNewPor->SetLeft( !m_pFrame->IsRightToLeft() ); return pNewPor; diff --git a/vcl/source/gdi/mtfxmldump.cxx b/vcl/source/gdi/mtfxmldump.cxx index f6e2a0bda869..26e1afd7a6c4 100644 --- a/vcl/source/gdi/mtfxmldump.cxx +++ b/vcl/source/gdi/mtfxmldump.cxx @@ -823,7 +823,15 @@ void MetafileXmlDump::writeXml(const GDIMetaFile& rMetaFile, tools::XmlWriter& r } rWriter.startElement("text"); - rWriter.content(pMetaTextArrayAction->GetText()); + + const OUString& rStr = pMetaTextArrayAction->GetText(); + // fix bad XML dump by removing forbidden 0x01 + // FIXME: expand footnote anchor point 0x01 instead of this + if ( rStr.indexOf(0x01) > -1 ) + rWriter.content(rStr.replaceAll("\001", "")); + else + rWriter.content(rStr); + rWriter.endElement(); rWriter.endElement();