diff options
author | Michael Stahl <Michael.Stahl@cib.de> | 2020-01-15 16:17:57 +0100 |
---|---|---|
committer | Thorsten Behrens <Thorsten.Behrens@CIB.de> | 2020-01-15 23:51:51 +0100 |
commit | 23ae7824ccd2df8fad6ee42ba66d2bc9a50843ff (patch) | |
tree | 14194ff2db269f8f93ea6d2d774840fc27832825 /sw | |
parent | bdd17d4dd5c51d563c5f866e69c47e458b3851b6 (diff) |
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.stahl@cib.de>
(cherry picked from commit 05d833a26208404e5f2b3d61298a57c9bcc7c1fe)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/86872
Reviewed-by: Thorsten Behrens <Thorsten.Behrens@CIB.de>
Diffstat (limited to 'sw')
-rw-r--r-- | sw/qa/extras/rtfexport/data/mw00_table_of_contents_templates.doc | bin | 0 -> 24064 bytes | |||
-rw-r--r-- | sw/qa/extras/rtfexport/rtfexport4.cxx | 14 | ||||
-rw-r--r-- | sw/source/filter/ww8/ww8atr.cxx | 8 |
3 files changed, 22 insertions, 0 deletions
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 Binary files differnew file mode 100644 index 000000000000..f0f80543bf4b --- /dev/null +++ b/sw/qa/extras/rtfexport/data/mw00_table_of_contents_templates.doc diff --git a/sw/qa/extras/rtfexport/rtfexport4.cxx b/sw/qa/extras/rtfexport/rtfexport4.cxx index 4590b7fa0b4e..92b672c88504 100644 --- a/sw/qa/extras/rtfexport/rtfexport4.cxx +++ b/sw/qa/extras/rtfexport/rtfexport4.cxx @@ -10,6 +10,7 @@ #include <swmodeltestbase.hxx> #include <com/sun/star/text/WritingMode2.hpp> +#include <com/sun/star/text/XDocumentIndex.hpp> #include <com/sun/star/style/ParagraphAdjust.hpp> #include <svx/swframetypes.hxx> @@ -165,6 +166,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 dd9bcf6d02ef..9719ba6ae2ff 100644 --- a/sw/source/filter/ww8/ww8atr.cxx +++ b/sw/source/filter/ww8/ww8atr.cxx @@ -2498,8 +2498,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); + } } } |