sw/qa/extras/rtfexport/data/mw00_table_of_contents_templates.doc |binary sw/qa/extras/rtfexport/rtfexport4.cxx | 14 ++++++++++ sw/source/filter/ww8/ww8atr.cxx | 8 +++++ 3 files changed, 22 insertions(+)
New commits: commit 05d833a26208404e5f2b3d61298a57c9bcc7c1fe Author: Michael Stahl <michael.st...@cib.de> AuthorDate: Wed Jan 15 16:17:57 2020 +0100 Commit: Michael Stahl <michael.st...@cib.de> CommitDate: Wed Jan 15 18:35:15 2020 +0100 tdf#129574 sw: fix RTF export of table of contents The problem is that the hyperlink that starts at the start of the first paragraph of the ToX content is written to RTF before the TOC field itself, so the hyperlink contains the entire ToX: {{\field{\*\fldinst HYPERLINK "#__RefHeading___Toc250984071" }{\fldrslt {\rtlch\langfe1024 \ltrch\lang1024\loch {\field{\*\fldinst { TOC \\o "1-3" \\h \\z }}{\fldrslt {1.India\tab 1}}}} This is because the HYPERLINK is written into m_aRun but the TOC into m_aRunText. Interestingly StartRun() asserts that m_aRunText should be empty, so we don't try to change StartURL() to write the HYPERLINK into m_aRunText. The only function that moves text from m_aRunText to m_aRun is EndRun(), so wrap the TOC field in StartRun()/EndRun(). This breaks the export of the ToX to DOCX because a mysterious SDT is no longer written around the field but only the field result, so only do this for RTF. Change-Id: I22e45c4a9c9ce6edb2b9114b4a29b2a373ec3284 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/86860 Tested-by: Jenkins Reviewed-by: Michael Stahl <michael.st...@cib.de> diff --git a/sw/qa/extras/rtfexport/data/mw00_table_of_contents_templates.doc b/sw/qa/extras/rtfexport/data/mw00_table_of_contents_templates.doc new file mode 100644 index 000000000000..f0f80543bf4b Binary files /dev/null and b/sw/qa/extras/rtfexport/data/mw00_table_of_contents_templates.doc differ diff --git a/sw/qa/extras/rtfexport/rtfexport4.cxx b/sw/qa/extras/rtfexport/rtfexport4.cxx index bbf4c60f6ff2..4a95b6f4338a 100644 --- a/sw/qa/extras/rtfexport/rtfexport4.cxx +++ b/sw/qa/extras/rtfexport/rtfexport4.cxx @@ -11,6 +11,7 @@ #include <com/sun/star/table/ShadowFormat.hpp> #include <com/sun/star/text/WritingMode2.hpp> +#include <com/sun/star/text/XDocumentIndex.hpp> #include <com/sun/star/style/ParagraphAdjust.hpp> #include <o3tl/cppunittraitshelper.hxx> #include <svx/swframetypes.hxx> @@ -166,6 +167,19 @@ DECLARE_RTFEXPORT_TEST(testParaAdjustDistribute, "para-adjust-distribute.rtf") getProperty<sal_Int16>(getParagraph(2), "ParaLastLineAdjust"))); } +DECLARE_RTFEXPORT_TEST(testTdf129574, "mw00_table_of_contents_templates.doc") +{ + uno::Reference<text::XDocumentIndexesSupplier> xIndexSupplier(mxComponent, uno::UNO_QUERY); + uno::Reference<container::XIndexAccess> xIndexes(xIndexSupplier->getDocumentIndexes()); + uno::Reference<text::XDocumentIndex> xTOC(xIndexes->getByIndex(0), uno::UNO_QUERY); + CPPUNIT_ASSERT(xTOC.is()); + uno::Reference<text::XTextRange> xTextRange(xTOC->getAnchor()); + // table of contents contains 4 paragraphs + CPPUNIT_ASSERT_EQUAL(OUString("1.Koffice 1" SAL_NEWLINE_STRING "2.Kword 1" SAL_NEWLINE_STRING + "3.Kspread 1" SAL_NEWLINE_STRING "4.Kpresenter 1"), + xTextRange->getString()); +} + DECLARE_RTFEXPORT_TEST(testCjklist34, "cjklist34.rtf") { sal_Int16 numFormat = getNumberingTypeOfParagraph(1); diff --git a/sw/source/filter/ww8/ww8atr.cxx b/sw/source/filter/ww8/ww8atr.cxx index 41a2d9c5fb3e..9e8d815d7de2 100644 --- a/sw/source/filter/ww8/ww8atr.cxx +++ b/sw/source/filter/ww8/ww8atr.cxx @@ -2493,8 +2493,16 @@ void AttributeOutputBase::StartTOX( const SwSection& rSect ) if (!sStr.isEmpty()) { GetExport( ).m_bInWriteTOX = true; + if (GetExport().GetExportFormat() == MSWordExportBase::ExportFormat::RTF) + { // tdf#129574: required for RTF; doesn't work with DOCX + StartRun(nullptr, -42, true); + } GetExport( ).OutputField( nullptr, eCode, sStr, FieldFlags::Start | FieldFlags::CmdStart | FieldFlags::CmdEnd ); + if (GetExport().GetExportFormat() == MSWordExportBase::ExportFormat::RTF) + { + EndRun(nullptr, -42, true); + } } } _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits